OSDN Git Service

* doc/tm.texi (STACK_CHECK_PROTECT): Document alternate default.
[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, 2008, 2009
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 3, 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 COPYING3.  If not see
21 ;; <http://www.gnu.org/licenses/>.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;;
26 ;; REGNOS
27 ;;
28
29 (define_constants
30   [(MQ_REGNO                    64)
31    (LR_REGNO                    65)
32    (CTR_REGNO                   66)
33    (CR0_REGNO                   68)
34    (CR1_REGNO                   69)
35    (CR2_REGNO                   70)
36    (CR3_REGNO                   71)
37    (CR4_REGNO                   72)
38    (CR5_REGNO                   73)
39    (CR6_REGNO                   74)
40    (CR7_REGNO                   75)
41    (MAX_CR_REGNO                75)
42    (XER_REGNO                   76)
43    (FIRST_ALTIVEC_REGNO         77)
44    (LAST_ALTIVEC_REGNO          108)
45    (VRSAVE_REGNO                109)
46    (VSCR_REGNO                  110)
47    (SPE_ACC_REGNO               111)
48    (SPEFSCR_REGNO               112)
49    (SFP_REGNO                   113)
50   ])
51
52 ;;
53 ;; UNSPEC usage
54 ;;
55
56 (define_constants
57   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
58    (UNSPEC_PROBE_STACK          4)      ; probe stack memory reference
59    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
60    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
61    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
62    (UNSPEC_MOVSI_GOT            8)
63    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
64    (UNSPEC_FCTIWZ               10)
65    (UNSPEC_FRIM                 11)
66    (UNSPEC_FRIN                 12)
67    (UNSPEC_FRIP                 13)
68    (UNSPEC_FRIZ                 14)
69    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
70    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
71    (UNSPEC_TLSGD                17)
72    (UNSPEC_TLSLD                18)
73    (UNSPEC_MOVESI_FROM_CR       19)
74    (UNSPEC_MOVESI_TO_CR         20)
75    (UNSPEC_TLSDTPREL            21)
76    (UNSPEC_TLSDTPRELHA          22)
77    (UNSPEC_TLSDTPRELLO          23)
78    (UNSPEC_TLSGOTDTPREL         24)
79    (UNSPEC_TLSTPREL             25)
80    (UNSPEC_TLSTPRELHA           26)
81    (UNSPEC_TLSTPRELLO           27)
82    (UNSPEC_TLSGOTTPREL          28)
83    (UNSPEC_TLSTLS               29)
84    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
85    (UNSPEC_MV_CR_GT             31)     ; move_from_CR_gt_bit
86    (UNSPEC_STFIWX               32)
87    (UNSPEC_POPCNTB              33)
88    (UNSPEC_FRES                 34)
89    (UNSPEC_SP_SET               35)
90    (UNSPEC_SP_TEST              36)
91    (UNSPEC_SYNC                 37)
92    (UNSPEC_LWSYNC               38)
93    (UNSPEC_ISYNC                39)
94    (UNSPEC_SYNC_OP              40)
95    (UNSPEC_ATOMIC               41)
96    (UNSPEC_CMPXCHG              42)
97    (UNSPEC_XCHG                 43)
98    (UNSPEC_AND                  44)
99    (UNSPEC_DLMZB                45)
100    (UNSPEC_DLMZB_CR             46)
101    (UNSPEC_DLMZB_STRLEN         47)
102    (UNSPEC_RSQRT                48)
103    (UNSPEC_TOCREL               49)
104    (UNSPEC_MACHOPIC_OFFSET      50)
105    (UNSPEC_BPERM                51)
106   ])
107
108 ;;
109 ;; UNSPEC_VOLATILE usage
110 ;;
111
112 (define_constants
113   [(UNSPECV_BLOCK               0)
114    (UNSPECV_LL                  1)      ; load-locked
115    (UNSPECV_SC                  2)      ; store-conditional
116    (UNSPECV_EH_RR               9)      ; eh_reg_restore
117   ])
118 \f
119 ;; Define an insn type attribute.  This is used in function unit delay
120 ;; computations.
121 (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,isel"
122   (const_string "integer"))
123
124 ;; Define floating point instruction sub-types for use with Xfpu.md
125 (define_attr "fp_type" "fp_default,fp_addsub_s,fp_addsub_d,fp_mul_s,fp_mul_d,fp_div_s,fp_div_d,fp_maddsub_s,fp_maddsub_d,fp_sqrt_s,fp_sqrt_d" (const_string "fp_default"))
126
127 ;; Length (in bytes).
128 ; '(pc)' in the following doesn't include the instruction itself; it is
129 ; calculated as if the instruction had zero size.
130 (define_attr "length" ""
131   (if_then_else (eq_attr "type" "branch")
132                 (if_then_else (and (ge (minus (match_dup 0) (pc))
133                                        (const_int -32768))
134                                    (lt (minus (match_dup 0) (pc))
135                                        (const_int 32764)))
136                               (const_int 4)
137                               (const_int 8))
138                 (const_int 4)))
139
140 ;; Processor type -- this attribute must exactly match the processor_type
141 ;; enumeration in rs6000.h.
142
143 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc476,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,ppce300c2,ppce300c3,ppce500mc,ppce500mc64,power4,power5,power6,power7,cell,ppca2"
144   (const (symbol_ref "rs6000_cpu_attr")))
145
146
147 ;; If this instruction is microcoded on the CELL processor
148 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
149 (define_attr "cell_micro" "not,conditional,always"
150   (if_then_else (eq_attr "type" "compare,delayed_compare,imul_compare,lmul_compare,load_ext,load_ext_ux,var_shift_rotate,var_delayed_compare")
151                 (const_string "always")
152                 (const_string "not")))
153
154 (automata_option "ndfa")
155
156 (include "rios1.md")
157 (include "rios2.md")
158 (include "rs64.md")
159 (include "mpc.md")
160 (include "40x.md")
161 (include "440.md")
162 (include "476.md")
163 (include "603.md")
164 (include "6xx.md")
165 (include "7xx.md")
166 (include "7450.md")
167 (include "8540.md")
168 (include "e300c2c3.md")
169 (include "e500mc.md")
170 (include "e500mc64.md")
171 (include "power4.md")
172 (include "power5.md")
173 (include "power6.md")
174 (include "power7.md")
175 (include "cell.md")
176 (include "xfpu.md")
177 (include "a2.md")
178
179 (include "predicates.md")
180 (include "constraints.md")
181
182 (include "darwin.md")
183
184 \f
185 ;; Mode iterators
186
187 ; This mode iterator allows :GPR to be used to indicate the allowable size
188 ; of whole values in GPRs.
189 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
190
191 ; Any supported integer mode.
192 (define_mode_iterator INT [QI HI SI DI TI])
193
194 ; Any supported integer mode that fits in one register.
195 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
196
197 ; extend modes for DImode
198 (define_mode_iterator QHSI [QI HI SI])
199
200 ; SImode or DImode, even if DImode doesn't fit in GPRs.
201 (define_mode_iterator SDI [SI DI])
202
203 ; The size of a pointer.  Also, the size of the value that a record-condition
204 ; (one with a '.') will compare.
205 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
206
207 ; Any hardware-supported floating-point mode
208 (define_mode_iterator FP [
209   (SF "TARGET_HARD_FLOAT 
210    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) || TARGET_E500_SINGLE)")
211   (DF "TARGET_HARD_FLOAT 
212    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)")
213   (TF "!TARGET_IEEEQUAD
214    && TARGET_HARD_FLOAT
215    && (TARGET_FPRS || TARGET_E500_DOUBLE)
216    && TARGET_LONG_DOUBLE_128")
217   (DD "TARGET_DFP")
218   (TD "TARGET_DFP")])
219
220 ; Various instructions that come in SI and DI forms.
221 ; A generic w/d attribute, for things like cmpw/cmpd.
222 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
223
224 ; DImode bits
225 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
226
227 ;; ISEL/ISEL64 target selection
228 (define_mode_attr sel [(SI "") (DI "64")])
229
230 ;; Suffix for reload patterns
231 (define_mode_attr ptrsize [(SI "32bit")
232                            (DI "64bit")])
233
234 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
235                             (DI "TARGET_64BIT")])
236
237 (define_mode_attr mptrsize [(SI "si")
238                             (DI "di")])
239
240 \f
241 ;; Start with fixed-point load and store insns.  Here we put only the more
242 ;; complex forms.  Basic data transfer is done later.
243
244 (define_expand "zero_extend<mode>di2"
245   [(set (match_operand:DI 0 "gpc_reg_operand" "")
246         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
247   "TARGET_POWERPC64"
248   "")
249
250 (define_insn "*zero_extend<mode>di2_internal1"
251   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
252         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
253   "TARGET_POWERPC64"
254   "@
255    l<wd>z%U1%X1 %0,%1
256    rldicl %0,%1,0,<dbits>"
257   [(set_attr "type" "load,*")])
258
259 (define_insn "*zero_extend<mode>di2_internal2"
260   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
261         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
262                     (const_int 0)))
263    (clobber (match_scratch:DI 2 "=r,r"))]
264   "TARGET_64BIT"
265   "@
266    rldicl. %2,%1,0,<dbits>
267    #"
268   [(set_attr "type" "compare")
269    (set_attr "length" "4,8")])
270
271 (define_split
272   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
273         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
274                     (const_int 0)))
275    (clobber (match_scratch:DI 2 ""))]
276   "TARGET_POWERPC64 && reload_completed"
277   [(set (match_dup 2)
278         (zero_extend:DI (match_dup 1)))
279    (set (match_dup 0)
280         (compare:CC (match_dup 2)
281                     (const_int 0)))]
282   "")
283
284 (define_insn "*zero_extend<mode>di2_internal3"
285   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
286         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
287                     (const_int 0)))
288    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
289         (zero_extend:DI (match_dup 1)))]
290   "TARGET_64BIT"
291   "@
292    rldicl. %0,%1,0,<dbits>
293    #"
294   [(set_attr "type" "compare")
295    (set_attr "length" "4,8")])
296
297 (define_split
298   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
299         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
300                     (const_int 0)))
301    (set (match_operand:DI 0 "gpc_reg_operand" "")
302         (zero_extend:DI (match_dup 1)))]
303   "TARGET_POWERPC64 && reload_completed"
304   [(set (match_dup 0)
305         (zero_extend:DI (match_dup 1)))
306    (set (match_dup 2)
307         (compare:CC (match_dup 0)
308                     (const_int 0)))]
309   "")
310
311 (define_insn "extendqidi2"
312   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
313         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
314   "TARGET_POWERPC64"
315   "extsb %0,%1"
316   [(set_attr "type" "exts")])
317
318 (define_insn ""
319   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
320         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
321                     (const_int 0)))
322    (clobber (match_scratch:DI 2 "=r,r"))]
323   "TARGET_64BIT"
324   "@
325    extsb. %2,%1
326    #"
327   [(set_attr "type" "compare")
328    (set_attr "length" "4,8")])
329
330 (define_split
331   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
332         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
333                     (const_int 0)))
334    (clobber (match_scratch:DI 2 ""))]
335   "TARGET_POWERPC64 && reload_completed"
336   [(set (match_dup 2)
337         (sign_extend:DI (match_dup 1)))
338    (set (match_dup 0)
339         (compare:CC (match_dup 2)
340                     (const_int 0)))]
341   "")
342
343 (define_insn ""
344   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
345         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
346                     (const_int 0)))
347    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
348         (sign_extend:DI (match_dup 1)))]
349   "TARGET_64BIT"
350   "@
351    extsb. %0,%1
352    #"
353   [(set_attr "type" "compare")
354    (set_attr "length" "4,8")])
355
356 (define_split
357   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
358         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
359                     (const_int 0)))
360    (set (match_operand:DI 0 "gpc_reg_operand" "")
361         (sign_extend:DI (match_dup 1)))]
362   "TARGET_POWERPC64 && reload_completed"
363   [(set (match_dup 0)
364         (sign_extend:DI (match_dup 1)))
365    (set (match_dup 2)
366         (compare:CC (match_dup 0)
367                     (const_int 0)))]
368   "")
369
370 (define_expand "extendhidi2"
371   [(set (match_operand:DI 0 "gpc_reg_operand" "")
372         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
373   "TARGET_POWERPC64"
374   "")
375
376 (define_insn ""
377   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
378         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
379   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
380   "@
381    lha%U1%X1 %0,%1
382    extsh %0,%1"
383   [(set_attr "type" "load_ext,exts")])
384
385 (define_insn ""
386   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
387         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
388   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
389   "extsh %0,%1"
390   [(set_attr "type" "exts")])
391
392 (define_insn ""
393   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
394         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
395                     (const_int 0)))
396    (clobber (match_scratch:DI 2 "=r,r"))]
397   "TARGET_64BIT"
398   "@
399    extsh. %2,%1
400    #"
401   [(set_attr "type" "compare")
402    (set_attr "length" "4,8")])
403
404 (define_split
405   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
406         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
407                     (const_int 0)))
408    (clobber (match_scratch:DI 2 ""))]
409   "TARGET_POWERPC64 && reload_completed"
410   [(set (match_dup 2)
411         (sign_extend:DI (match_dup 1)))
412    (set (match_dup 0)
413         (compare:CC (match_dup 2)
414                     (const_int 0)))]
415   "")
416
417 (define_insn ""
418   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
419         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
420                     (const_int 0)))
421    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
422         (sign_extend:DI (match_dup 1)))]
423   "TARGET_64BIT"
424   "@
425    extsh. %0,%1
426    #"
427   [(set_attr "type" "compare")
428    (set_attr "length" "4,8")])
429
430 (define_split
431   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
432         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
433                     (const_int 0)))
434    (set (match_operand:DI 0 "gpc_reg_operand" "")
435         (sign_extend:DI (match_dup 1)))]
436   "TARGET_POWERPC64 && reload_completed"
437   [(set (match_dup 0)
438         (sign_extend:DI (match_dup 1)))
439    (set (match_dup 2)
440         (compare:CC (match_dup 0)
441                     (const_int 0)))]
442   "")
443
444 (define_expand "extendsidi2"
445   [(set (match_operand:DI 0 "gpc_reg_operand" "")
446         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
447   "TARGET_POWERPC64"
448   "")
449
450 (define_insn ""
451   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
452         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
453   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
454   "@
455    lwa%U1%X1 %0,%1
456    extsw %0,%1"
457   [(set_attr "type" "load_ext,exts")])
458
459 (define_insn ""
460   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
461         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
462   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
463   "extsw %0,%1"
464   [(set_attr "type" "exts")])
465
466 (define_insn ""
467   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
468         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
469                     (const_int 0)))
470    (clobber (match_scratch:DI 2 "=r,r"))]
471   "TARGET_64BIT"
472   "@
473    extsw. %2,%1
474    #"
475   [(set_attr "type" "compare")
476    (set_attr "length" "4,8")])
477
478 (define_split
479   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
480         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
481                     (const_int 0)))
482    (clobber (match_scratch:DI 2 ""))]
483   "TARGET_POWERPC64 && reload_completed"
484   [(set (match_dup 2)
485         (sign_extend:DI (match_dup 1)))
486    (set (match_dup 0)
487         (compare:CC (match_dup 2)
488                     (const_int 0)))]
489   "")
490
491 (define_insn ""
492   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
493         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
494                     (const_int 0)))
495    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
496         (sign_extend:DI (match_dup 1)))]
497   "TARGET_64BIT"
498   "@
499    extsw. %0,%1
500    #"
501   [(set_attr "type" "compare")
502    (set_attr "length" "4,8")])
503
504 (define_split
505   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
506         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
507                     (const_int 0)))
508    (set (match_operand:DI 0 "gpc_reg_operand" "")
509         (sign_extend:DI (match_dup 1)))]
510   "TARGET_POWERPC64 && reload_completed"
511   [(set (match_dup 0)
512         (sign_extend:DI (match_dup 1)))
513    (set (match_dup 2)
514         (compare:CC (match_dup 0)
515                     (const_int 0)))]
516   "")
517
518 (define_expand "zero_extendqisi2"
519   [(set (match_operand:SI 0 "gpc_reg_operand" "")
520         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
521   ""
522   "")
523
524 (define_insn ""
525   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
526         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
527   ""
528   "@
529    lbz%U1%X1 %0,%1
530    {rlinm|rlwinm} %0,%1,0,0xff"
531   [(set_attr "type" "load,*")])
532
533 (define_insn ""
534   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
535         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
536                     (const_int 0)))
537    (clobber (match_scratch:SI 2 "=r,r"))]
538   ""
539   "@
540    {andil.|andi.} %2,%1,0xff
541    #"
542   [(set_attr "type" "fast_compare,compare")
543    (set_attr "length" "4,8")])
544
545 (define_split
546   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
547         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
548                     (const_int 0)))
549    (clobber (match_scratch:SI 2 ""))]
550   "reload_completed"
551   [(set (match_dup 2)
552         (zero_extend:SI (match_dup 1)))
553    (set (match_dup 0)
554         (compare:CC (match_dup 2)
555                     (const_int 0)))]
556   "")
557
558 (define_insn ""
559   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
560         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
561                     (const_int 0)))
562    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
563         (zero_extend:SI (match_dup 1)))]
564   ""
565   "@
566    {andil.|andi.} %0,%1,0xff
567    #"
568   [(set_attr "type" "fast_compare,compare")
569    (set_attr "length" "4,8")])
570
571 (define_split
572   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
573         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
574                     (const_int 0)))
575    (set (match_operand:SI 0 "gpc_reg_operand" "")
576         (zero_extend:SI (match_dup 1)))]
577   "reload_completed"
578   [(set (match_dup 0)
579         (zero_extend:SI (match_dup 1)))
580    (set (match_dup 2)
581         (compare:CC (match_dup 0)
582                     (const_int 0)))]
583   "")
584
585 (define_expand "extendqisi2"
586   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
587    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
588   ""
589   "
590 {
591   if (TARGET_POWERPC)
592     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
593   else if (TARGET_POWER)
594     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
595   else
596     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
597   DONE;
598 }")
599
600 (define_insn "extendqisi2_ppc"
601   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
602         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
603   "TARGET_POWERPC"
604   "extsb %0,%1"
605   [(set_attr "type" "exts")])
606
607 (define_insn ""
608   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
609         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
610                     (const_int 0)))
611    (clobber (match_scratch:SI 2 "=r,r"))]
612   "TARGET_POWERPC"
613   "@
614    extsb. %2,%1
615    #"
616   [(set_attr "type" "compare")
617    (set_attr "length" "4,8")])
618
619 (define_split
620   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
621         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
622                     (const_int 0)))
623    (clobber (match_scratch:SI 2 ""))]
624   "TARGET_POWERPC && reload_completed"
625   [(set (match_dup 2)
626         (sign_extend:SI (match_dup 1)))
627    (set (match_dup 0)
628         (compare:CC (match_dup 2)
629                     (const_int 0)))]
630   "")
631
632 (define_insn ""
633   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
634         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
635                     (const_int 0)))
636    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
637         (sign_extend:SI (match_dup 1)))]
638   "TARGET_POWERPC"
639   "@
640    extsb. %0,%1
641    #"
642   [(set_attr "type" "compare")
643    (set_attr "length" "4,8")])
644
645 (define_split
646   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
647         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
648                     (const_int 0)))
649    (set (match_operand:SI 0 "gpc_reg_operand" "")
650         (sign_extend:SI (match_dup 1)))]
651   "TARGET_POWERPC && reload_completed"
652   [(set (match_dup 0)
653         (sign_extend:SI (match_dup 1)))
654    (set (match_dup 2)
655         (compare:CC (match_dup 0)
656                     (const_int 0)))]
657   "")
658
659 (define_expand "extendqisi2_power"
660   [(parallel [(set (match_dup 2)
661                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
662                               (const_int 24)))
663               (clobber (scratch:SI))])
664    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
665                    (ashiftrt:SI (match_dup 2)
666                                 (const_int 24)))
667               (clobber (scratch:SI))])]
668   "TARGET_POWER"
669   "
670 { operands[1] = gen_lowpart (SImode, operands[1]);
671   operands[2] = gen_reg_rtx (SImode); }")
672
673 (define_expand "extendqisi2_no_power"
674   [(set (match_dup 2)
675         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
676                    (const_int 24)))
677    (set (match_operand:SI 0 "gpc_reg_operand" "")
678         (ashiftrt:SI (match_dup 2)
679                      (const_int 24)))]
680   "! TARGET_POWER && ! TARGET_POWERPC"
681   "
682 { operands[1] = gen_lowpart (SImode, operands[1]);
683   operands[2] = gen_reg_rtx (SImode); }")
684
685 (define_expand "zero_extendqihi2"
686   [(set (match_operand:HI 0 "gpc_reg_operand" "")
687         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
688   ""
689   "")
690
691 (define_insn ""
692   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
693         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
694   ""
695   "@
696    lbz%U1%X1 %0,%1
697    {rlinm|rlwinm} %0,%1,0,0xff"
698   [(set_attr "type" "load,*")])
699
700 (define_insn ""
701   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
702         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
703                     (const_int 0)))
704    (clobber (match_scratch:HI 2 "=r,r"))]
705   ""
706   "@
707    {andil.|andi.} %2,%1,0xff
708    #"
709   [(set_attr "type" "fast_compare,compare")
710    (set_attr "length" "4,8")])
711
712 (define_split
713   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
714         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
715                     (const_int 0)))
716    (clobber (match_scratch:HI 2 ""))]
717   "reload_completed"
718   [(set (match_dup 2)
719         (zero_extend:HI (match_dup 1)))
720    (set (match_dup 0)
721         (compare:CC (match_dup 2)
722                     (const_int 0)))]
723   "")
724
725 (define_insn ""
726   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
727         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
728                     (const_int 0)))
729    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
730         (zero_extend:HI (match_dup 1)))]
731   ""
732   "@
733    {andil.|andi.} %0,%1,0xff
734    #"
735   [(set_attr "type" "fast_compare,compare")
736    (set_attr "length" "4,8")])
737
738 (define_split
739   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
740         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
741                     (const_int 0)))
742    (set (match_operand:HI 0 "gpc_reg_operand" "")
743         (zero_extend:HI (match_dup 1)))]
744   "reload_completed"
745   [(set (match_dup 0)
746         (zero_extend:HI (match_dup 1)))
747    (set (match_dup 2)
748         (compare:CC (match_dup 0)
749                     (const_int 0)))]
750   "")
751
752 (define_expand "extendqihi2"
753   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
754    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
755   ""
756   "
757 {
758   if (TARGET_POWERPC)
759     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
760   else if (TARGET_POWER)
761     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
762   else
763     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
764   DONE;
765 }")
766
767 (define_insn "extendqihi2_ppc"
768   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
769         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
770   "TARGET_POWERPC"
771   "extsb %0,%1"
772   [(set_attr "type" "exts")])
773
774 (define_insn ""
775   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
776         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
777                     (const_int 0)))
778    (clobber (match_scratch:HI 2 "=r,r"))]
779   "TARGET_POWERPC"
780   "@
781    extsb. %2,%1
782    #"
783   [(set_attr "type" "compare")
784    (set_attr "length" "4,8")])
785
786 (define_split
787   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
788         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
789                     (const_int 0)))
790    (clobber (match_scratch:HI 2 ""))]
791   "TARGET_POWERPC && reload_completed"
792   [(set (match_dup 2)
793         (sign_extend:HI (match_dup 1)))
794    (set (match_dup 0)
795         (compare:CC (match_dup 2)
796                     (const_int 0)))]
797   "")
798
799 (define_insn ""
800   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
801         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
802                     (const_int 0)))
803    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
804         (sign_extend:HI (match_dup 1)))]
805   "TARGET_POWERPC"
806   "@
807    extsb. %0,%1
808    #"
809   [(set_attr "type" "compare")
810    (set_attr "length" "4,8")])
811
812 (define_split
813   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
814         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
815                     (const_int 0)))
816    (set (match_operand:HI 0 "gpc_reg_operand" "")
817         (sign_extend:HI (match_dup 1)))]
818   "TARGET_POWERPC && reload_completed"
819   [(set (match_dup 0)
820         (sign_extend:HI (match_dup 1)))
821    (set (match_dup 2)
822         (compare:CC (match_dup 0)
823                     (const_int 0)))]
824   "")
825
826 (define_expand "extendqihi2_power"
827   [(parallel [(set (match_dup 2)
828                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
829                               (const_int 24)))
830               (clobber (scratch:SI))])
831    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
832                    (ashiftrt:SI (match_dup 2)
833                                 (const_int 24)))
834               (clobber (scratch:SI))])]
835   "TARGET_POWER"
836   "
837 { operands[0] = gen_lowpart (SImode, operands[0]);
838   operands[1] = gen_lowpart (SImode, operands[1]);
839   operands[2] = gen_reg_rtx (SImode); }")
840
841 (define_expand "extendqihi2_no_power"
842   [(set (match_dup 2)
843         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
844                    (const_int 24)))
845    (set (match_operand:HI 0 "gpc_reg_operand" "")
846         (ashiftrt:SI (match_dup 2)
847                      (const_int 24)))]
848   "! TARGET_POWER && ! TARGET_POWERPC"
849   "
850 { operands[0] = gen_lowpart (SImode, operands[0]);
851   operands[1] = gen_lowpart (SImode, operands[1]);
852   operands[2] = gen_reg_rtx (SImode); }")
853
854 (define_expand "zero_extendhisi2"
855   [(set (match_operand:SI 0 "gpc_reg_operand" "")
856         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
857   ""
858   "")
859
860 (define_insn ""
861   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
862         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
863   ""
864   "@
865    lhz%U1%X1 %0,%1
866    {rlinm|rlwinm} %0,%1,0,0xffff"
867   [(set_attr "type" "load,*")])
868
869 (define_insn ""
870   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
871         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
872                     (const_int 0)))
873    (clobber (match_scratch:SI 2 "=r,r"))]
874   ""
875   "@
876    {andil.|andi.} %2,%1,0xffff
877    #"
878   [(set_attr "type" "fast_compare,compare")
879    (set_attr "length" "4,8")])
880
881 (define_split
882   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
883         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
884                     (const_int 0)))
885    (clobber (match_scratch:SI 2 ""))]
886   "reload_completed"
887   [(set (match_dup 2)
888         (zero_extend:SI (match_dup 1)))
889    (set (match_dup 0)
890         (compare:CC (match_dup 2)
891                     (const_int 0)))]
892   "")
893
894 (define_insn ""
895   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
896         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
897                     (const_int 0)))
898    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
899         (zero_extend:SI (match_dup 1)))]
900   ""
901   "@
902    {andil.|andi.} %0,%1,0xffff
903    #"
904   [(set_attr "type" "fast_compare,compare")
905    (set_attr "length" "4,8")])
906
907 (define_split
908   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
909         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
910                     (const_int 0)))
911    (set (match_operand:SI 0 "gpc_reg_operand" "")
912         (zero_extend:SI (match_dup 1)))]
913   "reload_completed"
914   [(set (match_dup 0)
915         (zero_extend:SI (match_dup 1)))
916    (set (match_dup 2)
917         (compare:CC (match_dup 0)
918                     (const_int 0)))]
919   "")
920
921 (define_expand "extendhisi2"
922   [(set (match_operand:SI 0 "gpc_reg_operand" "")
923         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
924   ""
925   "")
926
927 (define_insn ""
928   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
929         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
930   "rs6000_gen_cell_microcode"
931   "@
932    lha%U1%X1 %0,%1
933    {exts|extsh} %0,%1"
934   [(set_attr "type" "load_ext,exts")])
935
936 (define_insn ""
937   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
938         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
939   "!rs6000_gen_cell_microcode"
940   "{exts|extsh} %0,%1"
941   [(set_attr "type" "exts")])
942
943 (define_insn ""
944   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
945         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
946                     (const_int 0)))
947    (clobber (match_scratch:SI 2 "=r,r"))]
948   ""
949   "@
950    {exts.|extsh.} %2,%1
951    #"
952   [(set_attr "type" "compare")
953    (set_attr "length" "4,8")])
954
955 (define_split
956   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
957         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
958                     (const_int 0)))
959    (clobber (match_scratch:SI 2 ""))]
960   "reload_completed"
961   [(set (match_dup 2)
962         (sign_extend:SI (match_dup 1)))
963    (set (match_dup 0)
964         (compare:CC (match_dup 2)
965                     (const_int 0)))]
966   "")
967
968 (define_insn ""
969   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
970         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
971                     (const_int 0)))
972    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
973         (sign_extend:SI (match_dup 1)))]
974   ""
975   "@
976    {exts.|extsh.} %0,%1
977    #"
978   [(set_attr "type" "compare")
979    (set_attr "length" "4,8")])
980 \f
981 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
982
983 (define_insn "*macchwc"
984   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
985         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
986                                        (match_operand:SI 2 "gpc_reg_operand" "r")
987                                        (const_int 16))
988                                       (sign_extend:SI
989                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
990                              (match_operand:SI 4 "gpc_reg_operand" "0"))
991                     (const_int 0)))
992    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
993         (plus:SI (mult:SI (ashiftrt:SI
994                            (match_dup 2)
995                            (const_int 16))
996                           (sign_extend:SI
997                            (match_dup 1)))
998                  (match_dup 4)))]
999   "TARGET_MULHW"
1000   "macchw. %0, %1, %2"
1001   [(set_attr "type" "imul3")])
1002
1003 (define_insn "*macchw"
1004   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1005         (plus:SI (mult:SI (ashiftrt:SI
1006                            (match_operand:SI 2 "gpc_reg_operand" "r")
1007                            (const_int 16))
1008                           (sign_extend:SI
1009                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1010                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1011   "TARGET_MULHW"
1012   "macchw %0, %1, %2"
1013   [(set_attr "type" "imul3")])
1014
1015 (define_insn "*macchwuc"
1016   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1017         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1018                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1019                                        (const_int 16))
1020                                       (zero_extend:SI
1021                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1022                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1023                     (const_int 0)))
1024    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1025         (plus:SI (mult:SI (lshiftrt:SI
1026                            (match_dup 2)
1027                            (const_int 16))
1028                           (zero_extend:SI
1029                            (match_dup 1)))
1030                  (match_dup 4)))]
1031   "TARGET_MULHW"
1032   "macchwu. %0, %1, %2"
1033   [(set_attr "type" "imul3")])
1034
1035 (define_insn "*macchwu"
1036   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1037         (plus:SI (mult:SI (lshiftrt:SI
1038                            (match_operand:SI 2 "gpc_reg_operand" "r")
1039                            (const_int 16))
1040                           (zero_extend:SI
1041                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1042                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1043   "TARGET_MULHW"
1044   "macchwu %0, %1, %2"
1045   [(set_attr "type" "imul3")])
1046
1047 (define_insn "*machhwc"
1048   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1049         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1050                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1051                                        (const_int 16))
1052                                       (ashiftrt:SI
1053                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1054                                        (const_int 16)))
1055                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1056                     (const_int 0)))
1057    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1058         (plus:SI (mult:SI (ashiftrt:SI
1059                            (match_dup 1)
1060                            (const_int 16))
1061                           (ashiftrt:SI
1062                            (match_dup 2)
1063                            (const_int 16)))
1064                  (match_dup 4)))]
1065   "TARGET_MULHW"
1066   "machhw. %0, %1, %2"
1067   [(set_attr "type" "imul3")])
1068
1069 (define_insn "*machhw"
1070   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1071         (plus:SI (mult:SI (ashiftrt:SI
1072                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1073                            (const_int 16))
1074                           (ashiftrt:SI
1075                            (match_operand:SI 2 "gpc_reg_operand" "r")
1076                            (const_int 16)))
1077                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1078   "TARGET_MULHW"
1079   "machhw %0, %1, %2"
1080   [(set_attr "type" "imul3")])
1081
1082 (define_insn "*machhwuc"
1083   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1084         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1085                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1086                                        (const_int 16))
1087                                       (lshiftrt:SI
1088                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1089                                        (const_int 16)))
1090                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1091                     (const_int 0)))
1092    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1093         (plus:SI (mult:SI (lshiftrt:SI
1094                            (match_dup 1)
1095                            (const_int 16))
1096                           (lshiftrt:SI
1097                            (match_dup 2)
1098                            (const_int 16)))
1099                  (match_dup 4)))]
1100   "TARGET_MULHW"
1101   "machhwu. %0, %1, %2"
1102   [(set_attr "type" "imul3")])
1103
1104 (define_insn "*machhwu"
1105   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1106         (plus:SI (mult:SI (lshiftrt:SI
1107                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1108                            (const_int 16))
1109                           (lshiftrt:SI
1110                            (match_operand:SI 2 "gpc_reg_operand" "r")
1111                            (const_int 16)))
1112                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1113   "TARGET_MULHW"
1114   "machhwu %0, %1, %2"
1115   [(set_attr "type" "imul3")])
1116
1117 (define_insn "*maclhwc"
1118   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1119         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1120                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1121                                       (sign_extend:SI
1122                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1123                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1124                     (const_int 0)))
1125    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1126         (plus:SI (mult:SI (sign_extend:SI
1127                            (match_dup 1))
1128                           (sign_extend:SI
1129                            (match_dup 2)))
1130                  (match_dup 4)))]
1131   "TARGET_MULHW"
1132   "maclhw. %0, %1, %2"
1133   [(set_attr "type" "imul3")])
1134
1135 (define_insn "*maclhw"
1136   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1137         (plus:SI (mult:SI (sign_extend:SI
1138                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1139                           (sign_extend:SI
1140                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1141                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1142   "TARGET_MULHW"
1143   "maclhw %0, %1, %2"
1144   [(set_attr "type" "imul3")])
1145
1146 (define_insn "*maclhwuc"
1147   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1148         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1149                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1150                                       (zero_extend:SI
1151                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1152                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1153                     (const_int 0)))
1154    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1155         (plus:SI (mult:SI (zero_extend:SI
1156                            (match_dup 1))
1157                           (zero_extend:SI
1158                            (match_dup 2)))
1159                  (match_dup 4)))]
1160   "TARGET_MULHW"
1161   "maclhwu. %0, %1, %2"
1162   [(set_attr "type" "imul3")])
1163
1164 (define_insn "*maclhwu"
1165   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1166         (plus:SI (mult:SI (zero_extend:SI
1167                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1168                           (zero_extend:SI
1169                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1170                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1171   "TARGET_MULHW"
1172   "maclhwu %0, %1, %2"
1173   [(set_attr "type" "imul3")])
1174
1175 (define_insn "*nmacchwc"
1176   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1177         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1178                               (mult:SI (ashiftrt:SI
1179                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1180                                         (const_int 16))
1181                                        (sign_extend:SI
1182                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1183                     (const_int 0)))
1184    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1185         (minus:SI (match_dup 4)
1186                   (mult:SI (ashiftrt:SI
1187                             (match_dup 2)
1188                             (const_int 16))
1189                            (sign_extend:SI
1190                             (match_dup 1)))))]
1191   "TARGET_MULHW"
1192   "nmacchw. %0, %1, %2"
1193   [(set_attr "type" "imul3")])
1194
1195 (define_insn "*nmacchw"
1196   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1197         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1198                   (mult:SI (ashiftrt:SI
1199                             (match_operand:SI 2 "gpc_reg_operand" "r")
1200                             (const_int 16))
1201                            (sign_extend:SI
1202                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1203   "TARGET_MULHW"
1204   "nmacchw %0, %1, %2"
1205   [(set_attr "type" "imul3")])
1206
1207 (define_insn "*nmachhwc"
1208   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1209         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1210                               (mult:SI (ashiftrt:SI
1211                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1212                                         (const_int 16))
1213                                        (ashiftrt:SI
1214                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1215                                         (const_int 16))))
1216                     (const_int 0)))
1217    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1218         (minus:SI (match_dup 4)
1219                   (mult:SI (ashiftrt:SI
1220                             (match_dup 1)
1221                             (const_int 16))
1222                            (ashiftrt:SI
1223                             (match_dup 2)
1224                             (const_int 16)))))]
1225   "TARGET_MULHW"
1226   "nmachhw. %0, %1, %2"
1227   [(set_attr "type" "imul3")])
1228
1229 (define_insn "*nmachhw"
1230   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1231         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1232                   (mult:SI (ashiftrt:SI
1233                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1234                             (const_int 16))
1235                            (ashiftrt:SI
1236                             (match_operand:SI 2 "gpc_reg_operand" "r")
1237                             (const_int 16)))))]
1238   "TARGET_MULHW"
1239   "nmachhw %0, %1, %2"
1240   [(set_attr "type" "imul3")])
1241
1242 (define_insn "*nmaclhwc"
1243   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1244         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1245                               (mult:SI (sign_extend:SI
1246                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1247                                        (sign_extend:SI
1248                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1249                     (const_int 0)))
1250    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1251         (minus:SI (match_dup 4)
1252                   (mult:SI (sign_extend:SI
1253                             (match_dup 1))
1254                            (sign_extend:SI
1255                             (match_dup 2)))))]
1256   "TARGET_MULHW"
1257   "nmaclhw. %0, %1, %2"
1258   [(set_attr "type" "imul3")])
1259
1260 (define_insn "*nmaclhw"
1261   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1262         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1263                   (mult:SI (sign_extend:SI
1264                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1265                            (sign_extend:SI
1266                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1267   "TARGET_MULHW"
1268   "nmaclhw %0, %1, %2"
1269   [(set_attr "type" "imul3")])
1270
1271 (define_insn "*mulchwc"
1272   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1273         (compare:CC (mult:SI (ashiftrt:SI
1274                               (match_operand:SI 2 "gpc_reg_operand" "r")
1275                               (const_int 16))
1276                              (sign_extend:SI
1277                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1278                     (const_int 0)))
1279    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1280         (mult:SI (ashiftrt:SI
1281                   (match_dup 2)
1282                   (const_int 16))
1283                  (sign_extend:SI
1284                   (match_dup 1))))]
1285   "TARGET_MULHW"
1286   "mulchw. %0, %1, %2"
1287   [(set_attr "type" "imul3")])
1288
1289 (define_insn "*mulchw"
1290   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1291         (mult:SI (ashiftrt:SI
1292                   (match_operand:SI 2 "gpc_reg_operand" "r")
1293                   (const_int 16))
1294                  (sign_extend:SI
1295                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1296   "TARGET_MULHW"
1297   "mulchw %0, %1, %2"
1298   [(set_attr "type" "imul3")])
1299
1300 (define_insn "*mulchwuc"
1301   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1302         (compare:CC (mult:SI (lshiftrt:SI
1303                               (match_operand:SI 2 "gpc_reg_operand" "r")
1304                               (const_int 16))
1305                              (zero_extend:SI
1306                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1307                     (const_int 0)))
1308    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1309         (mult:SI (lshiftrt:SI
1310                   (match_dup 2)
1311                   (const_int 16))
1312                  (zero_extend:SI
1313                   (match_dup 1))))]
1314   "TARGET_MULHW"
1315   "mulchwu. %0, %1, %2"
1316   [(set_attr "type" "imul3")])
1317
1318 (define_insn "*mulchwu"
1319   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1320         (mult:SI (lshiftrt:SI
1321                   (match_operand:SI 2 "gpc_reg_operand" "r")
1322                   (const_int 16))
1323                  (zero_extend:SI
1324                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1325   "TARGET_MULHW"
1326   "mulchwu %0, %1, %2"
1327   [(set_attr "type" "imul3")])
1328
1329 (define_insn "*mulhhwc"
1330   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1331         (compare:CC (mult:SI (ashiftrt:SI
1332                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1333                               (const_int 16))
1334                              (ashiftrt:SI
1335                               (match_operand:SI 2 "gpc_reg_operand" "r")
1336                               (const_int 16)))
1337                     (const_int 0)))
1338    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1339         (mult:SI (ashiftrt:SI
1340                   (match_dup 1)
1341                   (const_int 16))
1342                  (ashiftrt:SI
1343                   (match_dup 2)
1344                   (const_int 16))))]
1345   "TARGET_MULHW"
1346   "mulhhw. %0, %1, %2"
1347   [(set_attr "type" "imul3")])
1348
1349 (define_insn "*mulhhw"
1350   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1351         (mult:SI (ashiftrt:SI
1352                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1353                   (const_int 16))
1354                  (ashiftrt:SI
1355                   (match_operand:SI 2 "gpc_reg_operand" "r")
1356                   (const_int 16))))]
1357   "TARGET_MULHW"
1358   "mulhhw %0, %1, %2"
1359   [(set_attr "type" "imul3")])
1360
1361 (define_insn "*mulhhwuc"
1362   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1363         (compare:CC (mult:SI (lshiftrt:SI
1364                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1365                               (const_int 16))
1366                              (lshiftrt:SI
1367                               (match_operand:SI 2 "gpc_reg_operand" "r")
1368                               (const_int 16)))
1369                     (const_int 0)))
1370    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1371         (mult:SI (lshiftrt:SI
1372                   (match_dup 1)
1373                   (const_int 16))
1374                  (lshiftrt:SI
1375                   (match_dup 2)
1376                   (const_int 16))))]
1377   "TARGET_MULHW"
1378   "mulhhwu. %0, %1, %2"
1379   [(set_attr "type" "imul3")])
1380
1381 (define_insn "*mulhhwu"
1382   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1383         (mult:SI (lshiftrt:SI
1384                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1385                   (const_int 16))
1386                  (lshiftrt:SI
1387                   (match_operand:SI 2 "gpc_reg_operand" "r")
1388                   (const_int 16))))]
1389   "TARGET_MULHW"
1390   "mulhhwu %0, %1, %2"
1391   [(set_attr "type" "imul3")])
1392
1393 (define_insn "*mullhwc"
1394   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1395         (compare:CC (mult:SI (sign_extend:SI
1396                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1397                              (sign_extend:SI
1398                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1399                     (const_int 0)))
1400    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1401         (mult:SI (sign_extend:SI
1402                   (match_dup 1))
1403                  (sign_extend:SI
1404                   (match_dup 2))))]
1405   "TARGET_MULHW"
1406   "mullhw. %0, %1, %2"
1407   [(set_attr "type" "imul3")])
1408
1409 (define_insn "*mullhw"
1410   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1411         (mult:SI (sign_extend:SI
1412                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1413                  (sign_extend:SI
1414                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1415   "TARGET_MULHW"
1416   "mullhw %0, %1, %2"
1417   [(set_attr "type" "imul3")])
1418
1419 (define_insn "*mullhwuc"
1420   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1421         (compare:CC (mult:SI (zero_extend:SI
1422                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1423                              (zero_extend:SI
1424                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1425                     (const_int 0)))
1426    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1427         (mult:SI (zero_extend:SI
1428                   (match_dup 1))
1429                  (zero_extend:SI
1430                   (match_dup 2))))]
1431   "TARGET_MULHW"
1432   "mullhwu. %0, %1, %2"
1433   [(set_attr "type" "imul3")])
1434
1435 (define_insn "*mullhwu"
1436   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1437         (mult:SI (zero_extend:SI
1438                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1439                  (zero_extend:SI
1440                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1441   "TARGET_MULHW"
1442   "mullhwu %0, %1, %2"
1443   [(set_attr "type" "imul3")])
1444 \f
1445 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1446 (define_insn "dlmzb"
1447   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1448         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1449                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1450                    UNSPEC_DLMZB_CR))
1451    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1452         (unspec:SI [(match_dup 1)
1453                     (match_dup 2)]
1454                    UNSPEC_DLMZB))]
1455   "TARGET_DLMZB"
1456   "dlmzb. %0, %1, %2")
1457
1458 (define_expand "strlensi"
1459   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1460         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1461                     (match_operand:QI 2 "const_int_operand" "")
1462                     (match_operand 3 "const_int_operand" "")]
1463                    UNSPEC_DLMZB_STRLEN))
1464    (clobber (match_scratch:CC 4 "=x"))]
1465   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1466 {
1467   rtx result = operands[0];
1468   rtx src = operands[1];
1469   rtx search_char = operands[2];
1470   rtx align = operands[3];
1471   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1472   rtx loop_label, end_label, mem, cr0, cond;
1473   if (search_char != const0_rtx
1474       || GET_CODE (align) != CONST_INT
1475       || INTVAL (align) < 8)
1476         FAIL;
1477   word1 = gen_reg_rtx (SImode);
1478   word2 = gen_reg_rtx (SImode);
1479   scratch_dlmzb = gen_reg_rtx (SImode);
1480   scratch_string = gen_reg_rtx (Pmode);
1481   loop_label = gen_label_rtx ();
1482   end_label = gen_label_rtx ();
1483   addr = force_reg (Pmode, XEXP (src, 0));
1484   emit_move_insn (scratch_string, addr);
1485   emit_label (loop_label);
1486   mem = change_address (src, SImode, scratch_string);
1487   emit_move_insn (word1, mem);
1488   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1489   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1490   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1491   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1492   emit_jump_insn (gen_rtx_SET (VOIDmode,
1493                                pc_rtx,
1494                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1495                                                      cond,
1496                                                      gen_rtx_LABEL_REF
1497                                                        (VOIDmode,
1498                                                         end_label),
1499                                                      pc_rtx)));
1500   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1501   emit_jump_insn (gen_rtx_SET (VOIDmode,
1502                                pc_rtx,
1503                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1504   emit_barrier ();
1505   emit_label (end_label);
1506   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1507   emit_insn (gen_subsi3 (result, scratch_string, addr));
1508   emit_insn (gen_subsi3 (result, result, const1_rtx));
1509   DONE;
1510 })
1511 \f
1512 (define_split
1513   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1514         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1515                     (const_int 0)))
1516    (set (match_operand:SI 0 "gpc_reg_operand" "")
1517         (sign_extend:SI (match_dup 1)))]
1518   "reload_completed"
1519   [(set (match_dup 0)
1520         (sign_extend:SI (match_dup 1)))
1521    (set (match_dup 2)
1522         (compare:CC (match_dup 0)
1523                     (const_int 0)))]
1524   "")
1525
1526 ;; Fixed-point arithmetic insns.
1527
1528 (define_expand "add<mode>3"
1529   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1530         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1531                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1532   ""
1533 {
1534   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1535     {
1536       if (non_short_cint_operand (operands[2], DImode))
1537         FAIL;
1538     }
1539   else if (GET_CODE (operands[2]) == CONST_INT
1540            && ! add_operand (operands[2], <MODE>mode))
1541     {
1542       rtx tmp = ((!can_create_pseudo_p ()
1543                   || rtx_equal_p (operands[0], operands[1]))
1544                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1545
1546       HOST_WIDE_INT val = INTVAL (operands[2]);
1547       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1548       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1549
1550       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1551         FAIL;
1552
1553       /* The ordering here is important for the prolog expander.
1554          When space is allocated from the stack, adding 'low' first may
1555          produce a temporary deallocation (which would be bad).  */
1556       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1557       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1558       DONE;
1559     }
1560 })
1561
1562 ;; Discourage ai/addic because of carry but provide it in an alternative
1563 ;; allowing register zero as source.
1564 (define_insn "*add<mode>3_internal1"
1565   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1566         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1567                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1568   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1569   "@
1570    {cax|add} %0,%1,%2
1571    {cal %0,%2(%1)|addi %0,%1,%2}
1572    {ai|addic} %0,%1,%2
1573    {cau|addis} %0,%1,%v2"
1574   [(set_attr "length" "4,4,4,4")])
1575
1576 (define_insn "addsi3_high"
1577   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1578         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1579                  (high:SI (match_operand 2 "" ""))))]
1580   "TARGET_MACHO && !TARGET_64BIT"
1581   "{cau|addis} %0,%1,ha16(%2)"
1582   [(set_attr "length" "4")])
1583
1584 (define_insn "*add<mode>3_internal2"
1585   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1586         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1587                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1588                     (const_int 0)))
1589    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1590   ""
1591   "@
1592    {cax.|add.} %3,%1,%2
1593    {ai.|addic.} %3,%1,%2
1594    #
1595    #"
1596   [(set_attr "type" "fast_compare,compare,compare,compare")
1597    (set_attr "length" "4,4,8,8")])
1598
1599 (define_split
1600   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1601         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1602                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1603                     (const_int 0)))
1604    (clobber (match_scratch:GPR 3 ""))]
1605   "reload_completed"
1606   [(set (match_dup 3)
1607         (plus:GPR (match_dup 1)
1608                  (match_dup 2)))
1609    (set (match_dup 0)
1610         (compare:CC (match_dup 3)
1611                     (const_int 0)))]
1612   "")
1613
1614 (define_insn "*add<mode>3_internal3"
1615   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1616         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1617                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1618                     (const_int 0)))
1619    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1620         (plus:P (match_dup 1)
1621                 (match_dup 2)))]
1622   ""
1623   "@
1624    {cax.|add.} %0,%1,%2
1625    {ai.|addic.} %0,%1,%2
1626    #
1627    #"
1628   [(set_attr "type" "fast_compare,compare,compare,compare")
1629    (set_attr "length" "4,4,8,8")])
1630
1631 (define_split
1632   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1633         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1634                             (match_operand:P 2 "reg_or_short_operand" ""))
1635                     (const_int 0)))
1636    (set (match_operand:P 0 "gpc_reg_operand" "")
1637         (plus:P (match_dup 1) (match_dup 2)))]
1638   "reload_completed"
1639   [(set (match_dup 0)
1640         (plus:P (match_dup 1)
1641                 (match_dup 2)))
1642    (set (match_dup 3)
1643         (compare:CC (match_dup 0)
1644                     (const_int 0)))]
1645   "")
1646
1647 ;; Split an add that we can't do in one insn into two insns, each of which
1648 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1649 ;; add should be last in case the result gets used in an address.
1650
1651 (define_split
1652   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1653         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1654                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1655   ""
1656   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1657    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1658 {
1659   HOST_WIDE_INT val = INTVAL (operands[2]);
1660   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1661   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1662
1663   operands[4] = GEN_INT (low);
1664   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1665     operands[3] = GEN_INT (rest);
1666   else if (can_create_pseudo_p ())
1667     {
1668       operands[3] = gen_reg_rtx (DImode);
1669       emit_move_insn (operands[3], operands[2]);
1670       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1671       DONE;
1672     }
1673   else
1674     FAIL;
1675 })
1676
1677 (define_insn "one_cmpl<mode>2"
1678   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1679         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1680   ""
1681   "nor %0,%1,%1")
1682
1683 (define_insn ""
1684   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1685         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1686                     (const_int 0)))
1687    (clobber (match_scratch:P 2 "=r,r"))]
1688   ""
1689   "@
1690    nor. %2,%1,%1
1691    #"
1692   [(set_attr "type" "fast_compare,compare")
1693    (set_attr "length" "4,8")])
1694
1695 (define_split
1696   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1697         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1698                     (const_int 0)))
1699    (clobber (match_scratch:P 2 ""))]
1700   "reload_completed"
1701   [(set (match_dup 2)
1702         (not:P (match_dup 1)))
1703    (set (match_dup 0)
1704         (compare:CC (match_dup 2)
1705                     (const_int 0)))]
1706   "")
1707
1708 (define_insn ""
1709   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1710         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1711                     (const_int 0)))
1712    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1713         (not:P (match_dup 1)))]
1714   ""
1715   "@
1716    nor. %0,%1,%1
1717    #"
1718   [(set_attr "type" "fast_compare,compare")
1719    (set_attr "length" "4,8")])
1720
1721 (define_split
1722   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1723         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1724                     (const_int 0)))
1725    (set (match_operand:P 0 "gpc_reg_operand" "")
1726         (not:P (match_dup 1)))]
1727   "reload_completed"
1728   [(set (match_dup 0)
1729         (not:P (match_dup 1)))
1730    (set (match_dup 2)
1731         (compare:CC (match_dup 0)
1732                     (const_int 0)))]
1733   "")
1734
1735 (define_insn ""
1736   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1737         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1738                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1739   "! TARGET_POWERPC"
1740   "{sf%I1|subf%I1c} %0,%2,%1")
1741
1742 (define_insn ""
1743   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1744         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1745                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1746   "TARGET_POWERPC"
1747   "@
1748    subf %0,%2,%1
1749    subfic %0,%2,%1")
1750
1751 (define_insn ""
1752   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1753         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1754                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1755                     (const_int 0)))
1756    (clobber (match_scratch:SI 3 "=r,r"))]
1757   "! TARGET_POWERPC"
1758   "@
1759    {sf.|subfc.} %3,%2,%1
1760    #"
1761   [(set_attr "type" "compare")
1762    (set_attr "length" "4,8")])
1763
1764 (define_insn ""
1765   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1766         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1767                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1768                     (const_int 0)))
1769    (clobber (match_scratch:P 3 "=r,r"))]
1770   "TARGET_POWERPC"
1771   "@
1772    subf. %3,%2,%1
1773    #"
1774   [(set_attr "type" "fast_compare")
1775    (set_attr "length" "4,8")])
1776
1777 (define_split
1778   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1779         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1780                              (match_operand:P 2 "gpc_reg_operand" ""))
1781                     (const_int 0)))
1782    (clobber (match_scratch:P 3 ""))]
1783   "reload_completed"
1784   [(set (match_dup 3)
1785         (minus:P (match_dup 1)
1786                   (match_dup 2)))
1787    (set (match_dup 0)
1788         (compare:CC (match_dup 3)
1789                     (const_int 0)))]
1790   "")
1791
1792 (define_insn ""
1793   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1794         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1795                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1796                     (const_int 0)))
1797    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1798         (minus:SI (match_dup 1) (match_dup 2)))]
1799   "! TARGET_POWERPC"
1800   "@
1801    {sf.|subfc.} %0,%2,%1
1802    #"
1803   [(set_attr "type" "compare")
1804    (set_attr "length" "4,8")])
1805
1806 (define_insn ""
1807   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1808         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1809                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1810                     (const_int 0)))
1811    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1812         (minus:P (match_dup 1)
1813                   (match_dup 2)))]
1814   "TARGET_POWERPC"
1815   "@
1816    subf. %0,%2,%1
1817    #"
1818   [(set_attr "type" "fast_compare")
1819    (set_attr "length" "4,8")])
1820
1821 (define_split
1822   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1823         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1824                              (match_operand:P 2 "gpc_reg_operand" ""))
1825                     (const_int 0)))
1826    (set (match_operand:P 0 "gpc_reg_operand" "")
1827         (minus:P (match_dup 1)
1828                   (match_dup 2)))]
1829   "reload_completed"
1830   [(set (match_dup 0)
1831         (minus:P (match_dup 1)
1832                   (match_dup 2)))
1833    (set (match_dup 3)
1834         (compare:CC (match_dup 0)
1835                     (const_int 0)))]
1836   "")
1837
1838 (define_expand "sub<mode>3"
1839   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1840         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1841                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1842   ""
1843   "
1844 {
1845   if (GET_CODE (operands[2]) == CONST_INT)
1846     {
1847       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1848                                  negate_rtx (<MODE>mode, operands[2])));
1849       DONE;
1850     }
1851 }")
1852
1853 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1854 ;; instruction and some auxiliary computations.  Then we just have a single
1855 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1856 ;; combine.
1857
1858 (define_expand "sminsi3"
1859   [(set (match_dup 3)
1860         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1861                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1862                          (const_int 0)
1863                          (minus:SI (match_dup 2) (match_dup 1))))
1864    (set (match_operand:SI 0 "gpc_reg_operand" "")
1865         (minus:SI (match_dup 2) (match_dup 3)))]
1866   "TARGET_POWER || TARGET_ISEL"
1867   "
1868 {
1869   if (TARGET_ISEL)
1870     {
1871       operands[2] = force_reg (SImode, operands[2]);
1872       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1873       DONE;
1874     }
1875
1876   operands[3] = gen_reg_rtx (SImode);
1877 }")
1878
1879 (define_split
1880   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1881         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1882                  (match_operand:SI 2 "reg_or_short_operand" "")))
1883    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1884   "TARGET_POWER"
1885   [(set (match_dup 3)
1886         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1887                          (const_int 0)
1888                          (minus:SI (match_dup 2) (match_dup 1))))
1889    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1890   "")
1891
1892 (define_expand "smaxsi3"
1893   [(set (match_dup 3)
1894         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1895                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1896                          (const_int 0)
1897                          (minus:SI (match_dup 2) (match_dup 1))))
1898    (set (match_operand:SI 0 "gpc_reg_operand" "")
1899         (plus:SI (match_dup 3) (match_dup 1)))]
1900   "TARGET_POWER || TARGET_ISEL"
1901   "
1902 {
1903   if (TARGET_ISEL)
1904     {
1905       operands[2] = force_reg (SImode, operands[2]);
1906       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1907       DONE;
1908     }
1909   operands[3] = gen_reg_rtx (SImode);
1910 }")
1911
1912 (define_split
1913   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1914         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1915                  (match_operand:SI 2 "reg_or_short_operand" "")))
1916    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1917   "TARGET_POWER"
1918   [(set (match_dup 3)
1919         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1920                          (const_int 0)
1921                          (minus:SI (match_dup 2) (match_dup 1))))
1922    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1923   "")
1924
1925 (define_expand "uminsi3"
1926   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1927                               (match_dup 5)))
1928    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1929                               (match_dup 5)))
1930    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1931                                        (const_int 0)
1932                                        (minus:SI (match_dup 4) (match_dup 3))))
1933    (set (match_operand:SI 0 "gpc_reg_operand" "")
1934         (minus:SI (match_dup 2) (match_dup 3)))]
1935   "TARGET_POWER || TARGET_ISEL"
1936   "
1937 {
1938   if (TARGET_ISEL)
1939     {
1940       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1941       DONE;
1942     }
1943   operands[3] = gen_reg_rtx (SImode);
1944   operands[4] = gen_reg_rtx (SImode);
1945   operands[5] = GEN_INT (-2147483647 - 1);
1946 }")
1947
1948 (define_expand "umaxsi3"
1949   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1950                               (match_dup 5)))
1951    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1952                               (match_dup 5)))
1953    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1954                                        (const_int 0)
1955                                        (minus:SI (match_dup 4) (match_dup 3))))
1956    (set (match_operand:SI 0 "gpc_reg_operand" "")
1957         (plus:SI (match_dup 3) (match_dup 1)))]
1958   "TARGET_POWER || TARGET_ISEL"
1959   "
1960 {
1961   if (TARGET_ISEL)
1962     {
1963       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1964       DONE;
1965     }
1966   operands[3] = gen_reg_rtx (SImode);
1967   operands[4] = gen_reg_rtx (SImode);
1968   operands[5] = GEN_INT (-2147483647 - 1);
1969 }")
1970
1971 (define_insn ""
1972   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1973         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1974                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1975                          (const_int 0)
1976                          (minus:SI (match_dup 2) (match_dup 1))))]
1977   "TARGET_POWER"
1978   "doz%I2 %0,%1,%2")
1979
1980 (define_insn ""
1981   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1982         (compare:CC
1983          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1984                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1985                           (const_int 0)
1986                           (minus:SI (match_dup 2) (match_dup 1)))
1987          (const_int 0)))
1988    (clobber (match_scratch:SI 3 "=r,r"))]
1989   "TARGET_POWER"
1990   "@
1991    doz%I2. %3,%1,%2
1992    #"
1993   [(set_attr "type" "delayed_compare")
1994    (set_attr "length" "4,8")])
1995
1996 (define_split
1997   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1998         (compare:CC
1999          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2000                               (match_operand:SI 2 "reg_or_short_operand" ""))
2001                           (const_int 0)
2002                           (minus:SI (match_dup 2) (match_dup 1)))
2003          (const_int 0)))
2004    (clobber (match_scratch:SI 3 ""))]
2005   "TARGET_POWER && reload_completed"
2006   [(set (match_dup 3)
2007         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2008                           (const_int 0)
2009                           (minus:SI (match_dup 2) (match_dup 1))))
2010    (set (match_dup 0)
2011         (compare:CC (match_dup 3)
2012                     (const_int 0)))]
2013   "")
2014
2015 (define_insn ""
2016   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2017         (compare:CC
2018          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2019                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2020                           (const_int 0)
2021                           (minus:SI (match_dup 2) (match_dup 1)))
2022          (const_int 0)))
2023    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2024         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2025                          (const_int 0)
2026                          (minus:SI (match_dup 2) (match_dup 1))))]
2027   "TARGET_POWER"
2028   "@
2029    doz%I2. %0,%1,%2
2030    #"
2031   [(set_attr "type" "delayed_compare")
2032    (set_attr "length" "4,8")])
2033
2034 (define_split
2035   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2036         (compare:CC
2037          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2038                               (match_operand:SI 2 "reg_or_short_operand" ""))
2039                           (const_int 0)
2040                           (minus:SI (match_dup 2) (match_dup 1)))
2041          (const_int 0)))
2042    (set (match_operand:SI 0 "gpc_reg_operand" "")
2043         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2044                          (const_int 0)
2045                          (minus:SI (match_dup 2) (match_dup 1))))]
2046   "TARGET_POWER && reload_completed"
2047   [(set (match_dup 0)
2048         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2049                          (const_int 0)
2050                          (minus:SI (match_dup 2) (match_dup 1))))
2051    (set (match_dup 3)
2052         (compare:CC (match_dup 0)
2053                     (const_int 0)))]
2054   "")
2055
2056 ;; We don't need abs with condition code because such comparisons should
2057 ;; never be done.
2058 (define_expand "abssi2"
2059   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2060         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2061   ""
2062   "
2063 {
2064   if (TARGET_ISEL)
2065     {
2066       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
2067       DONE;
2068     }
2069   else if (! TARGET_POWER)
2070     {
2071       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
2072       DONE;
2073     }
2074 }")
2075
2076 (define_insn "*abssi2_power"
2077   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2078         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2079   "TARGET_POWER"
2080   "abs %0,%1")
2081
2082 (define_insn_and_split "abs<mode>2_isel"
2083   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2084         (abs:GPR (match_operand:GPR 1 "gpc_reg_operand" "b")))
2085    (clobber (match_scratch:GPR 2 "=&b"))
2086    (clobber (match_scratch:CC 3 "=y"))]
2087   "TARGET_ISEL"
2088   "#"
2089   "&& reload_completed"
2090   [(set (match_dup 2) (neg:GPR (match_dup 1)))
2091    (set (match_dup 3)
2092         (compare:CC (match_dup 1)
2093                     (const_int 0)))
2094    (set (match_dup 0)
2095         (if_then_else:GPR (ge (match_dup 3)
2096                               (const_int 0))
2097                           (match_dup 1)
2098                           (match_dup 2)))]
2099   "")
2100
2101 (define_insn_and_split "nabs<mode>2_isel"
2102   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2103         (neg:GPR (abs:GPR (match_operand:GPR 1 "gpc_reg_operand" "b"))))
2104    (clobber (match_scratch:GPR 2 "=&b"))
2105    (clobber (match_scratch:CC 3 "=y"))]
2106   "TARGET_ISEL"
2107   "#"
2108   "&& reload_completed"
2109   [(set (match_dup 2) (neg:GPR (match_dup 1)))
2110    (set (match_dup 3)
2111         (compare:CC (match_dup 1)
2112                     (const_int 0)))
2113    (set (match_dup 0)
2114         (if_then_else:GPR (ge (match_dup 3)
2115                               (const_int 0))
2116                           (match_dup 2)
2117                           (match_dup 1)))]
2118   "")
2119
2120 (define_insn_and_split "abssi2_nopower"
2121   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2122         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2123    (clobber (match_scratch:SI 2 "=&r,&r"))]
2124   "! TARGET_POWER && ! TARGET_ISEL"
2125   "#"
2126   "&& reload_completed"
2127   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2128    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2129    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2130   "")
2131
2132 (define_insn "*nabs_power"
2133   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2134         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2135   "TARGET_POWER"
2136   "nabs %0,%1")
2137
2138 (define_insn_and_split "*nabs_nopower"
2139   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2140         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2141    (clobber (match_scratch:SI 2 "=&r,&r"))]
2142   "! TARGET_POWER"
2143   "#"
2144   "&& reload_completed"
2145   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2146    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2147    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2148   "")
2149
2150 (define_expand "neg<mode>2"
2151   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2152         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2153   ""
2154   "")
2155
2156 (define_insn "*neg<mode>2_internal"
2157   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2158         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2159   ""
2160   "neg %0,%1")
2161
2162 (define_insn ""
2163   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2164         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2165                     (const_int 0)))
2166    (clobber (match_scratch:P 2 "=r,r"))]
2167   ""
2168   "@
2169    neg. %2,%1
2170    #"
2171   [(set_attr "type" "fast_compare")
2172    (set_attr "length" "4,8")])
2173
2174 (define_split
2175   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2176         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2177                     (const_int 0)))
2178    (clobber (match_scratch:P 2 ""))]
2179   "reload_completed"
2180   [(set (match_dup 2)
2181         (neg:P (match_dup 1)))
2182    (set (match_dup 0)
2183         (compare:CC (match_dup 2)
2184                     (const_int 0)))]
2185   "")
2186
2187 (define_insn ""
2188   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2189         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2190                     (const_int 0)))
2191    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2192         (neg:P (match_dup 1)))]
2193   ""
2194   "@
2195    neg. %0,%1
2196    #"
2197   [(set_attr "type" "fast_compare")
2198    (set_attr "length" "4,8")])
2199
2200 (define_split
2201   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2202         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2203                     (const_int 0)))
2204    (set (match_operand:P 0 "gpc_reg_operand" "")
2205         (neg:P (match_dup 1)))]
2206   "reload_completed"
2207   [(set (match_dup 0)
2208         (neg:P (match_dup 1)))
2209    (set (match_dup 2)
2210         (compare:CC (match_dup 0)
2211                     (const_int 0)))]
2212   "")
2213
2214 (define_insn "clz<mode>2"
2215   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2216         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2217   ""
2218   "{cntlz|cntlz<wd>} %0,%1"
2219   [(set_attr "type" "cntlz")])
2220
2221 (define_expand "ctz<mode>2"
2222   [(set (match_dup 2)
2223         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2224    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2225                                           (match_dup 2)))
2226               (clobber (scratch:CC))])
2227    (set (match_dup 4) (clz:GPR (match_dup 3)))
2228    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2229         (minus:GPR (match_dup 5) (match_dup 4)))]
2230   ""
2231   {
2232      operands[2] = gen_reg_rtx (<MODE>mode);
2233      operands[3] = gen_reg_rtx (<MODE>mode);
2234      operands[4] = gen_reg_rtx (<MODE>mode);
2235      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2236   })
2237
2238 (define_expand "ffs<mode>2"
2239   [(set (match_dup 2)
2240         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2241    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2242                                           (match_dup 2)))
2243               (clobber (scratch:CC))])
2244    (set (match_dup 4) (clz:GPR (match_dup 3)))
2245    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2246         (minus:GPR (match_dup 5) (match_dup 4)))]
2247   ""
2248   {
2249      operands[2] = gen_reg_rtx (<MODE>mode);
2250      operands[3] = gen_reg_rtx (<MODE>mode);
2251      operands[4] = gen_reg_rtx (<MODE>mode);
2252      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2253   })
2254
2255 (define_insn "popcntb<mode>2"
2256   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2257         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2258                      UNSPEC_POPCNTB))]
2259   "TARGET_POPCNTB"
2260   "popcntb %0,%1")
2261
2262 (define_insn "popcntwsi2"
2263   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2264         (popcount:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2265   "TARGET_POPCNTD"
2266   "popcntw %0,%1")
2267
2268 (define_insn "popcntddi2"
2269   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2270         (popcount:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
2271   "TARGET_POPCNTD && TARGET_POWERPC64"
2272   "popcntd %0,%1")
2273
2274 (define_expand "popcount<mode>2"
2275   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2276         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2277   "TARGET_POPCNTB || TARGET_POPCNTD"
2278   {
2279     rs6000_emit_popcount (operands[0], operands[1]);
2280     DONE;
2281   })
2282
2283 (define_expand "parity<mode>2"
2284   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2285         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2286   "TARGET_POPCNTB"
2287   {
2288     rs6000_emit_parity (operands[0], operands[1]);
2289     DONE;
2290   })
2291
2292 ;; Since the hardware zeros the upper part of the register, save generating the
2293 ;; AND immediate if we are converting to unsigned
2294 (define_insn "*bswaphi2_extenddi"
2295   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2296         (zero_extend:DI
2297          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2298   "TARGET_POWERPC64"
2299   "lhbrx %0,%y1"
2300   [(set_attr "length" "4")
2301    (set_attr "type" "load")])
2302
2303 (define_insn "*bswaphi2_extendsi"
2304   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2305         (zero_extend:SI
2306          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2307   "TARGET_POWERPC"
2308   "lhbrx %0,%y1"
2309   [(set_attr "length" "4")
2310    (set_attr "type" "load")])
2311
2312 (define_expand "bswaphi2"
2313   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
2314                    (bswap:HI
2315                     (match_operand:HI 1 "reg_or_mem_operand" "")))
2316               (clobber (match_scratch:SI 2 ""))])]
2317   ""
2318 {
2319   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2320     operands[1] = force_reg (HImode, operands[1]);
2321 })
2322
2323 (define_insn "bswaphi2_internal"
2324   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
2325         (bswap:HI
2326          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
2327    (clobber (match_scratch:SI 2 "=X,X,&r"))]
2328   "TARGET_POWERPC"
2329   "@
2330    lhbrx %0,%y1
2331    sthbrx %1,%y0
2332    #"
2333   [(set_attr "length" "4,4,12")
2334    (set_attr "type" "load,store,*")])
2335
2336 (define_split
2337   [(set (match_operand:HI 0 "gpc_reg_operand" "")
2338         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
2339    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2340   "TARGET_POWERPC && reload_completed"
2341   [(set (match_dup 3)
2342         (zero_extract:SI (match_dup 4)
2343                          (const_int 8)
2344                          (const_int 16)))
2345    (set (match_dup 2)
2346         (and:SI (ashift:SI (match_dup 4)
2347                            (const_int 8))
2348                 (const_int 65280)))             ;; 0xff00
2349    (set (match_dup 3)
2350         (ior:SI (match_dup 3)
2351                 (match_dup 2)))]
2352   "
2353 {
2354   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2355   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2356 }")
2357
2358 (define_insn "*bswapsi2_extenddi"
2359   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2360         (zero_extend:DI
2361          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2362   "TARGET_POWERPC64"
2363   "lwbrx %0,%y1"
2364   [(set_attr "length" "4")
2365    (set_attr "type" "load")])
2366
2367 (define_expand "bswapsi2"
2368   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2369         (bswap:SI
2370          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2371   ""
2372 {
2373   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2374     operands[1] = force_reg (SImode, operands[1]);
2375 })
2376
2377 (define_insn "*bswapsi2_internal"
2378   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2379         (bswap:SI
2380          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2381   ""
2382   "@
2383    {lbrx|lwbrx} %0,%y1
2384    {stbrx|stwbrx} %1,%y0
2385    #"
2386   [(set_attr "length" "4,4,12")
2387    (set_attr "type" "load,store,*")])
2388
2389 (define_split
2390   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2391         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2392   "reload_completed"
2393   [(set (match_dup 0)
2394         (rotate:SI (match_dup 1) (const_int 8)))
2395    (set (zero_extract:SI (match_dup 0)
2396                          (const_int 8)
2397                          (const_int 0))
2398         (match_dup 1))
2399    (set (zero_extract:SI (match_dup 0)
2400                          (const_int 8)
2401                          (const_int 16))
2402         (rotate:SI (match_dup 1)
2403                    (const_int 16)))]
2404   "")
2405
2406 (define_expand "bswapdi2"
2407   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2408                    (bswap:DI
2409                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2410               (clobber (match_scratch:DI 2 ""))
2411               (clobber (match_scratch:DI 3 ""))
2412               (clobber (match_scratch:DI 4 ""))])]
2413   ""
2414 {
2415   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2416     operands[1] = force_reg (DImode, operands[1]);
2417
2418   if (!TARGET_POWERPC64)
2419     {
2420       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2421          that uses 64-bit registers needs the same scratch registers as 64-bit
2422          mode.  */
2423       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2424       DONE;
2425     }
2426 })
2427
2428 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2429 (define_insn "*bswapdi2_ldbrx"
2430   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2431         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2432    (clobber (match_scratch:DI 2 "=X,X,&r"))
2433    (clobber (match_scratch:DI 3 "=X,X,&r"))
2434    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2435   "TARGET_POWERPC64 && TARGET_LDBRX
2436    && (REG_P (operands[0]) || REG_P (operands[1]))"
2437   "@
2438    ldbrx %0,%y1
2439    stdbrx %1,%y0
2440    #"
2441   [(set_attr "length" "4,4,36")
2442    (set_attr "type" "load,store,*")])
2443
2444 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2445 (define_insn "*bswapdi2_64bit"
2446   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2447         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2448    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2449    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2450    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2451   "TARGET_POWERPC64 && !TARGET_LDBRX
2452    && (REG_P (operands[0]) || REG_P (operands[1]))"
2453   "#"
2454   [(set_attr "length" "16,12,36")])
2455
2456 (define_split
2457   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2458         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2459    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2460    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2461    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2462   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2463   [(const_int 0)]
2464   "
2465 {
2466   rtx dest   = operands[0];
2467   rtx src    = operands[1];
2468   rtx op2    = operands[2];
2469   rtx op3    = operands[3];
2470   rtx op4    = operands[4];
2471   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode, 4);
2472   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode, 4);
2473   rtx addr1;
2474   rtx addr2;
2475   rtx word_high;
2476   rtx word_low;
2477
2478   addr1 = XEXP (src, 0);
2479   if (GET_CODE (addr1) == PLUS)
2480     {
2481       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2482       addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2483     }
2484   else
2485     {
2486       emit_move_insn (op2, GEN_INT (4));
2487       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2488     }
2489
2490   if (BYTES_BIG_ENDIAN)
2491     {
2492       word_high = change_address (src, SImode, addr1);
2493       word_low  = change_address (src, SImode, addr2);
2494     }
2495   else
2496     {
2497       word_high = change_address (src, SImode, addr2);
2498       word_low  = change_address (src, SImode, addr1);
2499     }
2500
2501   emit_insn (gen_bswapsi2 (op3_32, word_low));
2502   emit_insn (gen_bswapsi2 (op4_32, word_high));
2503   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2504   emit_insn (gen_iordi3 (dest, dest, op4));
2505 }")
2506
2507 (define_split
2508   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2509         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2510    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2511    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2512    (clobber (match_operand:DI 4 "" ""))]
2513   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2514   [(const_int 0)]
2515   "
2516 {
2517   rtx dest   = operands[0];
2518   rtx src    = operands[1];
2519   rtx op2    = operands[2];
2520   rtx op3    = operands[3];
2521   rtx src_si = simplify_gen_subreg (SImode, src, DImode, 4);
2522   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode, 4);
2523   rtx addr1;
2524   rtx addr2;
2525   rtx word_high;
2526   rtx word_low;
2527
2528   addr1 = XEXP (dest, 0);
2529   if (GET_CODE (addr1) == PLUS)
2530     {
2531       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2532       addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2533     }
2534   else
2535     {
2536       emit_move_insn (op2, GEN_INT (4));
2537       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2538     }
2539
2540   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2541   if (BYTES_BIG_ENDIAN)
2542     {
2543       word_high = change_address (dest, SImode, addr1);
2544       word_low  = change_address (dest, SImode, addr2);
2545       emit_insn (gen_bswapsi2 (word_high, src_si));
2546       emit_insn (gen_bswapsi2 (word_low, op3_si));
2547     }
2548   else
2549     {
2550       word_high = change_address (dest, SImode, addr2);
2551       word_low  = change_address (dest, SImode, addr1);
2552       emit_insn (gen_bswapsi2 (word_low, src_si));
2553       emit_insn (gen_bswapsi2 (word_high, op3_si));
2554     }
2555 }")
2556
2557 (define_split
2558   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2559         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2560    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2561    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2562    (clobber (match_operand:DI 4 "" ""))]
2563   "TARGET_POWERPC64 && reload_completed"
2564   [(const_int 0)]
2565   "
2566 {
2567   rtx dest    = operands[0];
2568   rtx src     = operands[1];
2569   rtx op2     = operands[2];
2570   rtx op3     = operands[3];
2571   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, 4);
2572   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, 4);
2573   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, 4);
2574   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, 4);
2575
2576   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2577   emit_insn (gen_bswapsi2 (dest_si, src_si));
2578   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2579   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2580   emit_insn (gen_iordi3 (dest, dest, op3));
2581 }")
2582
2583 (define_insn "bswapdi2_32bit"
2584   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2585         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2586    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2587   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2588   "#"
2589   [(set_attr "length" "16,12,36")])
2590
2591 (define_split
2592   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2593         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2594    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2595   "!TARGET_POWERPC64 && reload_completed"
2596   [(const_int 0)]
2597   "
2598 {
2599   rtx dest   = operands[0];
2600   rtx src    = operands[1];
2601   rtx op2    = operands[2];
2602   rtx dest_hi = simplify_gen_subreg (SImode, dest, DImode, 0);
2603   rtx dest_lo = simplify_gen_subreg (SImode, dest, DImode, 4);
2604   rtx addr1;
2605   rtx addr2;
2606   rtx word_high;
2607   rtx word_low;
2608
2609   addr1 = XEXP (src, 0);
2610   if (GET_CODE (addr1) == PLUS)
2611     {
2612       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2613       addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2614     }
2615   else
2616     {
2617       emit_move_insn (op2, GEN_INT (4));
2618       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2619     }
2620
2621   if (BYTES_BIG_ENDIAN)
2622     {
2623       word_high = change_address (src, SImode, addr1);
2624       word_low  = change_address (src, SImode, addr2);
2625     }
2626   else
2627     {
2628       word_high = change_address (src, SImode, addr2);
2629       word_low  = change_address (src, SImode, addr1);
2630     }
2631
2632   emit_insn (gen_bswapsi2 (dest_hi, word_low));
2633   emit_insn (gen_bswapsi2 (dest_lo, word_high));
2634 }")
2635
2636 (define_split
2637   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2638         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2639    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2640   "!TARGET_POWERPC64 && reload_completed"
2641   [(const_int 0)]
2642   "
2643 {
2644   rtx dest     = operands[0];
2645   rtx src      = operands[1];
2646   rtx op2      = operands[2];
2647   rtx src_high = simplify_gen_subreg (SImode, src, DImode, 0);
2648   rtx src_low  = simplify_gen_subreg (SImode, src, DImode, 4);
2649   rtx addr1;
2650   rtx addr2;
2651   rtx word_high;
2652   rtx word_low;
2653
2654   addr1 = XEXP (dest, 0);
2655   if (GET_CODE (addr1) == PLUS)
2656     {
2657       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2658       addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2659     }
2660   else
2661     {
2662       emit_move_insn (op2, GEN_INT (4));
2663       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2664     }
2665
2666   if (BYTES_BIG_ENDIAN)
2667     {
2668       word_high = change_address (dest, SImode, addr1);
2669       word_low  = change_address (dest, SImode, addr2);
2670     }
2671   else
2672     {
2673       word_high = change_address (dest, SImode, addr2);
2674       word_low  = change_address (dest, SImode, addr1);
2675     }
2676
2677   emit_insn (gen_bswapsi2 (word_high, src_low));
2678   emit_insn (gen_bswapsi2 (word_low, src_high));
2679 }")
2680
2681 (define_split
2682   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2683         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2684    (clobber (match_operand:SI 2 "" ""))]
2685   "!TARGET_POWERPC64 && reload_completed"
2686   [(const_int 0)]
2687   "
2688 {
2689   rtx dest      = operands[0];
2690   rtx src       = operands[1];
2691   rtx src_high  = simplify_gen_subreg (SImode, src, DImode, 0);
2692   rtx src_low   = simplify_gen_subreg (SImode, src, DImode, 4);
2693   rtx dest_high = simplify_gen_subreg (SImode, dest, DImode, 0);
2694   rtx dest_low  = simplify_gen_subreg (SImode, dest, DImode, 4);
2695
2696   emit_insn (gen_bswapsi2 (dest_high, src_low));
2697   emit_insn (gen_bswapsi2 (dest_low, src_high));
2698 }")
2699
2700 (define_expand "mulsi3"
2701   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2702    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2703    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2704   ""
2705   "
2706 {
2707   if (TARGET_POWER)
2708     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2709   else
2710     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2711   DONE;
2712 }")
2713
2714 (define_insn "mulsi3_mq"
2715   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2716         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2717                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2718    (clobber (match_scratch:SI 3 "=q,q"))]
2719   "TARGET_POWER"
2720   "@
2721    {muls|mullw} %0,%1,%2
2722    {muli|mulli} %0,%1,%2"
2723    [(set (attr "type")
2724       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2725                 (const_string "imul3")
2726              (match_operand:SI 2 "short_cint_operand" "")
2727                 (const_string "imul2")]
2728         (const_string "imul")))])
2729
2730 (define_insn "mulsi3_no_mq"
2731   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2732         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2733                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2734   "! TARGET_POWER"
2735   "@
2736    {muls|mullw} %0,%1,%2
2737    {muli|mulli} %0,%1,%2"
2738    [(set (attr "type")
2739       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2740                 (const_string "imul3")
2741              (match_operand:SI 2 "short_cint_operand" "")
2742                 (const_string "imul2")]
2743         (const_string "imul")))])
2744
2745 (define_insn "*mulsi3_mq_internal1"
2746   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2747         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2748                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2749                     (const_int 0)))
2750    (clobber (match_scratch:SI 3 "=r,r"))
2751    (clobber (match_scratch:SI 4 "=q,q"))]
2752   "TARGET_POWER"
2753   "@
2754    {muls.|mullw.} %3,%1,%2
2755    #"
2756   [(set_attr "type" "imul_compare")
2757    (set_attr "length" "4,8")])
2758
2759 (define_split
2760   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2761         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2762                              (match_operand:SI 2 "gpc_reg_operand" ""))
2763                     (const_int 0)))
2764    (clobber (match_scratch:SI 3 ""))
2765    (clobber (match_scratch:SI 4 ""))]
2766   "TARGET_POWER && reload_completed"
2767   [(parallel [(set (match_dup 3)
2768         (mult:SI (match_dup 1) (match_dup 2)))
2769    (clobber (match_dup 4))])
2770    (set (match_dup 0)
2771         (compare:CC (match_dup 3)
2772                     (const_int 0)))]
2773   "")
2774
2775 (define_insn "*mulsi3_no_mq_internal1"
2776   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2777         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2778                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2779                     (const_int 0)))
2780    (clobber (match_scratch:SI 3 "=r,r"))]
2781   "! TARGET_POWER"
2782   "@
2783    {muls.|mullw.} %3,%1,%2
2784    #"
2785   [(set_attr "type" "imul_compare")
2786    (set_attr "length" "4,8")])
2787
2788 (define_split
2789   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2790         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2791                              (match_operand:SI 2 "gpc_reg_operand" ""))
2792                     (const_int 0)))
2793    (clobber (match_scratch:SI 3 ""))]
2794   "! TARGET_POWER && reload_completed"
2795   [(set (match_dup 3)
2796         (mult:SI (match_dup 1) (match_dup 2)))
2797    (set (match_dup 0)
2798         (compare:CC (match_dup 3)
2799                     (const_int 0)))]
2800   "")
2801
2802 (define_insn "*mulsi3_mq_internal2"
2803   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2804         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2805                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2806                     (const_int 0)))
2807    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2808         (mult:SI (match_dup 1) (match_dup 2)))
2809    (clobber (match_scratch:SI 4 "=q,q"))]
2810   "TARGET_POWER"
2811   "@
2812    {muls.|mullw.} %0,%1,%2
2813    #"
2814   [(set_attr "type" "imul_compare")
2815    (set_attr "length" "4,8")])
2816
2817 (define_split
2818   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2819         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2820                              (match_operand:SI 2 "gpc_reg_operand" ""))
2821                     (const_int 0)))
2822    (set (match_operand:SI 0 "gpc_reg_operand" "")
2823         (mult:SI (match_dup 1) (match_dup 2)))
2824    (clobber (match_scratch:SI 4 ""))]
2825   "TARGET_POWER && reload_completed"
2826   [(parallel [(set (match_dup 0)
2827         (mult:SI (match_dup 1) (match_dup 2)))
2828    (clobber (match_dup 4))])
2829    (set (match_dup 3)
2830         (compare:CC (match_dup 0)
2831                     (const_int 0)))]
2832   "")
2833
2834 (define_insn "*mulsi3_no_mq_internal2"
2835   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2836         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2837                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2838                     (const_int 0)))
2839    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2840         (mult:SI (match_dup 1) (match_dup 2)))]
2841   "! TARGET_POWER"
2842   "@
2843    {muls.|mullw.} %0,%1,%2
2844    #"
2845   [(set_attr "type" "imul_compare")
2846    (set_attr "length" "4,8")])
2847
2848 (define_split
2849   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2850         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2851                              (match_operand:SI 2 "gpc_reg_operand" ""))
2852                     (const_int 0)))
2853    (set (match_operand:SI 0 "gpc_reg_operand" "")
2854         (mult:SI (match_dup 1) (match_dup 2)))]
2855   "! TARGET_POWER && reload_completed"
2856   [(set (match_dup 0)
2857         (mult:SI (match_dup 1) (match_dup 2)))
2858    (set (match_dup 3)
2859         (compare:CC (match_dup 0)
2860                     (const_int 0)))]
2861   "")
2862
2863 ;; Operand 1 is divided by operand 2; quotient goes to operand
2864 ;; 0 and remainder to operand 3.
2865 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2866
2867 (define_expand "divmodsi4"
2868   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2869                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2870                            (match_operand:SI 2 "gpc_reg_operand" "")))
2871               (set (match_operand:SI 3 "register_operand" "")
2872                    (mod:SI (match_dup 1) (match_dup 2)))])]
2873   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2874   "
2875 {
2876   if (! TARGET_POWER && ! TARGET_POWERPC)
2877     {
2878       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2879       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2880       emit_insn (gen_divss_call ());
2881       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2882       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2883       DONE;
2884     }
2885 }")
2886
2887 (define_insn "*divmodsi4_internal"
2888   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2889         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2890                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2891    (set (match_operand:SI 3 "register_operand" "=q")
2892         (mod:SI (match_dup 1) (match_dup 2)))]
2893   "TARGET_POWER"
2894   "divs %0,%1,%2"
2895   [(set_attr "type" "idiv")])
2896
2897 (define_expand "udiv<mode>3"
2898   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2899         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2900                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2901   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2902   "
2903 {
2904   if (! TARGET_POWER && ! TARGET_POWERPC)
2905     {
2906       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2907       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2908       emit_insn (gen_quous_call ());
2909       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2910       DONE;
2911     }
2912   else if (TARGET_POWER)
2913     {
2914       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2915       DONE;
2916     }
2917 }")
2918
2919 (define_insn "udivsi3_mq"
2920   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2921         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2922                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2923    (clobber (match_scratch:SI 3 "=q"))]
2924   "TARGET_POWERPC && TARGET_POWER"
2925   "divwu %0,%1,%2"
2926   [(set_attr "type" "idiv")])
2927
2928 (define_insn "*udivsi3_no_mq"
2929   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2930         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2931                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2932   "TARGET_POWERPC && ! TARGET_POWER"
2933   "div<wd>u %0,%1,%2"
2934    [(set (attr "type")
2935       (cond [(match_operand:SI 0 "" "")
2936                 (const_string "idiv")]
2937         (const_string "ldiv")))])
2938
2939
2940 ;; For powers of two we can do srai/aze for divide and then adjust for
2941 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2942 ;; used; for PowerPC, force operands into register and do a normal divide;
2943 ;; for AIX common-mode, use quoss call on register operands.
2944 (define_expand "div<mode>3"
2945   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2946         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2947                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2948   ""
2949   "
2950 {
2951   if (GET_CODE (operands[2]) == CONST_INT
2952       && INTVAL (operands[2]) > 0
2953       && exact_log2 (INTVAL (operands[2])) >= 0)
2954     ;
2955   else if (TARGET_POWERPC)
2956     {
2957       operands[2] = force_reg (<MODE>mode, operands[2]);
2958       if (TARGET_POWER)
2959         {
2960           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2961           DONE;
2962         }
2963     }
2964   else if (TARGET_POWER)
2965     FAIL;
2966   else
2967     {
2968       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2969       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2970       emit_insn (gen_quoss_call ());
2971       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2972       DONE;
2973     }
2974 }")
2975
2976 (define_insn "divsi3_mq"
2977   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2978         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2979                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2980    (clobber (match_scratch:SI 3 "=q"))]
2981   "TARGET_POWERPC && TARGET_POWER"
2982   "divw %0,%1,%2"
2983   [(set_attr "type" "idiv")])
2984
2985 (define_insn "*div<mode>3_no_mq"
2986   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2987         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2988                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2989   "TARGET_POWERPC && ! TARGET_POWER"
2990   "div<wd> %0,%1,%2"
2991   [(set (attr "type")
2992      (cond [(match_operand:SI 0 "" "")
2993                 (const_string "idiv")]
2994         (const_string "ldiv")))])
2995
2996 (define_expand "mod<mode>3"
2997   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2998    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2999    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
3000   ""
3001   "
3002 {
3003   int i;
3004   rtx temp1;
3005   rtx temp2;
3006
3007   if (GET_CODE (operands[2]) != CONST_INT
3008       || INTVAL (operands[2]) <= 0
3009       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
3010     FAIL;
3011
3012   temp1 = gen_reg_rtx (<MODE>mode);
3013   temp2 = gen_reg_rtx (<MODE>mode);
3014
3015   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
3016   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
3017   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
3018   DONE;
3019 }")
3020
3021 (define_insn ""
3022   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3023         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3024                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
3025   ""
3026   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
3027   [(set_attr "type" "two")
3028    (set_attr "length" "8")])
3029
3030 (define_insn ""
3031   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3032         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
3033                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
3034                     (const_int 0)))
3035    (clobber (match_scratch:P 3 "=r,r"))]
3036   ""
3037   "@
3038    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
3039    #"
3040   [(set_attr "type" "compare")
3041    (set_attr "length" "8,12")
3042    (set_attr "cell_micro" "not")])
3043
3044 (define_split
3045   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3046         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3047                              (match_operand:GPR 2 "exact_log2_cint_operand"
3048                               ""))
3049                     (const_int 0)))
3050    (clobber (match_scratch:GPR 3 ""))]
3051   "reload_completed"
3052   [(set (match_dup 3)
3053         (div:<MODE> (match_dup 1) (match_dup 2)))
3054    (set (match_dup 0)
3055         (compare:CC (match_dup 3)
3056                     (const_int 0)))]
3057   "")
3058
3059 (define_insn ""
3060   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3061         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
3062                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
3063                     (const_int 0)))
3064    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
3065         (div:P (match_dup 1) (match_dup 2)))]
3066   ""
3067   "@
3068    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
3069    #"
3070   [(set_attr "type" "compare")
3071    (set_attr "length" "8,12")
3072    (set_attr "cell_micro" "not")])
3073
3074 (define_split
3075   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3076         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3077                              (match_operand:GPR 2 "exact_log2_cint_operand"
3078                               ""))
3079                     (const_int 0)))
3080    (set (match_operand:GPR 0 "gpc_reg_operand" "")
3081         (div:GPR (match_dup 1) (match_dup 2)))]
3082   "reload_completed"
3083   [(set (match_dup 0)
3084         (div:<MODE> (match_dup 1) (match_dup 2)))
3085    (set (match_dup 3)
3086         (compare:CC (match_dup 0)
3087                     (const_int 0)))]
3088   "")
3089
3090 (define_insn ""
3091   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3092         (udiv:SI
3093          (plus:DI (ashift:DI
3094                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
3095                    (const_int 32))
3096                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
3097          (match_operand:SI 3 "gpc_reg_operand" "r")))
3098    (set (match_operand:SI 2 "register_operand" "=*q")
3099         (umod:SI
3100          (plus:DI (ashift:DI
3101                    (zero_extend:DI (match_dup 1)) (const_int 32))
3102                   (zero_extend:DI (match_dup 4)))
3103          (match_dup 3)))]
3104   "TARGET_POWER"
3105   "div %0,%1,%3"
3106   [(set_attr "type" "idiv")])
3107
3108 ;; To do unsigned divide we handle the cases of the divisor looking like a
3109 ;; negative number.  If it is a constant that is less than 2**31, we don't
3110 ;; have to worry about the branches.  So make a few subroutines here.
3111 ;;
3112 ;; First comes the normal case.
3113 (define_expand "udivmodsi4_normal"
3114   [(set (match_dup 4) (const_int 0))
3115    (parallel [(set (match_operand:SI 0 "" "")
3116                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
3117                                                 (const_int 32))
3118                                      (zero_extend:DI (match_operand:SI 1 "" "")))
3119                             (match_operand:SI 2 "" "")))
3120               (set (match_operand:SI 3 "" "")
3121                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
3122                                                 (const_int 32))
3123                                      (zero_extend:DI (match_dup 1)))
3124                             (match_dup 2)))])]
3125   "TARGET_POWER"
3126   "
3127 { operands[4] = gen_reg_rtx (SImode); }")
3128
3129 ;; This handles the branches.
3130 (define_expand "udivmodsi4_tests"
3131   [(set (match_operand:SI 0 "" "") (const_int 0))
3132    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
3133    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
3134    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
3135                            (label_ref (match_operand:SI 4 "" "")) (pc)))
3136    (set (match_dup 0) (const_int 1))
3137    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
3138    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
3139    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
3140                            (label_ref (match_dup 4)) (pc)))]
3141   "TARGET_POWER"
3142   "
3143 { operands[5] = gen_reg_rtx (CCUNSmode);
3144   operands[6] = gen_reg_rtx (CCmode);
3145 }")
3146
3147 (define_expand "udivmodsi4"
3148   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
3149                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
3150                             (match_operand:SI 2 "reg_or_cint_operand" "")))
3151               (set (match_operand:SI 3 "gpc_reg_operand" "")
3152                    (umod:SI (match_dup 1) (match_dup 2)))])]
3153   ""
3154   "
3155 {
3156   rtx label = 0;
3157
3158   if (! TARGET_POWER)
3159     {
3160       if (! TARGET_POWERPC)
3161         {
3162           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
3163           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
3164           emit_insn (gen_divus_call ());
3165           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
3166           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
3167           DONE;
3168         }
3169       else
3170         FAIL;
3171     }
3172
3173   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
3174     {
3175       operands[2] = force_reg (SImode, operands[2]);
3176       label = gen_label_rtx ();
3177       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
3178                                   operands[3], label));
3179     }
3180   else
3181     operands[2] = force_reg (SImode, operands[2]);
3182
3183   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
3184                                operands[3]));
3185   if (label)
3186     emit_label (label);
3187
3188   DONE;
3189 }")
3190
3191 ;; AIX architecture-independent common-mode multiply (DImode),
3192 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
3193 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
3194 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
3195 ;; assumed unused if generating common-mode, so ignore.
3196 (define_insn "mulh_call"
3197   [(set (reg:SI 3)
3198         (truncate:SI
3199          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
3200                                (sign_extend:DI (reg:SI 4)))
3201                       (const_int 32))))
3202    (clobber (reg:SI LR_REGNO))]
3203   "! TARGET_POWER && ! TARGET_POWERPC"
3204   "bla __mulh"
3205   [(set_attr "type" "imul")])
3206
3207 (define_insn "mull_call"
3208   [(set (reg:DI 3)
3209         (mult:DI (sign_extend:DI (reg:SI 3))
3210                  (sign_extend:DI (reg:SI 4))))
3211    (clobber (reg:SI LR_REGNO))
3212    (clobber (reg:SI 0))]
3213   "! TARGET_POWER && ! TARGET_POWERPC"
3214   "bla __mull"
3215   [(set_attr "type" "imul")])
3216
3217 (define_insn "divss_call"
3218   [(set (reg:SI 3)
3219         (div:SI (reg:SI 3) (reg:SI 4)))
3220    (set (reg:SI 4)
3221         (mod:SI (reg:SI 3) (reg:SI 4)))
3222    (clobber (reg:SI LR_REGNO))
3223    (clobber (reg:SI 0))]
3224   "! TARGET_POWER && ! TARGET_POWERPC"
3225   "bla __divss"
3226   [(set_attr "type" "idiv")])
3227
3228 (define_insn "divus_call"
3229   [(set (reg:SI 3)
3230         (udiv:SI (reg:SI 3) (reg:SI 4)))
3231    (set (reg:SI 4)
3232         (umod:SI (reg:SI 3) (reg:SI 4)))
3233    (clobber (reg:SI LR_REGNO))
3234    (clobber (reg:SI 0))
3235    (clobber (match_scratch:CC 0 "=x"))
3236    (clobber (reg:CC CR1_REGNO))]
3237   "! TARGET_POWER && ! TARGET_POWERPC"
3238   "bla __divus"
3239   [(set_attr "type" "idiv")])
3240
3241 (define_insn "quoss_call"
3242   [(set (reg:SI 3)
3243         (div:SI (reg:SI 3) (reg:SI 4)))
3244    (clobber (reg:SI LR_REGNO))]
3245   "! TARGET_POWER && ! TARGET_POWERPC"
3246   "bla __quoss"
3247   [(set_attr "type" "idiv")])
3248
3249 (define_insn "quous_call"
3250   [(set (reg:SI 3)
3251         (udiv:SI (reg:SI 3) (reg:SI 4)))
3252    (clobber (reg:SI LR_REGNO))
3253    (clobber (reg:SI 0))
3254    (clobber (match_scratch:CC 0 "=x"))
3255    (clobber (reg:CC CR1_REGNO))]
3256   "! TARGET_POWER && ! TARGET_POWERPC"
3257   "bla __quous"
3258   [(set_attr "type" "idiv")])
3259 \f
3260 ;; Logical instructions
3261 ;; The logical instructions are mostly combined by using match_operator,
3262 ;; but the plain AND insns are somewhat different because there is no
3263 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
3264 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
3265
3266 (define_expand "andsi3"
3267   [(parallel
3268     [(set (match_operand:SI 0 "gpc_reg_operand" "")
3269           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3270                   (match_operand:SI 2 "and_operand" "")))
3271      (clobber (match_scratch:CC 3 ""))])]
3272   ""
3273   "")
3274
3275 (define_insn "andsi3_mc"
3276   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3277         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
3278                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
3279    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
3280   "rs6000_gen_cell_microcode"
3281   "@
3282    and %0,%1,%2
3283    {rlinm|rlwinm} %0,%1,0,%m2,%M2
3284    {andil.|andi.} %0,%1,%b2
3285    {andiu.|andis.} %0,%1,%u2"
3286   [(set_attr "type" "*,*,fast_compare,fast_compare")])
3287
3288 (define_insn "andsi3_nomc"
3289   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3290         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
3291                 (match_operand:SI 2 "and_operand" "?r,T")))
3292    (clobber (match_scratch:CC 3 "=X,X"))]
3293   "!rs6000_gen_cell_microcode"
3294   "@
3295    and %0,%1,%2
3296    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
3297
3298 (define_insn "andsi3_internal0_nomc"
3299   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3300         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
3301                 (match_operand:SI 2 "and_operand" "?r,T")))]
3302   "!rs6000_gen_cell_microcode"
3303   "@
3304    and %0,%1,%2
3305    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
3306
3307
3308 ;; Note to set cr's other than cr0 we do the and immediate and then
3309 ;; the test again -- this avoids a mfcr which on the higher end
3310 ;; machines causes an execution serialization
3311
3312 (define_insn "*andsi3_internal2_mc"
3313   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3314         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3315                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3316                     (const_int 0)))
3317    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
3318    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3319   "TARGET_32BIT && rs6000_gen_cell_microcode"
3320   "@
3321    and. %3,%1,%2
3322    {andil.|andi.} %3,%1,%b2
3323    {andiu.|andis.} %3,%1,%u2
3324    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
3325    #
3326    #
3327    #
3328    #"
3329   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
3330                      compare,compare,compare,compare")
3331    (set_attr "length" "4,4,4,4,8,8,8,8")])
3332
3333 (define_insn "*andsi3_internal3_mc"
3334   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3335         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3336                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3337                     (const_int 0)))
3338    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
3339    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3340   "TARGET_64BIT && rs6000_gen_cell_microcode"
3341   "@
3342    #
3343    {andil.|andi.} %3,%1,%b2
3344    {andiu.|andis.} %3,%1,%u2
3345    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
3346    #
3347    #
3348    #
3349    #"
3350   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
3351                      compare,compare,compare")
3352    (set_attr "length" "8,4,4,4,8,8,8,8")])
3353
3354 (define_split
3355   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3356         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3357                              (match_operand:GPR 2 "and_operand" ""))
3358                     (const_int 0)))
3359    (clobber (match_scratch:GPR 3 ""))
3360    (clobber (match_scratch:CC 4 ""))]
3361   "reload_completed"
3362   [(parallel [(set (match_dup 3)
3363                    (and:<MODE> (match_dup 1)
3364                                (match_dup 2)))
3365               (clobber (match_dup 4))])
3366    (set (match_dup 0)
3367         (compare:CC (match_dup 3)
3368                     (const_int 0)))]
3369   "")
3370
3371 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
3372 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
3373
3374 (define_split
3375   [(set (match_operand:CC 0 "cc_reg_operand" "")
3376         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3377                             (match_operand:SI 2 "gpc_reg_operand" ""))
3378                     (const_int 0)))
3379    (clobber (match_scratch:SI 3 ""))
3380    (clobber (match_scratch:CC 4 ""))]
3381   "TARGET_POWERPC64 && reload_completed"
3382   [(parallel [(set (match_dup 3)
3383                    (and:SI (match_dup 1)
3384                            (match_dup 2)))
3385               (clobber (match_dup 4))])
3386    (set (match_dup 0)
3387         (compare:CC (match_dup 3)
3388                     (const_int 0)))]
3389   "")
3390
3391 (define_insn "*andsi3_internal4"
3392   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3393         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3394                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3395                     (const_int 0)))
3396    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3397         (and:SI (match_dup 1)
3398                 (match_dup 2)))
3399    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3400   "TARGET_32BIT && rs6000_gen_cell_microcode"
3401   "@
3402    and. %0,%1,%2
3403    {andil.|andi.} %0,%1,%b2
3404    {andiu.|andis.} %0,%1,%u2
3405    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3406    #
3407    #
3408    #
3409    #"
3410   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
3411                      compare,compare,compare,compare")
3412    (set_attr "length" "4,4,4,4,8,8,8,8")])
3413
3414 (define_insn "*andsi3_internal5_mc"
3415   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3416         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3417                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3418                     (const_int 0)))
3419    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3420         (and:SI (match_dup 1)
3421                 (match_dup 2)))
3422    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3423   "TARGET_64BIT && rs6000_gen_cell_microcode"
3424   "@
3425    #
3426    {andil.|andi.} %0,%1,%b2
3427    {andiu.|andis.} %0,%1,%u2
3428    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3429    #
3430    #
3431    #
3432    #"
3433   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
3434                      compare,compare,compare")
3435    (set_attr "length" "8,4,4,4,8,8,8,8")])
3436
3437 (define_split
3438   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3439         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3440                             (match_operand:SI 2 "and_operand" ""))
3441                     (const_int 0)))
3442    (set (match_operand:SI 0 "gpc_reg_operand" "")
3443         (and:SI (match_dup 1)
3444                 (match_dup 2)))
3445    (clobber (match_scratch:CC 4 ""))]
3446   "reload_completed"
3447   [(parallel [(set (match_dup 0)
3448                    (and:SI (match_dup 1)
3449                            (match_dup 2)))
3450               (clobber (match_dup 4))])
3451    (set (match_dup 3)
3452         (compare:CC (match_dup 0)
3453                     (const_int 0)))]
3454   "")
3455
3456 (define_split
3457   [(set (match_operand:CC 3 "cc_reg_operand" "")
3458         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3459                             (match_operand:SI 2 "gpc_reg_operand" ""))
3460                     (const_int 0)))
3461    (set (match_operand:SI 0 "gpc_reg_operand" "")
3462         (and:SI (match_dup 1)
3463                 (match_dup 2)))
3464    (clobber (match_scratch:CC 4 ""))]
3465   "TARGET_POWERPC64 && reload_completed"
3466   [(parallel [(set (match_dup 0)
3467                    (and:SI (match_dup 1)
3468                            (match_dup 2)))
3469               (clobber (match_dup 4))])
3470    (set (match_dup 3)
3471         (compare:CC (match_dup 0)
3472                     (const_int 0)))]
3473   "")
3474
3475 ;; Handle the PowerPC64 rlwinm corner case
3476
3477 (define_insn_and_split "*andsi3_internal6"
3478   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3479         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3480                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3481   "TARGET_POWERPC64"
3482   "#"
3483   "TARGET_POWERPC64"
3484   [(set (match_dup 0)
3485         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3486                 (match_dup 4)))
3487    (set (match_dup 0)
3488         (rotate:SI (match_dup 0) (match_dup 5)))]
3489   "
3490 {
3491   int mb = extract_MB (operands[2]);
3492   int me = extract_ME (operands[2]);
3493   operands[3] = GEN_INT (me + 1);
3494   operands[5] = GEN_INT (32 - (me + 1));
3495   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3496 }"
3497   [(set_attr "length" "8")])
3498
3499 (define_expand "iorsi3"
3500   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3501         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3502                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3503   ""
3504   "
3505 {
3506   if (GET_CODE (operands[2]) == CONST_INT
3507       && ! logical_operand (operands[2], SImode))
3508     {
3509       HOST_WIDE_INT value = INTVAL (operands[2]);
3510       rtx tmp = ((!can_create_pseudo_p ()
3511                   || rtx_equal_p (operands[0], operands[1]))
3512                  ? operands[0] : gen_reg_rtx (SImode));
3513
3514       emit_insn (gen_iorsi3 (tmp, operands[1],
3515                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3516       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3517       DONE;
3518     }
3519 }")
3520
3521 (define_expand "xorsi3"
3522   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3523         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3524                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3525   ""
3526   "
3527 {
3528   if (GET_CODE (operands[2]) == CONST_INT
3529       && ! logical_operand (operands[2], SImode))
3530     {
3531       HOST_WIDE_INT value = INTVAL (operands[2]);
3532       rtx tmp = ((!can_create_pseudo_p ()
3533                   || rtx_equal_p (operands[0], operands[1]))
3534                  ? operands[0] : gen_reg_rtx (SImode));
3535
3536       emit_insn (gen_xorsi3 (tmp, operands[1],
3537                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3538       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3539       DONE;
3540     }
3541 }")
3542
3543 (define_insn "*boolsi3_internal1"
3544   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3545         (match_operator:SI 3 "boolean_or_operator"
3546          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3547           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3548   ""
3549   "@
3550    %q3 %0,%1,%2
3551    {%q3il|%q3i} %0,%1,%b2
3552    {%q3iu|%q3is} %0,%1,%u2")
3553
3554 (define_insn "*boolsi3_internal2"
3555   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3556         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3557          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3558           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3559          (const_int 0)))
3560    (clobber (match_scratch:SI 3 "=r,r"))]
3561   "TARGET_32BIT"
3562   "@
3563    %q4. %3,%1,%2
3564    #"
3565   [(set_attr "type" "fast_compare,compare")
3566    (set_attr "length" "4,8")])
3567
3568 (define_split
3569   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3570         (compare:CC (match_operator:SI 4 "boolean_operator"
3571          [(match_operand:SI 1 "gpc_reg_operand" "")
3572           (match_operand:SI 2 "gpc_reg_operand" "")])
3573          (const_int 0)))
3574    (clobber (match_scratch:SI 3 ""))]
3575   "TARGET_32BIT && reload_completed"
3576   [(set (match_dup 3) (match_dup 4))
3577    (set (match_dup 0)
3578         (compare:CC (match_dup 3)
3579                     (const_int 0)))]
3580   "")
3581
3582 (define_insn "*boolsi3_internal3"
3583   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3584         (compare:CC (match_operator:SI 4 "boolean_operator"
3585          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3586           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3587          (const_int 0)))
3588    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3589         (match_dup 4))]
3590   "TARGET_32BIT"
3591   "@
3592    %q4. %0,%1,%2
3593    #"
3594   [(set_attr "type" "fast_compare,compare")
3595    (set_attr "length" "4,8")])
3596
3597 (define_split
3598   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3599         (compare:CC (match_operator:SI 4 "boolean_operator"
3600          [(match_operand:SI 1 "gpc_reg_operand" "")
3601           (match_operand:SI 2 "gpc_reg_operand" "")])
3602          (const_int 0)))
3603    (set (match_operand:SI 0 "gpc_reg_operand" "")
3604         (match_dup 4))]
3605   "TARGET_32BIT && reload_completed"
3606   [(set (match_dup 0) (match_dup 4))
3607    (set (match_dup 3)
3608         (compare:CC (match_dup 0)
3609                     (const_int 0)))]
3610   "")
3611
3612 ;; Split a logical operation that we can't do in one insn into two insns,
3613 ;; each of which does one 16-bit part.  This is used by combine.
3614
3615 (define_split
3616   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3617         (match_operator:SI 3 "boolean_or_operator"
3618          [(match_operand:SI 1 "gpc_reg_operand" "")
3619           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3620   ""
3621   [(set (match_dup 0) (match_dup 4))
3622    (set (match_dup 0) (match_dup 5))]
3623 "
3624 {
3625   rtx i;
3626   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3627   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3628                                 operands[1], i);
3629   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3630   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3631                                 operands[0], i);
3632 }")
3633
3634 (define_insn "*boolcsi3_internal1"
3635   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3636         (match_operator:SI 3 "boolean_operator"
3637          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3638           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3639   ""
3640   "%q3 %0,%2,%1")
3641
3642 (define_insn "*boolcsi3_internal2"
3643   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3644         (compare:CC (match_operator:SI 4 "boolean_operator"
3645          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3646           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3647          (const_int 0)))
3648    (clobber (match_scratch:SI 3 "=r,r"))]
3649   "TARGET_32BIT"
3650   "@
3651    %q4. %3,%2,%1
3652    #"
3653   [(set_attr "type" "compare")
3654    (set_attr "length" "4,8")])
3655
3656 (define_split
3657   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3658         (compare:CC (match_operator:SI 4 "boolean_operator"
3659          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3660           (match_operand:SI 2 "gpc_reg_operand" "")])
3661          (const_int 0)))
3662    (clobber (match_scratch:SI 3 ""))]
3663   "TARGET_32BIT && reload_completed"
3664   [(set (match_dup 3) (match_dup 4))
3665    (set (match_dup 0)
3666         (compare:CC (match_dup 3)
3667                     (const_int 0)))]
3668   "")
3669
3670 (define_insn "*boolcsi3_internal3"
3671   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3672         (compare:CC (match_operator:SI 4 "boolean_operator"
3673          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3674           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3675          (const_int 0)))
3676    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3677         (match_dup 4))]
3678   "TARGET_32BIT"
3679   "@
3680    %q4. %0,%2,%1
3681    #"
3682   [(set_attr "type" "compare")
3683    (set_attr "length" "4,8")])
3684
3685 (define_split
3686   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3687         (compare:CC (match_operator:SI 4 "boolean_operator"
3688          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3689           (match_operand:SI 2 "gpc_reg_operand" "")])
3690          (const_int 0)))
3691    (set (match_operand:SI 0 "gpc_reg_operand" "")
3692         (match_dup 4))]
3693   "TARGET_32BIT && reload_completed"
3694   [(set (match_dup 0) (match_dup 4))
3695    (set (match_dup 3)
3696         (compare:CC (match_dup 0)
3697                     (const_int 0)))]
3698   "")
3699
3700 (define_insn "*boolccsi3_internal1"
3701   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3702         (match_operator:SI 3 "boolean_operator"
3703          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3704           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3705   ""
3706   "%q3 %0,%1,%2")
3707
3708 (define_insn "*boolccsi3_internal2"
3709   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3710         (compare:CC (match_operator:SI 4 "boolean_operator"
3711          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3712           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3713          (const_int 0)))
3714    (clobber (match_scratch:SI 3 "=r,r"))]
3715   "TARGET_32BIT"
3716   "@
3717    %q4. %3,%1,%2
3718    #"
3719   [(set_attr "type" "fast_compare,compare")
3720    (set_attr "length" "4,8")])
3721
3722 (define_split
3723   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3724         (compare:CC (match_operator:SI 4 "boolean_operator"
3725          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3726           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3727          (const_int 0)))
3728    (clobber (match_scratch:SI 3 ""))]
3729   "TARGET_32BIT && reload_completed"
3730   [(set (match_dup 3) (match_dup 4))
3731    (set (match_dup 0)
3732         (compare:CC (match_dup 3)
3733                     (const_int 0)))]
3734   "")
3735
3736 (define_insn "*boolccsi3_internal3"
3737   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3738         (compare:CC (match_operator:SI 4 "boolean_operator"
3739          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3740           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3741          (const_int 0)))
3742    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3743         (match_dup 4))]
3744   "TARGET_32BIT"
3745   "@
3746    %q4. %0,%1,%2
3747    #"
3748   [(set_attr "type" "fast_compare,compare")
3749    (set_attr "length" "4,8")])
3750
3751 (define_split
3752   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3753         (compare:CC (match_operator:SI 4 "boolean_operator"
3754          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3755           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3756          (const_int 0)))
3757    (set (match_operand:SI 0 "gpc_reg_operand" "")
3758         (match_dup 4))]
3759   "TARGET_32BIT && reload_completed"
3760   [(set (match_dup 0) (match_dup 4))
3761    (set (match_dup 3)
3762         (compare:CC (match_dup 0)
3763                     (const_int 0)))]
3764   "")
3765
3766 ;; maskir insn.  We need four forms because things might be in arbitrary
3767 ;; orders.  Don't define forms that only set CR fields because these
3768 ;; would modify an input register.
3769
3770 (define_insn "*maskir_internal1"
3771   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3772         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3773                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3774                 (and:SI (match_dup 2)
3775                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3776   "TARGET_POWER"
3777   "maskir %0,%3,%2")
3778
3779 (define_insn "*maskir_internal2"
3780   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3781         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3782                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3783                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3784                         (match_dup 2))))]
3785   "TARGET_POWER"
3786   "maskir %0,%3,%2")
3787
3788 (define_insn "*maskir_internal3"
3789   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3790         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3791                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3792                 (and:SI (not:SI (match_dup 2))
3793                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3794   "TARGET_POWER"
3795   "maskir %0,%3,%2")
3796
3797 (define_insn "*maskir_internal4"
3798   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3799         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3800                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3801                 (and:SI (not:SI (match_dup 2))
3802                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3803   "TARGET_POWER"
3804   "maskir %0,%3,%2")
3805
3806 (define_insn "*maskir_internal5"
3807   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3808         (compare:CC
3809          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3810                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3811                  (and:SI (match_dup 2)
3812                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3813          (const_int 0)))
3814    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3815         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3816                 (and:SI (match_dup 2) (match_dup 3))))]
3817   "TARGET_POWER"
3818   "@
3819    maskir. %0,%3,%2
3820    #"
3821   [(set_attr "type" "compare")
3822    (set_attr "length" "4,8")])
3823
3824 (define_split
3825   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3826         (compare:CC
3827          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3828                          (match_operand:SI 1 "gpc_reg_operand" ""))
3829                  (and:SI (match_dup 2)
3830                          (match_operand:SI 3 "gpc_reg_operand" "")))
3831          (const_int 0)))
3832    (set (match_operand:SI 0 "gpc_reg_operand" "")
3833         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3834                 (and:SI (match_dup 2) (match_dup 3))))]
3835   "TARGET_POWER && reload_completed"
3836   [(set (match_dup 0)
3837         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3838                 (and:SI (match_dup 2) (match_dup 3))))
3839    (set (match_dup 4)
3840         (compare:CC (match_dup 0)
3841                     (const_int 0)))]
3842   "")
3843
3844 (define_insn "*maskir_internal6"
3845   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3846         (compare:CC
3847          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3848                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3849                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3850                          (match_dup 2)))
3851          (const_int 0)))
3852    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3853         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3854                 (and:SI (match_dup 3) (match_dup 2))))]
3855   "TARGET_POWER"
3856   "@
3857    maskir. %0,%3,%2
3858    #"
3859   [(set_attr "type" "compare")
3860    (set_attr "length" "4,8")])
3861
3862 (define_split
3863   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3864         (compare:CC
3865          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3866                          (match_operand:SI 1 "gpc_reg_operand" ""))
3867                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3868                          (match_dup 2)))
3869          (const_int 0)))
3870    (set (match_operand:SI 0 "gpc_reg_operand" "")
3871         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3872                 (and:SI (match_dup 3) (match_dup 2))))]
3873   "TARGET_POWER && reload_completed"
3874   [(set (match_dup 0)
3875         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3876                 (and:SI (match_dup 3) (match_dup 2))))
3877    (set (match_dup 4)
3878         (compare:CC (match_dup 0)
3879                     (const_int 0)))]
3880   "")
3881
3882 (define_insn "*maskir_internal7"
3883   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3884         (compare:CC
3885          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3886                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3887                  (and:SI (not:SI (match_dup 2))
3888                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3889          (const_int 0)))
3890    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3891         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3892                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3893   "TARGET_POWER"
3894   "@
3895    maskir. %0,%3,%2
3896    #"
3897   [(set_attr "type" "compare")
3898    (set_attr "length" "4,8")])
3899
3900 (define_split
3901   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3902         (compare:CC
3903          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3904                          (match_operand:SI 3 "gpc_reg_operand" ""))
3905                  (and:SI (not:SI (match_dup 2))
3906                          (match_operand:SI 1 "gpc_reg_operand" "")))
3907          (const_int 0)))
3908    (set (match_operand:SI 0 "gpc_reg_operand" "")
3909         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3910                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3911   "TARGET_POWER && reload_completed"
3912   [(set (match_dup 0)
3913         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3914                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3915    (set (match_dup 4)
3916         (compare:CC (match_dup 0)
3917                     (const_int 0)))]
3918   "")
3919
3920 (define_insn "*maskir_internal8"
3921   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3922         (compare:CC
3923          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3924                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3925                  (and:SI (not:SI (match_dup 2))
3926                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3927          (const_int 0)))
3928    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3929         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3930                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3931   "TARGET_POWER"
3932   "@
3933    maskir. %0,%3,%2
3934    #"
3935   [(set_attr "type" "compare")
3936    (set_attr "length" "4,8")])
3937
3938 (define_split
3939   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3940         (compare:CC
3941          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3942                          (match_operand:SI 2 "gpc_reg_operand" ""))
3943                  (and:SI (not:SI (match_dup 2))
3944                          (match_operand:SI 1 "gpc_reg_operand" "")))
3945          (const_int 0)))
3946    (set (match_operand:SI 0 "gpc_reg_operand" "")
3947         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3948                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3949   "TARGET_POWER && reload_completed"
3950   [(set (match_dup 0)
3951         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3952                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3953    (set (match_dup 4)
3954         (compare:CC (match_dup 0)
3955                     (const_int 0)))]
3956   "")
3957 \f
3958 ;; Rotate and shift insns, in all their variants.  These support shifts,
3959 ;; field inserts and extracts, and various combinations thereof.
3960 (define_expand "insv"
3961   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3962                        (match_operand:SI 1 "const_int_operand" "")
3963                        (match_operand:SI 2 "const_int_operand" ""))
3964         (match_operand 3 "gpc_reg_operand" ""))]
3965   ""
3966   "
3967 {
3968   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3969      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3970      compiler if the address of the structure is taken later.  Likewise, do
3971      not handle invalid E500 subregs.  */
3972   if (GET_CODE (operands[0]) == SUBREG
3973       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3974           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3975               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3976     FAIL;
3977
3978   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3979     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
3980   else
3981     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
3982   DONE;
3983 }")
3984
3985 (define_insn "insvsi"
3986   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3987                          (match_operand:SI 1 "const_int_operand" "i")
3988                          (match_operand:SI 2 "const_int_operand" "i"))
3989         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3990   ""
3991   "*
3992 {
3993   int start = INTVAL (operands[2]) & 31;
3994   int size = INTVAL (operands[1]) & 31;
3995
3996   operands[4] = GEN_INT (32 - start - size);
3997   operands[1] = GEN_INT (start + size - 1);
3998   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3999 }"
4000   [(set_attr "type" "insert_word")])
4001
4002 (define_insn "*insvsi_internal1"
4003   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4004                          (match_operand:SI 1 "const_int_operand" "i")
4005                          (match_operand:SI 2 "const_int_operand" "i"))
4006         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4007                    (match_operand:SI 4 "const_int_operand" "i")))]
4008   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4009   "*
4010 {
4011   int shift = INTVAL (operands[4]) & 31;
4012   int start = INTVAL (operands[2]) & 31;
4013   int size = INTVAL (operands[1]) & 31;
4014
4015   operands[4] = GEN_INT (shift - start - size);
4016   operands[1] = GEN_INT (start + size - 1);
4017   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4018 }"
4019   [(set_attr "type" "insert_word")])
4020
4021 (define_insn "*insvsi_internal2"
4022   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4023                          (match_operand:SI 1 "const_int_operand" "i")
4024                          (match_operand:SI 2 "const_int_operand" "i"))
4025         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4026                      (match_operand:SI 4 "const_int_operand" "i")))]
4027   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4028   "*
4029 {
4030   int shift = INTVAL (operands[4]) & 31;
4031   int start = INTVAL (operands[2]) & 31;
4032   int size = INTVAL (operands[1]) & 31;
4033
4034   operands[4] = GEN_INT (32 - shift - start - size);
4035   operands[1] = GEN_INT (start + size - 1);
4036   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4037 }"
4038   [(set_attr "type" "insert_word")])
4039
4040 (define_insn "*insvsi_internal3"
4041   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4042                          (match_operand:SI 1 "const_int_operand" "i")
4043                          (match_operand:SI 2 "const_int_operand" "i"))
4044         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4045                      (match_operand:SI 4 "const_int_operand" "i")))]
4046   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4047   "*
4048 {
4049   int shift = INTVAL (operands[4]) & 31;
4050   int start = INTVAL (operands[2]) & 31;
4051   int size = INTVAL (operands[1]) & 31;
4052
4053   operands[4] = GEN_INT (32 - shift - start - size);
4054   operands[1] = GEN_INT (start + size - 1);
4055   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4056 }"
4057   [(set_attr "type" "insert_word")])
4058
4059 (define_insn "*insvsi_internal4"
4060   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4061                          (match_operand:SI 1 "const_int_operand" "i")
4062                          (match_operand:SI 2 "const_int_operand" "i"))
4063         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4064                          (match_operand:SI 4 "const_int_operand" "i")
4065                          (match_operand:SI 5 "const_int_operand" "i")))]
4066   "INTVAL (operands[4]) >= INTVAL (operands[1])"
4067   "*
4068 {
4069   int extract_start = INTVAL (operands[5]) & 31;
4070   int extract_size = INTVAL (operands[4]) & 31;
4071   int insert_start = INTVAL (operands[2]) & 31;
4072   int insert_size = INTVAL (operands[1]) & 31;
4073
4074 /* Align extract field with insert field */
4075   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
4076   operands[1] = GEN_INT (insert_start + insert_size - 1);
4077   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
4078 }"
4079   [(set_attr "type" "insert_word")])
4080
4081 ;; combine patterns for rlwimi
4082 (define_insn "*insvsi_internal5"
4083   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4084         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
4085                         (match_operand:SI 1 "mask_operand" "i"))
4086                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4087                                      (match_operand:SI 2 "const_int_operand" "i"))
4088                         (match_operand:SI 5 "mask_operand" "i"))))]
4089   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
4090   "*
4091 {
4092  int me = extract_ME(operands[5]);
4093  int mb = extract_MB(operands[5]);
4094  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
4095  operands[2] = GEN_INT(mb);
4096  operands[1] = GEN_INT(me);
4097  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4098 }"
4099   [(set_attr "type" "insert_word")])
4100
4101 (define_insn "*insvsi_internal6"
4102   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4103         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4104                                      (match_operand:SI 2 "const_int_operand" "i"))
4105                         (match_operand:SI 5 "mask_operand" "i"))
4106                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
4107                         (match_operand:SI 1 "mask_operand" "i"))))]
4108   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
4109   "*
4110 {
4111  int me = extract_ME(operands[5]);
4112  int mb = extract_MB(operands[5]);
4113  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
4114  operands[2] = GEN_INT(mb);
4115  operands[1] = GEN_INT(me);
4116  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4117 }"
4118   [(set_attr "type" "insert_word")])
4119
4120 (define_insn "insvdi"
4121   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4122                          (match_operand:SI 1 "const_int_operand" "i")
4123                          (match_operand:SI 2 "const_int_operand" "i"))
4124         (match_operand:DI 3 "gpc_reg_operand" "r"))]
4125   "TARGET_POWERPC64"
4126   "*
4127 {
4128   int start = INTVAL (operands[2]) & 63;
4129   int size = INTVAL (operands[1]) & 63;
4130
4131   operands[1] = GEN_INT (64 - start - size);
4132   return \"rldimi %0,%3,%H1,%H2\";
4133 }"
4134   [(set_attr "type" "insert_dword")])
4135
4136 (define_insn "*insvdi_internal2"
4137   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4138                          (match_operand:SI 1 "const_int_operand" "i")
4139                          (match_operand:SI 2 "const_int_operand" "i"))
4140         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4141                      (match_operand:SI 4 "const_int_operand" "i")))]
4142   "TARGET_POWERPC64
4143    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
4144   "*
4145 {
4146   int shift = INTVAL (operands[4]) & 63;
4147   int start = (INTVAL (operands[2]) & 63) - 32;
4148   int size = INTVAL (operands[1]) & 63;
4149
4150   operands[4] = GEN_INT (64 - shift - start - size);
4151   operands[2] = GEN_INT (start);
4152   operands[1] = GEN_INT (start + size - 1);
4153   return \"rlwimi %0,%3,%h4,%h2,%h1\";
4154 }")
4155
4156 (define_insn "*insvdi_internal3"
4157   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4158                          (match_operand:SI 1 "const_int_operand" "i")
4159                          (match_operand:SI 2 "const_int_operand" "i"))
4160         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4161                      (match_operand:SI 4 "const_int_operand" "i")))]
4162   "TARGET_POWERPC64
4163    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
4164   "*
4165 {
4166   int shift = INTVAL (operands[4]) & 63;
4167   int start = (INTVAL (operands[2]) & 63) - 32;
4168   int size = INTVAL (operands[1]) & 63;
4169
4170   operands[4] = GEN_INT (64 - shift - start - size);
4171   operands[2] = GEN_INT (start);
4172   operands[1] = GEN_INT (start + size - 1);
4173   return \"rlwimi %0,%3,%h4,%h2,%h1\";
4174 }")
4175
4176 (define_expand "extzv"
4177   [(set (match_operand 0 "gpc_reg_operand" "")
4178         (zero_extract (match_operand 1 "gpc_reg_operand" "")
4179                        (match_operand:SI 2 "const_int_operand" "")
4180                        (match_operand:SI 3 "const_int_operand" "")))]
4181   ""
4182   "
4183 {
4184   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
4185      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
4186      compiler if the address of the structure is taken later.  */
4187   if (GET_CODE (operands[0]) == SUBREG
4188       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
4189     FAIL;
4190
4191   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
4192     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
4193   else
4194     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
4195   DONE;
4196 }")
4197
4198 (define_insn "extzvsi"
4199   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4200         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4201                          (match_operand:SI 2 "const_int_operand" "i")
4202                          (match_operand:SI 3 "const_int_operand" "i")))]
4203   ""
4204   "*
4205 {
4206   int start = INTVAL (operands[3]) & 31;
4207   int size = INTVAL (operands[2]) & 31;
4208
4209   if (start + size >= 32)
4210     operands[3] = const0_rtx;
4211   else
4212     operands[3] = GEN_INT (start + size);
4213   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
4214 }")
4215
4216 (define_insn "*extzvsi_internal1"
4217   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4218         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4219                          (match_operand:SI 2 "const_int_operand" "i,i")
4220                          (match_operand:SI 3 "const_int_operand" "i,i"))
4221                     (const_int 0)))
4222    (clobber (match_scratch:SI 4 "=r,r"))]
4223   ""
4224   "*
4225 {
4226   int start = INTVAL (operands[3]) & 31;
4227   int size = INTVAL (operands[2]) & 31;
4228
4229   /* Force split for non-cc0 compare.  */
4230   if (which_alternative == 1)
4231      return \"#\";
4232
4233   /* If the bit-field being tested fits in the upper or lower half of a
4234      word, it is possible to use andiu. or andil. to test it.  This is
4235      useful because the condition register set-use delay is smaller for
4236      andi[ul]. than for rlinm.  This doesn't work when the starting bit
4237      position is 0 because the LT and GT bits may be set wrong.  */
4238
4239   if ((start > 0 && start + size <= 16) || start >= 16)
4240     {
4241       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
4242                               - (1 << (16 - (start & 15) - size))));
4243       if (start < 16)
4244         return \"{andiu.|andis.} %4,%1,%3\";
4245       else
4246         return \"{andil.|andi.} %4,%1,%3\";
4247     }
4248
4249   if (start + size >= 32)
4250     operands[3] = const0_rtx;
4251   else
4252     operands[3] = GEN_INT (start + size);
4253   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
4254 }"
4255   [(set_attr "type" "delayed_compare")
4256    (set_attr "length" "4,8")])
4257
4258 (define_split
4259   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4260         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
4261                          (match_operand:SI 2 "const_int_operand" "")
4262                          (match_operand:SI 3 "const_int_operand" ""))
4263                     (const_int 0)))
4264    (clobber (match_scratch:SI 4 ""))]
4265   "reload_completed"
4266   [(set (match_dup 4)
4267         (zero_extract:SI (match_dup 1) (match_dup 2)
4268                          (match_dup 3)))
4269    (set (match_dup 0)
4270         (compare:CC (match_dup 4)
4271                     (const_int 0)))]
4272   "")
4273
4274 (define_insn "*extzvsi_internal2"
4275   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4276         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4277                          (match_operand:SI 2 "const_int_operand" "i,i")
4278                          (match_operand:SI 3 "const_int_operand" "i,i"))
4279                     (const_int 0)))
4280    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4281         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
4282   ""
4283   "*
4284 {
4285   int start = INTVAL (operands[3]) & 31;
4286   int size = INTVAL (operands[2]) & 31;
4287
4288   /* Force split for non-cc0 compare.  */
4289   if (which_alternative == 1)
4290      return \"#\";
4291
4292   /* Since we are using the output value, we can't ignore any need for
4293      a shift.  The bit-field must end at the LSB.  */
4294   if (start >= 16 && start + size == 32)
4295     {
4296       operands[3] = GEN_INT ((1 << size) - 1);
4297       return \"{andil.|andi.} %0,%1,%3\";
4298     }
4299
4300   if (start + size >= 32)
4301     operands[3] = const0_rtx;
4302   else
4303     operands[3] = GEN_INT (start + size);
4304   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
4305 }"
4306   [(set_attr "type" "delayed_compare")
4307    (set_attr "length" "4,8")])
4308
4309 (define_split
4310   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4311         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
4312                          (match_operand:SI 2 "const_int_operand" "")
4313                          (match_operand:SI 3 "const_int_operand" ""))
4314                     (const_int 0)))
4315    (set (match_operand:SI 0 "gpc_reg_operand" "")
4316         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
4317   "reload_completed"
4318   [(set (match_dup 0)
4319         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
4320    (set (match_dup 4)
4321         (compare:CC (match_dup 0)
4322                     (const_int 0)))]
4323   "")
4324
4325 (define_insn "extzvdi"
4326   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4327         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4328                          (match_operand:SI 2 "const_int_operand" "i")
4329                          (match_operand:SI 3 "const_int_operand" "i")))]
4330   "TARGET_POWERPC64"
4331   "*
4332 {
4333   int start = INTVAL (operands[3]) & 63;
4334   int size = INTVAL (operands[2]) & 63;
4335
4336   if (start + size >= 64)
4337     operands[3] = const0_rtx;
4338   else
4339     operands[3] = GEN_INT (start + size);
4340   operands[2] = GEN_INT (64 - size);
4341   return \"rldicl %0,%1,%3,%2\";
4342 }")
4343
4344 (define_insn "*extzvdi_internal1"
4345   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
4346         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4347                          (match_operand:SI 2 "const_int_operand" "i")
4348                          (match_operand:SI 3 "const_int_operand" "i"))
4349                     (const_int 0)))
4350    (clobber (match_scratch:DI 4 "=r"))]
4351   "TARGET_64BIT && rs6000_gen_cell_microcode"
4352   "*
4353 {
4354   int start = INTVAL (operands[3]) & 63;
4355   int size = INTVAL (operands[2]) & 63;
4356
4357   if (start + size >= 64)
4358     operands[3] = const0_rtx;
4359   else
4360     operands[3] = GEN_INT (start + size);
4361   operands[2] = GEN_INT (64 - size);
4362   return \"rldicl. %4,%1,%3,%2\";
4363 }"
4364   [(set_attr "type" "compare")])
4365
4366 (define_insn "*extzvdi_internal2"
4367   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
4368         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4369                          (match_operand:SI 2 "const_int_operand" "i")
4370                          (match_operand:SI 3 "const_int_operand" "i"))
4371                     (const_int 0)))
4372    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4373         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
4374   "TARGET_64BIT && rs6000_gen_cell_microcode"
4375   "*
4376 {
4377   int start = INTVAL (operands[3]) & 63;
4378   int size = INTVAL (operands[2]) & 63;
4379
4380   if (start + size >= 64)
4381     operands[3] = const0_rtx;
4382   else
4383     operands[3] = GEN_INT (start + size);
4384   operands[2] = GEN_INT (64 - size);
4385   return \"rldicl. %0,%1,%3,%2\";
4386 }"
4387   [(set_attr "type" "compare")])
4388
4389 (define_insn "rotlsi3"
4390   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4391         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4392                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4393   ""
4394   "@
4395    {rlnm|rlwnm} %0,%1,%2,0xffffffff
4396    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
4397   [(set_attr "type" "var_shift_rotate,integer")])
4398
4399 (define_insn "*rotlsi3_64"
4400   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4401         (zero_extend:DI
4402             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4403                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4404   "TARGET_64BIT"
4405   "@
4406    {rlnm|rlwnm} %0,%1,%2,0xffffffff
4407    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
4408   [(set_attr "type" "var_shift_rotate,integer")])
4409
4410 (define_insn "*rotlsi3_internal2"
4411   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4412         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4413                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4414                     (const_int 0)))
4415    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4416   ""
4417   "@
4418    {rlnm.|rlwnm.} %3,%1,%2,0xffffffff
4419    {rlinm.|rlwinm.} %3,%1,%h2,0xffffffff
4420    #
4421    #"
4422   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4423    (set_attr "length" "4,4,8,8")])
4424
4425 (define_split
4426   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4427         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4428                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4429                     (const_int 0)))
4430    (clobber (match_scratch:SI 3 ""))]
4431   "reload_completed"
4432   [(set (match_dup 3)
4433         (rotate:SI (match_dup 1) (match_dup 2)))
4434    (set (match_dup 0)
4435         (compare:CC (match_dup 3)
4436                     (const_int 0)))]
4437   "")
4438
4439 (define_insn "*rotlsi3_internal3"
4440   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4441         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4442                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4443                     (const_int 0)))
4444    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4445         (rotate:SI (match_dup 1) (match_dup 2)))]
4446   ""
4447   "@
4448    {rlnm.|rlwnm.} %0,%1,%2,0xffffffff
4449    {rlinm.|rlwinm.} %0,%1,%h2,0xffffffff
4450    #
4451    #"
4452   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4453    (set_attr "length" "4,4,8,8")])
4454
4455 (define_split
4456   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4457         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4458                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4459                     (const_int 0)))
4460    (set (match_operand:SI 0 "gpc_reg_operand" "")
4461         (rotate:SI (match_dup 1) (match_dup 2)))]
4462   "reload_completed"
4463   [(set (match_dup 0)
4464         (rotate:SI (match_dup 1) (match_dup 2)))
4465    (set (match_dup 3)
4466         (compare:CC (match_dup 0)
4467                     (const_int 0)))]
4468   "")
4469
4470 (define_insn "*rotlsi3_internal4"
4471   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4472         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4473                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
4474                 (match_operand:SI 3 "mask_operand" "n,n")))]
4475   ""
4476   "@
4477    {rlnm|rlwnm} %0,%1,%2,%m3,%M3
4478    {rlinm|rlwinm} %0,%1,%h2,%m3,%M3"
4479   [(set_attr "type" "var_shift_rotate,integer")])
4480
4481 (define_insn "*rotlsi3_internal5"
4482   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4483         (compare:CC (and:SI
4484                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4485                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4486                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4487                     (const_int 0)))
4488    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
4489   ""
4490   "@
4491    {rlnm.|rlwnm.} %4,%1,%2,%m3,%M3
4492    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4493    #
4494    #"
4495   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4496    (set_attr "length" "4,4,8,8")])
4497
4498 (define_split
4499   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4500         (compare:CC (and:SI
4501                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4502                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4503                      (match_operand:SI 3 "mask_operand" ""))
4504                     (const_int 0)))
4505    (clobber (match_scratch:SI 4 ""))]
4506   "reload_completed"
4507   [(set (match_dup 4)
4508         (and:SI (rotate:SI (match_dup 1)
4509                                 (match_dup 2))
4510                      (match_dup 3)))
4511    (set (match_dup 0)
4512         (compare:CC (match_dup 4)
4513                     (const_int 0)))]
4514   "")
4515
4516 (define_insn "*rotlsi3_internal6"
4517   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
4518         (compare:CC (and:SI
4519                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4520                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4521                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4522                     (const_int 0)))
4523    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4524         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4525   ""
4526   "@
4527    {rlnm.|rlwnm.} %0,%1,%2,%m3,%M3
4528    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4529    #
4530    #"
4531   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4532    (set_attr "length" "4,4,8,8")])
4533
4534 (define_split
4535   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4536         (compare:CC (and:SI
4537                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4538                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4539                      (match_operand:SI 3 "mask_operand" ""))
4540                     (const_int 0)))
4541    (set (match_operand:SI 0 "gpc_reg_operand" "")
4542         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4543   "reload_completed"
4544   [(set (match_dup 0)
4545         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4546    (set (match_dup 4)
4547         (compare:CC (match_dup 0)
4548                     (const_int 0)))]
4549   "")
4550
4551 (define_insn "*rotlsi3_internal7"
4552   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4553         (zero_extend:SI
4554          (subreg:QI
4555           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4556                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4557   ""
4558   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff"
4559   [(set (attr "cell_micro")
4560      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4561         (const_string "not")
4562         (const_string "always")))])
4563
4564 (define_insn "*rotlsi3_internal8"
4565   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4566         (compare:CC (zero_extend:SI
4567                      (subreg:QI
4568                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4569                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4570                     (const_int 0)))
4571    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4572   ""
4573   "@
4574    {rlnm.|rlwnm.} %3,%1,%2,0xff
4575    {rlinm.|rlwinm.} %3,%1,%h2,0xff
4576    #
4577    #"
4578   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4579    (set_attr "length" "4,4,8,8")])
4580
4581 (define_split
4582   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4583         (compare:CC (zero_extend:SI
4584                      (subreg:QI
4585                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4586                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4587                     (const_int 0)))
4588    (clobber (match_scratch:SI 3 ""))]
4589   "reload_completed"
4590   [(set (match_dup 3)
4591         (zero_extend:SI (subreg:QI
4592                       (rotate:SI (match_dup 1)
4593                                  (match_dup 2)) 0)))
4594    (set (match_dup 0)
4595         (compare:CC (match_dup 3)
4596                     (const_int 0)))]
4597   "")
4598
4599 (define_insn "*rotlsi3_internal9"
4600   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4601         (compare:CC (zero_extend:SI
4602                      (subreg:QI
4603                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4604                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4605                     (const_int 0)))
4606    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4607         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4608   ""
4609   "@
4610    {rlnm.|rlwnm.} %0,%1,%2,0xff
4611    {rlinm.|rlwinm.} %0,%1,%h2,0xff
4612    #
4613    #"
4614   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4615    (set_attr "length" "4,4,8,8")])
4616
4617 (define_split
4618   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4619         (compare:CC (zero_extend:SI
4620                      (subreg:QI
4621                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4622                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4623                     (const_int 0)))
4624    (set (match_operand:SI 0 "gpc_reg_operand" "")
4625         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4626   "reload_completed"
4627   [(set (match_dup 0)
4628         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4629    (set (match_dup 3)
4630         (compare:CC (match_dup 0)
4631                     (const_int 0)))]
4632   "")
4633
4634 (define_insn "*rotlsi3_internal10"
4635   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4636         (zero_extend:SI
4637          (subreg:HI
4638           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4639                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4640   ""
4641   "@
4642    {rlnm|rlwnm} %0,%1,%2,0xffff
4643    {rlinm|rlwinm} %0,%1,%h2,0xffff"
4644   [(set_attr "type" "var_shift_rotate,integer")])
4645
4646
4647 (define_insn "*rotlsi3_internal11"
4648   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4649         (compare:CC (zero_extend:SI
4650                      (subreg:HI
4651                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4652                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4653                     (const_int 0)))
4654    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4655   ""
4656   "@
4657    {rlnm.|rlwnm.} %3,%1,%2,0xffff
4658    {rlinm.|rlwinm.} %3,%1,%h2,0xffff
4659    #
4660    #"
4661   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4662    (set_attr "length" "4,4,8,8")])
4663
4664 (define_split
4665   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4666         (compare:CC (zero_extend:SI
4667                      (subreg:HI
4668                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4669                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4670                     (const_int 0)))
4671    (clobber (match_scratch:SI 3 ""))]
4672   "reload_completed"
4673   [(set (match_dup 3)
4674         (zero_extend:SI (subreg:HI
4675                       (rotate:SI (match_dup 1)
4676                                  (match_dup 2)) 0)))
4677    (set (match_dup 0)
4678         (compare:CC (match_dup 3)
4679                     (const_int 0)))]
4680   "")
4681
4682 (define_insn "*rotlsi3_internal12"
4683   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4684         (compare:CC (zero_extend:SI
4685                      (subreg:HI
4686                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4687                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4688                     (const_int 0)))
4689    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4690         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4691   ""
4692   "@
4693    {rlnm.|rlwnm.} %0,%1,%2,0xffff
4694    {rlinm.|rlwinm.} %0,%1,%h2,0xffff
4695    #
4696    #"
4697   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4698    (set_attr "length" "4,4,8,8")])
4699
4700 (define_split
4701   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4702         (compare:CC (zero_extend:SI
4703                      (subreg:HI
4704                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4705                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4706                     (const_int 0)))
4707    (set (match_operand:SI 0 "gpc_reg_operand" "")
4708         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4709   "reload_completed"
4710   [(set (match_dup 0)
4711         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4712    (set (match_dup 3)
4713         (compare:CC (match_dup 0)
4714                     (const_int 0)))]
4715   "")
4716
4717 ;; Note that we use "sle." instead of "sl." so that we can set
4718 ;; SHIFT_COUNT_TRUNCATED.
4719
4720 (define_expand "ashlsi3"
4721   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4722    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4723    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4724   ""
4725   "
4726 {
4727   if (TARGET_POWER)
4728     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4729   else
4730     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4731   DONE;
4732 }")
4733
4734 (define_insn "ashlsi3_power"
4735   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4736         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4737                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4738    (clobber (match_scratch:SI 3 "=q,X"))]
4739   "TARGET_POWER"
4740   "@
4741    sle %0,%1,%2
4742    {sli|slwi} %0,%1,%h2")
4743
4744 (define_insn "ashlsi3_no_power"
4745   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4746         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4747                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4748   "! TARGET_POWER"
4749   "@
4750    {sl|slw} %0,%1,%2
4751    {sli|slwi} %0,%1,%h2"
4752   [(set_attr "type" "var_shift_rotate,shift")])
4753
4754 (define_insn "*ashlsi3_64"
4755   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4756         (zero_extend:DI
4757             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4758                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4759   "TARGET_POWERPC64"
4760   "@
4761    {sl|slw} %0,%1,%2
4762    {sli|slwi} %0,%1,%h2"
4763   [(set_attr "type" "var_shift_rotate,shift")])
4764
4765 (define_insn ""
4766   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4767         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4768                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4769                     (const_int 0)))
4770    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4771    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4772   "TARGET_POWER"
4773   "@
4774    sle. %3,%1,%2
4775    {sli.|slwi.} %3,%1,%h2
4776    #
4777    #"
4778   [(set_attr "type" "delayed_compare")
4779    (set_attr "length" "4,4,8,8")])
4780
4781 (define_split
4782   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4783         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4784                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4785                     (const_int 0)))
4786    (clobber (match_scratch:SI 3 ""))
4787    (clobber (match_scratch:SI 4 ""))]
4788   "TARGET_POWER && reload_completed"
4789   [(parallel [(set (match_dup 3)
4790         (ashift:SI (match_dup 1) (match_dup 2)))
4791    (clobber (match_dup 4))])
4792    (set (match_dup 0)
4793         (compare:CC (match_dup 3)
4794                     (const_int 0)))]
4795   "")
4796
4797 (define_insn ""
4798   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4799         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4800                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4801                     (const_int 0)))
4802    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4803   "! TARGET_POWER && TARGET_32BIT"
4804   "@
4805    {sl.|slw.} %3,%1,%2
4806    {sli.|slwi.} %3,%1,%h2
4807    #
4808    #"
4809   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4810    (set_attr "length" "4,4,8,8")])
4811
4812 (define_split
4813   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4814         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4815                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4816                     (const_int 0)))
4817    (clobber (match_scratch:SI 3 ""))]
4818   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4819   [(set (match_dup 3)
4820         (ashift:SI (match_dup 1) (match_dup 2)))
4821    (set (match_dup 0)
4822         (compare:CC (match_dup 3)
4823                     (const_int 0)))]
4824   "")
4825
4826 (define_insn ""
4827   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4828         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4829                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4830                     (const_int 0)))
4831    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4832         (ashift:SI (match_dup 1) (match_dup 2)))
4833    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4834   "TARGET_POWER"
4835   "@
4836    sle. %0,%1,%2
4837    {sli.|slwi.} %0,%1,%h2
4838    #
4839    #"
4840   [(set_attr "type" "delayed_compare")
4841    (set_attr "length" "4,4,8,8")])
4842
4843 (define_split
4844   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4845         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4846                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4847                     (const_int 0)))
4848    (set (match_operand:SI 0 "gpc_reg_operand" "")
4849         (ashift:SI (match_dup 1) (match_dup 2)))
4850    (clobber (match_scratch:SI 4 ""))]
4851   "TARGET_POWER && reload_completed"
4852   [(parallel [(set (match_dup 0)
4853         (ashift:SI (match_dup 1) (match_dup 2)))
4854    (clobber (match_dup 4))])
4855    (set (match_dup 3)
4856         (compare:CC (match_dup 0)
4857                     (const_int 0)))]
4858   "")
4859
4860 (define_insn ""
4861   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4862         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4863                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4864                     (const_int 0)))
4865    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4866         (ashift:SI (match_dup 1) (match_dup 2)))]
4867   "! TARGET_POWER && TARGET_32BIT"
4868   "@
4869    {sl.|slw.} %0,%1,%2
4870    {sli.|slwi.} %0,%1,%h2
4871    #
4872    #"
4873   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4874    (set_attr "length" "4,4,8,8")])
4875
4876 (define_split
4877   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4878         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4879                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4880                     (const_int 0)))
4881    (set (match_operand:SI 0 "gpc_reg_operand" "")
4882         (ashift:SI (match_dup 1) (match_dup 2)))]
4883   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4884   [(set (match_dup 0)
4885         (ashift:SI (match_dup 1) (match_dup 2)))
4886    (set (match_dup 3)
4887         (compare:CC (match_dup 0)
4888                     (const_int 0)))]
4889   "")
4890
4891 (define_insn "rlwinm"
4892   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4893         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4894                            (match_operand:SI 2 "const_int_operand" "i"))
4895                 (match_operand:SI 3 "mask_operand" "n")))]
4896   "includes_lshift_p (operands[2], operands[3])"
4897   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4898
4899 (define_insn ""
4900   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4901         (compare:CC
4902          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4903                             (match_operand:SI 2 "const_int_operand" "i,i"))
4904                  (match_operand:SI 3 "mask_operand" "n,n"))
4905          (const_int 0)))
4906    (clobber (match_scratch:SI 4 "=r,r"))]
4907   "includes_lshift_p (operands[2], operands[3])"
4908   "@
4909    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4910    #"
4911   [(set_attr "type" "delayed_compare")
4912    (set_attr "length" "4,8")])
4913
4914 (define_split
4915   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4916         (compare:CC
4917          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4918                             (match_operand:SI 2 "const_int_operand" ""))
4919                  (match_operand:SI 3 "mask_operand" ""))
4920          (const_int 0)))
4921    (clobber (match_scratch:SI 4 ""))]
4922   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4923   [(set (match_dup 4)
4924         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4925                  (match_dup 3)))
4926    (set (match_dup 0)
4927         (compare:CC (match_dup 4)
4928                     (const_int 0)))]
4929   "")
4930
4931 (define_insn ""
4932   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4933         (compare:CC
4934          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4935                             (match_operand:SI 2 "const_int_operand" "i,i"))
4936                  (match_operand:SI 3 "mask_operand" "n,n"))
4937          (const_int 0)))
4938    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4939         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4940   "includes_lshift_p (operands[2], operands[3])"
4941   "@
4942    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4943    #"
4944   [(set_attr "type" "delayed_compare")
4945    (set_attr "length" "4,8")])
4946
4947 (define_split
4948   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4949         (compare:CC
4950          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4951                             (match_operand:SI 2 "const_int_operand" ""))
4952                  (match_operand:SI 3 "mask_operand" ""))
4953          (const_int 0)))
4954    (set (match_operand:SI 0 "gpc_reg_operand" "")
4955         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4956   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4957   [(set (match_dup 0)
4958         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4959    (set (match_dup 4)
4960         (compare:CC (match_dup 0)
4961                     (const_int 0)))]
4962   "")
4963
4964 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
4965 ;; "sli x,x,0".
4966 (define_expand "lshrsi3"
4967   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4968    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4969    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4970   ""
4971   "
4972 {
4973   if (TARGET_POWER)
4974     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
4975   else
4976     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
4977   DONE;
4978 }")
4979
4980 (define_insn "lshrsi3_power"
4981   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4982         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4983                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
4984    (clobber (match_scratch:SI 3 "=q,X,X"))]
4985   "TARGET_POWER"
4986   "@
4987   sre %0,%1,%2
4988   mr %0,%1
4989   {s%A2i|s%A2wi} %0,%1,%h2")
4990
4991 (define_insn "lshrsi3_no_power"
4992   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4993         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4994                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
4995   "! TARGET_POWER"
4996   "@
4997   mr %0,%1
4998   {sr|srw} %0,%1,%2
4999   {sri|srwi} %0,%1,%h2"
5000   [(set_attr "type" "integer,var_shift_rotate,shift")])
5001
5002 (define_insn "*lshrsi3_64"
5003   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5004         (zero_extend:DI
5005             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5006                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5007   "TARGET_POWERPC64"
5008   "@
5009   {sr|srw} %0,%1,%2
5010   {sri|srwi} %0,%1,%h2"
5011   [(set_attr "type" "var_shift_rotate,shift")])
5012
5013 (define_insn ""
5014   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5015         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5016                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
5017                     (const_int 0)))
5018    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
5019    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
5020   "TARGET_POWER"
5021   "@
5022   sre. %3,%1,%2
5023   mr. %1,%1
5024   {s%A2i.|s%A2wi.} %3,%1,%h2
5025   #
5026   #
5027   #"
5028   [(set_attr "type" "delayed_compare")
5029    (set_attr "length" "4,4,4,8,8,8")])
5030
5031 (define_split
5032   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5033         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5034                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5035                     (const_int 0)))
5036    (clobber (match_scratch:SI 3 ""))
5037    (clobber (match_scratch:SI 4 ""))]
5038   "TARGET_POWER && reload_completed"
5039   [(parallel [(set (match_dup 3)
5040         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5041    (clobber (match_dup 4))])
5042    (set (match_dup 0)
5043         (compare:CC (match_dup 3)
5044                     (const_int 0)))]
5045   "")
5046
5047 (define_insn ""
5048   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5049         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5050                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
5051                     (const_int 0)))
5052    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
5053   "! TARGET_POWER && TARGET_32BIT"
5054   "@
5055    mr. %1,%1
5056    {sr.|srw.} %3,%1,%2
5057    {sri.|srwi.} %3,%1,%h2
5058    #
5059    #
5060    #"
5061   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5062    (set_attr "length" "4,4,4,8,8,8")])
5063
5064 (define_split
5065   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5066         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5067                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5068                     (const_int 0)))
5069    (clobber (match_scratch:SI 3 ""))]
5070   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5071   [(set (match_dup 3)
5072         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5073    (set (match_dup 0)
5074         (compare:CC (match_dup 3)
5075                     (const_int 0)))]
5076   "")
5077
5078 (define_insn ""
5079   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5080         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5081                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
5082                     (const_int 0)))
5083    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
5084         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5085    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
5086   "TARGET_POWER"
5087   "@
5088   sre. %0,%1,%2
5089   mr. %0,%1
5090   {s%A2i.|s%A2wi.} %0,%1,%h2
5091   #
5092   #
5093   #"
5094   [(set_attr "type" "delayed_compare")
5095    (set_attr "length" "4,4,4,8,8,8")])
5096
5097 (define_split
5098   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5099         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5100                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5101                     (const_int 0)))
5102    (set (match_operand:SI 0 "gpc_reg_operand" "")
5103         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5104    (clobber (match_scratch:SI 4 ""))]
5105   "TARGET_POWER && reload_completed"
5106   [(parallel [(set (match_dup 0)
5107         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5108    (clobber (match_dup 4))])
5109    (set (match_dup 3)
5110         (compare:CC (match_dup 0)
5111                     (const_int 0)))]
5112   "")
5113
5114 (define_insn ""
5115   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5116         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5117                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
5118                     (const_int 0)))
5119    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
5120         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
5121   "! TARGET_POWER && TARGET_32BIT"
5122   "@
5123    mr. %0,%1
5124    {sr.|srw.} %0,%1,%2
5125    {sri.|srwi.} %0,%1,%h2
5126    #
5127    #
5128    #"
5129   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5130    (set_attr "length" "4,4,4,8,8,8")])
5131
5132 (define_split
5133   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5134         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5135                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5136                     (const_int 0)))
5137    (set (match_operand:SI 0 "gpc_reg_operand" "")
5138         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
5139   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5140   [(set (match_dup 0)
5141         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5142    (set (match_dup 3)
5143         (compare:CC (match_dup 0)
5144                     (const_int 0)))]
5145   "")
5146
5147 (define_insn ""
5148   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5149         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5150                              (match_operand:SI 2 "const_int_operand" "i"))
5151                 (match_operand:SI 3 "mask_operand" "n")))]
5152   "includes_rshift_p (operands[2], operands[3])"
5153   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
5154
5155 (define_insn ""
5156   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5157         (compare:CC
5158          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5159                               (match_operand:SI 2 "const_int_operand" "i,i"))
5160                  (match_operand:SI 3 "mask_operand" "n,n"))
5161          (const_int 0)))
5162    (clobber (match_scratch:SI 4 "=r,r"))]
5163   "includes_rshift_p (operands[2], operands[3])"
5164   "@
5165    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
5166    #"
5167   [(set_attr "type" "delayed_compare")
5168    (set_attr "length" "4,8")])
5169
5170 (define_split
5171   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5172         (compare:CC
5173          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5174                               (match_operand:SI 2 "const_int_operand" ""))
5175                  (match_operand:SI 3 "mask_operand" ""))
5176          (const_int 0)))
5177    (clobber (match_scratch:SI 4 ""))]
5178   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
5179   [(set (match_dup 4)
5180         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
5181                  (match_dup 3)))
5182    (set (match_dup 0)
5183         (compare:CC (match_dup 4)
5184                     (const_int 0)))]
5185   "")
5186
5187 (define_insn ""
5188   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
5189         (compare:CC
5190          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5191                               (match_operand:SI 2 "const_int_operand" "i,i"))
5192                  (match_operand:SI 3 "mask_operand" "n,n"))
5193          (const_int 0)))
5194    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5195         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5196   "includes_rshift_p (operands[2], operands[3])"
5197   "@
5198    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
5199    #"
5200   [(set_attr "type" "delayed_compare")
5201    (set_attr "length" "4,8")])
5202
5203 (define_split
5204   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
5205         (compare:CC
5206          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5207                               (match_operand:SI 2 "const_int_operand" ""))
5208                  (match_operand:SI 3 "mask_operand" ""))
5209          (const_int 0)))
5210    (set (match_operand:SI 0 "gpc_reg_operand" "")
5211         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5212   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
5213   [(set (match_dup 0)
5214         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
5215    (set (match_dup 4)
5216         (compare:CC (match_dup 0)
5217                     (const_int 0)))]
5218   "")
5219
5220 (define_insn ""
5221   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5222         (zero_extend:SI
5223          (subreg:QI
5224           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5225                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
5226   "includes_rshift_p (operands[2], GEN_INT (255))"
5227   "{rlinm|rlwinm} %0,%1,%s2,0xff")
5228
5229 (define_insn ""
5230   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5231         (compare:CC
5232          (zero_extend:SI
5233           (subreg:QI
5234            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5235                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5236          (const_int 0)))
5237    (clobber (match_scratch:SI 3 "=r,r"))]
5238   "includes_rshift_p (operands[2], GEN_INT (255))"
5239   "@
5240    {rlinm.|rlwinm.} %3,%1,%s2,0xff
5241    #"
5242   [(set_attr "type" "delayed_compare")
5243    (set_attr "length" "4,8")])
5244
5245 (define_split
5246   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5247         (compare:CC
5248          (zero_extend:SI
5249           (subreg:QI
5250            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5251                         (match_operand:SI 2 "const_int_operand" "")) 0))
5252          (const_int 0)))
5253    (clobber (match_scratch:SI 3 ""))]
5254   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
5255   [(set (match_dup 3)
5256         (zero_extend:SI (subreg:QI
5257            (lshiftrt:SI (match_dup 1)
5258                         (match_dup 2)) 0)))
5259    (set (match_dup 0)
5260         (compare:CC (match_dup 3)
5261                     (const_int 0)))]
5262   "")
5263
5264 (define_insn ""
5265   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5266         (compare:CC
5267          (zero_extend:SI
5268           (subreg:QI
5269            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5270                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5271          (const_int 0)))
5272    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5273         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5274   "includes_rshift_p (operands[2], GEN_INT (255))"
5275   "@
5276    {rlinm.|rlwinm.} %0,%1,%s2,0xff
5277    #"
5278   [(set_attr "type" "delayed_compare")
5279    (set_attr "length" "4,8")])
5280
5281 (define_split
5282   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5283         (compare:CC
5284          (zero_extend:SI
5285           (subreg:QI
5286            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5287                         (match_operand:SI 2 "const_int_operand" "")) 0))
5288          (const_int 0)))
5289    (set (match_operand:SI 0 "gpc_reg_operand" "")
5290         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5291   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
5292   [(set (match_dup 0)
5293         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5294    (set (match_dup 3)
5295         (compare:CC (match_dup 0)
5296                     (const_int 0)))]
5297   "")
5298
5299 (define_insn ""
5300   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5301         (zero_extend:SI
5302          (subreg:HI
5303           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5304                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
5305   "includes_rshift_p (operands[2], GEN_INT (65535))"
5306   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
5307
5308 (define_insn ""
5309   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5310         (compare:CC
5311          (zero_extend:SI
5312           (subreg:HI
5313            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5314                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5315          (const_int 0)))
5316    (clobber (match_scratch:SI 3 "=r,r"))]
5317   "includes_rshift_p (operands[2], GEN_INT (65535))"
5318   "@
5319    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
5320    #"
5321   [(set_attr "type" "delayed_compare")
5322    (set_attr "length" "4,8")])
5323
5324 (define_split
5325   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5326         (compare:CC
5327          (zero_extend:SI
5328           (subreg:HI
5329            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5330                         (match_operand:SI 2 "const_int_operand" "")) 0))
5331          (const_int 0)))
5332    (clobber (match_scratch:SI 3 ""))]
5333   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5334   [(set (match_dup 3)
5335         (zero_extend:SI (subreg:HI
5336            (lshiftrt:SI (match_dup 1)
5337                         (match_dup 2)) 0)))
5338    (set (match_dup 0)
5339         (compare:CC (match_dup 3)
5340                     (const_int 0)))]
5341   "")
5342
5343 (define_insn ""
5344   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5345         (compare:CC
5346          (zero_extend:SI
5347           (subreg:HI
5348            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5349                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5350          (const_int 0)))
5351    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5352         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5353   "includes_rshift_p (operands[2], GEN_INT (65535))"
5354   "@
5355    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
5356    #"
5357   [(set_attr "type" "delayed_compare")
5358    (set_attr "length" "4,8")])
5359
5360 (define_split
5361   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5362         (compare:CC
5363          (zero_extend:SI
5364           (subreg:HI
5365            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5366                         (match_operand:SI 2 "const_int_operand" "")) 0))
5367          (const_int 0)))
5368    (set (match_operand:SI 0 "gpc_reg_operand" "")
5369         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5370   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5371   [(set (match_dup 0)
5372         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5373    (set (match_dup 3)
5374         (compare:CC (match_dup 0)
5375                     (const_int 0)))]
5376   "")
5377
5378 (define_insn ""
5379   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5380                          (const_int 1)
5381                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5382         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5383                      (const_int 31)))]
5384   "TARGET_POWER"
5385   "rrib %0,%1,%2")
5386
5387 (define_insn ""
5388   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5389                          (const_int 1)
5390                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5391         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5392                      (const_int 31)))]
5393   "TARGET_POWER"
5394   "rrib %0,%1,%2")
5395
5396 (define_insn ""
5397   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5398                          (const_int 1)
5399                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5400         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5401                          (const_int 1)
5402                          (const_int 0)))]
5403   "TARGET_POWER"
5404   "rrib %0,%1,%2")
5405
5406 (define_expand "ashrsi3"
5407   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5408         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5409                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
5410   ""
5411   "
5412 {
5413   if (TARGET_POWER)
5414     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
5415   else
5416     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
5417   DONE;
5418 }")
5419
5420 (define_insn "ashrsi3_power"
5421   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5422         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5423                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
5424    (clobber (match_scratch:SI 3 "=q,X"))]
5425   "TARGET_POWER"
5426   "@
5427    srea %0,%1,%2
5428    {srai|srawi} %0,%1,%h2"
5429   [(set_attr "type" "shift")])
5430
5431 (define_insn "ashrsi3_no_power"
5432   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5433         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5434                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
5435   "! TARGET_POWER"
5436   "@
5437    {sra|sraw} %0,%1,%2
5438    {srai|srawi} %0,%1,%h2"
5439   [(set_attr "type" "var_shift_rotate,shift")])
5440
5441 (define_insn "*ashrsi3_64"
5442   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5443         (sign_extend:DI
5444             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5445                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5446   "TARGET_POWERPC64"
5447   "@
5448    {sra|sraw} %0,%1,%2
5449    {srai|srawi} %0,%1,%h2"
5450   [(set_attr "type" "var_shift_rotate,shift")])
5451
5452 (define_insn ""
5453   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5454         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5455                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5456                     (const_int 0)))
5457    (clobber (match_scratch:SI 3 "=r,r,r,r"))
5458    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5459   "TARGET_POWER"
5460   "@
5461    srea. %3,%1,%2
5462    {srai.|srawi.} %3,%1,%h2
5463    #
5464    #"
5465   [(set_attr "type" "delayed_compare")
5466    (set_attr "length" "4,4,8,8")])
5467
5468 (define_split
5469   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5470         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5471                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5472                     (const_int 0)))
5473    (clobber (match_scratch:SI 3 ""))
5474    (clobber (match_scratch:SI 4 ""))]
5475   "TARGET_POWER && reload_completed"
5476   [(parallel [(set (match_dup 3)
5477         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5478    (clobber (match_dup 4))])
5479    (set (match_dup 0)
5480         (compare:CC (match_dup 3)
5481                     (const_int 0)))]
5482   "")
5483
5484 (define_insn ""
5485   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5486         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5487                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5488                     (const_int 0)))
5489    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
5490   "! TARGET_POWER"
5491   "@
5492    {sra.|sraw.} %3,%1,%2
5493    {srai.|srawi.} %3,%1,%h2
5494    #
5495    #"
5496   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5497    (set_attr "length" "4,4,8,8")])
5498
5499 (define_split
5500   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5501         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5502                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5503                     (const_int 0)))
5504    (clobber (match_scratch:SI 3 ""))]
5505   "! TARGET_POWER && reload_completed"
5506   [(set (match_dup 3)
5507         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5508    (set (match_dup 0)
5509         (compare:CC (match_dup 3)
5510                     (const_int 0)))]
5511   "")
5512
5513 (define_insn ""
5514   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5515         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5516                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5517                     (const_int 0)))
5518    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5519         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5520    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5521   "TARGET_POWER"
5522   "@
5523    srea. %0,%1,%2
5524    {srai.|srawi.} %0,%1,%h2
5525    #
5526    #"
5527   [(set_attr "type" "delayed_compare")
5528    (set_attr "length" "4,4,8,8")])
5529
5530 (define_split
5531   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5532         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5533                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5534                     (const_int 0)))
5535    (set (match_operand:SI 0 "gpc_reg_operand" "")
5536         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5537    (clobber (match_scratch:SI 4 ""))]
5538   "TARGET_POWER && reload_completed"
5539   [(parallel [(set (match_dup 0)
5540         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5541    (clobber (match_dup 4))])
5542    (set (match_dup 3)
5543         (compare:CC (match_dup 0)
5544                     (const_int 0)))]
5545   "")
5546
5547 (define_insn ""
5548   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5549         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5550                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5551                     (const_int 0)))
5552    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5553         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5554   "! TARGET_POWER"
5555   "@
5556    {sra.|sraw.} %0,%1,%2
5557    {srai.|srawi.} %0,%1,%h2
5558    #
5559    #"
5560   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5561    (set_attr "length" "4,4,8,8")])
5562 \f
5563 (define_split
5564   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5565         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5566                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5567                     (const_int 0)))
5568    (set (match_operand:SI 0 "gpc_reg_operand" "")
5569         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5570   "! TARGET_POWER && reload_completed"
5571   [(set (match_dup 0)
5572         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5573    (set (match_dup 3)
5574         (compare:CC (match_dup 0)
5575                     (const_int 0)))]
5576   "")
5577
5578 ;; Floating-point insns, excluding normal data motion.
5579 ;;
5580 ;; PowerPC has a full set of single-precision floating point instructions.
5581 ;;
5582 ;; For the POWER architecture, we pretend that we have both SFmode and
5583 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
5584 ;; The only conversions we will do will be when storing to memory.  In that
5585 ;; case, we will use the "frsp" instruction before storing.
5586 ;;
5587 ;; Note that when we store into a single-precision memory location, we need to
5588 ;; use the frsp insn first.  If the register being stored isn't dead, we
5589 ;; need a scratch register for the frsp.  But this is difficult when the store
5590 ;; is done by reload.  It is not incorrect to do the frsp on the register in
5591 ;; this case, we just lose precision that we would have otherwise gotten but
5592 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
5593
5594 (define_expand "extendsfdf2"
5595   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5596         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5597   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5598   "")
5599
5600 (define_insn_and_split "*extendsfdf2_fpr"
5601   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d")
5602         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
5603   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5604   "@
5605    #
5606    fmr %0,%1
5607    lfs%U1%X1 %0,%1"
5608   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5609   [(const_int 0)]
5610 {
5611   emit_note (NOTE_INSN_DELETED);
5612   DONE;
5613 }
5614   [(set_attr "type" "fp,fp,fpload")])
5615
5616 (define_expand "truncdfsf2"
5617   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5618         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5619   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5620   "")
5621
5622 (define_insn "*truncdfsf2_fpr"
5623   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5624         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5625   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5626   "frsp %0,%1"
5627   [(set_attr "type" "fp")])
5628
5629 (define_insn "aux_truncdfsf2"
5630   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5631         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
5632   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5633   "frsp %0,%1"
5634   [(set_attr "type" "fp")])
5635
5636 (define_expand "negsf2"
5637   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5638         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5639   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5640   "")
5641
5642 (define_insn "*negsf2"
5643   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5644         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5645   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5646   "fneg %0,%1"
5647   [(set_attr "type" "fp")])
5648
5649 (define_expand "abssf2"
5650   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5651         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5652   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5653   "")
5654
5655 (define_insn "*abssf2"
5656   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5657         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5658   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5659   "fabs %0,%1"
5660   [(set_attr "type" "fp")])
5661
5662 (define_insn ""
5663   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5664         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
5665   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5666   "fnabs %0,%1"
5667   [(set_attr "type" "fp")])
5668
5669 (define_expand "addsf3"
5670   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5671         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5672                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5673   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5674   "")
5675
5676 (define_insn ""
5677   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5678         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5679                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5680   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5681   "fadds %0,%1,%2"
5682   [(set_attr "type" "fp")
5683    (set_attr "fp_type" "fp_addsub_s")])
5684
5685 (define_insn ""
5686   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5687         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5688                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5689   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5690   "{fa|fadd} %0,%1,%2"
5691   [(set_attr "type" "fp")])
5692
5693 (define_expand "subsf3"
5694   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5695         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5696                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5697   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5698   "")
5699
5700 (define_insn ""
5701   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5702         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5703                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5704   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5705   "fsubs %0,%1,%2"
5706   [(set_attr "type" "fp")
5707    (set_attr "fp_type" "fp_addsub_s")])
5708
5709 (define_insn ""
5710   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5711         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5712                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5713   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5714   "{fs|fsub} %0,%1,%2"
5715   [(set_attr "type" "fp")])
5716
5717 (define_expand "mulsf3"
5718   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5719         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5720                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5721   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5722   "")
5723
5724 (define_insn ""
5725   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5726         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5727                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5728   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5729   "fmuls %0,%1,%2"
5730   [(set_attr "type" "fp")
5731    (set_attr "fp_type" "fp_mul_s")])
5732
5733 (define_insn ""
5734   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5735         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5736                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5737   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5738   "{fm|fmul} %0,%1,%2"
5739   [(set_attr "type" "dmul")])
5740
5741 (define_expand "divsf3"
5742   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5743         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5744                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5745   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5746   "")
5747
5748 (define_insn ""
5749   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5750         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5751                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5752   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS 
5753    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5754   "fdivs %0,%1,%2"
5755   [(set_attr "type" "sdiv")])
5756
5757 (define_insn ""
5758   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5759         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5760                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5761   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS 
5762    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5763   "{fd|fdiv} %0,%1,%2"
5764   [(set_attr "type" "ddiv")])
5765
5766 (define_expand "recipsf3"
5767   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5768         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")
5769                     (match_operand:SF 2 "gpc_reg_operand" "f")]
5770                    UNSPEC_FRES))]
5771   "TARGET_RECIP && TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT && !optimize_size
5772    && flag_finite_math_only && !flag_trapping_math"
5773 {
5774    rs6000_emit_swdivsf (operands[0], operands[1], operands[2]);
5775    DONE;
5776 })
5777
5778 (define_insn "fres"
5779   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5780         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5781   "TARGET_PPC_GFXOPT && flag_finite_math_only"
5782   "fres %0,%1"
5783   [(set_attr "type" "fp")])
5784
5785 (define_insn "*fmaddsf4_powerpc"
5786   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5787         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5788                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5789                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5790   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS
5791    && TARGET_SINGLE_FLOAT && TARGET_FUSED_MADD"
5792   "fmadds %0,%1,%2,%3"
5793   [(set_attr "type" "fp")
5794    (set_attr "fp_type" "fp_maddsub_s")])
5795
5796 (define_insn "*fmaddsf4_power"
5797   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5798         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5799                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5800                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5801   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5802   "{fma|fmadd} %0,%1,%2,%3"
5803   [(set_attr "type" "dmul")])
5804
5805 (define_insn "*fmsubsf4_powerpc"
5806   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5807         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5808                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5809                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5810   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS
5811    && TARGET_SINGLE_FLOAT && TARGET_FUSED_MADD"
5812   "fmsubs %0,%1,%2,%3"
5813   [(set_attr "type" "fp")
5814    (set_attr "fp_type" "fp_maddsub_s")])
5815
5816 (define_insn "*fmsubsf4_power"
5817   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5818         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5819                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5820                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5821   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5822   "{fms|fmsub} %0,%1,%2,%3"
5823   [(set_attr "type" "dmul")])
5824
5825 (define_insn "*fnmaddsf4_powerpc_1"
5826   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5827         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5828                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5829                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5830   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5831    && TARGET_SINGLE_FLOAT"
5832   "fnmadds %0,%1,%2,%3"
5833   [(set_attr "type" "fp")
5834    (set_attr "fp_type" "fp_maddsub_s")])
5835
5836 (define_insn "*fnmaddsf4_powerpc_2"
5837   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5838         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5839                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5840                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5841   "TARGET_POWERPC && TARGET_SINGLE_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5842    && ! HONOR_SIGNED_ZEROS (SFmode)"
5843   "fnmadds %0,%1,%2,%3"
5844   [(set_attr "type" "fp")
5845    (set_attr "fp_type" "fp_maddsub_s")])
5846
5847 (define_insn "*fnmaddsf4_power_1"
5848   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5849         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5850                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5851                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5852   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5853   "{fnma|fnmadd} %0,%1,%2,%3"
5854   [(set_attr "type" "dmul")])
5855
5856 (define_insn "*fnmaddsf4_power_2"
5857   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5858         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5859                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5860                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5861   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5862    && ! HONOR_SIGNED_ZEROS (SFmode)"
5863   "{fnma|fnmadd} %0,%1,%2,%3"
5864   [(set_attr "type" "dmul")])
5865
5866 (define_insn "*fnmsubsf4_powerpc_1"
5867   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5868         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5869                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5870                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5871   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5872    && TARGET_SINGLE_FLOAT"
5873   "fnmsubs %0,%1,%2,%3"
5874   [(set_attr "type" "fp")
5875    (set_attr "fp_type" "fp_maddsub_s")])
5876
5877 (define_insn "*fnmsubsf4_powerpc_2"
5878   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5879         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5880                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5881                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5882   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5883    && TARGET_SINGLE_FLOAT && ! HONOR_SIGNED_ZEROS (SFmode)"
5884   "fnmsubs %0,%1,%2,%3"
5885   [(set_attr "type" "fp")
5886    (set_attr "fp_type" "fp_maddsub_s")])
5887
5888 (define_insn "*fnmsubsf4_power_1"
5889   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5890         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5891                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5892                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5893   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5894   "{fnms|fnmsub} %0,%1,%2,%3"
5895   [(set_attr "type" "dmul")])
5896
5897 (define_insn "*fnmsubsf4_power_2"
5898   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5899         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5900                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5901                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5902   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5903    && ! HONOR_SIGNED_ZEROS (SFmode)"
5904   "{fnms|fnmsub} %0,%1,%2,%3"
5905   [(set_attr "type" "dmul")])
5906
5907 (define_expand "sqrtsf2"
5908   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5909         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5910   "(TARGET_PPC_GPOPT || TARGET_POWER2 || TARGET_XILINX_FPU)
5911    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5912    && !TARGET_SIMPLE_FPU"
5913   "")
5914
5915 (define_insn ""
5916   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5917         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5918   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU) && TARGET_HARD_FLOAT
5919    && TARGET_FPRS && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5920   "fsqrts %0,%1"
5921   [(set_attr "type" "ssqrt")])
5922
5923 (define_insn ""
5924   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5925         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5926   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS 
5927    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5928   "fsqrt %0,%1"
5929   [(set_attr "type" "dsqrt")])
5930
5931 (define_expand "rsqrtsf2"
5932   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5933         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
5934                    UNSPEC_RSQRT))]
5935   "TARGET_RECIP && TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT && !optimize_size
5936    && flag_finite_math_only && !flag_trapping_math"
5937 {
5938   rs6000_emit_swrsqrtsf (operands[0], operands[1]);
5939   DONE;
5940 })
5941
5942 (define_insn "*rsqrt_internal1"
5943   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5944         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
5945                    UNSPEC_RSQRT))]
5946   "TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT"
5947   "frsqrte %0,%1"
5948   [(set_attr "type" "fp")])
5949
5950 (define_expand "copysignsf3"
5951   [(set (match_dup 3)
5952         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
5953    (set (match_dup 4)
5954         (neg:SF (abs:SF (match_dup 1))))
5955    (set (match_operand:SF 0 "gpc_reg_operand" "")
5956         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
5957                              (match_dup 5))
5958                          (match_dup 3)
5959                          (match_dup 4)))]
5960   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5961    && !HONOR_NANS (SFmode) && !HONOR_SIGNED_ZEROS (SFmode)"
5962   {
5963      operands[3] = gen_reg_rtx (SFmode);
5964      operands[4] = gen_reg_rtx (SFmode);
5965      operands[5] = CONST0_RTX (SFmode);
5966   })
5967
5968 (define_expand "copysigndf3"
5969   [(set (match_dup 3)
5970         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
5971    (set (match_dup 4)
5972         (neg:DF (abs:DF (match_dup 1))))
5973    (set (match_operand:DF 0 "gpc_reg_operand" "")
5974         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
5975                              (match_dup 5))
5976                          (match_dup 3)
5977                          (match_dup 4)))]
5978   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5979    && ((TARGET_PPC_GFXOPT
5980         && !HONOR_NANS (DFmode)
5981         && !HONOR_SIGNED_ZEROS (DFmode))
5982        || VECTOR_UNIT_VSX_P (DFmode))"
5983   {
5984      if (VECTOR_UNIT_VSX_P (DFmode))
5985        {
5986          emit_insn (gen_vsx_copysigndf3 (operands[0], operands[1],
5987                                          operands[2], CONST0_RTX (DFmode)));
5988          DONE;
5989        }
5990      operands[3] = gen_reg_rtx (DFmode);
5991      operands[4] = gen_reg_rtx (DFmode);
5992      operands[5] = CONST0_RTX (DFmode);
5993   })
5994
5995 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5996 ;; fsel instruction and some auxiliary computations.  Then we just have a
5997 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5998 ;; combine.
5999 (define_expand "smaxsf3"
6000   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6001         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
6002                              (match_operand:SF 2 "gpc_reg_operand" ""))
6003                          (match_dup 1)
6004                          (match_dup 2)))]
6005   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6006    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6007   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
6008
6009 (define_expand "sminsf3"
6010   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6011         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
6012                              (match_operand:SF 2 "gpc_reg_operand" ""))
6013                          (match_dup 2)
6014                          (match_dup 1)))]
6015   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6016    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6017   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
6018
6019 (define_split
6020   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6021         (match_operator:SF 3 "min_max_operator"
6022          [(match_operand:SF 1 "gpc_reg_operand" "")
6023           (match_operand:SF 2 "gpc_reg_operand" "")]))]
6024   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6025    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6026   [(const_int 0)]
6027   "
6028 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
6029                       operands[1], operands[2]);
6030   DONE;
6031 }")
6032
6033 (define_expand "mov<mode>cc"
6034    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
6035          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
6036                            (match_operand:GPR 2 "gpc_reg_operand" "")
6037                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
6038   "TARGET_ISEL<sel>"
6039   "
6040 {
6041   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6042     DONE;
6043   else
6044     FAIL;
6045 }")
6046
6047 ;; We use the BASE_REGS for the isel input operands because, if rA is
6048 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
6049 ;; because we may switch the operands and rB may end up being rA.
6050 ;;
6051 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
6052 ;; leave out the mode in operand 4 and use one pattern, but reload can
6053 ;; change the mode underneath our feet and then gets confused trying
6054 ;; to reload the value.
6055 (define_insn "isel_signed_<mode>"
6056   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
6057         (if_then_else:GPR
6058          (match_operator 1 "comparison_operator"
6059                          [(match_operand:CC 4 "cc_reg_operand" "y")
6060                           (const_int 0)])
6061          (match_operand:GPR 2 "gpc_reg_operand" "b")
6062          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
6063   "TARGET_ISEL<sel>"
6064   "*
6065 { return output_isel (operands); }"
6066   [(set_attr "type" "isel")
6067    (set_attr "length" "4")])
6068
6069 (define_insn "isel_unsigned_<mode>"
6070   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
6071         (if_then_else:GPR
6072          (match_operator 1 "comparison_operator"
6073                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
6074                           (const_int 0)])
6075          (match_operand:GPR 2 "gpc_reg_operand" "b")
6076          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
6077   "TARGET_ISEL<sel>"
6078   "*
6079 { return output_isel (operands); }"
6080   [(set_attr "type" "isel")
6081    (set_attr "length" "4")])
6082
6083 (define_expand "movsfcc"
6084    [(set (match_operand:SF 0 "gpc_reg_operand" "")
6085          (if_then_else:SF (match_operand 1 "comparison_operator" "")
6086                           (match_operand:SF 2 "gpc_reg_operand" "")
6087                           (match_operand:SF 3 "gpc_reg_operand" "")))]
6088   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6089   "
6090 {
6091   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6092     DONE;
6093   else
6094     FAIL;
6095 }")
6096
6097 (define_insn "*fselsfsf4"
6098   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6099         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
6100                              (match_operand:SF 4 "zero_fp_constant" "F"))
6101                          (match_operand:SF 2 "gpc_reg_operand" "f")
6102                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
6103   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6104   "fsel %0,%1,%2,%3"
6105   [(set_attr "type" "fp")])
6106
6107 (define_insn "*fseldfsf4"
6108   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6109         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
6110                              (match_operand:DF 4 "zero_fp_constant" "F"))
6111                          (match_operand:SF 2 "gpc_reg_operand" "f")
6112                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
6113   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
6114   "fsel %0,%1,%2,%3"
6115   [(set_attr "type" "fp")])
6116
6117 (define_expand "negdf2"
6118   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6119         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6120   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6121   "")
6122
6123 (define_insn "*negdf2_fpr"
6124   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6125         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6126   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6127    && !VECTOR_UNIT_VSX_P (DFmode)"
6128   "fneg %0,%1"
6129   [(set_attr "type" "fp")])
6130
6131 (define_expand "absdf2"
6132   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6133         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6134   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6135   "")
6136
6137 (define_insn "*absdf2_fpr"
6138   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6139         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6140   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6141    && !VECTOR_UNIT_VSX_P (DFmode)"
6142   "fabs %0,%1"
6143   [(set_attr "type" "fp")])
6144
6145 (define_insn "*nabsdf2_fpr"
6146   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6147         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d"))))]
6148   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6149    && !VECTOR_UNIT_VSX_P (DFmode)"
6150   "fnabs %0,%1"
6151   [(set_attr "type" "fp")])
6152
6153 (define_expand "adddf3"
6154   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6155         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
6156                  (match_operand:DF 2 "gpc_reg_operand" "")))]
6157   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6158   "")
6159
6160 (define_insn "*adddf3_fpr"
6161   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6162         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6163                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
6164   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6165    && !VECTOR_UNIT_VSX_P (DFmode)"
6166   "{fa|fadd} %0,%1,%2"
6167   [(set_attr "type" "fp")
6168    (set_attr "fp_type" "fp_addsub_d")])
6169
6170 (define_expand "subdf3"
6171   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6172         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
6173                   (match_operand:DF 2 "gpc_reg_operand" "")))]
6174   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6175   "")
6176
6177 (define_insn "*subdf3_fpr"
6178   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6179         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "d")
6180                   (match_operand:DF 2 "gpc_reg_operand" "d")))]
6181   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6182    && !VECTOR_UNIT_VSX_P (DFmode)"
6183   "{fs|fsub} %0,%1,%2"
6184   [(set_attr "type" "fp")
6185    (set_attr "fp_type" "fp_addsub_d")])
6186
6187 (define_expand "muldf3"
6188   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6189         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
6190                  (match_operand:DF 2 "gpc_reg_operand" "")))]
6191   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6192   "")
6193
6194 (define_insn "*muldf3_fpr"
6195   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6196         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6197                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
6198   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6199    && !VECTOR_UNIT_VSX_P (DFmode)"
6200   "{fm|fmul} %0,%1,%2"
6201   [(set_attr "type" "dmul")
6202    (set_attr "fp_type" "fp_mul_d")])
6203
6204 (define_expand "divdf3"
6205   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6206         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
6207                 (match_operand:DF 2 "gpc_reg_operand" "")))]
6208   "TARGET_HARD_FLOAT
6209    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)
6210    && !TARGET_SIMPLE_FPU"
6211   "")
6212
6213 (define_insn "*divdf3_fpr"
6214   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6215         (div:DF (match_operand:DF 1 "gpc_reg_operand" "d")
6216                 (match_operand:DF 2 "gpc_reg_operand" "d")))]
6217   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && !TARGET_SIMPLE_FPU
6218    && !VECTOR_UNIT_VSX_P (DFmode)"
6219   "{fd|fdiv} %0,%1,%2"
6220   [(set_attr "type" "ddiv")])
6221
6222 (define_expand "recipdf3"
6223   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6224         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")
6225                     (match_operand:DF 2 "gpc_reg_operand" "d")]
6226                    UNSPEC_FRES))]
6227   "TARGET_RECIP && TARGET_HARD_FLOAT && TARGET_POPCNTB && !optimize_size
6228    && flag_finite_math_only && !flag_trapping_math"
6229 {
6230    rs6000_emit_swdivdf (operands[0], operands[1], operands[2]);
6231    DONE;
6232 })
6233
6234 (define_expand "fred"
6235   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6236         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRES))]
6237   "(TARGET_POPCNTB || VECTOR_UNIT_VSX_P (DFmode)) && flag_finite_math_only"
6238   "")
6239
6240 (define_insn "*fred_fpr"
6241   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6242         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
6243   "TARGET_POPCNTB && flag_finite_math_only && !VECTOR_UNIT_VSX_P (DFmode)"
6244   "fre %0,%1"
6245   [(set_attr "type" "fp")])
6246
6247 (define_insn "*fmadddf4_fpr"
6248   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6249         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6250                           (match_operand:DF 2 "gpc_reg_operand" "d"))
6251                  (match_operand:DF 3 "gpc_reg_operand" "d")))]
6252   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6253    && VECTOR_UNIT_NONE_P (DFmode)"
6254   "{fma|fmadd} %0,%1,%2,%3"
6255   [(set_attr "type" "dmul")
6256    (set_attr "fp_type" "fp_maddsub_d")])
6257
6258 (define_insn "*fmsubdf4_fpr"
6259   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6260         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6261                            (match_operand:DF 2 "gpc_reg_operand" "d"))
6262                   (match_operand:DF 3 "gpc_reg_operand" "d")))]
6263   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6264    && VECTOR_UNIT_NONE_P (DFmode)"
6265   "{fms|fmsub} %0,%1,%2,%3"
6266   [(set_attr "type" "dmul")
6267    (set_attr "fp_type" "fp_maddsub_d")])
6268
6269 (define_insn "*fnmadddf4_fpr_1"
6270   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6271         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6272                                   (match_operand:DF 2 "gpc_reg_operand" "d"))
6273                          (match_operand:DF 3 "gpc_reg_operand" "d"))))]
6274   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6275    && VECTOR_UNIT_NONE_P (DFmode)"
6276   "{fnma|fnmadd} %0,%1,%2,%3"
6277   [(set_attr "type" "dmul")
6278    (set_attr "fp_type" "fp_maddsub_d")])
6279
6280 (define_insn "*fnmadddf4_fpr_2"
6281   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6282         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d"))
6283                            (match_operand:DF 2 "gpc_reg_operand" "d"))
6284                   (match_operand:DF 3 "gpc_reg_operand" "d")))]
6285   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6286    && ! HONOR_SIGNED_ZEROS (DFmode) && VECTOR_UNIT_NONE_P (DFmode)"
6287   "{fnma|fnmadd} %0,%1,%2,%3"
6288   [(set_attr "type" "dmul")
6289    (set_attr "fp_type" "fp_maddsub_d")])
6290
6291 (define_insn "*fnmsubdf4_fpr_1"
6292   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6293         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6294                                    (match_operand:DF 2 "gpc_reg_operand" "d"))
6295                           (match_operand:DF 3 "gpc_reg_operand" "d"))))]
6296   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6297    && VECTOR_UNIT_NONE_P (DFmode)"
6298   "{fnms|fnmsub} %0,%1,%2,%3"
6299   [(set_attr "type" "dmul")
6300    (set_attr "fp_type" "fp_maddsub_d")])
6301
6302 (define_insn "*fnmsubdf4_fpr_2"
6303   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6304         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "d")
6305                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6306                            (match_operand:DF 2 "gpc_reg_operand" "d"))))]
6307   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6308    && ! HONOR_SIGNED_ZEROS (DFmode) && VECTOR_UNIT_NONE_P (DFmode)"
6309   "{fnms|fnmsub} %0,%1,%2,%3"
6310   [(set_attr "type" "dmul")
6311    (set_attr "fp_type" "fp_maddsub_d")])
6312
6313 (define_insn "sqrtdf2"
6314   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6315         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6316   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS 
6317    && TARGET_DOUBLE_FLOAT
6318    && !VECTOR_UNIT_VSX_P (DFmode)"
6319   "fsqrt %0,%1"
6320   [(set_attr "type" "dsqrt")])
6321
6322 ;; The conditional move instructions allow us to perform max and min
6323 ;; operations even when
6324
6325 (define_expand "smaxdf3"
6326   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6327         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
6328                              (match_operand:DF 2 "gpc_reg_operand" ""))
6329                          (match_dup 1)
6330                          (match_dup 2)))]
6331   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6332    && !flag_trapping_math"
6333   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
6334
6335 (define_expand "smindf3"
6336   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6337         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
6338                              (match_operand:DF 2 "gpc_reg_operand" ""))
6339                          (match_dup 2)
6340                          (match_dup 1)))]
6341   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6342    && !flag_trapping_math"
6343   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
6344
6345 (define_split
6346   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6347         (match_operator:DF 3 "min_max_operator"
6348          [(match_operand:DF 1 "gpc_reg_operand" "")
6349           (match_operand:DF 2 "gpc_reg_operand" "")]))]
6350   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6351    && !flag_trapping_math"
6352   [(const_int 0)]
6353   "
6354 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
6355                       operands[1], operands[2]);
6356   DONE;
6357 }")
6358
6359 (define_expand "movdfcc"
6360    [(set (match_operand:DF 0 "gpc_reg_operand" "")
6361          (if_then_else:DF (match_operand 1 "comparison_operator" "")
6362                           (match_operand:DF 2 "gpc_reg_operand" "")
6363                           (match_operand:DF 3 "gpc_reg_operand" "")))]
6364   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6365   "
6366 {
6367   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6368     DONE;
6369   else
6370     FAIL;
6371 }")
6372
6373 (define_insn "*fseldfdf4"
6374   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6375         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
6376                              (match_operand:DF 4 "zero_fp_constant" "F"))
6377                          (match_operand:DF 2 "gpc_reg_operand" "d")
6378                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
6379   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6380   "fsel %0,%1,%2,%3"
6381   [(set_attr "type" "fp")])
6382
6383 (define_insn "*fselsfdf4"
6384   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6385         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
6386                              (match_operand:SF 4 "zero_fp_constant" "F"))
6387                          (match_operand:DF 2 "gpc_reg_operand" "d")
6388                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
6389   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
6390   "fsel %0,%1,%2,%3"
6391   [(set_attr "type" "fp")])
6392 \f
6393 ;; Conversions to and from floating-point.
6394
6395 (define_expand "fixuns_truncsfsi2"
6396   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6397         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
6398   "TARGET_HARD_FLOAT && !TARGET_FPRS && TARGET_SINGLE_FLOAT"
6399   "")
6400
6401 (define_expand "fix_truncsfsi2"
6402  [(set (match_operand:SI 0 "gpc_reg_operand" "")
6403       (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
6404  "TARGET_HARD_FLOAT && !TARGET_FPRS && TARGET_SINGLE_FLOAT"
6405  "")
6406
6407 (define_expand "fixuns_truncdfsi2"
6408   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6409         (unsigned_fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
6410   "TARGET_HARD_FLOAT && TARGET_E500_DOUBLE"
6411   "")
6412
6413 (define_expand "fixuns_truncdfdi2"
6414   [(set (match_operand:DI 0 "register_operand" "")
6415         (unsigned_fix:DI (match_operand:DF 1 "register_operand" "")))]
6416   "TARGET_HARD_FLOAT && TARGET_VSX"
6417   "")
6418
6419 ; For each of these conversions, there is a define_expand, a define_insn
6420 ; with a '#' template, and a define_split (with C code).  The idea is
6421 ; to allow constant folding with the template of the define_insn,
6422 ; then to have the insns split later (between sched1 and final).
6423
6424 (define_expand "floatsidf2"
6425   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
6426                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
6427               (use (match_dup 2))
6428               (use (match_dup 3))
6429               (clobber (match_dup 4))
6430               (clobber (match_dup 5))
6431               (clobber (match_dup 6))])]
6432   "TARGET_HARD_FLOAT 
6433    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6434   "
6435 {
6436   if (TARGET_E500_DOUBLE)
6437     {
6438       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
6439       DONE;
6440     }
6441   if (TARGET_POWERPC64)
6442     {
6443       rtx x = convert_to_mode (DImode, operands[1], 0);
6444       emit_insn (gen_floatdidf2 (operands[0], x));
6445       DONE;
6446     }
6447
6448   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6449   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
6450   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
6451   operands[5] = gen_reg_rtx (DFmode);
6452   operands[6] = gen_reg_rtx (SImode);
6453 }")
6454
6455 (define_insn_and_split "*floatsidf2_internal"
6456   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6457         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6458    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6459    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6460    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6461    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
6462    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
6463   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6464   "#"
6465   ""
6466   [(pc)]
6467   "
6468 {
6469   rtx lowword, highword;
6470   gcc_assert (MEM_P (operands[4]));
6471   highword = adjust_address (operands[4], SImode, 0);
6472   lowword = adjust_address (operands[4], SImode, 4);
6473   if (! WORDS_BIG_ENDIAN)
6474     {
6475       rtx tmp;
6476       tmp = highword; highword = lowword; lowword = tmp;
6477     }
6478
6479   emit_insn (gen_xorsi3 (operands[6], operands[1],
6480                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
6481   emit_move_insn (lowword, operands[6]);
6482   emit_move_insn (highword, operands[2]);
6483   emit_move_insn (operands[5], operands[4]);
6484   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6485   DONE;
6486 }"
6487   [(set_attr "length" "24")])
6488
6489 (define_expand "floatunssisf2"
6490   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6491         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
6492   "TARGET_HARD_FLOAT && !TARGET_FPRS && TARGET_SINGLE_FLOAT"
6493   "")
6494
6495 (define_expand "floatunssidf2"
6496   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
6497                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
6498               (use (match_dup 2))
6499               (use (match_dup 3))
6500               (clobber (match_dup 4))
6501               (clobber (match_dup 5))])]
6502   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6503   "
6504 {
6505   if (TARGET_E500_DOUBLE)
6506     {
6507       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
6508       DONE;
6509     }
6510   if (TARGET_POWERPC64)
6511     {
6512       rtx x = convert_to_mode (DImode, operands[1], 1);
6513       emit_insn (gen_floatdidf2 (operands[0], x));
6514       DONE;
6515     }
6516
6517   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6518   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
6519   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
6520   operands[5] = gen_reg_rtx (DFmode);
6521 }")
6522
6523 (define_insn_and_split "*floatunssidf2_internal"
6524   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6525         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6526    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6527    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6528    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6529    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
6530   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6531   "#"
6532   ""
6533   [(pc)]
6534   "
6535 {
6536   rtx lowword, highword;
6537   gcc_assert (MEM_P (operands[4]));
6538   highword = adjust_address (operands[4], SImode, 0);
6539   lowword = adjust_address (operands[4], SImode, 4);
6540   if (! WORDS_BIG_ENDIAN)
6541     {
6542       rtx tmp;
6543       tmp = highword; highword = lowword; lowword = tmp;
6544     }
6545
6546   emit_move_insn (lowword, operands[1]);
6547   emit_move_insn (highword, operands[2]);
6548   emit_move_insn (operands[5], operands[4]);
6549   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6550   DONE;
6551 }"
6552   [(set_attr "length" "20")])
6553
6554 (define_expand "fix_truncdfsi2"
6555   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
6556                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
6557               (clobber (match_dup 2))
6558               (clobber (match_dup 3))])]
6559   "(TARGET_POWER2 || TARGET_POWERPC)
6560    && TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6561   "
6562 {
6563   if (TARGET_E500_DOUBLE)
6564     {
6565      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
6566      DONE;
6567     }
6568   operands[2] = gen_reg_rtx (DImode);
6569   if (TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
6570       && gpc_reg_operand(operands[0], GET_MODE (operands[0])))
6571     {
6572       operands[3] = gen_reg_rtx (DImode);
6573       emit_insn (gen_fix_truncdfsi2_mfpgpr (operands[0], operands[1],
6574                                             operands[2], operands[3]));
6575       DONE;
6576     }
6577   if (TARGET_PPC_GFXOPT)
6578     {
6579       rtx orig_dest = operands[0];
6580       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
6581         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
6582       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
6583                                                      operands[2]));
6584       if (operands[0] != orig_dest)
6585         emit_move_insn (orig_dest, operands[0]);
6586       DONE;
6587     }
6588   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
6589 }")
6590
6591 (define_insn_and_split "*fix_truncdfsi2_internal"
6592   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6593         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "d")))
6594    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))
6595    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o"))]
6596   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
6597    && TARGET_DOUBLE_FLOAT"
6598   "#"
6599   ""
6600   [(pc)]
6601   "
6602 {
6603   rtx lowword;
6604   gcc_assert (MEM_P (operands[3]));
6605   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6606
6607   emit_insn (gen_fctiwz (operands[2], operands[1]));
6608   emit_move_insn (operands[3], operands[2]);
6609   emit_move_insn (operands[0], lowword);
6610   DONE;
6611 }"
6612   [(set_attr "length" "16")])
6613
6614 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
6615   [(set (match_operand:SI 0 "memory_operand" "=Z")
6616         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "d")))
6617    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))]
6618   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
6619    && TARGET_DOUBLE_FLOAT 
6620    && TARGET_PPC_GFXOPT"
6621   "#"
6622   "&& 1"
6623   [(pc)]
6624   "
6625 {
6626   emit_insn (gen_fctiwz (operands[2], operands[1]));
6627   emit_insn (gen_stfiwx (operands[0], operands[2]));
6628   DONE;
6629 }"
6630   [(set_attr "length" "16")])
6631
6632 (define_insn_and_split "fix_truncdfsi2_mfpgpr"
6633   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6634         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "d")))
6635    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))
6636    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))]
6637   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
6638    && TARGET_DOUBLE_FLOAT"
6639   "#"
6640   "&& 1"
6641   [(set (match_dup 2) (unspec:DI [(fix:SI (match_dup 1))] UNSPEC_FCTIWZ))
6642    (set (match_dup 3) (match_dup 2))
6643    (set (match_dup 0) (subreg:SI (match_dup 3) 4))]
6644   ""
6645   [(set_attr "length" "12")])
6646
6647 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6648 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
6649 ; because the first makes it clear that operand 0 is not live
6650 ; before the instruction.
6651 (define_insn "fctiwz"
6652   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6653         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "d"))]
6654                    UNSPEC_FCTIWZ))]
6655   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
6656    && TARGET_DOUBLE_FLOAT"
6657   "{fcirz|fctiwz} %0,%1"
6658   [(set_attr "type" "fp")])
6659
6660 (define_expand "btruncdf2"
6661   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6662         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRIZ))]
6663   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6664   "")
6665
6666 (define_insn "*btruncdf2_fpr"
6667   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6668         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
6669   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6670    && !VECTOR_UNIT_VSX_P (DFmode)"
6671   "friz %0,%1"
6672   [(set_attr "type" "fp")])
6673
6674 (define_insn "btruncsf2"
6675   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6676         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
6677   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6678   "friz %0,%1"
6679   [(set_attr "type" "fp")])
6680
6681 (define_expand "ceildf2"
6682   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6683         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "")] UNSPEC_FRIP))]
6684   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6685   "")
6686
6687 (define_insn "*ceildf2_fpr"
6688   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6689         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRIP))]
6690   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6691    && !VECTOR_UNIT_VSX_P (DFmode)"
6692   "frip %0,%1"
6693   [(set_attr "type" "fp")])
6694
6695 (define_insn "ceilsf2"
6696  [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6697         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
6698   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT "
6699   "frip %0,%1"
6700   [(set_attr "type" "fp")])
6701
6702 (define_expand "floordf2"
6703   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6704         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "")] UNSPEC_FRIM))]
6705   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6706   "")
6707
6708 (define_insn "*floordf2_fpr"
6709   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6710         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRIM))]
6711   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6712    && !VECTOR_UNIT_VSX_P (DFmode)"
6713   "frim %0,%1"
6714   [(set_attr "type" "fp")])
6715
6716 (define_insn "floorsf2"
6717   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6718         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
6719   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT "
6720   "frim %0,%1"
6721   [(set_attr "type" "fp")])
6722
6723 ;; No VSX equivalent to frin
6724 (define_insn "rounddf2"
6725   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6726         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRIN))]
6727   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6728   "frin %0,%1"
6729   [(set_attr "type" "fp")])
6730
6731 (define_insn "roundsf2"
6732   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6733         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
6734   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT "
6735   "frin %0,%1"
6736   [(set_attr "type" "fp")])
6737
6738 (define_expand "ftruncdf2"
6739   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6740         (fix:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6741   "VECTOR_UNIT_VSX_P (DFmode)"
6742   "")
6743
6744 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6745 (define_insn "stfiwx"
6746   [(set (match_operand:SI 0 "memory_operand" "=Z")
6747         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
6748                    UNSPEC_STFIWX))]
6749   "TARGET_PPC_GFXOPT"
6750   "stfiwx %1,%y0"
6751   [(set_attr "type" "fpstore")])
6752
6753 (define_expand "floatsisf2"
6754   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6755         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
6756   "TARGET_HARD_FLOAT && !TARGET_FPRS"
6757   "")
6758
6759 (define_expand "floatdidf2"
6760   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6761         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
6762   "(TARGET_POWERPC64 || TARGET_XILINX_FPU || VECTOR_UNIT_VSX_P (DFmode))
6763    && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
6764   "")
6765
6766 (define_insn "*floatdidf2_fpr"
6767   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6768         (float:DF (match_operand:DI 1 "gpc_reg_operand" "!d#r")))]
6769   "(TARGET_POWERPC64 || TARGET_XILINX_FPU)
6770    && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6771    && !VECTOR_UNIT_VSX_P (DFmode)"
6772   "fcfid %0,%1"
6773   [(set_attr "type" "fp")])
6774
6775 (define_expand "floatunsdidf2"
6776   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6777         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
6778   "TARGET_VSX"
6779   "")
6780
6781 (define_expand "fix_truncdfdi2"
6782   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6783         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "")))]
6784   "(TARGET_POWERPC64 || TARGET_XILINX_FPU || VECTOR_UNIT_VSX_P (DFmode))
6785     && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
6786   "")
6787
6788 (define_insn "*fix_truncdfdi2_fpr"
6789   [(set (match_operand:DI 0 "gpc_reg_operand" "=!d#r")
6790         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d")))]
6791   "(TARGET_POWERPC64 || TARGET_XILINX_FPU)
6792     && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6793     && !VECTOR_UNIT_VSX_P (DFmode)"
6794   "fctidz %0,%1"
6795   [(set_attr "type" "fp")])
6796
6797 (define_expand "floatdisf2"
6798   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6799         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6800   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT "
6801   "
6802 {
6803   rtx val = operands[1];
6804   if (!flag_unsafe_math_optimizations)
6805     {
6806       rtx label = gen_label_rtx ();
6807       val = gen_reg_rtx (DImode);
6808       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
6809       emit_label (label);
6810     }
6811   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
6812   DONE;
6813 }")
6814
6815 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6816 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6817 ;; from double rounding.
6818 (define_insn_and_split "floatdisf2_internal1"
6819   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6820         (float:SF (match_operand:DI 1 "gpc_reg_operand" "!d#r")))
6821    (clobber (match_scratch:DF 2 "=d"))]
6822   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6823   "#"
6824   "&& reload_completed"
6825   [(set (match_dup 2)
6826         (float:DF (match_dup 1)))
6827    (set (match_dup 0)
6828         (float_truncate:SF (match_dup 2)))]
6829   "")
6830
6831 ;; Twiddles bits to avoid double rounding.
6832 ;; Bits that might be truncated when converting to DFmode are replaced
6833 ;; by a bit that won't be lost at that stage, but is below the SFmode
6834 ;; rounding position.
6835 (define_expand "floatdisf2_internal2"
6836   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6837                                    (const_int 53)))
6838    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6839                                                       (const_int 2047)))
6840               (clobber (scratch:CC))])
6841    (set (match_dup 3) (plus:DI (match_dup 3)
6842                                (const_int 1)))
6843    (set (match_dup 0) (plus:DI (match_dup 0)
6844                                (const_int 2047)))
6845    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6846                                      (const_int 2)))
6847    (set (match_dup 0) (ior:DI (match_dup 0)
6848                               (match_dup 1)))
6849    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6850                                          (const_int -2048)))
6851               (clobber (scratch:CC))])
6852    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6853                            (label_ref (match_operand:DI 2 "" ""))
6854                            (pc)))
6855    (set (match_dup 0) (match_dup 1))]
6856   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6857   "
6858 {
6859   operands[3] = gen_reg_rtx (DImode);
6860   operands[4] = gen_reg_rtx (CCUNSmode);
6861 }")
6862 \f
6863 ;; Define the DImode operations that can be done in a small number
6864 ;; of instructions.  The & constraints are to prevent the register
6865 ;; allocator from allocating registers that overlap with the inputs
6866 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6867 ;; also allow for the output being the same as one of the inputs.
6868
6869 (define_insn "*adddi3_noppc64"
6870   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6871         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6872                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6873   "! TARGET_POWERPC64"
6874   "*
6875 {
6876   if (WORDS_BIG_ENDIAN)
6877     return (GET_CODE (operands[2])) != CONST_INT
6878             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
6879             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
6880   else
6881     return (GET_CODE (operands[2])) != CONST_INT
6882             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
6883             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
6884 }"
6885   [(set_attr "type" "two")
6886    (set_attr "length" "8")])
6887
6888 (define_insn "*subdi3_noppc64"
6889   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6890         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6891                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6892   "! TARGET_POWERPC64"
6893   "*
6894 {
6895   if (WORDS_BIG_ENDIAN)
6896     return (GET_CODE (operands[1]) != CONST_INT)
6897             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
6898             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
6899   else
6900     return (GET_CODE (operands[1]) != CONST_INT)
6901             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
6902             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
6903 }"
6904   [(set_attr "type" "two")
6905    (set_attr "length" "8")])
6906
6907 (define_insn "*negdi2_noppc64"
6908   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6909         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6910   "! TARGET_POWERPC64"
6911   "*
6912 {
6913   return (WORDS_BIG_ENDIAN)
6914     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
6915     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
6916 }"
6917   [(set_attr "type" "two")
6918    (set_attr "length" "8")])
6919
6920 (define_expand "mulsidi3"
6921   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6922         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6923                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6924   "! TARGET_POWERPC64"
6925   "
6926 {
6927   if (! TARGET_POWER && ! TARGET_POWERPC)
6928     {
6929       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6930       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6931       emit_insn (gen_mull_call ());
6932       if (WORDS_BIG_ENDIAN)
6933         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
6934       else
6935         {
6936           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
6937                           gen_rtx_REG (SImode, 3));
6938           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
6939                           gen_rtx_REG (SImode, 4));
6940         }
6941       DONE;
6942     }
6943   else if (TARGET_POWER)
6944     {
6945       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
6946       DONE;
6947     }
6948 }")
6949
6950 (define_insn "mulsidi3_mq"
6951   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6952         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6953                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6954    (clobber (match_scratch:SI 3 "=q"))]
6955   "TARGET_POWER"
6956   "mul %0,%1,%2\;mfmq %L0"
6957   [(set_attr "type" "imul")
6958    (set_attr "length" "8")])
6959
6960 (define_insn "*mulsidi3_no_mq"
6961   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6962         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6963                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6964   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6965   "*
6966 {
6967   return (WORDS_BIG_ENDIAN)
6968     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6969     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6970 }"
6971   [(set_attr "type" "imul")
6972    (set_attr "length" "8")])
6973
6974 (define_split
6975   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6976         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6977                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6978   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6979   [(set (match_dup 3)
6980         (truncate:SI
6981          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6982                                (sign_extend:DI (match_dup 2)))
6983                       (const_int 32))))
6984    (set (match_dup 4)
6985         (mult:SI (match_dup 1)
6986                  (match_dup 2)))]
6987   "
6988 {
6989   int endian = (WORDS_BIG_ENDIAN == 0);
6990   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6991   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6992 }")
6993
6994 (define_expand "umulsidi3"
6995   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6996         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6997                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6998   "TARGET_POWERPC && ! TARGET_POWERPC64"
6999   "
7000 {
7001   if (TARGET_POWER)
7002     {
7003       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
7004       DONE;
7005     }
7006 }")
7007
7008 (define_insn "umulsidi3_mq"
7009   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7010         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7011                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
7012    (clobber (match_scratch:SI 3 "=q"))]
7013   "TARGET_POWERPC && TARGET_POWER"
7014   "*
7015 {
7016   return (WORDS_BIG_ENDIAN)
7017     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
7018     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
7019 }"
7020   [(set_attr "type" "imul")
7021    (set_attr "length" "8")])
7022
7023 (define_insn "*umulsidi3_no_mq"
7024   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7025         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7026                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
7027   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
7028   "*
7029 {
7030   return (WORDS_BIG_ENDIAN)
7031     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
7032     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
7033 }"
7034   [(set_attr "type" "imul")
7035    (set_attr "length" "8")])
7036
7037 (define_split
7038   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7039         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7040                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7041   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
7042   [(set (match_dup 3)
7043         (truncate:SI
7044          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
7045                                (zero_extend:DI (match_dup 2)))
7046                       (const_int 32))))
7047    (set (match_dup 4)
7048         (mult:SI (match_dup 1)
7049                  (match_dup 2)))]
7050   "
7051 {
7052   int endian = (WORDS_BIG_ENDIAN == 0);
7053   operands[3] = operand_subword (operands[0], endian, 0, DImode);
7054   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
7055 }")
7056
7057 (define_expand "smulsi3_highpart"
7058   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7059         (truncate:SI
7060          (lshiftrt:DI (mult:DI (sign_extend:DI
7061                                 (match_operand:SI 1 "gpc_reg_operand" ""))
7062                                (sign_extend:DI
7063                                 (match_operand:SI 2 "gpc_reg_operand" "")))
7064                       (const_int 32))))]
7065   ""
7066   "
7067 {
7068   if (! TARGET_POWER && ! TARGET_POWERPC)
7069     {
7070       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
7071       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
7072       emit_insn (gen_mulh_call ());
7073       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
7074       DONE;
7075     }
7076   else if (TARGET_POWER)
7077     {
7078       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
7079       DONE;
7080     }
7081 }")
7082
7083 (define_insn "smulsi3_highpart_mq"
7084   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7085         (truncate:SI
7086          (lshiftrt:DI (mult:DI (sign_extend:DI
7087                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7088                                (sign_extend:DI
7089                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7090                       (const_int 32))))
7091    (clobber (match_scratch:SI 3 "=q"))]
7092   "TARGET_POWER"
7093   "mul %0,%1,%2"
7094   [(set_attr "type" "imul")])
7095
7096 (define_insn "*smulsi3_highpart_no_mq"
7097   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7098         (truncate:SI
7099          (lshiftrt:DI (mult:DI (sign_extend:DI
7100                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7101                                (sign_extend:DI
7102                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7103                       (const_int 32))))]
7104   "TARGET_POWERPC && ! TARGET_POWER"
7105   "mulhw %0,%1,%2"
7106   [(set_attr "type" "imul")])
7107
7108 (define_expand "umulsi3_highpart"
7109   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7110         (truncate:SI
7111          (lshiftrt:DI (mult:DI (zero_extend:DI
7112                                 (match_operand:SI 1 "gpc_reg_operand" ""))
7113                                (zero_extend:DI
7114                                 (match_operand:SI 2 "gpc_reg_operand" "")))
7115                       (const_int 32))))]
7116   "TARGET_POWERPC"
7117   "
7118 {
7119   if (TARGET_POWER)
7120     {
7121       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
7122       DONE;
7123     }
7124 }")
7125
7126 (define_insn "umulsi3_highpart_mq"
7127   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7128         (truncate:SI
7129          (lshiftrt:DI (mult:DI (zero_extend:DI
7130                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7131                                (zero_extend:DI
7132                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7133                       (const_int 32))))
7134    (clobber (match_scratch:SI 3 "=q"))]
7135   "TARGET_POWERPC && TARGET_POWER"
7136   "mulhwu %0,%1,%2"
7137   [(set_attr "type" "imul")])
7138
7139 (define_insn "*umulsi3_highpart_no_mq"
7140   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7141         (truncate:SI
7142          (lshiftrt:DI (mult:DI (zero_extend:DI
7143                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7144                                (zero_extend:DI
7145                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7146                       (const_int 32))))]
7147   "TARGET_POWERPC && ! TARGET_POWER"
7148   "mulhwu %0,%1,%2"
7149   [(set_attr "type" "imul")])
7150
7151 ;; If operands 0 and 2 are in the same register, we have a problem.  But
7152 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
7153 ;; why we have the strange constraints below.
7154 (define_insn "ashldi3_power"
7155   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
7156         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
7157                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
7158    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
7159   "TARGET_POWER"
7160   "@
7161    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
7162    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
7163    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
7164    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
7165   [(set_attr "length" "8")])
7166
7167 (define_insn "lshrdi3_power"
7168   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
7169         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
7170                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
7171    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
7172   "TARGET_POWER"
7173   "@
7174    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
7175    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
7176    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
7177    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
7178   [(set_attr "length" "8")])
7179
7180 ;; Shift by a variable amount is too complex to be worth open-coding.  We
7181 ;; just handle shifts by constants.
7182 (define_insn "ashrdi3_power"
7183   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7184         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7185                      (match_operand:SI 2 "const_int_operand" "M,i")))
7186    (clobber (match_scratch:SI 3 "=X,q"))]
7187   "TARGET_POWER"
7188   "@
7189    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
7190    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
7191   [(set_attr "type" "shift")
7192    (set_attr "length" "8")])
7193
7194 (define_insn "ashrdi3_no_power"
7195   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
7196         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7197                      (match_operand:SI 2 "const_int_operand" "M,i")))]
7198   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
7199   "@
7200    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
7201    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
7202   [(set_attr "type" "two,three")
7203    (set_attr "length" "8,12")])
7204
7205 (define_insn "*ashrdisi3_noppc64"
7206   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7207         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7208                                 (const_int 32)) 4))]
7209   "TARGET_32BIT && !TARGET_POWERPC64"
7210   "*
7211 {
7212   if (REGNO (operands[0]) == REGNO (operands[1]))
7213     return \"\";
7214   else
7215     return \"mr %0,%1\";
7216 }"
7217    [(set_attr "length" "4")])
7218
7219 \f
7220 ;; PowerPC64 DImode operations.
7221
7222 (define_expand "absdi2"
7223   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7224         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
7225   "TARGET_POWERPC64"
7226   "
7227 {
7228   if (TARGET_ISEL)
7229     emit_insn (gen_absdi2_isel (operands[0], operands[1]));
7230   else
7231     emit_insn (gen_absdi2_internal (operands[0], operands[1]));
7232   DONE;
7233 }")
7234
7235 (define_insn_and_split "absdi2_internal"
7236   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7237         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
7238    (clobber (match_scratch:DI 2 "=&r,&r"))]
7239   "TARGET_POWERPC64 && !TARGET_ISEL"
7240   "#"
7241   "&& reload_completed"
7242   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
7243    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
7244    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
7245   "")
7246
7247 (define_insn_and_split "*nabsdi2"
7248   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7249         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
7250    (clobber (match_scratch:DI 2 "=&r,&r"))]
7251   "TARGET_POWERPC64 && !TARGET_ISEL"
7252   "#"
7253   "&& reload_completed"
7254   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
7255    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
7256    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
7257   "")
7258
7259 (define_insn "muldi3"
7260   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7261         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7262                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
7263   "TARGET_POWERPC64"
7264   "@
7265    mulld %0,%1,%2
7266    mulli %0,%1,%2"
7267    [(set (attr "type")
7268       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
7269                 (const_string "imul3")
7270              (match_operand:SI 2 "short_cint_operand" "")
7271                 (const_string "imul2")]
7272         (const_string "lmul")))])
7273
7274 (define_insn "*muldi3_internal1"
7275   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7276         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7277                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
7278                     (const_int 0)))
7279    (clobber (match_scratch:DI 3 "=r,r"))]
7280   "TARGET_POWERPC64"
7281   "@
7282    mulld. %3,%1,%2
7283    #"
7284   [(set_attr "type" "lmul_compare")
7285    (set_attr "length" "4,8")])
7286
7287 (define_split
7288   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7289         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
7290                              (match_operand:DI 2 "gpc_reg_operand" ""))
7291                     (const_int 0)))
7292    (clobber (match_scratch:DI 3 ""))]
7293   "TARGET_POWERPC64 && reload_completed"
7294   [(set (match_dup 3)
7295         (mult:DI (match_dup 1) (match_dup 2)))
7296    (set (match_dup 0)
7297         (compare:CC (match_dup 3)
7298                     (const_int 0)))]
7299   "")
7300
7301 (define_insn "*muldi3_internal2"
7302   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7303         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7304                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
7305                     (const_int 0)))
7306    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7307         (mult:DI (match_dup 1) (match_dup 2)))]
7308   "TARGET_POWERPC64"
7309   "@
7310    mulld. %0,%1,%2
7311    #"
7312   [(set_attr "type" "lmul_compare")
7313    (set_attr "length" "4,8")])
7314
7315 (define_split
7316   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7317         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
7318                              (match_operand:DI 2 "gpc_reg_operand" ""))
7319                     (const_int 0)))
7320    (set (match_operand:DI 0 "gpc_reg_operand" "")
7321         (mult:DI (match_dup 1) (match_dup 2)))]
7322   "TARGET_POWERPC64 && reload_completed"
7323   [(set (match_dup 0)
7324         (mult:DI (match_dup 1) (match_dup 2)))
7325    (set (match_dup 3)
7326         (compare:CC (match_dup 0)
7327                     (const_int 0)))]
7328   "")
7329
7330 (define_insn "smuldi3_highpart"
7331   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7332         (truncate:DI
7333          (lshiftrt:TI (mult:TI (sign_extend:TI
7334                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
7335                                (sign_extend:TI
7336                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
7337                       (const_int 64))))]
7338   "TARGET_POWERPC64"
7339   "mulhd %0,%1,%2"
7340   [(set_attr "type" "lmul")])
7341
7342 (define_insn "umuldi3_highpart"
7343   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7344         (truncate:DI
7345          (lshiftrt:TI (mult:TI (zero_extend:TI
7346                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
7347                                (zero_extend:TI
7348                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
7349                       (const_int 64))))]
7350   "TARGET_POWERPC64"
7351   "mulhdu %0,%1,%2"
7352   [(set_attr "type" "lmul")])
7353
7354 (define_insn "rotldi3"
7355   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7356         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7357                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
7358   "TARGET_POWERPC64"
7359   "@
7360    rldcl %0,%1,%2,0
7361    rldicl %0,%1,%H2,0"
7362   [(set_attr "type" "var_shift_rotate,integer")])
7363
7364 (define_insn "*rotldi3_internal2"
7365   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7366         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7367                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7368                     (const_int 0)))
7369    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7370   "TARGET_64BIT"
7371   "@
7372    rldcl. %3,%1,%2,0
7373    rldicl. %3,%1,%H2,0
7374    #
7375    #"
7376   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7377    (set_attr "length" "4,4,8,8")])
7378
7379 (define_split
7380   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7381         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7382                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7383                     (const_int 0)))
7384    (clobber (match_scratch:DI 3 ""))]
7385   "TARGET_POWERPC64 && reload_completed"
7386   [(set (match_dup 3)
7387         (rotate:DI (match_dup 1) (match_dup 2)))
7388    (set (match_dup 0)
7389         (compare:CC (match_dup 3)
7390                     (const_int 0)))]
7391   "")
7392
7393 (define_insn "*rotldi3_internal3"
7394   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7395         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7396                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7397                     (const_int 0)))
7398    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7399         (rotate:DI (match_dup 1) (match_dup 2)))]
7400   "TARGET_64BIT"
7401   "@
7402    rldcl. %0,%1,%2,0
7403    rldicl. %0,%1,%H2,0
7404    #
7405    #"
7406   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7407    (set_attr "length" "4,4,8,8")])
7408
7409 (define_split
7410   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7411         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7412                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7413                     (const_int 0)))
7414    (set (match_operand:DI 0 "gpc_reg_operand" "")
7415         (rotate:DI (match_dup 1) (match_dup 2)))]
7416   "TARGET_POWERPC64 && reload_completed"
7417   [(set (match_dup 0)
7418         (rotate:DI (match_dup 1) (match_dup 2)))
7419    (set (match_dup 3)
7420         (compare:CC (match_dup 0)
7421                     (const_int 0)))]
7422   "")
7423
7424 (define_insn "*rotldi3_internal4"
7425   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7426         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7427                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
7428                 (match_operand:DI 3 "mask64_operand" "n,n")))]
7429   "TARGET_POWERPC64"
7430   "@
7431    rldc%B3 %0,%1,%2,%S3
7432    rldic%B3 %0,%1,%H2,%S3"
7433   [(set_attr "type" "var_shift_rotate,integer")])
7434
7435 (define_insn "*rotldi3_internal5"
7436   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7437         (compare:CC (and:DI
7438                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7439                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7440                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7441                     (const_int 0)))
7442    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
7443   "TARGET_64BIT"
7444   "@
7445    rldc%B3. %4,%1,%2,%S3
7446    rldic%B3. %4,%1,%H2,%S3
7447    #
7448    #"
7449   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7450    (set_attr "length" "4,4,8,8")])
7451
7452 (define_split
7453   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7454         (compare:CC (and:DI
7455                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7456                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7457                      (match_operand:DI 3 "mask64_operand" ""))
7458                     (const_int 0)))
7459    (clobber (match_scratch:DI 4 ""))]
7460   "TARGET_POWERPC64 && reload_completed"
7461   [(set (match_dup 4)
7462         (and:DI (rotate:DI (match_dup 1)
7463                                 (match_dup 2))
7464                      (match_dup 3)))
7465    (set (match_dup 0)
7466         (compare:CC (match_dup 4)
7467                     (const_int 0)))]
7468   "")
7469
7470 (define_insn "*rotldi3_internal6"
7471   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
7472         (compare:CC (and:DI
7473                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7474                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7475                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7476                     (const_int 0)))
7477    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7478         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7479   "TARGET_64BIT"
7480   "@
7481    rldc%B3. %0,%1,%2,%S3
7482    rldic%B3. %0,%1,%H2,%S3
7483    #
7484    #"
7485   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7486    (set_attr "length" "4,4,8,8")])
7487
7488 (define_split
7489   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7490         (compare:CC (and:DI
7491                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7492                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7493                      (match_operand:DI 3 "mask64_operand" ""))
7494                     (const_int 0)))
7495    (set (match_operand:DI 0 "gpc_reg_operand" "")
7496         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7497   "TARGET_POWERPC64 && reload_completed"
7498   [(set (match_dup 0)
7499         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
7500    (set (match_dup 4)
7501         (compare:CC (match_dup 0)
7502                     (const_int 0)))]
7503   "")
7504
7505 (define_insn "*rotldi3_internal7"
7506   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7507         (zero_extend:DI
7508          (subreg:QI
7509           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7510                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7511   "TARGET_POWERPC64"
7512   "@
7513    rldcl %0,%1,%2,56
7514    rldicl %0,%1,%H2,56"
7515   [(set_attr "type" "var_shift_rotate,integer")])
7516
7517 (define_insn "*rotldi3_internal8"
7518   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7519         (compare:CC (zero_extend:DI
7520                      (subreg:QI
7521                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7522                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7523                     (const_int 0)))
7524    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7525   "TARGET_64BIT"
7526   "@
7527    rldcl. %3,%1,%2,56
7528    rldicl. %3,%1,%H2,56
7529    #
7530    #"
7531   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7532    (set_attr "length" "4,4,8,8")])
7533
7534 (define_split
7535   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7536         (compare:CC (zero_extend:DI
7537                      (subreg:QI
7538                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7539                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7540                     (const_int 0)))
7541    (clobber (match_scratch:DI 3 ""))]
7542   "TARGET_POWERPC64 && reload_completed"
7543   [(set (match_dup 3)
7544         (zero_extend:DI (subreg:QI
7545                       (rotate:DI (match_dup 1)
7546                                  (match_dup 2)) 0)))
7547    (set (match_dup 0)
7548         (compare:CC (match_dup 3)
7549                     (const_int 0)))]
7550   "")
7551
7552 (define_insn "*rotldi3_internal9"
7553   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7554         (compare:CC (zero_extend:DI
7555                      (subreg:QI
7556                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7557                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7558                     (const_int 0)))
7559    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7560         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7561   "TARGET_64BIT"
7562   "@
7563    rldcl. %0,%1,%2,56
7564    rldicl. %0,%1,%H2,56
7565    #
7566    #"
7567   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7568    (set_attr "length" "4,4,8,8")])
7569
7570 (define_split
7571   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7572         (compare:CC (zero_extend:DI
7573                      (subreg:QI
7574                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7575                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7576                     (const_int 0)))
7577    (set (match_operand:DI 0 "gpc_reg_operand" "")
7578         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7579   "TARGET_POWERPC64 && reload_completed"
7580   [(set (match_dup 0)
7581         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7582    (set (match_dup 3)
7583         (compare:CC (match_dup 0)
7584                     (const_int 0)))]
7585   "")
7586
7587 (define_insn "*rotldi3_internal10"
7588   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7589         (zero_extend:DI
7590          (subreg:HI
7591           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7592                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7593   "TARGET_POWERPC64"
7594   "@
7595    rldcl %0,%1,%2,48
7596    rldicl %0,%1,%H2,48"
7597   [(set_attr "type" "var_shift_rotate,integer")])
7598
7599 (define_insn "*rotldi3_internal11"
7600   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7601         (compare:CC (zero_extend:DI
7602                      (subreg:HI
7603                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7604                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7605                     (const_int 0)))
7606    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7607   "TARGET_64BIT"
7608   "@
7609    rldcl. %3,%1,%2,48
7610    rldicl. %3,%1,%H2,48
7611    #
7612    #"
7613   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7614    (set_attr "length" "4,4,8,8")])
7615
7616 (define_split
7617   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7618         (compare:CC (zero_extend:DI
7619                      (subreg:HI
7620                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7621                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7622                     (const_int 0)))
7623    (clobber (match_scratch:DI 3 ""))]
7624   "TARGET_POWERPC64 && reload_completed"
7625   [(set (match_dup 3)
7626         (zero_extend:DI (subreg:HI
7627                       (rotate:DI (match_dup 1)
7628                                  (match_dup 2)) 0)))
7629    (set (match_dup 0)
7630         (compare:CC (match_dup 3)
7631                     (const_int 0)))]
7632   "")
7633
7634 (define_insn "*rotldi3_internal12"
7635   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7636         (compare:CC (zero_extend:DI
7637                      (subreg:HI
7638                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7639                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7640                     (const_int 0)))
7641    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7642         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7643   "TARGET_64BIT"
7644   "@
7645    rldcl. %0,%1,%2,48
7646    rldicl. %0,%1,%H2,48
7647    #
7648    #"
7649   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7650    (set_attr "length" "4,4,8,8")])
7651
7652 (define_split
7653   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7654         (compare:CC (zero_extend:DI
7655                      (subreg:HI
7656                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7657                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7658                     (const_int 0)))
7659    (set (match_operand:DI 0 "gpc_reg_operand" "")
7660         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7661   "TARGET_POWERPC64 && reload_completed"
7662   [(set (match_dup 0)
7663         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7664    (set (match_dup 3)
7665         (compare:CC (match_dup 0)
7666                     (const_int 0)))]
7667   "")
7668
7669 (define_insn "*rotldi3_internal13"
7670   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7671         (zero_extend:DI
7672          (subreg:SI
7673           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7674                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7675   "TARGET_POWERPC64"
7676   "@
7677    rldcl %0,%1,%2,32
7678    rldicl %0,%1,%H2,32"
7679   [(set_attr "type" "var_shift_rotate,integer")])
7680
7681 (define_insn "*rotldi3_internal14"
7682   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7683         (compare:CC (zero_extend:DI
7684                      (subreg:SI
7685                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7686                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7687                     (const_int 0)))
7688    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7689   "TARGET_64BIT"
7690   "@
7691    rldcl. %3,%1,%2,32
7692    rldicl. %3,%1,%H2,32
7693    #
7694    #"
7695   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7696    (set_attr "length" "4,4,8,8")])
7697
7698 (define_split
7699   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7700         (compare:CC (zero_extend:DI
7701                      (subreg:SI
7702                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7703                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7704                     (const_int 0)))
7705    (clobber (match_scratch:DI 3 ""))]
7706   "TARGET_POWERPC64 && reload_completed"
7707   [(set (match_dup 3)
7708         (zero_extend:DI (subreg:SI
7709                       (rotate:DI (match_dup 1)
7710                                  (match_dup 2)) 0)))
7711    (set (match_dup 0)
7712         (compare:CC (match_dup 3)
7713                     (const_int 0)))]
7714   "")
7715
7716 (define_insn "*rotldi3_internal15"
7717   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7718         (compare:CC (zero_extend:DI
7719                      (subreg:SI
7720                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7721                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7722                     (const_int 0)))
7723    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7724         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7725   "TARGET_64BIT"
7726   "@
7727    rldcl. %0,%1,%2,32
7728    rldicl. %0,%1,%H2,32
7729    #
7730    #"
7731   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7732    (set_attr "length" "4,4,8,8")])
7733
7734 (define_split
7735   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7736         (compare:CC (zero_extend:DI
7737                      (subreg:SI
7738                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7739                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7740                     (const_int 0)))
7741    (set (match_operand:DI 0 "gpc_reg_operand" "")
7742         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7743   "TARGET_POWERPC64 && reload_completed"
7744   [(set (match_dup 0)
7745         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7746    (set (match_dup 3)
7747         (compare:CC (match_dup 0)
7748                     (const_int 0)))]
7749   "")
7750
7751 (define_expand "ashldi3"
7752   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7753         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7754                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
7755   "TARGET_POWERPC64 || TARGET_POWER"
7756   "
7757 {
7758   if (TARGET_POWERPC64)
7759     ;
7760   else if (TARGET_POWER)
7761     {
7762       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
7763       DONE;
7764     }
7765   else
7766     FAIL;
7767 }")
7768
7769 (define_insn "*ashldi3_internal1"
7770   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7771         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7772                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7773   "TARGET_POWERPC64"
7774   "@
7775    sld %0,%1,%2
7776    sldi %0,%1,%H2"
7777   [(set_attr "type" "var_shift_rotate,shift")])
7778
7779 (define_insn "*ashldi3_internal2"
7780   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7781         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7782                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7783                     (const_int 0)))
7784    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7785   "TARGET_64BIT"
7786   "@
7787    sld. %3,%1,%2
7788    sldi. %3,%1,%H2
7789    #
7790    #"
7791   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7792    (set_attr "length" "4,4,8,8")])
7793
7794 (define_split
7795   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7796         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7797                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7798                     (const_int 0)))
7799    (clobber (match_scratch:DI 3 ""))]
7800   "TARGET_POWERPC64 && reload_completed"
7801   [(set (match_dup 3)
7802         (ashift:DI (match_dup 1) (match_dup 2)))
7803    (set (match_dup 0)
7804         (compare:CC (match_dup 3)
7805                     (const_int 0)))]
7806   "")
7807
7808 (define_insn "*ashldi3_internal3"
7809   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7810         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7811                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7812                     (const_int 0)))
7813    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7814         (ashift:DI (match_dup 1) (match_dup 2)))]
7815   "TARGET_64BIT"
7816   "@
7817    sld. %0,%1,%2
7818    sldi. %0,%1,%H2
7819    #
7820    #"
7821   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7822    (set_attr "length" "4,4,8,8")])
7823
7824 (define_split
7825   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7826         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7827                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7828                     (const_int 0)))
7829    (set (match_operand:DI 0 "gpc_reg_operand" "")
7830         (ashift:DI (match_dup 1) (match_dup 2)))]
7831   "TARGET_POWERPC64 && reload_completed"
7832   [(set (match_dup 0)
7833         (ashift:DI (match_dup 1) (match_dup 2)))
7834    (set (match_dup 3)
7835         (compare:CC (match_dup 0)
7836                     (const_int 0)))]
7837   "")
7838
7839 (define_insn "*ashldi3_internal4"
7840   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7841         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7842                            (match_operand:SI 2 "const_int_operand" "i"))
7843                 (match_operand:DI 3 "const_int_operand" "n")))]
7844   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7845   "rldic %0,%1,%H2,%W3")
7846
7847 (define_insn "ashldi3_internal5"
7848   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7849         (compare:CC
7850          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7851                             (match_operand:SI 2 "const_int_operand" "i,i"))
7852                  (match_operand:DI 3 "const_int_operand" "n,n"))
7853          (const_int 0)))
7854    (clobber (match_scratch:DI 4 "=r,r"))]
7855   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7856   "@
7857    rldic. %4,%1,%H2,%W3
7858    #"
7859   [(set_attr "type" "compare")
7860    (set_attr "length" "4,8")])
7861
7862 (define_split
7863   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7864         (compare:CC
7865          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7866                             (match_operand:SI 2 "const_int_operand" ""))
7867                  (match_operand:DI 3 "const_int_operand" ""))
7868          (const_int 0)))
7869    (clobber (match_scratch:DI 4 ""))]
7870   "TARGET_POWERPC64 && reload_completed
7871    && includes_rldic_lshift_p (operands[2], operands[3])"
7872   [(set (match_dup 4)
7873         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7874                 (match_dup 3)))
7875    (set (match_dup 0)
7876         (compare:CC (match_dup 4)
7877                     (const_int 0)))]
7878   "")
7879
7880 (define_insn "*ashldi3_internal6"
7881   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7882         (compare:CC
7883          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7884                             (match_operand:SI 2 "const_int_operand" "i,i"))
7885                     (match_operand:DI 3 "const_int_operand" "n,n"))
7886          (const_int 0)))
7887    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7888         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7889   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7890   "@
7891    rldic. %0,%1,%H2,%W3
7892    #"
7893   [(set_attr "type" "compare")
7894    (set_attr "length" "4,8")])
7895
7896 (define_split
7897   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7898         (compare:CC
7899          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7900                             (match_operand:SI 2 "const_int_operand" ""))
7901                  (match_operand:DI 3 "const_int_operand" ""))
7902          (const_int 0)))
7903    (set (match_operand:DI 0 "gpc_reg_operand" "")
7904         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7905   "TARGET_POWERPC64 && reload_completed
7906    && includes_rldic_lshift_p (operands[2], operands[3])"
7907   [(set (match_dup 0)
7908         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7909                 (match_dup 3)))
7910    (set (match_dup 4)
7911         (compare:CC (match_dup 0)
7912                     (const_int 0)))]
7913   "")
7914
7915 (define_insn "*ashldi3_internal7"
7916   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7917         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7918                            (match_operand:SI 2 "const_int_operand" "i"))
7919                 (match_operand:DI 3 "mask64_operand" "n")))]
7920   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7921   "rldicr %0,%1,%H2,%S3")
7922
7923 (define_insn "ashldi3_internal8"
7924   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7925         (compare:CC
7926          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7927                             (match_operand:SI 2 "const_int_operand" "i,i"))
7928                  (match_operand:DI 3 "mask64_operand" "n,n"))
7929          (const_int 0)))
7930    (clobber (match_scratch:DI 4 "=r,r"))]
7931   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7932   "@
7933    rldicr. %4,%1,%H2,%S3
7934    #"
7935   [(set_attr "type" "compare")
7936    (set_attr "length" "4,8")])
7937
7938 (define_split
7939   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7940         (compare:CC
7941          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7942                             (match_operand:SI 2 "const_int_operand" ""))
7943                  (match_operand:DI 3 "mask64_operand" ""))
7944          (const_int 0)))
7945    (clobber (match_scratch:DI 4 ""))]
7946   "TARGET_POWERPC64 && reload_completed
7947    && includes_rldicr_lshift_p (operands[2], operands[3])"
7948   [(set (match_dup 4)
7949         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7950                 (match_dup 3)))
7951    (set (match_dup 0)
7952         (compare:CC (match_dup 4)
7953                     (const_int 0)))]
7954   "")
7955
7956 (define_insn "*ashldi3_internal9"
7957   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7958         (compare:CC
7959          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7960                             (match_operand:SI 2 "const_int_operand" "i,i"))
7961                     (match_operand:DI 3 "mask64_operand" "n,n"))
7962          (const_int 0)))
7963    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7964         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7965   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7966   "@
7967    rldicr. %0,%1,%H2,%S3
7968    #"
7969   [(set_attr "type" "compare")
7970    (set_attr "length" "4,8")])
7971
7972 (define_split
7973   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7974         (compare:CC
7975          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7976                             (match_operand:SI 2 "const_int_operand" ""))
7977                  (match_operand:DI 3 "mask64_operand" ""))
7978          (const_int 0)))
7979    (set (match_operand:DI 0 "gpc_reg_operand" "")
7980         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7981   "TARGET_POWERPC64 && reload_completed
7982    && includes_rldicr_lshift_p (operands[2], operands[3])"
7983   [(set (match_dup 0)
7984         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7985                 (match_dup 3)))
7986    (set (match_dup 4)
7987         (compare:CC (match_dup 0)
7988                     (const_int 0)))]
7989   "")
7990
7991 (define_expand "lshrdi3"
7992   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7993         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7994                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7995   "TARGET_POWERPC64 || TARGET_POWER"
7996   "
7997 {
7998   if (TARGET_POWERPC64)
7999     ;
8000   else if (TARGET_POWER)
8001     {
8002       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
8003       DONE;
8004     }
8005   else
8006     FAIL;
8007 }")
8008
8009 (define_insn "*lshrdi3_internal1"
8010   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8011         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8012                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8013   "TARGET_POWERPC64"
8014   "@
8015    srd %0,%1,%2
8016    srdi %0,%1,%H2"
8017   [(set_attr "type" "var_shift_rotate,shift")])
8018
8019 (define_insn "*lshrdi3_internal2"
8020   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8021         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8022                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8023                     (const_int 0)))
8024    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8025   "TARGET_64BIT "
8026   "@
8027    srd. %3,%1,%2
8028    srdi. %3,%1,%H2
8029    #
8030    #"
8031   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8032    (set_attr "length" "4,4,8,8")])
8033
8034 (define_split
8035   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8036         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8037                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8038                     (const_int 0)))
8039    (clobber (match_scratch:DI 3 ""))]
8040   "TARGET_POWERPC64 && reload_completed"
8041   [(set (match_dup 3)
8042         (lshiftrt:DI (match_dup 1) (match_dup 2)))
8043    (set (match_dup 0)
8044         (compare:CC (match_dup 3)
8045                     (const_int 0)))]
8046   "")
8047
8048 (define_insn "*lshrdi3_internal3"
8049   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8050         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8051                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8052                     (const_int 0)))
8053    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8054         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
8055   "TARGET_64BIT"
8056   "@
8057    srd. %0,%1,%2
8058    srdi. %0,%1,%H2
8059    #
8060    #"
8061   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8062    (set_attr "length" "4,4,8,8")])
8063
8064 (define_split
8065   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8066         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8067                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8068                     (const_int 0)))
8069    (set (match_operand:DI 0 "gpc_reg_operand" "")
8070         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
8071   "TARGET_POWERPC64 && reload_completed"
8072   [(set (match_dup 0)
8073         (lshiftrt:DI (match_dup 1) (match_dup 2)))
8074    (set (match_dup 3)
8075         (compare:CC (match_dup 0)
8076                     (const_int 0)))]
8077   "")
8078
8079 (define_expand "ashrdi3"
8080   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8081         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8082                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
8083   "WORDS_BIG_ENDIAN"
8084   "
8085 {
8086   if (TARGET_POWERPC64)
8087     ;
8088   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
8089     {
8090       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
8091       DONE;
8092     }
8093   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
8094            && WORDS_BIG_ENDIAN)
8095     {
8096       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
8097       DONE;
8098     }
8099   else
8100     FAIL;
8101 }")
8102
8103 (define_insn "*ashrdi3_internal1"
8104   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8105         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8106                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8107   "TARGET_POWERPC64"
8108   "@
8109    srad %0,%1,%2
8110    sradi %0,%1,%H2"
8111   [(set_attr "type" "var_shift_rotate,shift")])
8112
8113 (define_insn "*ashrdi3_internal2"
8114   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8115         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8116                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8117                     (const_int 0)))
8118    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8119   "TARGET_64BIT"
8120   "@
8121    srad. %3,%1,%2
8122    sradi. %3,%1,%H2
8123    #
8124    #"
8125   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8126    (set_attr "length" "4,4,8,8")])
8127
8128 (define_split
8129   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
8130         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8131                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8132                     (const_int 0)))
8133    (clobber (match_scratch:DI 3 ""))]
8134   "TARGET_POWERPC64 && reload_completed"
8135   [(set (match_dup 3)
8136         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8137    (set (match_dup 0)
8138         (compare:CC (match_dup 3)
8139                     (const_int 0)))]
8140   "")
8141
8142 (define_insn "*ashrdi3_internal3"
8143   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8144         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8145                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8146                     (const_int 0)))
8147    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8148         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8149   "TARGET_64BIT"
8150   "@
8151    srad. %0,%1,%2
8152    sradi. %0,%1,%H2
8153    #
8154    #"
8155   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8156    (set_attr "length" "4,4,8,8")])
8157
8158 (define_split
8159   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
8160         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8161                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8162                     (const_int 0)))
8163    (set (match_operand:DI 0 "gpc_reg_operand" "")
8164         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8165   "TARGET_POWERPC64 && reload_completed"
8166   [(set (match_dup 0)
8167         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8168    (set (match_dup 3)
8169         (compare:CC (match_dup 0)
8170                     (const_int 0)))]
8171   "")
8172
8173 (define_expand "anddi3"
8174   [(parallel
8175     [(set (match_operand:DI 0 "gpc_reg_operand" "")
8176           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8177                   (match_operand:DI 2 "and64_2_operand" "")))
8178      (clobber (match_scratch:CC 3 ""))])]
8179   "TARGET_POWERPC64"
8180   "")
8181
8182 (define_insn "anddi3_mc"
8183   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
8184         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
8185                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
8186    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
8187   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
8188   "@
8189    and %0,%1,%2
8190    rldic%B2 %0,%1,0,%S2
8191    rlwinm %0,%1,0,%m2,%M2
8192    andi. %0,%1,%b2
8193    andis. %0,%1,%u2
8194    #"
8195   [(set_attr "type" "*,*,*,fast_compare,fast_compare,*")
8196    (set_attr "length" "4,4,4,4,4,8")])
8197
8198 (define_insn "anddi3_nomc"
8199   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8200         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
8201                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
8202    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
8203   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
8204   "@
8205    and %0,%1,%2
8206    rldic%B2 %0,%1,0,%S2
8207    rlwinm %0,%1,0,%m2,%M2
8208    #"
8209   [(set_attr "length" "4,4,4,8")])
8210
8211 (define_split
8212   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8213         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8214                 (match_operand:DI 2 "mask64_2_operand" "")))
8215    (clobber (match_scratch:CC 3 ""))]
8216   "TARGET_POWERPC64
8217     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8218     && !mask_operand (operands[2], DImode)
8219     && !mask64_operand (operands[2], DImode)"
8220   [(set (match_dup 0)
8221         (and:DI (rotate:DI (match_dup 1)
8222                            (match_dup 4))
8223                 (match_dup 5)))
8224    (set (match_dup 0)
8225         (and:DI (rotate:DI (match_dup 0)
8226                            (match_dup 6))
8227                 (match_dup 7)))]
8228 {
8229   build_mask64_2_operands (operands[2], &operands[4]);
8230 })
8231
8232 (define_insn "*anddi3_internal2_mc"
8233   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8234         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8235                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8236                     (const_int 0)))
8237    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
8238    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8239   "TARGET_64BIT && rs6000_gen_cell_microcode"
8240   "@
8241    and. %3,%1,%2
8242    rldic%B2. %3,%1,0,%S2
8243    rlwinm. %3,%1,0,%m2,%M2
8244    andi. %3,%1,%b2
8245    andis. %3,%1,%u2
8246    #
8247    #
8248    #
8249    #
8250    #
8251    #
8252    #"
8253   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8254                      fast_compare,compare,compare,compare,compare,compare,\
8255                      compare,compare")
8256    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8257
8258 (define_split
8259   [(set (match_operand:CC 0 "cc_reg_operand" "")
8260         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8261                             (match_operand:DI 2 "mask64_2_operand" ""))
8262                     (const_int 0)))
8263    (clobber (match_scratch:DI 3 ""))
8264    (clobber (match_scratch:CC 4 ""))]
8265   "TARGET_64BIT && reload_completed
8266     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8267     && !mask_operand (operands[2], DImode)
8268     && !mask64_operand (operands[2], DImode)"
8269   [(set (match_dup 3)
8270         (and:DI (rotate:DI (match_dup 1)
8271                            (match_dup 5))
8272                 (match_dup 6)))
8273    (parallel [(set (match_dup 0)
8274                    (compare:CC (and:DI (rotate:DI (match_dup 3)
8275                                                   (match_dup 7))
8276                                        (match_dup 8))
8277                                (const_int 0)))
8278               (clobber (match_dup 3))])]
8279   "
8280 {
8281   build_mask64_2_operands (operands[2], &operands[5]);
8282 }")
8283
8284 (define_insn "*anddi3_internal3_mc"
8285   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8286         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8287                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8288                     (const_int 0)))
8289    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
8290         (and:DI (match_dup 1) (match_dup 2)))
8291    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8292   "TARGET_64BIT && rs6000_gen_cell_microcode"
8293   "@
8294    and. %0,%1,%2
8295    rldic%B2. %0,%1,0,%S2
8296    rlwinm. %0,%1,0,%m2,%M2
8297    andi. %0,%1,%b2
8298    andis. %0,%1,%u2
8299    #
8300    #
8301    #
8302    #
8303    #
8304    #
8305    #"
8306   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8307                      fast_compare,compare,compare,compare,compare,compare,\
8308                      compare,compare")
8309    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8310
8311 (define_split
8312   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8313         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8314                             (match_operand:DI 2 "and64_2_operand" ""))
8315                     (const_int 0)))
8316    (set (match_operand:DI 0 "gpc_reg_operand" "")
8317         (and:DI (match_dup 1) (match_dup 2)))
8318    (clobber (match_scratch:CC 4 ""))]
8319   "TARGET_64BIT && reload_completed"
8320   [(parallel [(set (match_dup 0)
8321                     (and:DI (match_dup 1) (match_dup 2)))
8322                (clobber (match_dup 4))])
8323    (set (match_dup 3)
8324         (compare:CC (match_dup 0)
8325                     (const_int 0)))]
8326   "")
8327
8328 (define_split
8329   [(set (match_operand:CC 3 "cc_reg_operand" "")
8330         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8331                             (match_operand:DI 2 "mask64_2_operand" ""))
8332                     (const_int 0)))
8333    (set (match_operand:DI 0 "gpc_reg_operand" "")
8334         (and:DI (match_dup 1) (match_dup 2)))
8335    (clobber (match_scratch:CC 4 ""))]
8336   "TARGET_64BIT && reload_completed
8337     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8338     && !mask_operand (operands[2], DImode)
8339     && !mask64_operand (operands[2], DImode)"
8340   [(set (match_dup 0)
8341         (and:DI (rotate:DI (match_dup 1)
8342                            (match_dup 5))
8343                 (match_dup 6)))
8344    (parallel [(set (match_dup 3)
8345                    (compare:CC (and:DI (rotate:DI (match_dup 0)
8346                                                   (match_dup 7))
8347                                        (match_dup 8))
8348                                (const_int 0)))
8349               (set (match_dup 0)
8350                    (and:DI (rotate:DI (match_dup 0)
8351                                       (match_dup 7))
8352                            (match_dup 8)))])]
8353   "
8354 {
8355   build_mask64_2_operands (operands[2], &operands[5]);
8356 }")
8357
8358 (define_expand "iordi3"
8359   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8360         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
8361                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8362   "TARGET_POWERPC64"
8363   "
8364 {
8365   if (non_logical_cint_operand (operands[2], DImode))
8366     {
8367       HOST_WIDE_INT value;
8368       rtx tmp = ((!can_create_pseudo_p ()
8369                   || rtx_equal_p (operands[0], operands[1]))
8370                  ? operands[0] : gen_reg_rtx (DImode));
8371
8372       if (GET_CODE (operands[2]) == CONST_INT)
8373         {
8374           value = INTVAL (operands[2]);
8375           emit_insn (gen_iordi3 (tmp, operands[1],
8376                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8377         }
8378       else
8379         {
8380           value = CONST_DOUBLE_LOW (operands[2]);
8381           emit_insn (gen_iordi3 (tmp, operands[1],
8382                                  immed_double_const (value
8383                                                      & (~ (HOST_WIDE_INT) 0xffff),
8384                                                      0, DImode)));
8385         }
8386
8387       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8388       DONE;
8389     }
8390 }")
8391
8392 (define_expand "xordi3"
8393   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8394         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
8395                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8396   "TARGET_POWERPC64"
8397   "
8398 {
8399   if (non_logical_cint_operand (operands[2], DImode))
8400     {
8401       HOST_WIDE_INT value;
8402       rtx tmp = ((!can_create_pseudo_p ()
8403                   || rtx_equal_p (operands[0], operands[1]))
8404                  ? operands[0] : gen_reg_rtx (DImode));
8405
8406       if (GET_CODE (operands[2]) == CONST_INT)
8407         {
8408           value = INTVAL (operands[2]);
8409           emit_insn (gen_xordi3 (tmp, operands[1],
8410                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8411         }
8412       else
8413         {
8414           value = CONST_DOUBLE_LOW (operands[2]);
8415           emit_insn (gen_xordi3 (tmp, operands[1],
8416                                  immed_double_const (value
8417                                                      & (~ (HOST_WIDE_INT) 0xffff),
8418                                                      0, DImode)));
8419         }
8420
8421       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8422       DONE;
8423     }
8424 }")
8425
8426 (define_insn "*booldi3_internal1"
8427   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
8428         (match_operator:DI 3 "boolean_or_operator"
8429          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
8430           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
8431   "TARGET_POWERPC64"
8432   "@
8433    %q3 %0,%1,%2
8434    %q3i %0,%1,%b2
8435    %q3is %0,%1,%u2")
8436
8437 (define_insn "*booldi3_internal2"
8438   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8439         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8440          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8441           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8442          (const_int 0)))
8443    (clobber (match_scratch:DI 3 "=r,r"))]
8444   "TARGET_64BIT"
8445   "@
8446    %q4. %3,%1,%2
8447    #"
8448   [(set_attr "type" "fast_compare,compare")
8449    (set_attr "length" "4,8")])
8450
8451 (define_split
8452   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8453         (compare:CC (match_operator:DI 4 "boolean_operator"
8454          [(match_operand:DI 1 "gpc_reg_operand" "")
8455           (match_operand:DI 2 "gpc_reg_operand" "")])
8456          (const_int 0)))
8457    (clobber (match_scratch:DI 3 ""))]
8458   "TARGET_POWERPC64 && reload_completed"
8459   [(set (match_dup 3) (match_dup 4))
8460    (set (match_dup 0)
8461         (compare:CC (match_dup 3)
8462                     (const_int 0)))]
8463   "")
8464
8465 (define_insn "*booldi3_internal3"
8466   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8467         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8468          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8469           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8470          (const_int 0)))
8471    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8472         (match_dup 4))]
8473   "TARGET_64BIT"
8474   "@
8475    %q4. %0,%1,%2
8476    #"
8477   [(set_attr "type" "fast_compare,compare")
8478    (set_attr "length" "4,8")])
8479
8480 (define_split
8481   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8482         (compare:CC (match_operator:DI 4 "boolean_operator"
8483          [(match_operand:DI 1 "gpc_reg_operand" "")
8484           (match_operand:DI 2 "gpc_reg_operand" "")])
8485          (const_int 0)))
8486    (set (match_operand:DI 0 "gpc_reg_operand" "")
8487         (match_dup 4))]
8488   "TARGET_POWERPC64 && reload_completed"
8489   [(set (match_dup 0) (match_dup 4))
8490    (set (match_dup 3)
8491         (compare:CC (match_dup 0)
8492                     (const_int 0)))]
8493   "")
8494
8495 ;; Split a logical operation that we can't do in one insn into two insns,
8496 ;; each of which does one 16-bit part.  This is used by combine.
8497
8498 (define_split
8499   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8500         (match_operator:DI 3 "boolean_or_operator"
8501          [(match_operand:DI 1 "gpc_reg_operand" "")
8502           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
8503   "TARGET_POWERPC64"
8504   [(set (match_dup 0) (match_dup 4))
8505    (set (match_dup 0) (match_dup 5))]
8506 "
8507 {
8508   rtx i3,i4;
8509
8510   if (GET_CODE (operands[2]) == CONST_DOUBLE)
8511     {
8512       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
8513       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
8514                                         0, DImode);
8515       i4 = GEN_INT (value & 0xffff);
8516     }
8517   else
8518     {
8519       i3 = GEN_INT (INTVAL (operands[2])
8520                              & (~ (HOST_WIDE_INT) 0xffff));
8521       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
8522     }
8523   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8524                                 operands[1], i3);
8525   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8526                                 operands[0], i4);
8527 }")
8528
8529 (define_insn "*boolcdi3_internal1"
8530   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8531         (match_operator:DI 3 "boolean_operator"
8532          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8533           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
8534   "TARGET_POWERPC64"
8535   "%q3 %0,%2,%1")
8536
8537 (define_insn "*boolcdi3_internal2"
8538   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8539         (compare:CC (match_operator:DI 4 "boolean_operator"
8540          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8541           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8542          (const_int 0)))
8543    (clobber (match_scratch:DI 3 "=r,r"))]
8544   "TARGET_64BIT"
8545   "@
8546    %q4. %3,%2,%1
8547    #"
8548   [(set_attr "type" "fast_compare,compare")
8549    (set_attr "length" "4,8")])
8550
8551 (define_split
8552   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8553         (compare:CC (match_operator:DI 4 "boolean_operator"
8554          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8555           (match_operand:DI 2 "gpc_reg_operand" "")])
8556          (const_int 0)))
8557    (clobber (match_scratch:DI 3 ""))]
8558   "TARGET_POWERPC64 && reload_completed"
8559   [(set (match_dup 3) (match_dup 4))
8560    (set (match_dup 0)
8561         (compare:CC (match_dup 3)
8562                     (const_int 0)))]
8563   "")
8564
8565 (define_insn "*boolcdi3_internal3"
8566   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8567         (compare:CC (match_operator:DI 4 "boolean_operator"
8568          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8569           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8570          (const_int 0)))
8571    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8572         (match_dup 4))]
8573   "TARGET_64BIT"
8574   "@
8575    %q4. %0,%2,%1
8576    #"
8577   [(set_attr "type" "fast_compare,compare")
8578    (set_attr "length" "4,8")])
8579
8580 (define_split
8581   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8582         (compare:CC (match_operator:DI 4 "boolean_operator"
8583          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8584           (match_operand:DI 2 "gpc_reg_operand" "")])
8585          (const_int 0)))
8586    (set (match_operand:DI 0 "gpc_reg_operand" "")
8587         (match_dup 4))]
8588   "TARGET_POWERPC64 && reload_completed"
8589   [(set (match_dup 0) (match_dup 4))
8590    (set (match_dup 3)
8591         (compare:CC (match_dup 0)
8592                     (const_int 0)))]
8593   "")
8594
8595 (define_insn "*boolccdi3_internal1"
8596   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8597         (match_operator:DI 3 "boolean_operator"
8598          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8599           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
8600   "TARGET_POWERPC64"
8601   "%q3 %0,%1,%2")
8602
8603 (define_insn "*boolccdi3_internal2"
8604   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8605         (compare:CC (match_operator:DI 4 "boolean_operator"
8606          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8607           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8608          (const_int 0)))
8609    (clobber (match_scratch:DI 3 "=r,r"))]
8610   "TARGET_64BIT"
8611   "@
8612    %q4. %3,%1,%2
8613    #"
8614   [(set_attr "type" "fast_compare,compare")
8615    (set_attr "length" "4,8")])
8616
8617 (define_split
8618   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8619         (compare:CC (match_operator:DI 4 "boolean_operator"
8620          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8621           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8622          (const_int 0)))
8623    (clobber (match_scratch:DI 3 ""))]
8624   "TARGET_POWERPC64 && reload_completed"
8625   [(set (match_dup 3) (match_dup 4))
8626    (set (match_dup 0)
8627         (compare:CC (match_dup 3)
8628                     (const_int 0)))]
8629   "")
8630
8631 (define_insn "*boolccdi3_internal3"
8632   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8633         (compare:CC (match_operator:DI 4 "boolean_operator"
8634          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8635           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8636          (const_int 0)))
8637    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8638         (match_dup 4))]
8639   "TARGET_64BIT"
8640   "@
8641    %q4. %0,%1,%2
8642    #"
8643   [(set_attr "type" "fast_compare,compare")
8644    (set_attr "length" "4,8")])
8645
8646 (define_split
8647   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8648         (compare:CC (match_operator:DI 4 "boolean_operator"
8649          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8650           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8651          (const_int 0)))
8652    (set (match_operand:DI 0 "gpc_reg_operand" "")
8653         (match_dup 4))]
8654   "TARGET_POWERPC64 && reload_completed"
8655   [(set (match_dup 0) (match_dup 4))
8656    (set (match_dup 3)
8657         (compare:CC (match_dup 0)
8658                     (const_int 0)))]
8659   "")
8660
8661 (define_expand "smindi3"
8662   [(match_operand:DI 0 "gpc_reg_operand" "")
8663    (match_operand:DI 1 "gpc_reg_operand" "")
8664    (match_operand:DI 2 "gpc_reg_operand" "")]
8665   "TARGET_ISEL64"
8666   "
8667 {
8668   rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
8669   DONE;
8670 }")
8671
8672 (define_expand "smaxdi3"
8673   [(match_operand:DI 0 "gpc_reg_operand" "")
8674    (match_operand:DI 1 "gpc_reg_operand" "")
8675    (match_operand:DI 2 "gpc_reg_operand" "")]
8676   "TARGET_ISEL64"
8677   "
8678 {
8679   rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
8680   DONE;
8681 }")
8682
8683 (define_expand "umindi3"
8684   [(match_operand:DI 0 "gpc_reg_operand" "")
8685    (match_operand:DI 1 "gpc_reg_operand" "")
8686    (match_operand:DI 2 "gpc_reg_operand" "")]
8687   "TARGET_ISEL64"
8688   "
8689 {
8690   rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
8691   DONE;
8692 }")
8693
8694 (define_expand "umaxdi3"
8695   [(match_operand:DI 0 "gpc_reg_operand" "")
8696    (match_operand:DI 1 "gpc_reg_operand" "")
8697    (match_operand:DI 2 "gpc_reg_operand" "")]
8698   "TARGET_ISEL64"
8699   "
8700 {
8701   rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
8702   DONE;
8703 }")
8704
8705 \f
8706 ;; Now define ways of moving data around.
8707
8708 ;; Set up a register with a value from the GOT table
8709
8710 (define_expand "movsi_got"
8711   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8712         (unspec:SI [(match_operand:SI 1 "got_operand" "")
8713                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
8714   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8715   "
8716 {
8717   if (GET_CODE (operands[1]) == CONST)
8718     {
8719       rtx offset = const0_rtx;
8720       HOST_WIDE_INT value;
8721
8722       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
8723       value = INTVAL (offset);
8724       if (value != 0)
8725         {
8726           rtx tmp = (!can_create_pseudo_p ()
8727                      ? operands[0]
8728                      : gen_reg_rtx (Pmode));
8729           emit_insn (gen_movsi_got (tmp, operands[1]));
8730           emit_insn (gen_addsi3 (operands[0], tmp, offset));
8731           DONE;
8732         }
8733     }
8734
8735   operands[2] = rs6000_got_register (operands[1]);
8736 }")
8737
8738 (define_insn "*movsi_got_internal"
8739   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8740         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8741                     (match_operand:SI 2 "gpc_reg_operand" "b")]
8742                    UNSPEC_MOVSI_GOT))]
8743   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8744   "{l|lwz} %0,%a1@got(%2)"
8745   [(set_attr "type" "load")])
8746
8747 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
8748 ;; didn't get allocated to a hard register.
8749 (define_split
8750   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8751         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8752                     (match_operand:SI 2 "memory_operand" "")]
8753                    UNSPEC_MOVSI_GOT))]
8754   "DEFAULT_ABI == ABI_V4
8755     && flag_pic == 1
8756     && (reload_in_progress || reload_completed)"
8757   [(set (match_dup 0) (match_dup 2))
8758    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
8759                                  UNSPEC_MOVSI_GOT))]
8760   "")
8761
8762 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8763 ;; do the load 16-bits at a time.  We could do this by loading from memory,
8764 ;; and this is even supposed to be faster, but it is simpler not to get
8765 ;; integers in the TOC.
8766 (define_insn "movsi_low"
8767   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8768         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8769                            (match_operand 2 "" ""))))]
8770   "TARGET_MACHO && ! TARGET_64BIT"
8771   "{l|lwz} %0,lo16(%2)(%1)"
8772   [(set_attr "type" "load")
8773    (set_attr "length" "4")])
8774
8775 (define_insn "*movsi_internal1"
8776   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
8777         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
8778   "!TARGET_SINGLE_FPU &&
8779    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8780   "@
8781    mr %0,%1
8782    {cal|la} %0,%a1
8783    {l%U1%X1|lwz%U1%X1} %0,%1
8784    {st%U0%X0|stw%U0%X0} %1,%0
8785    {lil|li} %0,%1
8786    {liu|lis} %0,%v1
8787    #
8788    {cal|la} %0,%a1
8789    mf%1 %0
8790    mt%0 %1
8791    mt%0 %1
8792    mt%0 %1
8793    {cror 0,0,0|nop}"
8794   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
8795    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
8796
8797 (define_insn "*movsi_internal1_single"
8798   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h,m,*f")
8799         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0,f,m"))]
8800   "TARGET_SINGLE_FPU &&
8801    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8802   "@
8803    mr %0,%1
8804    {cal|la} %0,%a1
8805    {l%U1%X1|lwz%U1%X1} %0,%1
8806    {st%U0%X0|stw%U0%X0} %1,%0
8807    {lil|li} %0,%1
8808    {liu|lis} %0,%v1
8809    #
8810    {cal|la} %0,%a1
8811    mf%1 %0
8812    mt%0 %1
8813    mt%0 %1
8814    mt%0 %1
8815    {cror 0,0,0|nop}
8816    stfs%U0%X0 %1, %0
8817    lfs%U1%X1 %0, %1"
8818   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*,*,*")
8819    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4,4,4")])
8820
8821 ;; Split a load of a large constant into the appropriate two-insn
8822 ;; sequence.
8823
8824 (define_split
8825   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8826         (match_operand:SI 1 "const_int_operand" ""))]
8827   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
8828    && (INTVAL (operands[1]) & 0xffff) != 0"
8829   [(set (match_dup 0)
8830         (match_dup 2))
8831    (set (match_dup 0)
8832         (ior:SI (match_dup 0)
8833                 (match_dup 3)))]
8834   "
8835 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
8836
8837   if (tem == operands[0])
8838     DONE;
8839   else
8840     FAIL;
8841 }")
8842
8843 (define_insn "*mov<mode>_internal2"
8844   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8845         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
8846                     (const_int 0)))
8847    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8848   ""
8849   "@
8850    {cmpi|cmp<wd>i} %2,%0,0
8851    mr. %0,%1
8852    #"
8853   [(set_attr "type" "cmp,compare,cmp")
8854    (set_attr "length" "4,4,8")])
8855
8856 (define_split
8857   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
8858         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
8859                     (const_int 0)))
8860    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
8861   "reload_completed"
8862   [(set (match_dup 0) (match_dup 1))
8863    (set (match_dup 2)
8864         (compare:CC (match_dup 0)
8865                     (const_int 0)))]
8866   "")
8867 \f
8868 (define_insn "*movhi_internal"
8869   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8870         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8871   "gpc_reg_operand (operands[0], HImode)
8872    || gpc_reg_operand (operands[1], HImode)"
8873   "@
8874    mr %0,%1
8875    lhz%U1%X1 %0,%1
8876    sth%U0%X0 %1,%0
8877    {lil|li} %0,%w1
8878    mf%1 %0
8879    mt%0 %1
8880    mt%0 %1
8881    {cror 0,0,0|nop}"
8882   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
8883
8884 (define_expand "mov<mode>"
8885   [(set (match_operand:INT 0 "general_operand" "")
8886         (match_operand:INT 1 "any_operand" ""))]
8887   ""
8888   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8889
8890 (define_insn "*movqi_internal"
8891   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8892         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8893   "gpc_reg_operand (operands[0], QImode)
8894    || gpc_reg_operand (operands[1], QImode)"
8895   "@
8896    mr %0,%1
8897    lbz%U1%X1 %0,%1
8898    stb%U0%X0 %1,%0
8899    {lil|li} %0,%1
8900    mf%1 %0
8901    mt%0 %1
8902    mt%0 %1
8903    {cror 0,0,0|nop}"
8904   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
8905 \f
8906 ;; Here is how to move condition codes around.  When we store CC data in
8907 ;; an integer register or memory, we store just the high-order 4 bits.
8908 ;; This lets us not shift in the most common case of CR0.
8909 (define_expand "movcc"
8910   [(set (match_operand:CC 0 "nonimmediate_operand" "")
8911         (match_operand:CC 1 "nonimmediate_operand" ""))]
8912   ""
8913   "")
8914
8915 (define_insn "*movcc_internal1"
8916   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,q,cl,r,m")
8917         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,r,m,r"))]
8918   "register_operand (operands[0], CCmode)
8919    || register_operand (operands[1], CCmode)"
8920   "@
8921    mcrf %0,%1
8922    mtcrf 128,%1
8923    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
8924    crxor %0,%0,%0
8925    mfcr %0%Q1
8926    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
8927    mr %0,%1
8928    {lil|li} %0,%1
8929    mf%1 %0
8930    mt%0 %1
8931    mt%0 %1
8932    {l%U1%X1|lwz%U1%X1} %0,%1
8933    {st%U0%U1|stw%U0%U1} %1,%0"
8934   [(set (attr "type")
8935      (cond [(eq_attr "alternative" "0,3")
8936                 (const_string "cr_logical")
8937             (eq_attr "alternative" "1,2")
8938                 (const_string "mtcr")
8939             (eq_attr "alternative" "6,7,9")
8940                 (const_string "integer")
8941             (eq_attr "alternative" "8")
8942                 (const_string "mfjmpr")
8943             (eq_attr "alternative" "10")
8944                 (const_string "mtjmpr")
8945             (eq_attr "alternative" "11")
8946                 (const_string "load")
8947             (eq_attr "alternative" "12")
8948                 (const_string "store")
8949             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
8950                 (const_string "mfcrf")
8951            ]
8952         (const_string "mfcr")))
8953    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4,4")])
8954 \f
8955 ;; For floating-point, we normally deal with the floating-point registers
8956 ;; unless -msoft-float is used.  The sole exception is that parameter passing
8957 ;; can produce floating-point values in fixed-point registers.  Unless the
8958 ;; value is a simple constant or already in memory, we deal with this by
8959 ;; allocating memory and copying the value explicitly via that memory location.
8960 (define_expand "movsf"
8961   [(set (match_operand:SF 0 "nonimmediate_operand" "")
8962         (match_operand:SF 1 "any_operand" ""))]
8963   ""
8964   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
8965
8966 (define_split
8967   [(set (match_operand:SF 0 "gpc_reg_operand" "")
8968         (match_operand:SF 1 "const_double_operand" ""))]
8969   "reload_completed
8970    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8971        || (GET_CODE (operands[0]) == SUBREG
8972            && GET_CODE (SUBREG_REG (operands[0])) == REG
8973            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8974   [(set (match_dup 2) (match_dup 3))]
8975   "
8976 {
8977   long l;
8978   REAL_VALUE_TYPE rv;
8979
8980   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8981   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
8982
8983   if (! TARGET_POWERPC64)
8984     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
8985   else
8986     operands[2] = gen_lowpart (SImode, operands[0]);
8987
8988   operands[3] = gen_int_mode (l, SImode);
8989 }")
8990
8991 (define_insn "*movsf_hardfloat"
8992   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
8993         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
8994   "(gpc_reg_operand (operands[0], SFmode)
8995    || gpc_reg_operand (operands[1], SFmode))
8996    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
8997   "@
8998    mr %0,%1
8999    {l%U1%X1|lwz%U1%X1} %0,%1
9000    {st%U0%X0|stw%U0%X0} %1,%0
9001    fmr %0,%1
9002    lfs%U1%X1 %0,%1
9003    stfs%U0%X0 %1,%0
9004    mt%0 %1
9005    mt%0 %1
9006    mf%1 %0
9007    {cror 0,0,0|nop}
9008    #
9009    #"
9010   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
9011    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
9012
9013 (define_insn "*movsf_softfloat"
9014   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
9015         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
9016   "(gpc_reg_operand (operands[0], SFmode)
9017    || gpc_reg_operand (operands[1], SFmode))
9018    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
9019   "@
9020    mr %0,%1
9021    mt%0 %1
9022    mt%0 %1
9023    mf%1 %0
9024    {l%U1%X1|lwz%U1%X1} %0,%1
9025    {st%U0%X0|stw%U0%X0} %1,%0
9026    {lil|li} %0,%1
9027    {liu|lis} %0,%v1
9028    {cal|la} %0,%a1
9029    #
9030    #
9031    {cror 0,0,0|nop}"
9032   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
9033    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
9034
9035 \f
9036 (define_expand "movdf"
9037   [(set (match_operand:DF 0 "nonimmediate_operand" "")
9038         (match_operand:DF 1 "any_operand" ""))]
9039   ""
9040   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
9041
9042 (define_split
9043   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9044         (match_operand:DF 1 "const_int_operand" ""))]
9045   "! TARGET_POWERPC64 && reload_completed
9046    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9047        || (GET_CODE (operands[0]) == SUBREG
9048            && GET_CODE (SUBREG_REG (operands[0])) == REG
9049            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9050   [(set (match_dup 2) (match_dup 4))
9051    (set (match_dup 3) (match_dup 1))]
9052   "
9053 {
9054   int endian = (WORDS_BIG_ENDIAN == 0);
9055   HOST_WIDE_INT value = INTVAL (operands[1]);
9056
9057   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
9058   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
9059 #if HOST_BITS_PER_WIDE_INT == 32
9060   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
9061 #else
9062   operands[4] = GEN_INT (value >> 32);
9063   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9064 #endif
9065 }")
9066
9067 (define_split
9068   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9069         (match_operand:DF 1 "const_double_operand" ""))]
9070   "! TARGET_POWERPC64 && reload_completed
9071    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9072        || (GET_CODE (operands[0]) == SUBREG
9073            && GET_CODE (SUBREG_REG (operands[0])) == REG
9074            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9075   [(set (match_dup 2) (match_dup 4))
9076    (set (match_dup 3) (match_dup 5))]
9077   "
9078 {
9079   int endian = (WORDS_BIG_ENDIAN == 0);
9080   long l[2];
9081   REAL_VALUE_TYPE rv;
9082
9083   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9084   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
9085
9086   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
9087   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
9088   operands[4] = gen_int_mode (l[endian], SImode);
9089   operands[5] = gen_int_mode (l[1 - endian], SImode);
9090 }")
9091
9092 (define_split
9093   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9094         (match_operand:DF 1 "const_double_operand" ""))]
9095   "TARGET_POWERPC64 && reload_completed
9096    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9097        || (GET_CODE (operands[0]) == SUBREG
9098            && GET_CODE (SUBREG_REG (operands[0])) == REG
9099            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9100   [(set (match_dup 2) (match_dup 3))]
9101   "
9102 {
9103   int endian = (WORDS_BIG_ENDIAN == 0);
9104   long l[2];
9105   REAL_VALUE_TYPE rv;
9106 #if HOST_BITS_PER_WIDE_INT >= 64
9107   HOST_WIDE_INT val;
9108 #endif
9109
9110   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9111   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
9112
9113   operands[2] = gen_lowpart (DImode, operands[0]);
9114   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
9115 #if HOST_BITS_PER_WIDE_INT >= 64
9116   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
9117          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
9118
9119   operands[3] = gen_int_mode (val, DImode);
9120 #else
9121   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
9122 #endif
9123 }")
9124
9125 ;; Don't have reload use general registers to load a constant.  First,
9126 ;; it might not work if the output operand is the equivalent of
9127 ;; a non-offsettable memref, but also it is less efficient than loading
9128 ;; the constant into an FP register, since it will probably be used there.
9129 ;; The "??" is a kludge until we can figure out a more reasonable way
9130 ;; of handling these non-offsettable values.
9131 (define_insn "*movdf_hardfloat32"
9132   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,ws,?wa,ws,?wa,Z,?Z,d,d,m,wa,!r,!r,!r")
9133         (match_operand:DF 1 "input_operand" "r,m,r,ws,wa,Z,Z,ws,wa,d,m,d,j,G,H,F"))]
9134   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9135    && (gpc_reg_operand (operands[0], DFmode)
9136        || gpc_reg_operand (operands[1], DFmode))"
9137   "*
9138 {
9139   switch (which_alternative)
9140     {
9141     default:
9142       gcc_unreachable ();
9143     case 0:
9144       /* We normally copy the low-numbered register first.  However, if
9145          the first register operand 0 is the same as the second register
9146          of operand 1, we must copy in the opposite order.  */
9147       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9148         return \"mr %L0,%L1\;mr %0,%1\";
9149       else
9150         return \"mr %0,%1\;mr %L0,%L1\";
9151     case 1:
9152       if (rs6000_offsettable_memref_p (operands[1])
9153           || (GET_CODE (operands[1]) == MEM
9154               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
9155                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
9156                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC
9157                   || GET_CODE (XEXP (operands[1], 0)) == PRE_MODIFY)))
9158         {
9159           /* If the low-address word is used in the address, we must load
9160              it last.  Otherwise, load it first.  Note that we cannot have
9161              auto-increment in that case since the address register is
9162              known to be dead.  */
9163           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
9164                                  operands[1], 0))
9165             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
9166           else
9167             return \"{l%U1%X1|lwz%U1%X1} %0,%1\;{l|lwz} %L0,%L1\";
9168         }
9169       else
9170         {
9171           rtx addreg;
9172
9173           addreg = find_addr_reg (XEXP (operands[1], 0));
9174           if (refers_to_regno_p (REGNO (operands[0]),
9175                                  REGNO (operands[0]) + 1,
9176                                  operands[1], 0))
9177             {
9178               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
9179               output_asm_insn (\"{l%X1|lwz%X1} %L0,%1\", operands);
9180               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
9181               return \"{l%X1|lwz%X1} %0,%1\";
9182             }
9183           else
9184             {
9185               output_asm_insn (\"{l%X1|lwz%X1} %0,%1\", operands);
9186               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
9187               output_asm_insn (\"{l%X1|lwz%X1} %L0,%1\", operands);
9188               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
9189               return \"\";
9190             }
9191         }
9192     case 2:
9193       if (rs6000_offsettable_memref_p (operands[0])
9194           || (GET_CODE (operands[0]) == MEM
9195               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
9196                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
9197                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
9198                   || GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY)))
9199         return \"{st%U0%X0|stw%U0%X0} %1,%0\;{st|stw} %L1,%L0\";
9200       else
9201         {
9202           rtx addreg;
9203
9204           addreg = find_addr_reg (XEXP (operands[0], 0));
9205           output_asm_insn (\"{st%X0|stw%X0} %1,%0\", operands);
9206           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
9207           output_asm_insn (\"{st%X0|stw%X0} %L1,%0\", operands);
9208           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
9209           return \"\";
9210         }
9211     case 3:
9212     case 4:
9213       return \"xxlor %x0,%x1,%x1\";
9214     case 5:
9215     case 6:
9216       return \"lxsd%U1x %x0,%y1\";
9217     case 7:
9218     case 8:
9219       return \"stxsd%U0x %x1,%y0\";
9220     case 9:
9221       return \"fmr %0,%1\";
9222     case 10:
9223       return \"lfd%U1%X1 %0,%1\";
9224     case 11:
9225       return \"stfd%U0%X0 %1,%0\";
9226     case 12:
9227       return \"xxlxor %x0,%x0,%x0\";
9228     case 13:
9229     case 14:
9230     case 15:
9231       return \"#\";
9232     }
9233 }"
9234   [(set_attr "type" "two,load,store,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,*,*,*")
9235    (set_attr "length" "8,16,16,4,4,4,4,4,4,4,4,4,4,8,12,16")])
9236
9237 (define_insn "*movdf_softfloat32"
9238   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
9239         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
9240   "! TARGET_POWERPC64 
9241    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
9242        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
9243    && (gpc_reg_operand (operands[0], DFmode)
9244        || gpc_reg_operand (operands[1], DFmode))"
9245   "*
9246 {
9247   switch (which_alternative)
9248     {
9249     default:
9250       gcc_unreachable ();
9251     case 0:
9252       /* We normally copy the low-numbered register first.  However, if
9253          the first register operand 0 is the same as the second register of
9254          operand 1, we must copy in the opposite order.  */
9255       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9256         return \"mr %L0,%L1\;mr %0,%1\";
9257       else
9258         return \"mr %0,%1\;mr %L0,%L1\";
9259     case 1:
9260       /* If the low-address word is used in the address, we must load
9261          it last.  Otherwise, load it first.  Note that we cannot have
9262          auto-increment in that case since the address register is
9263          known to be dead.  */
9264       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
9265                              operands[1], 0))
9266         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
9267       else
9268         return \"{l%U1%X1|lwz%U1%X1} %0,%1\;{l|lwz} %L0,%L1\";
9269     case 2:
9270       return \"{st%U0%X0|stw%U0%X0} %1,%0\;{st|stw} %L1,%L0\";
9271     case 3:
9272     case 4:
9273     case 5:
9274       return \"#\";
9275     }
9276 }"
9277   [(set_attr "type" "two,load,store,*,*,*")
9278    (set_attr "length" "8,8,8,8,12,16")])
9279
9280 ; ld/std require word-aligned displacements -> 'Y' constraint.
9281 ; List Y->r and r->Y before r->r for reload.
9282 (define_insn "*movdf_hardfloat64_mfpgpr"
9283   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,ws,?wa,ws,?wa,Z,?Z,d,d,m,wa,*c*l,!r,*h,!r,!r,!r,r,d")
9284         (match_operand:DF 1 "input_operand" "r,Y,r,ws,?wa,Z,Z,ws,wa,d,m,d,j,r,h,0,G,H,F,d,r"))]
9285   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
9286    && TARGET_DOUBLE_FLOAT
9287    && (gpc_reg_operand (operands[0], DFmode)
9288        || gpc_reg_operand (operands[1], DFmode))"
9289   "@
9290    std%U0%X0 %1,%0
9291    ld%U1%X1 %0,%1
9292    mr %0,%1
9293    xxlor %x0,%x1,%x1
9294    xxlor %x0,%x1,%x1
9295    lxsd%U1x %x0,%y1
9296    lxsd%U1x %x0,%y1
9297    stxsd%U0x %x1,%y0
9298    stxsd%U0x %x1,%y0
9299    fmr %0,%1
9300    lfd%U1%X1 %0,%1
9301    stfd%U0%X0 %1,%0
9302    xxlxor %x0,%x0,%x0
9303    mt%0 %1
9304    mf%1 %0
9305    {cror 0,0,0|nop}
9306    #
9307    #
9308    #
9309    mftgpr %0,%1
9310    mffgpr %0,%1"
9311   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
9312    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
9313
9314 ; ld/std require word-aligned displacements -> 'Y' constraint.
9315 ; List Y->r and r->Y before r->r for reload.
9316 (define_insn "*movdf_hardfloat64"
9317   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,ws,?wa,ws,?wa,Z,?Z,d,d,m,wa,*c*l,!r,*h,!r,!r,!r")
9318         (match_operand:DF 1 "input_operand" "r,Y,r,ws,wa,Z,Z,ws,wa,d,m,d,j,r,h,0,G,H,F"))]
9319   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
9320    && TARGET_DOUBLE_FLOAT
9321    && (gpc_reg_operand (operands[0], DFmode)
9322        || gpc_reg_operand (operands[1], DFmode))"
9323   "@
9324    std%U0%X0 %1,%0
9325    ld%U1%X1 %0,%1
9326    mr %0,%1
9327    xxlor %x0,%x1,%x1
9328    xxlor %x0,%x1,%x1
9329    lxsd%U1x %x0,%y1
9330    lxsd%U1x %x0,%y1
9331    stxsd%U0x %x1,%y0
9332    stxsd%U0x %x1,%y0
9333    fmr %0,%1
9334    lfd%U1%X1 %0,%1
9335    stfd%U0%X0 %1,%0
9336    xxlxor %x0,%x0,%x0
9337    mt%0 %1
9338    mf%1 %0
9339    {cror 0,0,0|nop}
9340    #
9341    #
9342    #"
9343   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,mtjmpr,mfjmpr,*,*,*,*")
9344    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16")])
9345
9346 (define_insn "*movdf_softfloat64"
9347   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
9348         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
9349   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
9350    && (gpc_reg_operand (operands[0], DFmode)
9351        || gpc_reg_operand (operands[1], DFmode))"
9352   "@
9353    ld%U1%X1 %0,%1
9354    std%U0%X0 %1,%0
9355    mr %0,%1
9356    mt%0 %1
9357    mf%1 %0
9358    #
9359    #
9360    #
9361    {cror 0,0,0|nop}"
9362   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
9363    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
9364 \f
9365 (define_expand "movtf"
9366   [(set (match_operand:TF 0 "general_operand" "")
9367         (match_operand:TF 1 "any_operand" ""))]
9368   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
9369   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
9370
9371 ; It's important to list the o->f and f->o moves before f->f because
9372 ; otherwise reload, given m->f, will try to pick f->f and reload it,
9373 ; which doesn't make progress.  Likewise r->Y must be before r->r.
9374 (define_insn_and_split "*movtf_internal"
9375   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,d,d,r,Y,r")
9376         (match_operand:TF 1 "input_operand"         "d,o,d,YGHF,r,r"))]
9377   "!TARGET_IEEEQUAD
9378    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
9379    && (gpc_reg_operand (operands[0], TFmode)
9380        || gpc_reg_operand (operands[1], TFmode))"
9381   "#"
9382   "&& reload_completed"
9383   [(pc)]
9384 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9385   [(set_attr "length" "8,8,8,20,20,16")])
9386
9387 (define_insn_and_split "*movtf_softfloat"
9388   [(set (match_operand:TF 0 "rs6000_nonimmediate_operand" "=r,Y,r")
9389         (match_operand:TF 1 "input_operand"         "YGHF,r,r"))]
9390   "!TARGET_IEEEQUAD
9391    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
9392    && (gpc_reg_operand (operands[0], TFmode)
9393        || gpc_reg_operand (operands[1], TFmode))"
9394   "#"
9395   "&& reload_completed"
9396   [(pc)]
9397 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9398   [(set_attr "length" "20,20,16")])
9399
9400 (define_expand "extenddftf2"
9401   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9402         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
9403   "!TARGET_IEEEQUAD
9404    && TARGET_HARD_FLOAT
9405    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9406    && TARGET_LONG_DOUBLE_128"
9407 {
9408   if (TARGET_E500_DOUBLE)
9409     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
9410   else
9411     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
9412   DONE;
9413 })
9414
9415 (define_expand "extenddftf2_fprs"
9416   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9417                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
9418               (use (match_dup 2))])]
9419   "!TARGET_IEEEQUAD
9420    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9421    && TARGET_LONG_DOUBLE_128"
9422 {
9423   operands[2] = CONST0_RTX (DFmode);
9424   /* Generate GOT reference early for SVR4 PIC.  */
9425   if (DEFAULT_ABI == ABI_V4 && flag_pic)
9426     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
9427 })
9428
9429 (define_insn_and_split "*extenddftf2_internal"
9430   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,d,&d,r")
9431        (float_extend:TF (match_operand:DF 1 "input_operand" "dr,md,md,rmGHF")))
9432    (use (match_operand:DF 2 "zero_reg_mem_operand" "rd,m,d,n"))]
9433   "!TARGET_IEEEQUAD
9434    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9435    && TARGET_LONG_DOUBLE_128"
9436   "#"
9437   "&& reload_completed"
9438   [(pc)]
9439 {
9440   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
9441   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
9442   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
9443                   operands[1]);
9444   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
9445                   operands[2]);
9446   DONE;
9447 })
9448
9449 (define_expand "extendsftf2"
9450   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9451         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
9452   "!TARGET_IEEEQUAD
9453    && TARGET_HARD_FLOAT
9454    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9455    && TARGET_LONG_DOUBLE_128"
9456 {
9457   rtx tmp = gen_reg_rtx (DFmode);
9458   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
9459   emit_insn (gen_extenddftf2 (operands[0], tmp));
9460   DONE;
9461 })
9462
9463 (define_expand "trunctfdf2"
9464   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9465         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
9466   "!TARGET_IEEEQUAD
9467    && TARGET_HARD_FLOAT
9468    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9469    && TARGET_LONG_DOUBLE_128"
9470   "")
9471
9472 (define_insn_and_split "trunctfdf2_internal1"
9473   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
9474         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
9475   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
9476    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9477   "@
9478    #
9479    fmr %0,%1"
9480   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
9481   [(const_int 0)]
9482 {
9483   emit_note (NOTE_INSN_DELETED);
9484   DONE;
9485 }
9486   [(set_attr "type" "fp")])
9487
9488 (define_insn "trunctfdf2_internal2"
9489   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9490         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9491   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
9492    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9493    && TARGET_LONG_DOUBLE_128"
9494   "fadd %0,%1,%L1"
9495   [(set_attr "type" "fp")
9496    (set_attr "fp_type" "fp_addsub_d")])
9497
9498 (define_expand "trunctfsf2"
9499   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9500         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
9501   "!TARGET_IEEEQUAD
9502    && TARGET_HARD_FLOAT
9503    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9504    && TARGET_LONG_DOUBLE_128"
9505 {
9506   if (TARGET_E500_DOUBLE)
9507     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
9508   else
9509     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
9510   DONE;
9511 })
9512
9513 (define_insn_and_split "trunctfsf2_fprs"
9514   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
9515         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
9516    (clobber (match_scratch:DF 2 "=d"))]
9517   "!TARGET_IEEEQUAD
9518    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
9519    && TARGET_LONG_DOUBLE_128"
9520   "#"
9521   "&& reload_completed"
9522   [(set (match_dup 2)
9523         (float_truncate:DF (match_dup 1)))
9524    (set (match_dup 0)
9525         (float_truncate:SF (match_dup 2)))]
9526   "")
9527
9528 (define_expand "floatsitf2"
9529   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9530         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
9531   "!TARGET_IEEEQUAD
9532    && TARGET_HARD_FLOAT
9533    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9534    && TARGET_LONG_DOUBLE_128"
9535 {
9536   rtx tmp = gen_reg_rtx (DFmode);
9537   expand_float (tmp, operands[1], false);
9538   emit_insn (gen_extenddftf2 (operands[0], tmp));
9539   DONE;
9540 })
9541
9542 ; fadd, but rounding towards zero.
9543 ; This is probably not the optimal code sequence.
9544 (define_insn "fix_trunc_helper"
9545   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9546         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
9547                    UNSPEC_FIX_TRUNC_TF))
9548    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
9549   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
9550   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
9551   [(set_attr "type" "fp")
9552    (set_attr "length" "20")])
9553
9554 (define_expand "fix_trunctfsi2"
9555   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9556         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
9557   "!TARGET_IEEEQUAD
9558    && (TARGET_POWER2 || TARGET_POWERPC)
9559    && TARGET_HARD_FLOAT
9560    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9561    && TARGET_LONG_DOUBLE_128"
9562 {
9563   if (TARGET_E500_DOUBLE)
9564     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
9565   else
9566     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
9567   DONE;
9568 })
9569
9570 (define_expand "fix_trunctfsi2_fprs"
9571   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
9572                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
9573               (clobber (match_dup 2))
9574               (clobber (match_dup 3))
9575               (clobber (match_dup 4))
9576               (clobber (match_dup 5))])]
9577   "!TARGET_IEEEQUAD
9578    && (TARGET_POWER2 || TARGET_POWERPC)
9579    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9580 {
9581   operands[2] = gen_reg_rtx (DFmode);
9582   operands[3] = gen_reg_rtx (DFmode);
9583   operands[4] = gen_reg_rtx (DImode);
9584   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
9585 })
9586
9587 (define_insn_and_split "*fix_trunctfsi2_internal"
9588   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9589         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
9590    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
9591    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
9592    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
9593    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
9594   "!TARGET_IEEEQUAD
9595    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9596   "#"
9597   ""
9598   [(pc)]
9599 {
9600   rtx lowword;
9601   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
9602
9603   gcc_assert (MEM_P (operands[5]));
9604   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
9605
9606   emit_insn (gen_fctiwz (operands[4], operands[2]));
9607   emit_move_insn (operands[5], operands[4]);
9608   emit_move_insn (operands[0], lowword);
9609   DONE;
9610 })
9611
9612 (define_expand "negtf2"
9613   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9614         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9615   "!TARGET_IEEEQUAD
9616    && TARGET_HARD_FLOAT
9617    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9618    && TARGET_LONG_DOUBLE_128"
9619   "")
9620
9621 (define_insn "negtf2_internal"
9622   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
9623         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9624   "!TARGET_IEEEQUAD
9625    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9626   "*
9627 {
9628   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9629     return \"fneg %L0,%L1\;fneg %0,%1\";
9630   else
9631     return \"fneg %0,%1\;fneg %L0,%L1\";
9632 }"
9633   [(set_attr "type" "fp")
9634    (set_attr "length" "8")])
9635
9636 (define_expand "abstf2"
9637   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9638         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9639   "!TARGET_IEEEQUAD
9640    && TARGET_HARD_FLOAT
9641    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9642    && TARGET_LONG_DOUBLE_128"
9643   "
9644 {
9645   rtx label = gen_label_rtx ();
9646   if (TARGET_E500_DOUBLE)
9647     {
9648       if (flag_finite_math_only && !flag_trapping_math)
9649         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
9650       else
9651         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
9652     }
9653   else
9654     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
9655   emit_label (label);
9656   DONE;
9657 }")
9658
9659 (define_expand "abstf2_internal"
9660   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9661         (match_operand:TF 1 "gpc_reg_operand" ""))
9662    (set (match_dup 3) (match_dup 5))
9663    (set (match_dup 5) (abs:DF (match_dup 5)))
9664    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
9665    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
9666                            (label_ref (match_operand 2 "" ""))
9667                            (pc)))
9668    (set (match_dup 6) (neg:DF (match_dup 6)))]
9669   "!TARGET_IEEEQUAD
9670    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9671    && TARGET_LONG_DOUBLE_128"
9672   "
9673 {
9674   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
9675   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
9676   operands[3] = gen_reg_rtx (DFmode);
9677   operands[4] = gen_reg_rtx (CCFPmode);
9678   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
9679   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
9680 }")
9681 \f
9682 ;; Next come the multi-word integer load and store and the load and store
9683 ;; multiple insns.
9684
9685 ; List r->r after r->"o<>", otherwise reload will try to reload a
9686 ; non-offsettable address by using r->r which won't make progress.
9687 (define_insn "*movdi_internal32"
9688   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=o<>,r,r,*d,*d,m,r")
9689         (match_operand:DI 1 "input_operand" "r,r,m,d,m,d,IJKnGHF"))]
9690   "! TARGET_POWERPC64
9691    && (gpc_reg_operand (operands[0], DImode)
9692        || gpc_reg_operand (operands[1], DImode))"
9693   "@
9694    #
9695    #
9696    #
9697    fmr %0,%1
9698    lfd%U1%X1 %0,%1
9699    stfd%U0%X0 %1,%0
9700    #"
9701   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
9702
9703 (define_split
9704   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9705         (match_operand:DI 1 "const_int_operand" ""))]
9706   "! TARGET_POWERPC64 && reload_completed"
9707   [(set (match_dup 2) (match_dup 4))
9708    (set (match_dup 3) (match_dup 1))]
9709   "
9710 {
9711   HOST_WIDE_INT value = INTVAL (operands[1]);
9712   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9713                                        DImode);
9714   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9715                                        DImode);
9716 #if HOST_BITS_PER_WIDE_INT == 32
9717   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
9718 #else
9719   operands[4] = GEN_INT (value >> 32);
9720   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9721 #endif
9722 }")
9723
9724 (define_split
9725   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "")
9726         (match_operand:DI 1 "input_operand" ""))]
9727   "reload_completed && !TARGET_POWERPC64
9728    && gpr_or_gpr_p (operands[0], operands[1])"
9729   [(pc)]
9730 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9731
9732 (define_insn "*movdi_mfpgpr"
9733   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*d,*d,m,r,*h,*h,r,*d")
9734         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,d,m,d,*h,r,0,*d,r"))]
9735   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
9736    && (gpc_reg_operand (operands[0], DImode)
9737        || gpc_reg_operand (operands[1], DImode))"
9738   "@
9739    mr %0,%1
9740    ld%U1%X1 %0,%1
9741    std%U0%X0 %1,%0
9742    li %0,%1
9743    lis %0,%v1
9744    #
9745    {cal|la} %0,%a1
9746    fmr %0,%1
9747    lfd%U1%X1 %0,%1
9748    stfd%U0%X0 %1,%0
9749    mf%1 %0
9750    mt%0 %1
9751    {cror 0,0,0|nop}
9752    mftgpr %0,%1
9753    mffgpr %0,%1"
9754   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*,mftgpr,mffgpr")
9755    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4")])
9756
9757 (define_insn "*movdi_internal64"
9758   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*d,*d,m,r,*h,*h")
9759         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,d,m,d,*h,r,0"))]
9760   "TARGET_POWERPC64 && (!TARGET_MFPGPR || !TARGET_HARD_FLOAT || !TARGET_FPRS)
9761    && (gpc_reg_operand (operands[0], DImode)
9762        || gpc_reg_operand (operands[1], DImode))"
9763   "@
9764    mr %0,%1
9765    ld%U1%X1 %0,%1
9766    std%U0%X0 %1,%0
9767    li %0,%1
9768    lis %0,%v1
9769    #
9770    {cal|la} %0,%a1
9771    fmr %0,%1
9772    lfd%U1%X1 %0,%1
9773    stfd%U0%X0 %1,%0
9774    mf%1 %0
9775    mt%0 %1
9776    {cror 0,0,0|nop}"
9777   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
9778    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
9779
9780 ;; immediate value valid for a single instruction hiding in a const_double
9781 (define_insn ""
9782   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9783         (match_operand:DI 1 "const_double_operand" "F"))]
9784   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
9785    && GET_CODE (operands[1]) == CONST_DOUBLE
9786    && num_insns_constant (operands[1], DImode) == 1"
9787   "*
9788 {
9789   return ((unsigned HOST_WIDE_INT)
9790           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
9791          ? \"li %0,%1\" : \"lis %0,%v1\";
9792 }")
9793
9794 ;; Generate all one-bits and clear left or right.
9795 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
9796 (define_split
9797   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9798         (match_operand:DI 1 "mask64_operand" ""))]
9799   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9800   [(set (match_dup 0) (const_int -1))
9801    (set (match_dup 0)
9802         (and:DI (rotate:DI (match_dup 0)
9803                            (const_int 0))
9804                 (match_dup 1)))]
9805   "")
9806
9807 ;; Split a load of a large constant into the appropriate five-instruction
9808 ;; sequence.  Handle anything in a constant number of insns.
9809 ;; When non-easy constants can go in the TOC, this should use
9810 ;; easy_fp_constant predicate.
9811 (define_split
9812   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9813         (match_operand:DI 1 "const_int_operand" ""))]
9814   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9815   [(set (match_dup 0) (match_dup 2))
9816    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9817   "
9818 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9819
9820   if (tem == operands[0])
9821     DONE;
9822   else
9823     FAIL;
9824 }")
9825
9826 (define_split
9827   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9828         (match_operand:DI 1 "const_double_operand" ""))]
9829   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9830   [(set (match_dup 0) (match_dup 2))
9831    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9832   "
9833 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9834
9835   if (tem == operands[0])
9836     DONE;
9837   else
9838     FAIL;
9839 }")
9840 \f
9841 ;; TImode is similar, except that we usually want to compute the address into
9842 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
9843 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
9844
9845 ;; We say that MQ is clobbered in the last alternative because the first
9846 ;; alternative would never get used otherwise since it would need a reload
9847 ;; while the 2nd alternative would not.  We put memory cases first so they
9848 ;; are preferred.  Otherwise, we'd try to reload the output instead of
9849 ;; giving the SCRATCH mq.
9850
9851 (define_insn "*movti_power"
9852   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
9853         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
9854    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
9855   "TARGET_POWER && ! TARGET_POWERPC64
9856    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9857   "*
9858 {
9859   switch (which_alternative)
9860     {
9861     default:
9862       gcc_unreachable ();
9863
9864     case 0:
9865       if (TARGET_STRING)
9866         return \"{stsi|stswi} %1,%P0,16\";
9867     case 1:
9868     case 2:
9869       return \"#\";
9870     case 3:
9871       /* If the address is not used in the output, we can use lsi.  Otherwise,
9872          fall through to generating four loads.  */
9873       if (TARGET_STRING
9874           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9875         return \"{lsi|lswi} %0,%P1,16\";
9876       /* ... fall through ...  */
9877     case 4:
9878     case 5:
9879       return \"#\";
9880     }
9881 }"
9882   [(set_attr "type" "store,store,*,load,load,*")])
9883
9884 (define_insn "*movti_string"
9885   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
9886         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
9887   "! TARGET_POWER && ! TARGET_POWERPC64
9888    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9889   "*
9890 {
9891   switch (which_alternative)
9892     {
9893     default:
9894       gcc_unreachable ();
9895     case 0:
9896       if (TARGET_STRING)
9897         return \"{stsi|stswi} %1,%P0,16\";
9898     case 1:
9899     case 2:
9900       return \"#\";
9901     case 3:
9902       /* If the address is not used in the output, we can use lsi.  Otherwise,
9903          fall through to generating four loads.  */
9904       if (TARGET_STRING
9905           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9906         return \"{lsi|lswi} %0,%P1,16\";
9907       /* ... fall through ...  */
9908     case 4:
9909     case 5:
9910       return \"#\";
9911     }
9912 }"
9913   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")
9914    (set (attr "cell_micro") (if_then_else (eq (symbol_ref "TARGET_STRING") (const_int 1))
9915                                           (const_string "always")
9916                                           (const_string "conditional")))])
9917
9918 (define_insn "*movti_ppc64"
9919   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
9920         (match_operand:TI 1 "input_operand" "r,r,m"))]
9921   "(TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
9922     || gpc_reg_operand (operands[1], TImode)))
9923    && VECTOR_MEM_NONE_P (TImode)"
9924   "#"
9925   [(set_attr "type" "*,store,load")])
9926
9927 (define_split
9928   [(set (match_operand:TI 0 "gpc_reg_operand" "")
9929         (match_operand:TI 1 "const_double_operand" ""))]
9930   "TARGET_POWERPC64 && VECTOR_MEM_NONE_P (TImode)"
9931   [(set (match_dup 2) (match_dup 4))
9932    (set (match_dup 3) (match_dup 5))]
9933   "
9934 {
9935   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9936                                        TImode);
9937   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9938                                        TImode);
9939   if (GET_CODE (operands[1]) == CONST_DOUBLE)
9940     {
9941       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
9942       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
9943     }
9944   else if (GET_CODE (operands[1]) == CONST_INT)
9945     {
9946       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
9947       operands[5] = operands[1];
9948     }
9949   else
9950     FAIL;
9951 }")
9952
9953 (define_split
9954   [(set (match_operand:TI 0 "nonimmediate_operand" "")
9955         (match_operand:TI 1 "input_operand" ""))]
9956   "reload_completed && VECTOR_MEM_NONE_P (TImode)
9957    && gpr_or_gpr_p (operands[0], operands[1])"
9958   [(pc)]
9959 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9960 \f
9961 (define_expand "load_multiple"
9962   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9963                           (match_operand:SI 1 "" ""))
9964                      (use (match_operand:SI 2 "" ""))])]
9965   "TARGET_STRING && !TARGET_POWERPC64"
9966   "
9967 {
9968   int regno;
9969   int count;
9970   rtx op1;
9971   int i;
9972
9973   /* Support only loading a constant number of fixed-point registers from
9974      memory and only bother with this if more than two; the machine
9975      doesn't support more than eight.  */
9976   if (GET_CODE (operands[2]) != CONST_INT
9977       || INTVAL (operands[2]) <= 2
9978       || INTVAL (operands[2]) > 8
9979       || GET_CODE (operands[1]) != MEM
9980       || GET_CODE (operands[0]) != REG
9981       || REGNO (operands[0]) >= 32)
9982     FAIL;
9983
9984   count = INTVAL (operands[2]);
9985   regno = REGNO (operands[0]);
9986
9987   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
9988   op1 = replace_equiv_address (operands[1],
9989                                force_reg (SImode, XEXP (operands[1], 0)));
9990
9991   for (i = 0; i < count; i++)
9992     XVECEXP (operands[3], 0, i)
9993       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
9994                      adjust_address_nv (op1, SImode, i * 4));
9995 }")
9996
9997 (define_insn "*ldmsi8"
9998   [(match_parallel 0 "load_multiple_operation"
9999     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10000           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10001      (set (match_operand:SI 3 "gpc_reg_operand" "")
10002           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10003      (set (match_operand:SI 4 "gpc_reg_operand" "")
10004           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10005      (set (match_operand:SI 5 "gpc_reg_operand" "")
10006           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10007      (set (match_operand:SI 6 "gpc_reg_operand" "")
10008           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10009      (set (match_operand:SI 7 "gpc_reg_operand" "")
10010           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10011      (set (match_operand:SI 8 "gpc_reg_operand" "")
10012           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
10013      (set (match_operand:SI 9 "gpc_reg_operand" "")
10014           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
10015   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10016   "*
10017 { return rs6000_output_load_multiple (operands); }"
10018   [(set_attr "type" "load_ux")
10019    (set_attr "length" "32")])
10020
10021 (define_insn "*ldmsi7"
10022   [(match_parallel 0 "load_multiple_operation"
10023     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10024           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10025      (set (match_operand:SI 3 "gpc_reg_operand" "")
10026           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10027      (set (match_operand:SI 4 "gpc_reg_operand" "")
10028           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10029      (set (match_operand:SI 5 "gpc_reg_operand" "")
10030           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10031      (set (match_operand:SI 6 "gpc_reg_operand" "")
10032           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10033      (set (match_operand:SI 7 "gpc_reg_operand" "")
10034           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10035      (set (match_operand:SI 8 "gpc_reg_operand" "")
10036           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
10037   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10038   "*
10039 { return rs6000_output_load_multiple (operands); }"
10040   [(set_attr "type" "load_ux")
10041    (set_attr "length" "32")])
10042
10043 (define_insn "*ldmsi6"
10044   [(match_parallel 0 "load_multiple_operation"
10045     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10046           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10047      (set (match_operand:SI 3 "gpc_reg_operand" "")
10048           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10049      (set (match_operand:SI 4 "gpc_reg_operand" "")
10050           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10051      (set (match_operand:SI 5 "gpc_reg_operand" "")
10052           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10053      (set (match_operand:SI 6 "gpc_reg_operand" "")
10054           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10055      (set (match_operand:SI 7 "gpc_reg_operand" "")
10056           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
10057   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10058   "*
10059 { return rs6000_output_load_multiple (operands); }"
10060   [(set_attr "type" "load_ux")
10061    (set_attr "length" "32")])
10062
10063 (define_insn "*ldmsi5"
10064   [(match_parallel 0 "load_multiple_operation"
10065     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10066           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10067      (set (match_operand:SI 3 "gpc_reg_operand" "")
10068           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10069      (set (match_operand:SI 4 "gpc_reg_operand" "")
10070           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10071      (set (match_operand:SI 5 "gpc_reg_operand" "")
10072           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10073      (set (match_operand:SI 6 "gpc_reg_operand" "")
10074           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
10075   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10076   "*
10077 { return rs6000_output_load_multiple (operands); }"
10078   [(set_attr "type" "load_ux")
10079    (set_attr "length" "32")])
10080
10081 (define_insn "*ldmsi4"
10082   [(match_parallel 0 "load_multiple_operation"
10083     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10084           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10085      (set (match_operand:SI 3 "gpc_reg_operand" "")
10086           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10087      (set (match_operand:SI 4 "gpc_reg_operand" "")
10088           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10089      (set (match_operand:SI 5 "gpc_reg_operand" "")
10090           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
10091   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10092   "*
10093 { return rs6000_output_load_multiple (operands); }"
10094   [(set_attr "type" "load_ux")
10095    (set_attr "length" "32")])
10096
10097 (define_insn "*ldmsi3"
10098   [(match_parallel 0 "load_multiple_operation"
10099     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10100           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10101      (set (match_operand:SI 3 "gpc_reg_operand" "")
10102           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10103      (set (match_operand:SI 4 "gpc_reg_operand" "")
10104           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
10105   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
10106   "*
10107 { return rs6000_output_load_multiple (operands); }"
10108   [(set_attr "type" "load_ux")
10109    (set_attr "length" "32")])
10110
10111 (define_expand "store_multiple"
10112   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10113                           (match_operand:SI 1 "" ""))
10114                      (clobber (scratch:SI))
10115                      (use (match_operand:SI 2 "" ""))])]
10116   "TARGET_STRING && !TARGET_POWERPC64"
10117   "
10118 {
10119   int regno;
10120   int count;
10121   rtx to;
10122   rtx op0;
10123   int i;
10124
10125   /* Support only storing a constant number of fixed-point registers to
10126      memory and only bother with this if more than two; the machine
10127      doesn't support more than eight.  */
10128   if (GET_CODE (operands[2]) != CONST_INT
10129       || INTVAL (operands[2]) <= 2
10130       || INTVAL (operands[2]) > 8
10131       || GET_CODE (operands[0]) != MEM
10132       || GET_CODE (operands[1]) != REG
10133       || REGNO (operands[1]) >= 32)
10134     FAIL;
10135
10136   count = INTVAL (operands[2]);
10137   regno = REGNO (operands[1]);
10138
10139   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
10140   to = force_reg (SImode, XEXP (operands[0], 0));
10141   op0 = replace_equiv_address (operands[0], to);
10142
10143   XVECEXP (operands[3], 0, 0)
10144     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
10145   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
10146                                                  gen_rtx_SCRATCH (SImode));
10147
10148   for (i = 1; i < count; i++)
10149     XVECEXP (operands[3], 0, i + 1)
10150       = gen_rtx_SET (VOIDmode,
10151                      adjust_address_nv (op0, SImode, i * 4),
10152                      gen_rtx_REG (SImode, regno + i));
10153 }")
10154
10155 (define_insn "*stmsi8"
10156   [(match_parallel 0 "store_multiple_operation"
10157     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10158           (match_operand:SI 2 "gpc_reg_operand" "r"))
10159      (clobber (match_scratch:SI 3 "=X"))
10160      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10161           (match_operand:SI 4 "gpc_reg_operand" "r"))
10162      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10163           (match_operand:SI 5 "gpc_reg_operand" "r"))
10164      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10165           (match_operand:SI 6 "gpc_reg_operand" "r"))
10166      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10167           (match_operand:SI 7 "gpc_reg_operand" "r"))
10168      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10169           (match_operand:SI 8 "gpc_reg_operand" "r"))
10170      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10171           (match_operand:SI 9 "gpc_reg_operand" "r"))
10172      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10173           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10174   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
10175   "{stsi|stswi} %2,%1,%O0"
10176   [(set_attr "type" "store_ux")
10177    (set_attr "cell_micro" "always")])
10178
10179 (define_insn "*stmsi7"
10180   [(match_parallel 0 "store_multiple_operation"
10181     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10182           (match_operand:SI 2 "gpc_reg_operand" "r"))
10183      (clobber (match_scratch:SI 3 "=X"))
10184      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10185           (match_operand:SI 4 "gpc_reg_operand" "r"))
10186      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10187           (match_operand:SI 5 "gpc_reg_operand" "r"))
10188      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10189           (match_operand:SI 6 "gpc_reg_operand" "r"))
10190      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10191           (match_operand:SI 7 "gpc_reg_operand" "r"))
10192      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10193           (match_operand:SI 8 "gpc_reg_operand" "r"))
10194      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10195           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10196   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
10197   "{stsi|stswi} %2,%1,%O0"
10198   [(set_attr "type" "store_ux")
10199    (set_attr "cell_micro" "always")])
10200
10201 (define_insn "*stmsi6"
10202   [(match_parallel 0 "store_multiple_operation"
10203     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10204           (match_operand:SI 2 "gpc_reg_operand" "r"))
10205      (clobber (match_scratch:SI 3 "=X"))
10206      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10207           (match_operand:SI 4 "gpc_reg_operand" "r"))
10208      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10209           (match_operand:SI 5 "gpc_reg_operand" "r"))
10210      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10211           (match_operand:SI 6 "gpc_reg_operand" "r"))
10212      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10213           (match_operand:SI 7 "gpc_reg_operand" "r"))
10214      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10215           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10216   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
10217   "{stsi|stswi} %2,%1,%O0"
10218   [(set_attr "type" "store_ux")
10219    (set_attr "cell_micro" "always")])
10220
10221 (define_insn "*stmsi5"
10222   [(match_parallel 0 "store_multiple_operation"
10223     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10224           (match_operand:SI 2 "gpc_reg_operand" "r"))
10225      (clobber (match_scratch:SI 3 "=X"))
10226      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10227           (match_operand:SI 4 "gpc_reg_operand" "r"))
10228      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10229           (match_operand:SI 5 "gpc_reg_operand" "r"))
10230      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10231           (match_operand:SI 6 "gpc_reg_operand" "r"))
10232      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10233           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10234   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
10235   "{stsi|stswi} %2,%1,%O0"
10236   [(set_attr "type" "store_ux")
10237    (set_attr "cell_micro" "always")])
10238
10239 (define_insn "*stmsi4"
10240   [(match_parallel 0 "store_multiple_operation"
10241     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10242           (match_operand:SI 2 "gpc_reg_operand" "r"))
10243      (clobber (match_scratch:SI 3 "=X"))
10244      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10245           (match_operand:SI 4 "gpc_reg_operand" "r"))
10246      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10247           (match_operand:SI 5 "gpc_reg_operand" "r"))
10248      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10249           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10250   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
10251   "{stsi|stswi} %2,%1,%O0"
10252   [(set_attr "type" "store_ux")
10253    (set_attr "cell_micro" "always")])
10254
10255 (define_insn "*stmsi3"
10256   [(match_parallel 0 "store_multiple_operation"
10257     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10258           (match_operand:SI 2 "gpc_reg_operand" "r"))
10259      (clobber (match_scratch:SI 3 "=X"))
10260      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10261           (match_operand:SI 4 "gpc_reg_operand" "r"))
10262      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10263           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10264   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
10265   "{stsi|stswi} %2,%1,%O0"
10266   [(set_attr "type" "store_ux")
10267    (set_attr "cell_micro" "always")])
10268
10269 (define_insn "*stmsi8_power"
10270   [(match_parallel 0 "store_multiple_operation"
10271     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10272           (match_operand:SI 2 "gpc_reg_operand" "r"))
10273      (clobber (match_scratch:SI 3 "=q"))
10274      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10275           (match_operand:SI 4 "gpc_reg_operand" "r"))
10276      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10277           (match_operand:SI 5 "gpc_reg_operand" "r"))
10278      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10279           (match_operand:SI 6 "gpc_reg_operand" "r"))
10280      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10281           (match_operand:SI 7 "gpc_reg_operand" "r"))
10282      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10283           (match_operand:SI 8 "gpc_reg_operand" "r"))
10284      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10285           (match_operand:SI 9 "gpc_reg_operand" "r"))
10286      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10287           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10288   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 9"
10289   "{stsi|stswi} %2,%1,%O0"
10290   [(set_attr "type" "store_ux")
10291    (set_attr "cell_micro" "always")])
10292
10293 (define_insn "*stmsi7_power"
10294   [(match_parallel 0 "store_multiple_operation"
10295     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10296           (match_operand:SI 2 "gpc_reg_operand" "r"))
10297      (clobber (match_scratch:SI 3 "=q"))
10298      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10299           (match_operand:SI 4 "gpc_reg_operand" "r"))
10300      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10301           (match_operand:SI 5 "gpc_reg_operand" "r"))
10302      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10303           (match_operand:SI 6 "gpc_reg_operand" "r"))
10304      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10305           (match_operand:SI 7 "gpc_reg_operand" "r"))
10306      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10307           (match_operand:SI 8 "gpc_reg_operand" "r"))
10308      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10309           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10310   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 8"
10311   "{stsi|stswi} %2,%1,%O0"
10312   [(set_attr "type" "store_ux")
10313    (set_attr "cell_micro" "always")])
10314
10315 (define_insn "*stmsi6_power"
10316   [(match_parallel 0 "store_multiple_operation"
10317     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10318           (match_operand:SI 2 "gpc_reg_operand" "r"))
10319      (clobber (match_scratch:SI 3 "=q"))
10320      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10321           (match_operand:SI 4 "gpc_reg_operand" "r"))
10322      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10323           (match_operand:SI 5 "gpc_reg_operand" "r"))
10324      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10325           (match_operand:SI 6 "gpc_reg_operand" "r"))
10326      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10327           (match_operand:SI 7 "gpc_reg_operand" "r"))
10328      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10329           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10330   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 7"
10331   "{stsi|stswi} %2,%1,%O0"
10332   [(set_attr "type" "store_ux")
10333    (set_attr "cell_micro" "always")])
10334
10335 (define_insn "*stmsi5_power"
10336   [(match_parallel 0 "store_multiple_operation"
10337     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10338           (match_operand:SI 2 "gpc_reg_operand" "r"))
10339      (clobber (match_scratch:SI 3 "=q"))
10340      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10341           (match_operand:SI 4 "gpc_reg_operand" "r"))
10342      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10343           (match_operand:SI 5 "gpc_reg_operand" "r"))
10344      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10345           (match_operand:SI 6 "gpc_reg_operand" "r"))
10346      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10347           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10348   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 6"
10349   "{stsi|stswi} %2,%1,%O0"
10350   [(set_attr "type" "store_ux")
10351    (set_attr "cell_micro" "always")])
10352
10353 (define_insn "*stmsi4_power"
10354   [(match_parallel 0 "store_multiple_operation"
10355     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10356           (match_operand:SI 2 "gpc_reg_operand" "r"))
10357      (clobber (match_scratch:SI 3 "=q"))
10358      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10359           (match_operand:SI 4 "gpc_reg_operand" "r"))
10360      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10361           (match_operand:SI 5 "gpc_reg_operand" "r"))
10362      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10363           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10364   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 5"
10365   "{stsi|stswi} %2,%1,%O0"
10366   [(set_attr "type" "store_ux")
10367    (set_attr "cell_micro" "always")])
10368
10369 (define_insn "*stmsi3_power"
10370   [(match_parallel 0 "store_multiple_operation"
10371     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10372           (match_operand:SI 2 "gpc_reg_operand" "r"))
10373      (clobber (match_scratch:SI 3 "=q"))
10374      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10375           (match_operand:SI 4 "gpc_reg_operand" "r"))
10376      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10377           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10378   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 4"
10379   "{stsi|stswi} %2,%1,%O0"
10380   [(set_attr "type" "store_ux")
10381    (set_attr "cell_micro" "always")])
10382 \f
10383 (define_expand "setmemsi"
10384   [(parallel [(set (match_operand:BLK 0 "" "")
10385                    (match_operand 2 "const_int_operand" ""))
10386               (use (match_operand:SI 1 "" ""))
10387               (use (match_operand:SI 3 "" ""))])]
10388   ""
10389   "
10390 {
10391   /* If value to set is not zero, use the library routine.  */
10392   if (operands[2] != const0_rtx)
10393     FAIL;
10394
10395   if (expand_block_clear (operands))
10396     DONE;
10397   else
10398     FAIL;
10399 }")
10400
10401 ;; String/block move insn.
10402 ;; Argument 0 is the destination
10403 ;; Argument 1 is the source
10404 ;; Argument 2 is the length
10405 ;; Argument 3 is the alignment
10406
10407 (define_expand "movmemsi"
10408   [(parallel [(set (match_operand:BLK 0 "" "")
10409                    (match_operand:BLK 1 "" ""))
10410               (use (match_operand:SI 2 "" ""))
10411               (use (match_operand:SI 3 "" ""))])]
10412   ""
10413   "
10414 {
10415   if (expand_block_move (operands))
10416     DONE;
10417   else
10418     FAIL;
10419 }")
10420
10421 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
10422 ;; register allocator doesn't have a clue about allocating 8 word registers.
10423 ;; rD/rS = r5 is preferred, efficient form.
10424 (define_expand "movmemsi_8reg"
10425   [(parallel [(set (match_operand 0 "" "")
10426                    (match_operand 1 "" ""))
10427               (use (match_operand 2 "" ""))
10428               (use (match_operand 3 "" ""))
10429               (clobber (reg:SI  5))
10430               (clobber (reg:SI  6))
10431               (clobber (reg:SI  7))
10432               (clobber (reg:SI  8))
10433               (clobber (reg:SI  9))
10434               (clobber (reg:SI 10))
10435               (clobber (reg:SI 11))
10436               (clobber (reg:SI 12))
10437               (clobber (match_scratch:SI 4 ""))])]
10438   "TARGET_STRING"
10439   "")
10440
10441 (define_insn ""
10442   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10443         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10444    (use (match_operand:SI 2 "immediate_operand" "i"))
10445    (use (match_operand:SI 3 "immediate_operand" "i"))
10446    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10447    (clobber (reg:SI  6))
10448    (clobber (reg:SI  7))
10449    (clobber (reg:SI  8))
10450    (clobber (reg:SI  9))
10451    (clobber (reg:SI 10))
10452    (clobber (reg:SI 11))
10453    (clobber (reg:SI 12))
10454    (clobber (match_scratch:SI 5 "=q"))]
10455   "TARGET_STRING && TARGET_POWER
10456    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10457        || INTVAL (operands[2]) == 0)
10458    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10459    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10460    && REGNO (operands[4]) == 5"
10461   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10462   [(set_attr "type" "store_ux")
10463    (set_attr "cell_micro" "always")
10464    (set_attr "length" "8")])
10465
10466 (define_insn ""
10467   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10468         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10469    (use (match_operand:SI 2 "immediate_operand" "i"))
10470    (use (match_operand:SI 3 "immediate_operand" "i"))
10471    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10472    (clobber (reg:SI  6))
10473    (clobber (reg:SI  7))
10474    (clobber (reg:SI  8))
10475    (clobber (reg:SI  9))
10476    (clobber (reg:SI 10))
10477    (clobber (reg:SI 11))
10478    (clobber (reg:SI 12))
10479    (clobber (match_scratch:SI 5 "=X"))]
10480   "TARGET_STRING && ! TARGET_POWER
10481    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10482        || INTVAL (operands[2]) == 0)
10483    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10484    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10485    && REGNO (operands[4]) == 5"
10486   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10487   [(set_attr "type" "store_ux")
10488    (set_attr "cell_micro" "always")
10489    (set_attr "length" "8")])
10490
10491 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
10492 ;; register allocator doesn't have a clue about allocating 6 word registers.
10493 ;; rD/rS = r5 is preferred, efficient form.
10494 (define_expand "movmemsi_6reg"
10495   [(parallel [(set (match_operand 0 "" "")
10496                    (match_operand 1 "" ""))
10497               (use (match_operand 2 "" ""))
10498               (use (match_operand 3 "" ""))
10499               (clobber (reg:SI  5))
10500               (clobber (reg:SI  6))
10501               (clobber (reg:SI  7))
10502               (clobber (reg:SI  8))
10503               (clobber (reg:SI  9))
10504               (clobber (reg:SI 10))
10505               (clobber (match_scratch:SI 4 ""))])]
10506   "TARGET_STRING"
10507   "")
10508
10509 (define_insn ""
10510   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10511         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10512    (use (match_operand:SI 2 "immediate_operand" "i"))
10513    (use (match_operand:SI 3 "immediate_operand" "i"))
10514    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10515    (clobber (reg:SI  6))
10516    (clobber (reg:SI  7))
10517    (clobber (reg:SI  8))
10518    (clobber (reg:SI  9))
10519    (clobber (reg:SI 10))
10520    (clobber (match_scratch:SI 5 "=q"))]
10521   "TARGET_STRING && TARGET_POWER
10522    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
10523    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10524    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10525    && REGNO (operands[4]) == 5"
10526   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10527   [(set_attr "type" "store_ux")
10528    (set_attr "cell_micro" "always")
10529    (set_attr "length" "8")])
10530
10531 (define_insn ""
10532   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10533         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10534    (use (match_operand:SI 2 "immediate_operand" "i"))
10535    (use (match_operand:SI 3 "immediate_operand" "i"))
10536    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10537    (clobber (reg:SI  6))
10538    (clobber (reg:SI  7))
10539    (clobber (reg:SI  8))
10540    (clobber (reg:SI  9))
10541    (clobber (reg:SI 10))
10542    (clobber (match_scratch:SI 5 "=X"))]
10543   "TARGET_STRING && ! TARGET_POWER
10544    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
10545    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10546    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10547    && REGNO (operands[4]) == 5"
10548   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10549   [(set_attr "type" "store_ux")
10550    (set_attr "cell_micro" "always")
10551    (set_attr "length" "8")])
10552
10553 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
10554 ;; problems with TImode.
10555 ;; rD/rS = r5 is preferred, efficient form.
10556 (define_expand "movmemsi_4reg"
10557   [(parallel [(set (match_operand 0 "" "")
10558                    (match_operand 1 "" ""))
10559               (use (match_operand 2 "" ""))
10560               (use (match_operand 3 "" ""))
10561               (clobber (reg:SI 5))
10562               (clobber (reg:SI 6))
10563               (clobber (reg:SI 7))
10564               (clobber (reg:SI 8))
10565               (clobber (match_scratch:SI 4 ""))])]
10566   "TARGET_STRING"
10567   "")
10568
10569 (define_insn ""
10570   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10571         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10572    (use (match_operand:SI 2 "immediate_operand" "i"))
10573    (use (match_operand:SI 3 "immediate_operand" "i"))
10574    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10575    (clobber (reg:SI 6))
10576    (clobber (reg:SI 7))
10577    (clobber (reg:SI 8))
10578    (clobber (match_scratch:SI 5 "=q"))]
10579   "TARGET_STRING && TARGET_POWER
10580    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
10581    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
10582    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
10583    && REGNO (operands[4]) == 5"
10584   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10585   [(set_attr "type" "store_ux")
10586    (set_attr "cell_micro" "always")
10587    (set_attr "length" "8")])
10588
10589 (define_insn ""
10590   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10591         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10592    (use (match_operand:SI 2 "immediate_operand" "i"))
10593    (use (match_operand:SI 3 "immediate_operand" "i"))
10594    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10595    (clobber (reg:SI 6))
10596    (clobber (reg:SI 7))
10597    (clobber (reg:SI 8))
10598    (clobber (match_scratch:SI 5 "=X"))]
10599   "TARGET_STRING && ! TARGET_POWER
10600    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
10601    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
10602    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
10603    && REGNO (operands[4]) == 5"
10604   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10605   [(set_attr "type" "store_ux")
10606    (set_attr "cell_micro" "always")
10607    (set_attr "length" "8")])
10608
10609 ;; Move up to 8 bytes at a time.
10610 (define_expand "movmemsi_2reg"
10611   [(parallel [(set (match_operand 0 "" "")
10612                    (match_operand 1 "" ""))
10613               (use (match_operand 2 "" ""))
10614               (use (match_operand 3 "" ""))
10615               (clobber (match_scratch:DI 4 ""))
10616               (clobber (match_scratch:SI 5 ""))])]
10617   "TARGET_STRING && ! TARGET_POWERPC64"
10618   "")
10619
10620 (define_insn ""
10621   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10622         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10623    (use (match_operand:SI 2 "immediate_operand" "i"))
10624    (use (match_operand:SI 3 "immediate_operand" "i"))
10625    (clobber (match_scratch:DI 4 "=&r"))
10626    (clobber (match_scratch:SI 5 "=q"))]
10627   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
10628    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
10629   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10630   [(set_attr "type" "store_ux")
10631    (set_attr "cell_micro" "always")
10632    (set_attr "length" "8")])
10633
10634 (define_insn ""
10635   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10636         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10637    (use (match_operand:SI 2 "immediate_operand" "i"))
10638    (use (match_operand:SI 3 "immediate_operand" "i"))
10639    (clobber (match_scratch:DI 4 "=&r"))
10640    (clobber (match_scratch:SI 5 "=X"))]
10641   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
10642    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
10643   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10644   [(set_attr "type" "store_ux")
10645    (set_attr "cell_micro" "always")
10646    (set_attr "length" "8")])
10647
10648 ;; Move up to 4 bytes at a time.
10649 (define_expand "movmemsi_1reg"
10650   [(parallel [(set (match_operand 0 "" "")
10651                    (match_operand 1 "" ""))
10652               (use (match_operand 2 "" ""))
10653               (use (match_operand 3 "" ""))
10654               (clobber (match_scratch:SI 4 ""))
10655               (clobber (match_scratch:SI 5 ""))])]
10656   "TARGET_STRING"
10657   "")
10658
10659 (define_insn ""
10660   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10661         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10662    (use (match_operand:SI 2 "immediate_operand" "i"))
10663    (use (match_operand:SI 3 "immediate_operand" "i"))
10664    (clobber (match_scratch:SI 4 "=&r"))
10665    (clobber (match_scratch:SI 5 "=q"))]
10666   "TARGET_STRING && TARGET_POWER
10667    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
10668   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10669   [(set_attr "type" "store_ux")
10670    (set_attr "cell_micro" "always")
10671    (set_attr "length" "8")])
10672
10673 (define_insn ""
10674   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10675         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10676    (use (match_operand:SI 2 "immediate_operand" "i"))
10677    (use (match_operand:SI 3 "immediate_operand" "i"))
10678    (clobber (match_scratch:SI 4 "=&r"))
10679    (clobber (match_scratch:SI 5 "=X"))]
10680   "TARGET_STRING && ! TARGET_POWER
10681    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
10682   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10683   [(set_attr "type" "store_ux")
10684    (set_attr "cell_micro" "always")
10685    (set_attr "length" "8")])
10686 \f
10687 ;; Define insns that do load or store with update.  Some of these we can
10688 ;; get by using pre-decrement or pre-increment, but the hardware can also
10689 ;; do cases where the increment is not the size of the object.
10690 ;;
10691 ;; In all these cases, we use operands 0 and 1 for the register being
10692 ;; incremented because those are the operands that local-alloc will
10693 ;; tie and these are the pair most likely to be tieable (and the ones
10694 ;; that will benefit the most).
10695
10696 (define_insn "*movdi_update1"
10697   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
10698         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
10699                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
10700    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
10701         (plus:DI (match_dup 1) (match_dup 2)))]
10702   "TARGET_POWERPC64 && TARGET_UPDATE
10703    && (!avoiding_indexed_address_p (DImode)
10704        || !gpc_reg_operand (operands[2], DImode))"
10705   "@
10706    ldux %3,%0,%2
10707    ldu %3,%2(%0)"
10708   [(set_attr "type" "load_ux,load_u")])
10709
10710 (define_insn "movdi_<mode>_update"
10711   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10712                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10713         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10714    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10715         (plus:P (match_dup 1) (match_dup 2)))]
10716   "TARGET_POWERPC64 && TARGET_UPDATE
10717    && (!avoiding_indexed_address_p (Pmode)
10718        || !gpc_reg_operand (operands[2], Pmode)
10719        || (REG_P (operands[0])
10720            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10721   "@
10722    stdux %3,%0,%2
10723    stdu %3,%2(%0)"
10724   [(set_attr "type" "store_ux,store_u")])
10725
10726 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
10727 ;; needed for stack allocation, even if the user passes -mno-update.
10728 (define_insn "movdi_<mode>_update_stack"
10729   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10730                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10731         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10732    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10733         (plus:P (match_dup 1) (match_dup 2)))]
10734   "TARGET_POWERPC64"
10735   "@
10736    stdux %3,%0,%2
10737    stdu %3,%2(%0)"
10738   [(set_attr "type" "store_ux,store_u")])
10739
10740 (define_insn "*movsi_update1"
10741   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10742         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10743                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10744    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10745         (plus:SI (match_dup 1) (match_dup 2)))]
10746   "TARGET_UPDATE
10747    && (!avoiding_indexed_address_p (SImode)
10748        || !gpc_reg_operand (operands[2], SImode))"
10749   "@
10750    {lux|lwzux} %3,%0,%2
10751    {lu|lwzu} %3,%2(%0)"
10752   [(set_attr "type" "load_ux,load_u")])
10753
10754 (define_insn "*movsi_update2"
10755   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
10756         (sign_extend:DI
10757          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
10758                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
10759    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
10760         (plus:DI (match_dup 1) (match_dup 2)))]
10761   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
10762    && !avoiding_indexed_address_p (DImode)"
10763   "lwaux %3,%0,%2"
10764   [(set_attr "type" "load_ext_ux")])
10765
10766 (define_insn "movsi_update"
10767   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10768                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10769         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10770    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10771         (plus:SI (match_dup 1) (match_dup 2)))]
10772   "TARGET_UPDATE
10773    && (!avoiding_indexed_address_p (SImode)
10774        || !gpc_reg_operand (operands[2], SImode)
10775        || (REG_P (operands[0])
10776            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10777   "@
10778    {stux|stwux} %3,%0,%2
10779    {stu|stwu} %3,%2(%0)"
10780   [(set_attr "type" "store_ux,store_u")])
10781
10782 ;; This is an unconditional pattern; needed for stack allocation, even
10783 ;; if the user passes -mno-update.
10784 (define_insn "movsi_update_stack"
10785   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10786                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10787         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10788    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10789         (plus:SI (match_dup 1) (match_dup 2)))]
10790   ""
10791   "@
10792    {stux|stwux} %3,%0,%2
10793    {stu|stwu} %3,%2(%0)"
10794   [(set_attr "type" "store_ux,store_u")])
10795
10796 (define_insn "*movhi_update1"
10797   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
10798         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10799                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10800    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10801         (plus:SI (match_dup 1) (match_dup 2)))]
10802   "TARGET_UPDATE
10803    && (!avoiding_indexed_address_p (SImode)
10804        || !gpc_reg_operand (operands[2], SImode))"
10805   "@
10806    lhzux %3,%0,%2
10807    lhzu %3,%2(%0)"
10808   [(set_attr "type" "load_ux,load_u")])
10809
10810 (define_insn "*movhi_update2"
10811   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10812         (zero_extend:SI
10813          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10814                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10815    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10816         (plus:SI (match_dup 1) (match_dup 2)))]
10817   "TARGET_UPDATE
10818    && (!avoiding_indexed_address_p (SImode)
10819        || !gpc_reg_operand (operands[2], SImode))"
10820   "@
10821    lhzux %3,%0,%2
10822    lhzu %3,%2(%0)"
10823   [(set_attr "type" "load_ux,load_u")])
10824
10825 (define_insn "*movhi_update3"
10826   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10827         (sign_extend:SI
10828          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10829                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10830    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10831         (plus:SI (match_dup 1) (match_dup 2)))]
10832   "TARGET_UPDATE && rs6000_gen_cell_microcode
10833    && (!avoiding_indexed_address_p (SImode)
10834        || !gpc_reg_operand (operands[2], SImode))"
10835   "@
10836    lhaux %3,%0,%2
10837    lhau %3,%2(%0)"
10838   [(set_attr "type" "load_ext_ux,load_ext_u")])
10839
10840 (define_insn "*movhi_update4"
10841   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10842                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10843         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
10844    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10845         (plus:SI (match_dup 1) (match_dup 2)))]
10846   "TARGET_UPDATE
10847    && (!avoiding_indexed_address_p (SImode)
10848        || !gpc_reg_operand (operands[2], SImode))"
10849   "@
10850    sthux %3,%0,%2
10851    sthu %3,%2(%0)"
10852   [(set_attr "type" "store_ux,store_u")])
10853
10854 (define_insn "*movqi_update1"
10855   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
10856         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10857                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10858    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10859         (plus:SI (match_dup 1) (match_dup 2)))]
10860   "TARGET_UPDATE
10861    && (!avoiding_indexed_address_p (SImode)
10862        || !gpc_reg_operand (operands[2], SImode))"
10863   "@
10864    lbzux %3,%0,%2
10865    lbzu %3,%2(%0)"
10866   [(set_attr "type" "load_ux,load_u")])
10867
10868 (define_insn "*movqi_update2"
10869   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10870         (zero_extend:SI
10871          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10872                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10873    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10874         (plus:SI (match_dup 1) (match_dup 2)))]
10875   "TARGET_UPDATE
10876    && (!avoiding_indexed_address_p (SImode)
10877        || !gpc_reg_operand (operands[2], SImode))"
10878   "@
10879    lbzux %3,%0,%2
10880    lbzu %3,%2(%0)"
10881   [(set_attr "type" "load_ux,load_u")])
10882
10883 (define_insn "*movqi_update3"
10884   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10885                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10886         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
10887    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10888         (plus:SI (match_dup 1) (match_dup 2)))]
10889   "TARGET_UPDATE
10890    && (!avoiding_indexed_address_p (SImode)
10891        || !gpc_reg_operand (operands[2], SImode))"
10892   "@
10893    stbux %3,%0,%2
10894    stbu %3,%2(%0)"
10895   [(set_attr "type" "store_ux,store_u")])
10896
10897 (define_insn "*movsf_update1"
10898   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
10899         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10900                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10901    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10902         (plus:SI (match_dup 1) (match_dup 2)))]
10903   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10904    && (!avoiding_indexed_address_p (SImode)
10905        || !gpc_reg_operand (operands[2], SImode))"
10906   "@
10907    lfsux %3,%0,%2
10908    lfsu %3,%2(%0)"
10909   [(set_attr "type" "fpload_ux,fpload_u")])
10910
10911 (define_insn "*movsf_update2"
10912   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10913                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10914         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
10915    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10916         (plus:SI (match_dup 1) (match_dup 2)))]
10917   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10918    && (!avoiding_indexed_address_p (SImode)
10919        || !gpc_reg_operand (operands[2], SImode))"
10920   "@
10921    stfsux %3,%0,%2
10922    stfsu %3,%2(%0)"
10923   [(set_attr "type" "fpstore_ux,fpstore_u")])
10924
10925 (define_insn "*movsf_update3"
10926   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
10927         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10928                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10929    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10930         (plus:SI (match_dup 1) (match_dup 2)))]
10931   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
10932    && (!avoiding_indexed_address_p (SImode)
10933        || !gpc_reg_operand (operands[2], SImode))"
10934   "@
10935    {lux|lwzux} %3,%0,%2
10936    {lu|lwzu} %3,%2(%0)"
10937   [(set_attr "type" "load_ux,load_u")])
10938
10939 (define_insn "*movsf_update4"
10940   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10941                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10942         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
10943    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10944         (plus:SI (match_dup 1) (match_dup 2)))]
10945   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
10946    && (!avoiding_indexed_address_p (SImode)
10947        || !gpc_reg_operand (operands[2], SImode))"
10948   "@
10949    {stux|stwux} %3,%0,%2
10950    {stu|stwu} %3,%2(%0)"
10951   [(set_attr "type" "store_ux,store_u")])
10952
10953 (define_insn "*movdf_update1"
10954   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
10955         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10956                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10957    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10958         (plus:SI (match_dup 1) (match_dup 2)))]
10959   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
10960    && (!avoiding_indexed_address_p (SImode)
10961        || !gpc_reg_operand (operands[2], SImode))"
10962   "@
10963    lfdux %3,%0,%2
10964    lfdu %3,%2(%0)"
10965   [(set_attr "type" "fpload_ux,fpload_u")])
10966
10967 (define_insn "*movdf_update2"
10968   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10969                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10970         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
10971    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10972         (plus:SI (match_dup 1) (match_dup 2)))]
10973   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
10974    && (!avoiding_indexed_address_p (SImode)
10975        || !gpc_reg_operand (operands[2], SImode))"
10976   "@
10977    stfdux %3,%0,%2
10978    stfdu %3,%2(%0)"
10979   [(set_attr "type" "fpstore_ux,fpstore_u")])
10980
10981 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
10982
10983 (define_insn "*lfq_power2"
10984   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
10985         (match_operand:V2DF 1 "memory_operand" ""))]
10986   "TARGET_POWER2
10987    && TARGET_HARD_FLOAT && TARGET_FPRS"
10988   "lfq%U1%X1 %0,%1")
10989
10990 (define_peephole2
10991   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10992         (match_operand:DF 1 "memory_operand" ""))
10993    (set (match_operand:DF 2 "gpc_reg_operand" "")
10994         (match_operand:DF 3 "memory_operand" ""))]
10995   "TARGET_POWER2
10996    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
10997    && registers_ok_for_quad_peep (operands[0], operands[2])
10998    && mems_ok_for_quad_peep (operands[1], operands[3])"
10999   [(set (match_dup 0)
11000         (match_dup 1))]
11001   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
11002    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
11003
11004 (define_insn "*stfq_power2"
11005   [(set (match_operand:V2DF 0 "memory_operand" "")
11006         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
11007   "TARGET_POWER2
11008    && TARGET_HARD_FLOAT && TARGET_FPRS"
11009   "stfq%U0%X0 %1,%0")
11010
11011
11012 (define_peephole2
11013   [(set (match_operand:DF 0 "memory_operand" "")
11014         (match_operand:DF 1 "gpc_reg_operand" ""))
11015    (set (match_operand:DF 2 "memory_operand" "")
11016         (match_operand:DF 3 "gpc_reg_operand" ""))]
11017   "TARGET_POWER2
11018    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
11019    && registers_ok_for_quad_peep (operands[1], operands[3])
11020    && mems_ok_for_quad_peep (operands[0], operands[2])"
11021   [(set (match_dup 0)
11022         (match_dup 1))]
11023   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
11024    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
11025
11026 ;; After inserting conditional returns we can sometimes have
11027 ;; unnecessary register moves.  Unfortunately we cannot have a
11028 ;; modeless peephole here, because some single SImode sets have early
11029 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
11030 ;; sequences, using get_attr_length here will smash the operands
11031 ;; array.  Neither is there an early_cobbler_p predicate.
11032 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
11033 (define_peephole2
11034   [(set (match_operand:DF 0 "gpc_reg_operand" "")
11035         (match_operand:DF 1 "any_operand" ""))
11036    (set (match_operand:DF 2 "gpc_reg_operand" "")
11037         (match_dup 0))]
11038   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
11039    && peep2_reg_dead_p (2, operands[0])"
11040   [(set (match_dup 2) (match_dup 1))])
11041
11042 (define_peephole2
11043   [(set (match_operand:SF 0 "gpc_reg_operand" "")
11044         (match_operand:SF 1 "any_operand" ""))
11045    (set (match_operand:SF 2 "gpc_reg_operand" "")
11046         (match_dup 0))]
11047   "peep2_reg_dead_p (2, operands[0])"
11048   [(set (match_dup 2) (match_dup 1))])
11049
11050 \f
11051 ;; TLS support.
11052
11053 ;; Mode attributes for different ABIs.
11054 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
11055 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
11056 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
11057 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
11058
11059 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
11060   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11061         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11062               (match_operand 4 "" "g")))
11063    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11064                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11065                    UNSPEC_TLSGD)
11066    (clobber (reg:SI LR_REGNO))]
11067   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11068   "addi %0,%1,%2@got@tlsgd\;bl %z3\;%."
11069   "&& TARGET_TLS_MARKERS"
11070   [(set (match_dup 0)
11071         (unspec:TLSmode [(match_dup 1)
11072                          (match_dup 2)]
11073                         UNSPEC_TLSGD))
11074    (parallel [(set (match_dup 0)
11075                    (call (mem:TLSmode (match_dup 3))
11076                          (match_dup 4)))
11077               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11078               (clobber (reg:SI LR_REGNO))])]
11079   ""
11080   [(set_attr "type" "two")
11081    (set_attr "length" "12")])
11082
11083 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
11084   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11085         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11086               (match_operand 4 "" "g")))
11087    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11088                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11089                    UNSPEC_TLSGD)
11090    (clobber (reg:SI LR_REGNO))]
11091   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11092 {
11093   if (flag_pic)
11094     {
11095       if (TARGET_SECURE_PLT && flag_pic == 2)
11096         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
11097       else
11098         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
11099     }
11100   else
11101     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
11102 }
11103   "&& TARGET_TLS_MARKERS"
11104   [(set (match_dup 0)
11105         (unspec:TLSmode [(match_dup 1)
11106                          (match_dup 2)]
11107                         UNSPEC_TLSGD))
11108    (parallel [(set (match_dup 0)
11109                    (call (mem:TLSmode (match_dup 3))
11110                          (match_dup 4)))
11111               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11112               (clobber (reg:SI LR_REGNO))])]
11113   ""
11114   [(set_attr "type" "two")
11115    (set_attr "length" "8")])
11116
11117 (define_insn "*tls_gd<TLSmode:tls_abi_suffix>"
11118   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11119         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11120                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11121                         UNSPEC_TLSGD))]
11122   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11123   "addi %0,%1,%2@got@tlsgd"
11124   [(set_attr "length" "4")])
11125
11126 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
11127   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11128         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11129               (match_operand 2 "" "g")))
11130    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11131                    UNSPEC_TLSGD)
11132    (clobber (reg:SI LR_REGNO))]
11133   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11134   "bl %z1(%3@tlsgd)\;%."
11135   [(set_attr "type" "branch")
11136    (set_attr "length" "8")])
11137
11138 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
11139   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11140         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11141               (match_operand 2 "" "g")))
11142    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11143                    UNSPEC_TLSGD)
11144    (clobber (reg:SI LR_REGNO))]
11145   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11146 {
11147   if (flag_pic)
11148     {
11149       if (TARGET_SECURE_PLT && flag_pic == 2)
11150         return "bl %z1+32768(%3@tlsgd)@plt";
11151       return "bl %z1(%3@tlsgd)@plt";
11152     }
11153   return "bl %z1(%3@tlsgd)";
11154 }
11155   [(set_attr "type" "branch")
11156    (set_attr "length" "4")])
11157
11158 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
11159   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11160         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11161               (match_operand 3 "" "g")))
11162    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11163                    UNSPEC_TLSLD)
11164    (clobber (reg:SI LR_REGNO))]
11165   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11166   "addi %0,%1,%&@got@tlsld\;bl %z2\;%."
11167   "&& TARGET_TLS_MARKERS"
11168   [(set (match_dup 0)
11169         (unspec:TLSmode [(match_dup 1)]
11170                         UNSPEC_TLSLD))
11171    (parallel [(set (match_dup 0)
11172                    (call (mem:TLSmode (match_dup 2))
11173                          (match_dup 3)))
11174               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11175               (clobber (reg:SI LR_REGNO))])]
11176   ""
11177   [(set_attr "length" "12")])
11178
11179 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
11180   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11181         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11182               (match_operand 3 "" "g")))
11183    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11184                    UNSPEC_TLSLD)
11185    (clobber (reg:SI LR_REGNO))]
11186   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11187 {
11188   if (flag_pic)
11189     {
11190       if (TARGET_SECURE_PLT && flag_pic == 2)
11191         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11192       else
11193         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11194     }
11195   else
11196     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11197 }
11198   "&& TARGET_TLS_MARKERS"
11199   [(set (match_dup 0)
11200         (unspec:TLSmode [(match_dup 1)]
11201                         UNSPEC_TLSLD))
11202    (parallel [(set (match_dup 0)
11203                    (call (mem:TLSmode (match_dup 2))
11204                          (match_dup 3)))
11205               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11206               (clobber (reg:SI LR_REGNO))])]
11207   ""
11208   [(set_attr "length" "8")])
11209
11210 (define_insn "*tls_ld<TLSmode:tls_abi_suffix>"
11211   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11212         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11213                         UNSPEC_TLSLD))]
11214   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11215   "addi %0,%1,%&@got@tlsld"
11216   [(set_attr "length" "4")])
11217
11218 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11219   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11220         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11221               (match_operand 2 "" "g")))
11222    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11223    (clobber (reg:SI LR_REGNO))]
11224   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11225   "bl %z1(%&@tlsld)\;%."
11226   [(set_attr "type" "branch")
11227    (set_attr "length" "8")])
11228
11229 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11230   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11231         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11232               (match_operand 2 "" "g")))
11233    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11234    (clobber (reg:SI LR_REGNO))]
11235   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11236 {
11237   if (flag_pic)
11238     {
11239       if (TARGET_SECURE_PLT && flag_pic == 2)
11240         return "bl %z1+32768(%&@tlsld)@plt";
11241       return "bl %z1(%&@tlsld)@plt";
11242     }
11243   return "bl %z1(%&@tlsld)";
11244 }
11245   [(set_attr "type" "branch")
11246    (set_attr "length" "4")])
11247
11248 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11249   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11250         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11251                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11252                         UNSPEC_TLSDTPREL))]
11253   "HAVE_AS_TLS"
11254   "addi %0,%1,%2@dtprel")
11255
11256 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11257   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11258         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11259                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11260                         UNSPEC_TLSDTPRELHA))]
11261   "HAVE_AS_TLS"
11262   "addis %0,%1,%2@dtprel@ha")
11263
11264 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11265   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11266         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11267                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11268                         UNSPEC_TLSDTPRELLO))]
11269   "HAVE_AS_TLS"
11270   "addi %0,%1,%2@dtprel@l")
11271
11272 (define_insn "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11273   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11274         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11275                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11276                         UNSPEC_TLSGOTDTPREL))]
11277   "HAVE_AS_TLS"
11278   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)")
11279
11280 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11281   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11282         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11283                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11284                         UNSPEC_TLSTPREL))]
11285   "HAVE_AS_TLS"
11286   "addi %0,%1,%2@tprel")
11287
11288 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11289   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11290         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11291                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11292                         UNSPEC_TLSTPRELHA))]
11293   "HAVE_AS_TLS"
11294   "addis %0,%1,%2@tprel@ha")
11295
11296 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11297   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11298         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11299                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11300                         UNSPEC_TLSTPRELLO))]
11301   "HAVE_AS_TLS"
11302   "addi %0,%1,%2@tprel@l")
11303
11304 ;; "b" output constraint here and on tls_tls input to support linker tls
11305 ;; optimization.  The linker may edit the instructions emitted by a
11306 ;; tls_got_tprel/tls_tls pair to addis,addi.
11307 (define_insn "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11308   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11309         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11310                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11311                         UNSPEC_TLSGOTTPREL))]
11312   "HAVE_AS_TLS"
11313   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)")
11314
11315 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11316   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11317         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11318                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11319                         UNSPEC_TLSTLS))]
11320   "HAVE_AS_TLS"
11321   "add %0,%1,%2@tls")
11322
11323 \f
11324 ;; Next come insns related to the calling sequence.
11325 ;;
11326 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11327 ;; We move the back-chain and decrement the stack pointer.
11328
11329 (define_expand "allocate_stack"
11330   [(set (match_operand 0 "gpc_reg_operand" "")
11331         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11332    (set (reg 1)
11333         (minus (reg 1) (match_dup 1)))]
11334   ""
11335   "
11336 { rtx chain = gen_reg_rtx (Pmode);
11337   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11338   rtx neg_op0;
11339   rtx insn, par, set, mem;
11340
11341   emit_move_insn (chain, stack_bot);
11342
11343   /* Check stack bounds if necessary.  */
11344   if (crtl->limit_stack)
11345     {
11346       rtx available;
11347       available = expand_binop (Pmode, sub_optab,
11348                                 stack_pointer_rtx, stack_limit_rtx,
11349                                 NULL_RTX, 1, OPTAB_WIDEN);
11350       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11351     }
11352
11353   if (GET_CODE (operands[1]) != CONST_INT
11354       || INTVAL (operands[1]) < -32767
11355       || INTVAL (operands[1]) > 32768)
11356     {
11357       neg_op0 = gen_reg_rtx (Pmode);
11358       if (TARGET_32BIT)
11359         emit_insn (gen_negsi2 (neg_op0, operands[1]));
11360       else
11361         emit_insn (gen_negdi2 (neg_op0, operands[1]));
11362     }
11363   else
11364     neg_op0 = GEN_INT (- INTVAL (operands[1]));
11365
11366   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
11367                                        : gen_movdi_di_update_stack))
11368                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
11369                          chain));
11370   /* Since we didn't use gen_frame_mem to generate the MEM, grab
11371      it now and set the alias set/attributes. The above gen_*_update
11372      calls will generate a PARALLEL with the MEM set being the first
11373      operation. */
11374   par = PATTERN (insn);
11375   gcc_assert (GET_CODE (par) == PARALLEL);
11376   set = XVECEXP (par, 0, 0);
11377   gcc_assert (GET_CODE (set) == SET);
11378   mem = SET_DEST (set);
11379   gcc_assert (MEM_P (mem));
11380   MEM_NOTRAP_P (mem) = 1;
11381   set_mem_alias_set (mem, get_frame_alias_set ());
11382
11383   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
11384   DONE;
11385 }")
11386
11387 ;; These patterns say how to save and restore the stack pointer.  We need not
11388 ;; save the stack pointer at function level since we are careful to
11389 ;; preserve the backchain.  At block level, we have to restore the backchain
11390 ;; when we restore the stack pointer.
11391 ;;
11392 ;; For nonlocal gotos, we must save both the stack pointer and its
11393 ;; backchain and restore both.  Note that in the nonlocal case, the
11394 ;; save area is a memory location.
11395
11396 (define_expand "save_stack_function"
11397   [(match_operand 0 "any_operand" "")
11398    (match_operand 1 "any_operand" "")]
11399   ""
11400   "DONE;")
11401
11402 (define_expand "restore_stack_function"
11403   [(match_operand 0 "any_operand" "")
11404    (match_operand 1 "any_operand" "")]
11405   ""
11406   "DONE;")
11407
11408 ;; Adjust stack pointer (op0) to a new value (op1).
11409 ;; First copy old stack backchain to new location, and ensure that the
11410 ;; scheduler won't reorder the sp assignment before the backchain write.
11411 (define_expand "restore_stack_block"
11412   [(set (match_dup 2) (match_dup 3))
11413    (set (match_dup 4) (match_dup 2))
11414    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
11415    (set (match_operand 0 "register_operand" "")
11416         (match_operand 1 "register_operand" ""))]
11417   ""
11418   "
11419 {
11420   operands[1] = force_reg (Pmode, operands[1]);
11421   operands[2] = gen_reg_rtx (Pmode);
11422   operands[3] = gen_frame_mem (Pmode, operands[0]);
11423   operands[4] = gen_frame_mem (Pmode, operands[1]);
11424   operands[5] = gen_frame_mem (BLKmode, operands[0]);
11425 }")
11426
11427 (define_expand "save_stack_nonlocal"
11428   [(set (match_dup 3) (match_dup 4))
11429    (set (match_operand 0 "memory_operand" "") (match_dup 3))
11430    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
11431   ""
11432   "
11433 {
11434   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11435
11436   /* Copy the backchain to the first word, sp to the second.  */
11437   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
11438   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
11439   operands[3] = gen_reg_rtx (Pmode);
11440   operands[4] = gen_frame_mem (Pmode, operands[1]);
11441 }")
11442
11443 (define_expand "restore_stack_nonlocal"
11444   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
11445    (set (match_dup 3) (match_dup 4))
11446    (set (match_dup 5) (match_dup 2))
11447    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
11448    (set (match_operand 0 "register_operand" "") (match_dup 3))]
11449   ""
11450   "
11451 {
11452   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11453
11454   /* Restore the backchain from the first word, sp from the second.  */
11455   operands[2] = gen_reg_rtx (Pmode);
11456   operands[3] = gen_reg_rtx (Pmode);
11457   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
11458   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
11459   operands[5] = gen_frame_mem (Pmode, operands[3]);
11460   operands[6] = gen_frame_mem (BLKmode, operands[0]);
11461 }")
11462 \f
11463 ;; TOC register handling.
11464
11465 ;; Code to initialize the TOC register...
11466
11467 (define_insn "load_toc_aix_si"
11468   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11469                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
11470               (use (reg:SI 2))])]
11471   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
11472   "*
11473 {
11474   char buf[30];
11475   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11476   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11477   operands[2] = gen_rtx_REG (Pmode, 2);
11478   return \"{l|lwz} %0,%1(%2)\";
11479 }"
11480   [(set_attr "type" "load")])
11481
11482 (define_insn "load_toc_aix_di"
11483   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11484                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
11485               (use (reg:DI 2))])]
11486   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
11487   "*
11488 {
11489   char buf[30];
11490 #ifdef TARGET_RELOCATABLE
11491   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
11492                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
11493 #else
11494   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11495 #endif
11496   if (TARGET_ELF)
11497     strcat (buf, \"@toc\");
11498   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11499   operands[2] = gen_rtx_REG (Pmode, 2);
11500   return \"ld %0,%1(%2)\";
11501 }"
11502   [(set_attr "type" "load")])
11503
11504 (define_insn "load_toc_v4_pic_si"
11505   [(set (reg:SI LR_REGNO)
11506         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
11507   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
11508   "bl _GLOBAL_OFFSET_TABLE_@local-4"
11509   [(set_attr "type" "branch")
11510    (set_attr "length" "4")])
11511
11512 (define_insn "load_toc_v4_PIC_1"
11513   [(set (reg:SI LR_REGNO)
11514         (match_operand:SI 0 "immediate_operand" "s"))
11515    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11516   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
11517    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11518   "bcl 20,31,%0\\n%0:"
11519   [(set_attr "type" "branch")
11520    (set_attr "length" "4")])
11521
11522 (define_insn "load_toc_v4_PIC_1b"
11523   [(set (reg:SI LR_REGNO)
11524         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")]
11525                 UNSPEC_TOCPTR))]
11526   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11527   "bcl 20,31,$+8\\n\\t.long %0-$"
11528   [(set_attr "type" "branch")
11529    (set_attr "length" "8")])
11530
11531 (define_insn "load_toc_v4_PIC_2"
11532   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11533         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11534                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
11535                              (match_operand:SI 3 "immediate_operand" "s")))))]
11536   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11537   "{l|lwz} %0,%2-%3(%1)"
11538   [(set_attr "type" "load")])
11539
11540 (define_insn "load_toc_v4_PIC_3b"
11541   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
11542         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
11543                  (high:SI
11544                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11545                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
11546   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
11547   "{cau|addis} %0,%1,%2-%3@ha")
11548
11549 (define_insn "load_toc_v4_PIC_3c"
11550   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11551         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11552                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11553                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
11554   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
11555   "{cal %0,%2-%3@l(%1)|addi %0,%1,%2-%3@l}")
11556
11557 ;; If the TOC is shared over a translation unit, as happens with all
11558 ;; the kinds of PIC that we support, we need to restore the TOC
11559 ;; pointer only when jumping over units of translation.
11560 ;; On Darwin, we need to reload the picbase.
11561
11562 (define_expand "builtin_setjmp_receiver"
11563   [(use (label_ref (match_operand 0 "" "")))]
11564   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11565    || (TARGET_TOC && TARGET_MINIMAL_TOC)
11566    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
11567   "
11568 {
11569 #if TARGET_MACHO
11570   if (DEFAULT_ABI == ABI_DARWIN)
11571     {
11572       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
11573       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
11574       rtx tmplabrtx;
11575       char tmplab[20];
11576
11577       crtl->uses_pic_offset_table = 1;
11578       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
11579                                   CODE_LABEL_NUMBER (operands[0]));
11580       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
11581
11582       emit_insn (gen_load_macho_picbase (tmplabrtx));
11583       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
11584       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
11585     }
11586   else
11587 #endif
11588     rs6000_emit_load_toc_table (FALSE);
11589   DONE;
11590 }")
11591
11592 ;; Elf specific ways of loading addresses for non-PIC code.
11593 ;; The output of this could be r0, but we make a very strong
11594 ;; preference for a base register because it will usually
11595 ;; be needed there.
11596 (define_insn "elf_high"
11597   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
11598         (high:SI (match_operand 1 "" "")))]
11599   "TARGET_ELF && ! TARGET_64BIT"
11600   "{liu|lis} %0,%1@ha")
11601
11602 (define_insn "elf_low"
11603   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11604         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
11605                    (match_operand 2 "" "")))]
11606    "TARGET_ELF && ! TARGET_64BIT"
11607    "@
11608     {cal|la} %0,%2@l(%1)
11609     {ai|addic} %0,%1,%K2")
11610 \f
11611 ;; A function pointer under AIX is a pointer to a data area whose first word
11612 ;; contains the actual address of the function, whose second word contains a
11613 ;; pointer to its TOC, and whose third word contains a value to place in the
11614 ;; static chain register (r11).  Note that if we load the static chain, our
11615 ;; "trampoline" need not have any executable code.
11616
11617 (define_expand "call_indirect_aix32"
11618   [(set (match_dup 2)
11619         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
11620    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
11621         (reg:SI 2))
11622    (set (reg:SI 11)
11623         (mem:SI (plus:SI (match_dup 0)
11624                          (const_int 8))))
11625    (parallel [(call (mem:SI (match_dup 2))
11626                     (match_operand 1 "" ""))
11627               (use (mem:SI (plus:SI (match_dup 0) (const_int 4))))
11628               (use (reg:SI 11))
11629               (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11630               (clobber (reg:SI LR_REGNO))])]
11631   "TARGET_32BIT"
11632   "
11633 { operands[2] = gen_reg_rtx (SImode); }")
11634
11635 (define_expand "call_indirect_aix64"
11636   [(set (match_dup 2)
11637         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
11638    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
11639         (reg:DI 2))
11640    (set (reg:DI 11)
11641         (mem:DI (plus:DI (match_dup 0)
11642                          (const_int 16))))
11643    (parallel [(call (mem:SI (match_dup 2))
11644                     (match_operand 1 "" ""))
11645               (use (mem:DI (plus:DI (match_dup 0) (const_int 8))))
11646               (use (reg:DI 11))
11647               (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11648               (clobber (reg:SI LR_REGNO))])]
11649   "TARGET_64BIT"
11650   "
11651 { operands[2] = gen_reg_rtx (DImode); }")
11652
11653 (define_expand "call_value_indirect_aix32"
11654   [(set (match_dup 3)
11655         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11656    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
11657         (reg:SI 2))
11658    (set (reg:SI 11)
11659         (mem:SI (plus:SI (match_dup 1)
11660                          (const_int 8))))
11661    (parallel [(set (match_operand 0 "" "")
11662                    (call (mem:SI (match_dup 3))
11663                          (match_operand 2 "" "")))
11664               (use (mem:SI (plus:SI (match_dup 1) (const_int 4))))
11665               (use (reg:SI 11))
11666               (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11667               (clobber (reg:SI LR_REGNO))])]
11668   "TARGET_32BIT"
11669   "
11670 { operands[3] = gen_reg_rtx (SImode); }")
11671
11672 (define_expand "call_value_indirect_aix64"
11673   [(set (match_dup 3)
11674         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11675    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
11676         (reg:DI 2))
11677    (set (reg:DI 11)
11678         (mem:DI (plus:DI (match_dup 1)
11679                          (const_int 16))))
11680    (parallel [(set (match_operand 0 "" "")
11681                    (call (mem:SI (match_dup 3))
11682                          (match_operand 2 "" "")))
11683               (use (mem:DI (plus:DI (match_dup 1) (const_int 8))))
11684               (use (reg:DI 11))
11685               (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11686               (clobber (reg:SI LR_REGNO))])]
11687   "TARGET_64BIT"
11688   "
11689 { operands[3] = gen_reg_rtx (DImode); }")
11690
11691 ;; Now the definitions for the call and call_value insns
11692 (define_expand "call"
11693   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11694                     (match_operand 1 "" ""))
11695               (use (match_operand 2 "" ""))
11696               (clobber (reg:SI LR_REGNO))])]
11697   ""
11698   "
11699 {
11700 #if TARGET_MACHO
11701   if (MACHOPIC_INDIRECT)
11702     operands[0] = machopic_indirect_call_target (operands[0]);
11703 #endif
11704
11705   gcc_assert (GET_CODE (operands[0]) == MEM);
11706   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11707
11708   operands[0] = XEXP (operands[0], 0);
11709
11710   if (GET_CODE (operands[0]) != SYMBOL_REF
11711       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
11712       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
11713     {
11714       if (INTVAL (operands[2]) & CALL_LONG)
11715         operands[0] = rs6000_longcall_ref (operands[0]);
11716
11717       switch (DEFAULT_ABI)
11718         {
11719         case ABI_V4:
11720         case ABI_DARWIN:
11721           operands[0] = force_reg (Pmode, operands[0]);
11722           break;
11723
11724         case ABI_AIX:
11725           /* AIX function pointers are really pointers to a three word
11726              area.  */
11727           emit_call_insn (TARGET_32BIT
11728                           ? gen_call_indirect_aix32 (force_reg (SImode,
11729                                                                 operands[0]),
11730                                                      operands[1])
11731                           : gen_call_indirect_aix64 (force_reg (DImode,
11732                                                                 operands[0]),
11733                                                      operands[1]));
11734           DONE;
11735
11736         default:
11737           gcc_unreachable ();
11738         }
11739     }
11740 }")
11741
11742 (define_expand "call_value"
11743   [(parallel [(set (match_operand 0 "" "")
11744                    (call (mem:SI (match_operand 1 "address_operand" ""))
11745                          (match_operand 2 "" "")))
11746               (use (match_operand 3 "" ""))
11747               (clobber (reg:SI LR_REGNO))])]
11748   ""
11749   "
11750 {
11751 #if TARGET_MACHO
11752   if (MACHOPIC_INDIRECT)
11753     operands[1] = machopic_indirect_call_target (operands[1]);
11754 #endif
11755
11756   gcc_assert (GET_CODE (operands[1]) == MEM);
11757   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11758
11759   operands[1] = XEXP (operands[1], 0);
11760
11761   if (GET_CODE (operands[1]) != SYMBOL_REF
11762       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
11763       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
11764     {
11765       if (INTVAL (operands[3]) & CALL_LONG)
11766         operands[1] = rs6000_longcall_ref (operands[1]);
11767
11768       switch (DEFAULT_ABI)
11769         {
11770         case ABI_V4:
11771         case ABI_DARWIN:
11772           operands[1] = force_reg (Pmode, operands[1]);
11773           break;
11774
11775         case ABI_AIX:
11776           /* AIX function pointers are really pointers to a three word
11777              area.  */
11778           emit_call_insn (TARGET_32BIT
11779                           ? gen_call_value_indirect_aix32 (operands[0],
11780                                                            force_reg (SImode,
11781                                                                       operands[1]),
11782                                                            operands[2])
11783                           : gen_call_value_indirect_aix64 (operands[0],
11784                                                            force_reg (DImode,
11785                                                                       operands[1]),
11786                                                            operands[2]));
11787           DONE;
11788
11789         default:
11790           gcc_unreachable ();
11791         }
11792     }
11793 }")
11794
11795 ;; Call to function in current module.  No TOC pointer reload needed.
11796 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11797 ;; either the function was not prototyped, or it was prototyped as a
11798 ;; variable argument function.  It is > 0 if FP registers were passed
11799 ;; and < 0 if they were not.
11800
11801 (define_insn "*call_local32"
11802   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11803          (match_operand 1 "" "g,g"))
11804    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11805    (clobber (reg:SI LR_REGNO))]
11806   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11807   "*
11808 {
11809   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11810     output_asm_insn (\"crxor 6,6,6\", operands);
11811
11812   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11813     output_asm_insn (\"creqv 6,6,6\", operands);
11814
11815   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11816 }"
11817   [(set_attr "type" "branch")
11818    (set_attr "length" "4,8")])
11819
11820 (define_insn "*call_local64"
11821   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11822          (match_operand 1 "" "g,g"))
11823    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11824    (clobber (reg:SI LR_REGNO))]
11825   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11826   "*
11827 {
11828   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11829     output_asm_insn (\"crxor 6,6,6\", operands);
11830
11831   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11832     output_asm_insn (\"creqv 6,6,6\", operands);
11833
11834   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11835 }"
11836   [(set_attr "type" "branch")
11837    (set_attr "length" "4,8")])
11838
11839 (define_insn "*call_value_local32"
11840   [(set (match_operand 0 "" "")
11841         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11842               (match_operand 2 "" "g,g")))
11843    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11844    (clobber (reg:SI LR_REGNO))]
11845   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11846   "*
11847 {
11848   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11849     output_asm_insn (\"crxor 6,6,6\", operands);
11850
11851   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11852     output_asm_insn (\"creqv 6,6,6\", operands);
11853
11854   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11855 }"
11856   [(set_attr "type" "branch")
11857    (set_attr "length" "4,8")])
11858
11859
11860 (define_insn "*call_value_local64"
11861   [(set (match_operand 0 "" "")
11862         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11863               (match_operand 2 "" "g,g")))
11864    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11865    (clobber (reg:SI LR_REGNO))]
11866   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11867   "*
11868 {
11869   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11870     output_asm_insn (\"crxor 6,6,6\", operands);
11871
11872   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11873     output_asm_insn (\"creqv 6,6,6\", operands);
11874
11875   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11876 }"
11877   [(set_attr "type" "branch")
11878    (set_attr "length" "4,8")])
11879
11880 ;; Call to function which may be in another module.  Restore the TOC
11881 ;; pointer (r2) after the call unless this is System V.
11882 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11883 ;; either the function was not prototyped, or it was prototyped as a
11884 ;; variable argument function.  It is > 0 if FP registers were passed
11885 ;; and < 0 if they were not.
11886
11887 (define_insn_and_split "*call_indirect_nonlocal_aix32_internal"
11888   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
11889                  (match_operand 1 "" "g,g"))
11890    (use (mem:SI (plus:SI (match_operand:SI 2 "register_operand" "b,b") (const_int 4))))
11891    (use (reg:SI 11))
11892    (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11893    (clobber (reg:SI LR_REGNO))]
11894   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
11895   "#"
11896   "&& reload_completed"
11897   [(set (reg:SI 2)
11898         (mem:SI (plus:SI (match_dup 2) (const_int 4))))
11899    (parallel [(call (mem:SI (match_dup 0))
11900                     (match_dup 1))
11901               (use (reg:SI 2))
11902               (use (reg:SI 11))
11903               (set (reg:SI 2)
11904                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11905               (clobber (reg:SI LR_REGNO))])]
11906   ""
11907   [(set_attr "type" "jmpreg")
11908    (set_attr "length" "12")])
11909
11910 (define_insn "*call_indirect_nonlocal_aix32"
11911   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
11912          (match_operand 1 "" "g,g"))
11913    (use (reg:SI 2))
11914    (use (reg:SI 11))
11915    (set (reg:SI 2)
11916         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11917    (clobber (reg:SI LR_REGNO))]
11918   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
11919   "b%T0l\;{l|lwz} 2,20(1)"
11920   [(set_attr "type" "jmpreg")
11921    (set_attr "length" "8")])
11922
11923 (define_insn "*call_nonlocal_aix32"
11924   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
11925          (match_operand 1 "" "g"))
11926    (use (match_operand:SI 2 "immediate_operand" "O"))
11927    (clobber (reg:SI LR_REGNO))]
11928   "TARGET_32BIT
11929    && DEFAULT_ABI == ABI_AIX
11930    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11931   "bl %z0\;%."
11932   [(set_attr "type" "branch")
11933    (set_attr "length" "8")])
11934    
11935 (define_insn_and_split "*call_indirect_nonlocal_aix64_internal"
11936   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
11937                  (match_operand 1 "" "g,g"))
11938    (use (mem:DI (plus:DI (match_operand:DI 2 "register_operand" "b,b")
11939                          (const_int 8))))
11940    (use (reg:DI 11))
11941    (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11942    (clobber (reg:SI LR_REGNO))]
11943   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
11944   "#"
11945   "&& reload_completed"
11946   [(set (reg:DI 2)
11947         (mem:DI (plus:DI (match_dup 2) (const_int 8))))
11948    (parallel [(call (mem:SI (match_dup 0))
11949                     (match_dup 1))
11950               (use (reg:DI 2))
11951               (use (reg:DI 11))
11952               (set (reg:DI 2)
11953                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11954               (clobber (reg:SI LR_REGNO))])]
11955   ""
11956   [(set_attr "type" "jmpreg")
11957    (set_attr "length" "12")])
11958
11959 (define_insn "*call_indirect_nonlocal_aix64"
11960   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
11961          (match_operand 1 "" "g,g"))
11962    (use (reg:DI 2))
11963    (use (reg:DI 11))
11964    (set (reg:DI 2)
11965         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11966    (clobber (reg:SI LR_REGNO))]
11967   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
11968   "b%T0l\;ld 2,40(1)"
11969   [(set_attr "type" "jmpreg")
11970    (set_attr "length" "8")])
11971
11972 (define_insn "*call_nonlocal_aix64"
11973   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
11974          (match_operand 1 "" "g"))
11975    (use (match_operand:SI 2 "immediate_operand" "O"))
11976    (clobber (reg:SI LR_REGNO))]
11977   "TARGET_64BIT
11978    && DEFAULT_ABI == ABI_AIX
11979    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11980   "bl %z0\;%."
11981   [(set_attr "type" "branch")
11982    (set_attr "length" "8")])
11983
11984 (define_insn_and_split "*call_value_indirect_nonlocal_aix32_internal"
11985   [(set (match_operand 0 "" "")
11986         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
11987                       (match_operand 2 "" "g,g")))
11988         (use (mem:SI (plus:SI (match_operand:SI 3 "register_operand" "b,b")
11989                               (const_int 4))))
11990         (use (reg:SI 11))
11991         (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11992         (clobber (reg:SI LR_REGNO))]
11993   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
11994   "#"
11995   "&& reload_completed"
11996   [(set (reg:SI 2)
11997         (mem:SI (plus:SI (match_dup 3) (const_int 4))))
11998    (parallel [(set (match_dup 0) (call (mem:SI (match_dup 1))
11999                                        (match_dup 2)))
12000               (use (reg:SI 2))
12001               (use (reg:SI 11))
12002               (set (reg:SI 2)
12003                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12004               (clobber (reg:SI LR_REGNO))])]
12005   ""
12006   [(set_attr "type" "jmpreg")
12007    (set_attr "length" "12")])
12008
12009 (define_insn "*call_value_indirect_nonlocal_aix32"
12010   [(set (match_operand 0 "" "")
12011         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
12012               (match_operand 2 "" "g,g")))
12013    (use (reg:SI 2))
12014    (use (reg:SI 11))
12015    (set (reg:SI 2)
12016         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12017    (clobber (reg:SI LR_REGNO))]
12018   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12019   "b%T1l\;{l|lwz} 2,20(1)"
12020   [(set_attr "type" "jmpreg")
12021    (set_attr "length" "8")])
12022
12023 (define_insn "*call_value_nonlocal_aix32"
12024   [(set (match_operand 0 "" "")
12025         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12026               (match_operand 2 "" "g")))
12027    (use (match_operand:SI 3 "immediate_operand" "O"))
12028    (clobber (reg:SI LR_REGNO))]
12029   "TARGET_32BIT
12030    && DEFAULT_ABI == ABI_AIX
12031    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12032   "bl %z1\;%."
12033   [(set_attr "type" "branch")
12034    (set_attr "length" "8")])
12035
12036 (define_insn_and_split "*call_value_indirect_nonlocal_aix64_internal"
12037   [(set (match_operand 0 "" "")
12038         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
12039                       (match_operand 2 "" "g,g")))
12040         (use (mem:DI (plus:DI (match_operand:DI 3 "register_operand" "b,b")
12041                               (const_int 8))))
12042         (use (reg:DI 11))
12043         (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12044         (clobber (reg:SI LR_REGNO))]
12045   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
12046   "#"
12047   "&& reload_completed"
12048   [(set (reg:DI 2)
12049         (mem:DI (plus:DI (match_dup 3) (const_int 8))))
12050    (parallel [(set (match_dup 0) (call (mem:SI (match_dup 1))
12051                                        (match_dup 2)))
12052               (use (reg:DI 2))
12053               (use (reg:DI 11))
12054               (set (reg:DI 2)
12055                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12056               (clobber (reg:SI LR_REGNO))])]
12057   ""
12058   [(set_attr "type" "jmpreg")
12059    (set_attr "length" "12")])
12060
12061 (define_insn "*call_value_indirect_nonlocal_aix64"
12062   [(set (match_operand 0 "" "")
12063         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
12064               (match_operand 2 "" "g,g")))
12065    (use (reg:DI 2))
12066    (use (reg:DI 11))
12067    (set (reg:DI 2)
12068         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12069    (clobber (reg:SI LR_REGNO))]
12070   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12071   "b%T1l\;ld 2,40(1)"
12072   [(set_attr "type" "jmpreg")
12073    (set_attr "length" "8")])
12074
12075 (define_insn "*call_value_nonlocal_aix64"
12076   [(set (match_operand 0 "" "")
12077         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12078               (match_operand 2 "" "g")))
12079    (use (match_operand:SI 3 "immediate_operand" "O"))
12080    (clobber (reg:SI LR_REGNO))]
12081   "TARGET_64BIT
12082    && DEFAULT_ABI == ABI_AIX
12083    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12084   "bl %z1\;%."
12085   [(set_attr "type" "branch")
12086    (set_attr "length" "8")])
12087
12088 ;; A function pointer under System V is just a normal pointer
12089 ;; operands[0] is the function pointer
12090 ;; operands[1] is the stack size to clean up
12091 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12092 ;; which indicates how to set cr1
12093
12094 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12095   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12096          (match_operand 1 "" "g,g,g,g"))
12097    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12098    (clobber (reg:SI LR_REGNO))]
12099   "DEFAULT_ABI == ABI_V4
12100    || DEFAULT_ABI == ABI_DARWIN"
12101 {
12102   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12103     output_asm_insn ("crxor 6,6,6", operands);
12104
12105   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12106     output_asm_insn ("creqv 6,6,6", operands);
12107
12108   return "b%T0l";
12109 }
12110   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12111    (set_attr "length" "4,4,8,8")])
12112
12113 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12114   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12115          (match_operand 1 "" "g,g"))
12116    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12117    (clobber (reg:SI LR_REGNO))]
12118   "(DEFAULT_ABI == ABI_DARWIN
12119    || (DEFAULT_ABI == ABI_V4
12120        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12121 {
12122   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12123     output_asm_insn ("crxor 6,6,6", operands);
12124
12125   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12126     output_asm_insn ("creqv 6,6,6", operands);
12127
12128 #if TARGET_MACHO
12129   return output_call(insn, operands, 0, 2);
12130 #else
12131   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12132     {
12133       gcc_assert (!TARGET_SECURE_PLT);
12134       return "bl %z0@plt";
12135     }
12136   else
12137     return "bl %z0";
12138 #endif
12139 }
12140   "DEFAULT_ABI == ABI_V4
12141    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12142    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12143   [(parallel [(call (mem:SI (match_dup 0))
12144                     (match_dup 1))
12145               (use (match_dup 2))
12146               (use (match_dup 3))
12147               (clobber (reg:SI LR_REGNO))])]
12148 {
12149   operands[3] = pic_offset_table_rtx;
12150 }
12151   [(set_attr "type" "branch,branch")
12152    (set_attr "length" "4,8")])
12153
12154 (define_insn "*call_nonlocal_sysv_secure<mode>"
12155   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12156          (match_operand 1 "" "g,g"))
12157    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12158    (use (match_operand:SI 3 "register_operand" "r,r"))
12159    (clobber (reg:SI LR_REGNO))]
12160   "(DEFAULT_ABI == ABI_V4
12161     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12162     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
12163 {
12164   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12165     output_asm_insn ("crxor 6,6,6", operands);
12166
12167   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12168     output_asm_insn ("creqv 6,6,6", operands);
12169
12170   if (flag_pic == 2)
12171     /* The magic 32768 offset here and in the other sysv call insns
12172        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12173        See sysv4.h:toc_section.  */
12174     return "bl %z0+32768@plt";
12175   else
12176     return "bl %z0@plt";
12177 }
12178   [(set_attr "type" "branch,branch")
12179    (set_attr "length" "4,8")])
12180
12181 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12182   [(set (match_operand 0 "" "")
12183         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12184               (match_operand 2 "" "g,g,g,g")))
12185    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12186    (clobber (reg:SI LR_REGNO))]
12187   "DEFAULT_ABI == ABI_V4
12188    || DEFAULT_ABI == ABI_DARWIN"
12189 {
12190   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12191     output_asm_insn ("crxor 6,6,6", operands);
12192
12193   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12194     output_asm_insn ("creqv 6,6,6", operands);
12195
12196   return "b%T1l";
12197 }
12198   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12199    (set_attr "length" "4,4,8,8")])
12200
12201 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12202   [(set (match_operand 0 "" "")
12203         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12204               (match_operand 2 "" "g,g")))
12205    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12206    (clobber (reg:SI LR_REGNO))]
12207   "(DEFAULT_ABI == ABI_DARWIN
12208    || (DEFAULT_ABI == ABI_V4
12209        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12210 {
12211   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12212     output_asm_insn ("crxor 6,6,6", operands);
12213
12214   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12215     output_asm_insn ("creqv 6,6,6", operands);
12216
12217 #if TARGET_MACHO
12218   return output_call(insn, operands, 1, 3);
12219 #else
12220   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12221     {
12222       gcc_assert (!TARGET_SECURE_PLT);
12223       return "bl %z1@plt";
12224     }
12225   else
12226     return "bl %z1";
12227 #endif
12228 }
12229   "DEFAULT_ABI == ABI_V4
12230    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12231    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12232   [(parallel [(set (match_dup 0)
12233                    (call (mem:SI (match_dup 1))
12234                          (match_dup 2)))
12235               (use (match_dup 3))
12236               (use (match_dup 4))
12237               (clobber (reg:SI LR_REGNO))])]
12238 {
12239   operands[4] = pic_offset_table_rtx;
12240 }
12241   [(set_attr "type" "branch,branch")
12242    (set_attr "length" "4,8")])
12243
12244 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12245   [(set (match_operand 0 "" "")
12246         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12247               (match_operand 2 "" "g,g")))
12248    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12249    (use (match_operand:SI 4 "register_operand" "r,r"))
12250    (clobber (reg:SI LR_REGNO))]
12251   "(DEFAULT_ABI == ABI_V4
12252     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12253     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12254 {
12255   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12256     output_asm_insn ("crxor 6,6,6", operands);
12257
12258   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12259     output_asm_insn ("creqv 6,6,6", operands);
12260
12261   if (flag_pic == 2)
12262     return "bl %z1+32768@plt";
12263   else
12264     return "bl %z1@plt";
12265 }
12266   [(set_attr "type" "branch,branch")
12267    (set_attr "length" "4,8")])
12268
12269 ;; Call subroutine returning any type.
12270 (define_expand "untyped_call"
12271   [(parallel [(call (match_operand 0 "" "")
12272                     (const_int 0))
12273               (match_operand 1 "" "")
12274               (match_operand 2 "" "")])]
12275   ""
12276   "
12277 {
12278   int i;
12279
12280   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12281
12282   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12283     {
12284       rtx set = XVECEXP (operands[2], 0, i);
12285       emit_move_insn (SET_DEST (set), SET_SRC (set));
12286     }
12287
12288   /* The optimizer does not know that the call sets the function value
12289      registers we stored in the result block.  We avoid problems by
12290      claiming that all hard registers are used and clobbered at this
12291      point.  */
12292   emit_insn (gen_blockage ());
12293
12294   DONE;
12295 }")
12296
12297 ;; sibling call patterns
12298 (define_expand "sibcall"
12299   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12300                     (match_operand 1 "" ""))
12301               (use (match_operand 2 "" ""))
12302               (use (reg:SI LR_REGNO))
12303               (return)])]
12304   ""
12305   "
12306 {
12307 #if TARGET_MACHO
12308   if (MACHOPIC_INDIRECT)
12309     operands[0] = machopic_indirect_call_target (operands[0]);
12310 #endif
12311
12312   gcc_assert (GET_CODE (operands[0]) == MEM);
12313   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12314
12315   operands[0] = XEXP (operands[0], 0);
12316 }")
12317
12318 ;; this and similar patterns must be marked as using LR, otherwise
12319 ;; dataflow will try to delete the store into it.  This is true
12320 ;; even when the actual reg to jump to is in CTR, when LR was
12321 ;; saved and restored around the PIC-setting BCL.
12322 (define_insn "*sibcall_local32"
12323   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12324          (match_operand 1 "" "g,g"))
12325    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12326    (use (reg:SI LR_REGNO))
12327    (return)]
12328   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12329   "*
12330 {
12331   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12332     output_asm_insn (\"crxor 6,6,6\", operands);
12333
12334   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12335     output_asm_insn (\"creqv 6,6,6\", operands);
12336
12337   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12338 }"
12339   [(set_attr "type" "branch")
12340    (set_attr "length" "4,8")])
12341
12342 (define_insn "*sibcall_local64"
12343   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12344          (match_operand 1 "" "g,g"))
12345    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12346    (use (reg:SI LR_REGNO))
12347    (return)]
12348   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12349   "*
12350 {
12351   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12352     output_asm_insn (\"crxor 6,6,6\", operands);
12353
12354   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12355     output_asm_insn (\"creqv 6,6,6\", operands);
12356
12357   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12358 }"
12359   [(set_attr "type" "branch")
12360    (set_attr "length" "4,8")])
12361
12362 (define_insn "*sibcall_value_local32"
12363   [(set (match_operand 0 "" "")
12364         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12365               (match_operand 2 "" "g,g")))
12366    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12367    (use (reg:SI LR_REGNO))
12368    (return)]
12369   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12370   "*
12371 {
12372   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12373     output_asm_insn (\"crxor 6,6,6\", operands);
12374
12375   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12376     output_asm_insn (\"creqv 6,6,6\", operands);
12377
12378   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12379 }"
12380   [(set_attr "type" "branch")
12381    (set_attr "length" "4,8")])
12382
12383
12384 (define_insn "*sibcall_value_local64"
12385   [(set (match_operand 0 "" "")
12386         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12387               (match_operand 2 "" "g,g")))
12388    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12389    (use (reg:SI LR_REGNO))
12390    (return)]
12391   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12392   "*
12393 {
12394   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12395     output_asm_insn (\"crxor 6,6,6\", operands);
12396
12397   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12398     output_asm_insn (\"creqv 6,6,6\", operands);
12399
12400   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12401 }"
12402   [(set_attr "type" "branch")
12403    (set_attr "length" "4,8")])
12404
12405 (define_insn "*sibcall_nonlocal_aix32"
12406   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
12407          (match_operand 1 "" "g"))
12408    (use (match_operand:SI 2 "immediate_operand" "O"))
12409    (use (reg:SI LR_REGNO))
12410    (return)]
12411   "TARGET_32BIT
12412    && DEFAULT_ABI == ABI_AIX
12413    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12414   "b %z0"
12415   [(set_attr "type" "branch")
12416    (set_attr "length" "4")])
12417
12418 (define_insn "*sibcall_nonlocal_aix64"
12419   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
12420          (match_operand 1 "" "g"))
12421    (use (match_operand:SI 2 "immediate_operand" "O"))
12422    (use (reg:SI LR_REGNO))
12423    (return)]
12424   "TARGET_64BIT
12425    && DEFAULT_ABI == ABI_AIX
12426    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12427   "b %z0"
12428   [(set_attr "type" "branch")
12429    (set_attr "length" "4")])
12430
12431 (define_insn "*sibcall_value_nonlocal_aix32"
12432   [(set (match_operand 0 "" "")
12433         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12434               (match_operand 2 "" "g")))
12435    (use (match_operand:SI 3 "immediate_operand" "O"))
12436    (use (reg:SI LR_REGNO))
12437    (return)]
12438   "TARGET_32BIT
12439    && DEFAULT_ABI == ABI_AIX
12440    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12441   "b %z1"
12442   [(set_attr "type" "branch")
12443    (set_attr "length" "4")])
12444
12445 (define_insn "*sibcall_value_nonlocal_aix64"
12446   [(set (match_operand 0 "" "")
12447         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12448               (match_operand 2 "" "g")))
12449    (use (match_operand:SI 3 "immediate_operand" "O"))
12450    (use (reg:SI LR_REGNO))
12451    (return)]
12452   "TARGET_64BIT
12453    && DEFAULT_ABI == ABI_AIX
12454    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12455   "b %z1"
12456   [(set_attr "type" "branch")
12457    (set_attr "length" "4")])
12458
12459 (define_insn "*sibcall_nonlocal_sysv<mode>"
12460   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12461          (match_operand 1 "" ""))
12462    (use (match_operand 2 "immediate_operand" "O,n"))
12463    (use (reg:SI LR_REGNO))
12464    (return)]
12465   "(DEFAULT_ABI == ABI_DARWIN
12466      || DEFAULT_ABI == ABI_V4)
12467    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12468   "*
12469 {
12470   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12471     output_asm_insn (\"crxor 6,6,6\", operands);
12472
12473   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12474     output_asm_insn (\"creqv 6,6,6\", operands);
12475
12476   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12477     {
12478       gcc_assert (!TARGET_SECURE_PLT);
12479       return \"b %z0@plt\";
12480     }
12481   else
12482     return \"b %z0\";
12483 }"
12484   [(set_attr "type" "branch,branch")
12485    (set_attr "length" "4,8")])
12486
12487 (define_expand "sibcall_value"
12488   [(parallel [(set (match_operand 0 "register_operand" "")
12489                 (call (mem:SI (match_operand 1 "address_operand" ""))
12490                       (match_operand 2 "" "")))
12491               (use (match_operand 3 "" ""))
12492               (use (reg:SI LR_REGNO))
12493               (return)])]
12494   ""
12495   "
12496 {
12497 #if TARGET_MACHO
12498   if (MACHOPIC_INDIRECT)
12499     operands[1] = machopic_indirect_call_target (operands[1]);
12500 #endif
12501
12502   gcc_assert (GET_CODE (operands[1]) == MEM);
12503   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12504
12505   operands[1] = XEXP (operands[1], 0);
12506 }")
12507
12508 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
12509   [(set (match_operand 0 "" "")
12510         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12511               (match_operand 2 "" "")))
12512    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12513    (use (reg:SI LR_REGNO))
12514    (return)]
12515   "(DEFAULT_ABI == ABI_DARWIN
12516        || DEFAULT_ABI == ABI_V4)
12517    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12518   "*
12519 {
12520   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12521     output_asm_insn (\"crxor 6,6,6\", operands);
12522
12523   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12524     output_asm_insn (\"creqv 6,6,6\", operands);
12525
12526   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12527     {
12528       gcc_assert (!TARGET_SECURE_PLT);
12529       return \"b %z1@plt\";
12530     }
12531   else
12532     return \"b %z1\";
12533 }"
12534   [(set_attr "type" "branch,branch")
12535    (set_attr "length" "4,8")])
12536
12537 (define_expand "sibcall_epilogue"
12538   [(use (const_int 0))]
12539   "TARGET_SCHED_PROLOG"
12540   "
12541 {
12542       rs6000_emit_epilogue (TRUE);
12543       DONE;
12544 }")
12545
12546 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12547 ;; all of memory.  This blocks insns from being moved across this point.
12548
12549 (define_insn "blockage"
12550   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
12551   ""
12552   "")
12553
12554 (define_insn "probe_stack"
12555   [(unspec [(match_operand 0 "memory_operand" "=m")] UNSPEC_PROBE_STACK)]
12556   ""
12557   "{st%U0%X0|stw%U0%X0} 0,%0"
12558   [(set_attr "type" "store")
12559    (set_attr "length" "4")])
12560 \f
12561 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
12562 ;; signed & unsigned, and one type of branch.
12563 ;;
12564 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
12565 ;; insns, and branches.
12566
12567 (define_expand "cbranch<mode>4"
12568   [(use (match_operator 0 "rs6000_cbranch_operator"
12569          [(match_operand:GPR 1 "gpc_reg_operand" "")
12570           (match_operand:GPR 2 "reg_or_short_operand" "")]))
12571    (use (match_operand 3 ""))]
12572   ""
12573   "
12574 {
12575   /* Take care of the possibility that operands[2] might be negative but
12576      this might be a logical operation.  That insn doesn't exist.  */
12577   if (GET_CODE (operands[2]) == CONST_INT
12578       && INTVAL (operands[2]) < 0)
12579     {
12580       operands[2] = force_reg (<MODE>mode, operands[2]);
12581       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
12582                                     GET_MODE (operands[0]),
12583                                     operands[1], operands[2]);
12584    }
12585
12586   rs6000_emit_cbranch (<MODE>mode, operands);
12587   DONE;
12588 }")
12589
12590 (define_expand "cbranch<mode>4"
12591   [(use (match_operator 0 "rs6000_cbranch_operator"
12592          [(match_operand:FP 1 "gpc_reg_operand" "")
12593           (match_operand:FP 2 "gpc_reg_operand" "")]))
12594    (use (match_operand 3 ""))]
12595   ""
12596   "
12597 {
12598   rs6000_emit_cbranch (<MODE>mode, operands);
12599   DONE;
12600 }")
12601
12602 (define_expand "cstore<mode>4"
12603   [(use (match_operator 1 "rs6000_cbranch_operator"
12604          [(match_operand:GPR 2 "gpc_reg_operand" "")
12605           (match_operand:GPR 3 "reg_or_short_operand" "")]))
12606    (clobber (match_operand:SI 0 "register_operand"))]
12607   ""
12608   "
12609 {
12610   /* Take care of the possibility that operands[3] might be negative but
12611      this might be a logical operation.  That insn doesn't exist.  */
12612   if (GET_CODE (operands[3]) == CONST_INT
12613       && INTVAL (operands[3]) < 0)
12614     {
12615       operands[3] = force_reg (<MODE>mode, operands[3]);
12616       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
12617                                     GET_MODE (operands[1]),
12618                                     operands[2], operands[3]);
12619     }
12620
12621   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
12622      For SEQ, likewise, except that comparisons with zero should be done
12623      with an scc insns.  However, due to the order that combine see the
12624      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
12625      the cases we don't want to handle or are best handled by portable
12626      code.  */
12627   if (GET_CODE (operands[1]) == NE)
12628     FAIL;
12629   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
12630        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
12631       && operands[3] == const0_rtx)
12632     FAIL;
12633   rs6000_emit_sCOND (<MODE>mode, operands);
12634   DONE;
12635 }")
12636
12637 (define_expand "cstore<mode>4"
12638   [(use (match_operator 1 "rs6000_cbranch_operator"
12639          [(match_operand:FP 2 "gpc_reg_operand" "")
12640           (match_operand:FP 3 "gpc_reg_operand" "")]))
12641    (clobber (match_operand:SI 0 "register_operand"))]
12642   ""
12643   "
12644 {
12645   rs6000_emit_sCOND (<MODE>mode, operands);
12646   DONE;
12647 }")
12648
12649
12650 (define_expand "stack_protect_set"
12651   [(match_operand 0 "memory_operand" "")
12652    (match_operand 1 "memory_operand" "")]
12653   ""
12654 {
12655 #ifdef TARGET_THREAD_SSP_OFFSET
12656   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12657   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12658   operands[1] = gen_rtx_MEM (Pmode, addr);
12659 #endif
12660   if (TARGET_64BIT)
12661     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
12662   else
12663     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
12664   DONE;
12665 })
12666
12667 (define_insn "stack_protect_setsi"
12668   [(set (match_operand:SI 0 "memory_operand" "=m")
12669         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12670    (set (match_scratch:SI 2 "=&r") (const_int 0))]
12671   "TARGET_32BIT"
12672   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
12673   [(set_attr "type" "three")
12674    (set_attr "length" "12")])
12675
12676 (define_insn "stack_protect_setdi"
12677   [(set (match_operand:DI 0 "memory_operand" "=m")
12678         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12679    (set (match_scratch:DI 2 "=&r") (const_int 0))]
12680   "TARGET_64BIT"
12681   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
12682   [(set_attr "type" "three")
12683    (set_attr "length" "12")])
12684
12685 (define_expand "stack_protect_test"
12686   [(match_operand 0 "memory_operand" "")
12687    (match_operand 1 "memory_operand" "")
12688    (match_operand 2 "" "")]
12689   ""
12690 {
12691   rtx test, op0, op1;
12692 #ifdef TARGET_THREAD_SSP_OFFSET
12693   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12694   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12695   operands[1] = gen_rtx_MEM (Pmode, addr);
12696 #endif
12697   op0 = operands[0];
12698   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
12699   test = gen_rtx_EQ (VOIDmode, op0, op1);
12700   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
12701   DONE;
12702 })
12703
12704 (define_insn "stack_protect_testsi"
12705   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12706         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
12707                       (match_operand:SI 2 "memory_operand" "m,m")]
12708                      UNSPEC_SP_TEST))
12709    (set (match_scratch:SI 4 "=r,r") (const_int 0))
12710    (clobber (match_scratch:SI 3 "=&r,&r"))]
12711   "TARGET_32BIT"
12712   "@
12713    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
12714    {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"
12715   [(set_attr "length" "16,20")])
12716
12717 (define_insn "stack_protect_testdi"
12718   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12719         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
12720                       (match_operand:DI 2 "memory_operand" "m,m")]
12721                      UNSPEC_SP_TEST))
12722    (set (match_scratch:DI 4 "=r,r") (const_int 0))
12723    (clobber (match_scratch:DI 3 "=&r,&r"))]
12724   "TARGET_64BIT"
12725   "@
12726    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
12727    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
12728   [(set_attr "length" "16,20")])
12729
12730 \f
12731 ;; Here are the actual compare insns.
12732 (define_insn "*cmp<mode>_internal1"
12733   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
12734         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
12735                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
12736   ""
12737   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
12738   [(set_attr "type" "cmp")])
12739
12740 ;; If we are comparing a register for equality with a large constant,
12741 ;; we can do this with an XOR followed by a compare.  But this is profitable
12742 ;; only if the large constant is only used for the comparison (and in this
12743 ;; case we already have a register to reuse as scratch).
12744 ;;
12745 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
12746 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
12747
12748 (define_peephole2
12749   [(set (match_operand:SI 0 "register_operand")
12750         (match_operand:SI 1 "logical_const_operand" ""))
12751    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
12752                        [(match_dup 0)
12753                         (match_operand:SI 2 "logical_const_operand" "")]))
12754    (set (match_operand:CC 4 "cc_reg_operand" "")
12755         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
12756                     (match_dup 0)))
12757    (set (pc)
12758         (if_then_else (match_operator 6 "equality_operator"
12759                        [(match_dup 4) (const_int 0)])
12760                       (match_operand 7 "" "")
12761                       (match_operand 8 "" "")))]
12762   "peep2_reg_dead_p (3, operands[0])
12763    && peep2_reg_dead_p (4, operands[4])"
12764  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
12765   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
12766   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
12767  
12768 {
12769   /* Get the constant we are comparing against, and see what it looks like
12770      when sign-extended from 16 to 32 bits.  Then see what constant we could
12771      XOR with SEXTC to get the sign-extended value.  */
12772   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
12773                                               SImode,
12774                                               operands[1], operands[2]);
12775   HOST_WIDE_INT c = INTVAL (cnst);
12776   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
12777   HOST_WIDE_INT xorv = c ^ sextc;
12778
12779   operands[9] = GEN_INT (xorv);
12780   operands[10] = GEN_INT (sextc);
12781 })
12782
12783 (define_insn "*cmpsi_internal2"
12784   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12785         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12786                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
12787   ""
12788   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
12789   [(set_attr "type" "cmp")])
12790
12791 (define_insn "*cmpdi_internal2"
12792   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12793         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
12794                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
12795   ""
12796   "cmpld%I2 %0,%1,%b2"
12797   [(set_attr "type" "cmp")])
12798
12799 ;; The following two insns don't exist as single insns, but if we provide
12800 ;; them, we can swap an add and compare, which will enable us to overlap more
12801 ;; of the required delay between a compare and branch.  We generate code for
12802 ;; them by splitting.
12803
12804 (define_insn ""
12805   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
12806         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
12807                     (match_operand:SI 2 "short_cint_operand" "i")))
12808    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12809         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12810   ""
12811   "#"
12812   [(set_attr "length" "8")])
12813
12814 (define_insn ""
12815   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
12816         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12817                        (match_operand:SI 2 "u_short_cint_operand" "i")))
12818    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12819         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12820   ""
12821   "#"
12822   [(set_attr "length" "8")])
12823
12824 (define_split
12825   [(set (match_operand:CC 3 "cc_reg_operand" "")
12826         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
12827                     (match_operand:SI 2 "short_cint_operand" "")))
12828    (set (match_operand:SI 0 "gpc_reg_operand" "")
12829         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12830   ""
12831   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
12832    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12833
12834 (define_split
12835   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
12836         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
12837                        (match_operand:SI 2 "u_short_cint_operand" "")))
12838    (set (match_operand:SI 0 "gpc_reg_operand" "")
12839         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12840   ""
12841   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
12842    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12843
12844 (define_insn "*cmpsf_internal1"
12845   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12846         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
12847                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
12848   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
12849   "fcmpu %0,%1,%2"
12850   [(set_attr "type" "fpcompare")])
12851
12852 (define_insn "*cmpdf_internal1"
12853   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12854         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
12855                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
12856   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
12857    && !VECTOR_UNIT_VSX_P (DFmode)"
12858   "fcmpu %0,%1,%2"
12859   [(set_attr "type" "fpcompare")])
12860
12861 ;; Only need to compare second words if first words equal
12862 (define_insn "*cmptf_internal1"
12863   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12864         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12865                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
12866   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
12867    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12868   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
12869   [(set_attr "type" "fpcompare")
12870    (set_attr "length" "12")])
12871
12872 (define_insn_and_split "*cmptf_internal2"
12873   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12874         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12875                       (match_operand:TF 2 "gpc_reg_operand" "d")))
12876     (clobber (match_scratch:DF 3 "=d"))
12877     (clobber (match_scratch:DF 4 "=d"))
12878     (clobber (match_scratch:DF 5 "=d"))
12879     (clobber (match_scratch:DF 6 "=d"))
12880     (clobber (match_scratch:DF 7 "=d"))
12881     (clobber (match_scratch:DF 8 "=d"))
12882     (clobber (match_scratch:DF 9 "=d"))
12883     (clobber (match_scratch:DF 10 "=d"))]
12884   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
12885    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12886   "#"
12887   "&& reload_completed"
12888   [(set (match_dup 3) (match_dup 13))
12889    (set (match_dup 4) (match_dup 14))
12890    (set (match_dup 9) (abs:DF (match_dup 5)))
12891    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
12892    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
12893                            (label_ref (match_dup 11))
12894                            (pc)))
12895    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
12896    (set (pc) (label_ref (match_dup 12)))
12897    (match_dup 11)
12898    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
12899    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
12900    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
12901    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
12902    (match_dup 12)]
12903 {
12904   REAL_VALUE_TYPE rv;
12905   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
12906   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
12907
12908   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
12909   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
12910   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
12911   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
12912   operands[11] = gen_label_rtx ();
12913   operands[12] = gen_label_rtx ();
12914   real_inf (&rv);
12915   operands[13] = force_const_mem (DFmode,
12916                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
12917   operands[14] = force_const_mem (DFmode,
12918                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
12919                                                                 DFmode));
12920   if (TARGET_TOC)
12921     {
12922       operands[13] = gen_const_mem (DFmode,
12923                                     create_TOC_reference (XEXP (operands[13], 0)));
12924       operands[14] = gen_const_mem (DFmode,
12925                                     create_TOC_reference (XEXP (operands[14], 0)));
12926       set_mem_alias_set (operands[13], get_TOC_alias_set ());
12927       set_mem_alias_set (operands[14], get_TOC_alias_set ());
12928     }
12929 })
12930 \f
12931 ;; Now we have the scc insns.  We can do some combinations because of the
12932 ;; way the machine works.
12933 ;;
12934 ;; Note that this is probably faster if we can put an insn between the
12935 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
12936 ;; cases the insns below which don't use an intermediate CR field will
12937 ;; be used instead.
12938 (define_insn ""
12939   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12940         (match_operator:SI 1 "scc_comparison_operator"
12941                            [(match_operand 2 "cc_reg_operand" "y")
12942                             (const_int 0)]))]
12943   ""
12944   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
12945   [(set (attr "type")
12946      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12947                 (const_string "mfcrf")
12948            ]
12949         (const_string "mfcr")))
12950    (set_attr "length" "8")])
12951
12952 ;; Same as above, but get the GT bit.
12953 (define_insn "move_from_CR_gt_bit"
12954   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12955         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
12956   "TARGET_HARD_FLOAT && !TARGET_FPRS"
12957   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
12958   [(set_attr "type" "mfcr")
12959    (set_attr "length" "8")])
12960
12961 ;; Same as above, but get the OV/ORDERED bit.
12962 (define_insn "move_from_CR_ov_bit"
12963   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12964         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
12965   "TARGET_ISEL"
12966   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
12967   [(set_attr "type" "mfcr")
12968    (set_attr "length" "8")])
12969
12970 (define_insn ""
12971   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12972         (match_operator:DI 1 "scc_comparison_operator"
12973                            [(match_operand 2 "cc_reg_operand" "y")
12974                             (const_int 0)]))]
12975   "TARGET_POWERPC64"
12976   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
12977   [(set (attr "type")
12978      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12979                 (const_string "mfcrf")
12980            ]
12981         (const_string "mfcr")))
12982    (set_attr "length" "8")])
12983
12984 (define_insn ""
12985   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12986         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12987                                        [(match_operand 2 "cc_reg_operand" "y,y")
12988                                         (const_int 0)])
12989                     (const_int 0)))
12990    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
12991         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12992   "TARGET_32BIT"
12993   "@
12994    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
12995    #"
12996   [(set_attr "type" "delayed_compare")
12997    (set_attr "length" "8,16")])
12998
12999 (define_split
13000   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13001         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13002                                        [(match_operand 2 "cc_reg_operand" "")
13003                                         (const_int 0)])
13004                     (const_int 0)))
13005    (set (match_operand:SI 3 "gpc_reg_operand" "")
13006         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13007   "TARGET_32BIT && reload_completed"
13008   [(set (match_dup 3)
13009         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
13010    (set (match_dup 0)
13011         (compare:CC (match_dup 3)
13012                     (const_int 0)))]
13013   "")
13014
13015 (define_insn ""
13016   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13017         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13018                                       [(match_operand 2 "cc_reg_operand" "y")
13019                                        (const_int 0)])
13020                    (match_operand:SI 3 "const_int_operand" "n")))]
13021   ""
13022   "*
13023 {
13024   int is_bit = ccr_bit (operands[1], 1);
13025   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13026   int count;
13027
13028   if (is_bit >= put_bit)
13029     count = is_bit - put_bit;
13030   else
13031     count = 32 - (put_bit - is_bit);
13032
13033   operands[4] = GEN_INT (count);
13034   operands[5] = GEN_INT (put_bit);
13035
13036   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
13037 }"
13038   [(set (attr "type")
13039      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
13040                 (const_string "mfcrf")
13041            ]
13042         (const_string "mfcr")))
13043    (set_attr "length" "8")])
13044
13045 (define_insn ""
13046   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13047         (compare:CC
13048          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13049                                        [(match_operand 2 "cc_reg_operand" "y,y")
13050                                         (const_int 0)])
13051                     (match_operand:SI 3 "const_int_operand" "n,n"))
13052          (const_int 0)))
13053    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
13054         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13055                    (match_dup 3)))]
13056   ""
13057   "*
13058 {
13059   int is_bit = ccr_bit (operands[1], 1);
13060   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13061   int count;
13062
13063   /* Force split for non-cc0 compare.  */
13064   if (which_alternative == 1)
13065      return \"#\";
13066
13067   if (is_bit >= put_bit)
13068     count = is_bit - put_bit;
13069   else
13070     count = 32 - (put_bit - is_bit);
13071
13072   operands[5] = GEN_INT (count);
13073   operands[6] = GEN_INT (put_bit);
13074
13075   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
13076 }"
13077   [(set_attr "type" "delayed_compare")
13078    (set_attr "length" "8,16")])
13079
13080 (define_split
13081   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13082         (compare:CC
13083          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13084                                        [(match_operand 2 "cc_reg_operand" "")
13085                                         (const_int 0)])
13086                     (match_operand:SI 3 "const_int_operand" ""))
13087          (const_int 0)))
13088    (set (match_operand:SI 4 "gpc_reg_operand" "")
13089         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13090                    (match_dup 3)))]
13091   "reload_completed"
13092   [(set (match_dup 4)
13093         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13094                    (match_dup 3)))
13095    (set (match_dup 0)
13096         (compare:CC (match_dup 4)
13097                     (const_int 0)))]
13098   "")
13099
13100 ;; There is a 3 cycle delay between consecutive mfcr instructions
13101 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13102
13103 (define_peephole
13104   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13105         (match_operator:SI 1 "scc_comparison_operator"
13106                            [(match_operand 2 "cc_reg_operand" "y")
13107                             (const_int 0)]))
13108    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13109         (match_operator:SI 4 "scc_comparison_operator"
13110                            [(match_operand 5 "cc_reg_operand" "y")
13111                             (const_int 0)]))]
13112   "REGNO (operands[2]) != REGNO (operands[5])"
13113   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13114   [(set_attr "type" "mfcr")
13115    (set_attr "length" "12")])
13116
13117 (define_peephole
13118   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13119         (match_operator:DI 1 "scc_comparison_operator"
13120                            [(match_operand 2 "cc_reg_operand" "y")
13121                             (const_int 0)]))
13122    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13123         (match_operator:DI 4 "scc_comparison_operator"
13124                            [(match_operand 5 "cc_reg_operand" "y")
13125                             (const_int 0)]))]
13126   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13127   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13128   [(set_attr "type" "mfcr")
13129    (set_attr "length" "12")])
13130
13131 ;; There are some scc insns that can be done directly, without a compare.
13132 ;; These are faster because they don't involve the communications between
13133 ;; the FXU and branch units.   In fact, we will be replacing all of the
13134 ;; integer scc insns here or in the portable methods in emit_store_flag.
13135 ;;
13136 ;; Also support (neg (scc ..)) since that construct is used to replace
13137 ;; branches, (plus (scc ..) ..) since that construct is common and
13138 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13139 ;; cases where it is no more expensive than (neg (scc ..)).
13140
13141 ;; Have reload force a constant into a register for the simple insns that
13142 ;; otherwise won't accept constants.  We do this because it is faster than
13143 ;; the cmp/mfcr sequence we would otherwise generate.
13144
13145 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13146                               (DI "rKJI")])
13147
13148 (define_insn_and_split "*eq<mode>"
13149   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13150         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13151                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13152   "!TARGET_POWER"
13153   "#"
13154   "!TARGET_POWER"
13155   [(set (match_dup 0)
13156         (clz:GPR (match_dup 3)))
13157    (set (match_dup 0)
13158         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13159   {
13160     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13161       {
13162         /* Use output operand as intermediate.  */
13163         operands[3] = operands[0];
13164
13165         if (logical_operand (operands[2], <MODE>mode))
13166           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13167                                   gen_rtx_XOR (<MODE>mode,
13168                                                operands[1], operands[2])));
13169         else
13170           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13171                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13172                                                 negate_rtx (<MODE>mode,
13173                                                             operands[2]))));
13174       }
13175     else
13176       operands[3] = operands[1];
13177
13178     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13179   })
13180
13181 (define_insn_and_split "*eq<mode>_compare"
13182   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13183         (compare:CC
13184          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13185                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13186          (const_int 0)))
13187    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13188         (eq:P (match_dup 1) (match_dup 2)))]
13189   "!TARGET_POWER && optimize_size"
13190   "#"
13191   "!TARGET_POWER && optimize_size"
13192   [(set (match_dup 0)
13193         (clz:P (match_dup 4)))
13194    (parallel [(set (match_dup 3)
13195                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13196                                (const_int 0)))
13197               (set (match_dup 0)
13198                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13199   {
13200     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13201       {
13202         /* Use output operand as intermediate.  */
13203         operands[4] = operands[0];
13204
13205         if (logical_operand (operands[2], <MODE>mode))
13206           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13207                                   gen_rtx_XOR (<MODE>mode,
13208                                                operands[1], operands[2])));
13209         else
13210           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13211                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13212                                                 negate_rtx (<MODE>mode,
13213                                                             operands[2]))));
13214       }
13215     else
13216       operands[4] = operands[1];
13217
13218     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13219   })
13220
13221 (define_insn "*eqsi_power"
13222   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
13223         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13224                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
13225    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
13226   "TARGET_POWER"
13227   "@
13228    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13229    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
13230    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13231    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13232    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
13233   [(set_attr "type" "three,two,three,three,three")
13234    (set_attr "length" "12,8,12,12,12")])
13235
13236 ;; We have insns of the form shown by the first define_insn below.  If
13237 ;; there is something inside the comparison operation, we must split it.
13238 (define_split
13239   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13240         (plus:SI (match_operator 1 "comparison_operator"
13241                                  [(match_operand:SI 2 "" "")
13242                                   (match_operand:SI 3
13243                                                     "reg_or_cint_operand" "")])
13244                  (match_operand:SI 4 "gpc_reg_operand" "")))
13245    (clobber (match_operand:SI 5 "register_operand" ""))]
13246   "! gpc_reg_operand (operands[2], SImode)"
13247   [(set (match_dup 5) (match_dup 2))
13248    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
13249                                (match_dup 4)))])
13250
13251 (define_insn "*plus_eqsi"
13252   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13253         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13254                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13255                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13256   "TARGET_32BIT"
13257   "@
13258    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13259    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
13260    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13261    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13262    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
13263   [(set_attr "type" "three,two,three,three,three")
13264    (set_attr "length" "12,8,12,12,12")])
13265
13266 (define_insn "*compare_plus_eqsi"
13267   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13268         (compare:CC
13269          (plus:SI
13270           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13271                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13272           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13273          (const_int 0)))
13274    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13275   "TARGET_32BIT && optimize_size"
13276   "@
13277    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13278    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
13279    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13280    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13281    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13282    #
13283    #
13284    #
13285    #
13286    #"
13287   [(set_attr "type" "compare")
13288    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13289
13290 (define_split
13291   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13292         (compare:CC
13293          (plus:SI
13294           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13295                  (match_operand:SI 2 "scc_eq_operand" ""))
13296           (match_operand:SI 3 "gpc_reg_operand" ""))
13297          (const_int 0)))
13298    (clobber (match_scratch:SI 4 ""))]
13299   "TARGET_32BIT && optimize_size && reload_completed"
13300   [(set (match_dup 4)
13301         (plus:SI (eq:SI (match_dup 1)
13302                  (match_dup 2))
13303           (match_dup 3)))
13304    (set (match_dup 0)
13305         (compare:CC (match_dup 4)
13306                     (const_int 0)))]
13307   "")
13308
13309 (define_insn "*plus_eqsi_compare"
13310   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13311         (compare:CC
13312          (plus:SI
13313           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13314                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13315           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13316          (const_int 0)))
13317    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13318         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13319   "TARGET_32BIT && optimize_size"
13320   "@
13321    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13322    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
13323    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13324    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13325    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13326    #
13327    #
13328    #
13329    #
13330    #"
13331   [(set_attr "type" "compare")
13332    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13333
13334 (define_split
13335   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13336         (compare:CC
13337          (plus:SI
13338           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13339                  (match_operand:SI 2 "scc_eq_operand" ""))
13340           (match_operand:SI 3 "gpc_reg_operand" ""))
13341          (const_int 0)))
13342    (set (match_operand:SI 0 "gpc_reg_operand" "")
13343         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13344   "TARGET_32BIT && optimize_size && reload_completed"
13345   [(set (match_dup 0)
13346         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13347    (set (match_dup 4)
13348         (compare:CC (match_dup 0)
13349                     (const_int 0)))]
13350   "")
13351
13352 (define_insn "*neg_eq0<mode>"
13353   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13354         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13355                      (const_int 0))))]
13356   ""
13357   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
13358   [(set_attr "type" "two")
13359    (set_attr "length" "8")])
13360
13361 (define_insn_and_split "*neg_eq<mode>"
13362   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13363         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
13364                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
13365   ""
13366   "#"
13367   ""
13368   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
13369   {
13370     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13371       {
13372         /* Use output operand as intermediate.  */
13373         operands[3] = operands[0];
13374
13375         if (logical_operand (operands[2], <MODE>mode))
13376           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13377                                   gen_rtx_XOR (<MODE>mode,
13378                                                operands[1], operands[2])));
13379         else
13380           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13381                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13382                                                 negate_rtx (<MODE>mode,
13383                                                             operands[2]))));
13384       }
13385     else
13386       operands[3] = operands[1];
13387   })
13388
13389 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
13390 ;; since it nabs/sr is just as fast.
13391 (define_insn "*ne0si"
13392   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13393         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
13394                      (const_int 31)))
13395    (clobber (match_scratch:SI 2 "=&r"))]
13396   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
13397   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
13398   [(set_attr "type" "two")
13399    (set_attr "length" "8")])
13400
13401 (define_insn "*ne0di"
13402   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13403         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
13404                      (const_int 63)))
13405    (clobber (match_scratch:DI 2 "=&r"))]
13406   "TARGET_64BIT"
13407   "addic %2,%1,-1\;subfe %0,%2,%1"
13408   [(set_attr "type" "two")
13409    (set_attr "length" "8")])
13410
13411 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
13412 (define_insn "*plus_ne0si"
13413   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13414         (plus:SI (lshiftrt:SI
13415                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
13416                   (const_int 31))
13417                  (match_operand:SI 2 "gpc_reg_operand" "r")))
13418    (clobber (match_scratch:SI 3 "=&r"))]
13419   "TARGET_32BIT"
13420   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
13421   [(set_attr "type" "two")
13422    (set_attr "length" "8")])
13423
13424 (define_insn "*plus_ne0di"
13425   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13426         (plus:DI (lshiftrt:DI
13427                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
13428                   (const_int 63))
13429                  (match_operand:DI 2 "gpc_reg_operand" "r")))
13430    (clobber (match_scratch:DI 3 "=&r"))]
13431   "TARGET_64BIT"
13432   "addic %3,%1,-1\;addze %0,%2"
13433   [(set_attr "type" "two")
13434    (set_attr "length" "8")])
13435
13436 (define_insn "*compare_plus_ne0si"
13437   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13438         (compare:CC
13439          (plus:SI (lshiftrt:SI
13440                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
13441                    (const_int 31))
13442                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13443          (const_int 0)))
13444    (clobber (match_scratch:SI 3 "=&r,&r"))
13445    (clobber (match_scratch:SI 4 "=X,&r"))]
13446   "TARGET_32BIT"
13447   "@
13448    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
13449    #"
13450   [(set_attr "type" "compare")
13451    (set_attr "length" "8,12")])
13452
13453 (define_split
13454   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13455         (compare:CC
13456          (plus:SI (lshiftrt:SI
13457                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
13458                    (const_int 31))
13459                   (match_operand:SI 2 "gpc_reg_operand" ""))
13460          (const_int 0)))
13461    (clobber (match_scratch:SI 3 ""))
13462    (clobber (match_scratch:SI 4 ""))]
13463   "TARGET_32BIT && reload_completed"
13464   [(parallel [(set (match_dup 3)
13465                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
13466                                          (const_int 31))
13467                             (match_dup 2)))
13468               (clobber (match_dup 4))])
13469    (set (match_dup 0)
13470         (compare:CC (match_dup 3)
13471                     (const_int 0)))]
13472   "")
13473
13474 (define_insn "*compare_plus_ne0di"
13475   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13476         (compare:CC
13477          (plus:DI (lshiftrt:DI
13478                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
13479                    (const_int 63))
13480                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13481          (const_int 0)))
13482    (clobber (match_scratch:DI 3 "=&r,&r"))]
13483   "TARGET_64BIT"
13484   "@
13485    addic %3,%1,-1\;addze. %3,%2
13486    #"
13487   [(set_attr "type" "compare")
13488    (set_attr "length" "8,12")])
13489
13490 (define_split
13491   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13492         (compare:CC
13493          (plus:DI (lshiftrt:DI
13494                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
13495                    (const_int 63))
13496                   (match_operand:DI 2 "gpc_reg_operand" ""))
13497          (const_int 0)))
13498    (clobber (match_scratch:DI 3 ""))]
13499   "TARGET_64BIT && reload_completed"
13500   [(set (match_dup 3)
13501         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
13502                    (const_int 63))
13503                   (match_dup 2)))
13504    (set (match_dup 0)
13505         (compare:CC (match_dup 3)
13506                     (const_int 0)))]
13507   "")
13508
13509 (define_insn "*plus_ne0si_compare"
13510   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13511         (compare:CC
13512          (plus:SI (lshiftrt:SI
13513                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
13514                    (const_int 31))
13515                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13516          (const_int 0)))
13517    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13518         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13519                  (match_dup 2)))
13520    (clobber (match_scratch:SI 3 "=&r,&r"))]
13521   "TARGET_32BIT"
13522   "@
13523    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
13524    #"
13525   [(set_attr "type" "compare")
13526    (set_attr "length" "8,12")])
13527
13528 (define_split
13529   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13530         (compare:CC
13531          (plus:SI (lshiftrt:SI
13532                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
13533                    (const_int 31))
13534                   (match_operand:SI 2 "gpc_reg_operand" ""))
13535          (const_int 0)))
13536    (set (match_operand:SI 0 "gpc_reg_operand" "")
13537         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13538                  (match_dup 2)))
13539    (clobber (match_scratch:SI 3 ""))]
13540   "TARGET_32BIT && reload_completed"
13541   [(parallel [(set (match_dup 0)
13542         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13543                  (match_dup 2)))
13544    (clobber (match_dup 3))])
13545    (set (match_dup 4)
13546         (compare:CC (match_dup 0)
13547                     (const_int 0)))]
13548   "")
13549
13550 (define_insn "*plus_ne0di_compare"
13551   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13552         (compare:CC
13553          (plus:DI (lshiftrt:DI
13554                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
13555                    (const_int 63))
13556                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13557          (const_int 0)))
13558    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13559         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13560                  (match_dup 2)))
13561    (clobber (match_scratch:DI 3 "=&r,&r"))]
13562   "TARGET_64BIT"
13563   "@
13564    addic %3,%1,-1\;addze. %0,%2
13565    #"
13566   [(set_attr "type" "compare")
13567    (set_attr "length" "8,12")])
13568
13569 (define_split
13570   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
13571         (compare:CC
13572          (plus:DI (lshiftrt:DI
13573                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
13574                    (const_int 63))
13575                   (match_operand:DI 2 "gpc_reg_operand" ""))
13576          (const_int 0)))
13577    (set (match_operand:DI 0 "gpc_reg_operand" "")
13578         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13579                  (match_dup 2)))
13580    (clobber (match_scratch:DI 3 ""))]
13581   "TARGET_64BIT && reload_completed"
13582   [(parallel [(set (match_dup 0)
13583         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13584                  (match_dup 2)))
13585    (clobber (match_dup 3))])
13586    (set (match_dup 4)
13587         (compare:CC (match_dup 0)
13588                     (const_int 0)))]
13589   "")
13590
13591 (define_insn ""
13592   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13593         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13594                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
13595    (clobber (match_scratch:SI 3 "=r,X"))]
13596   "TARGET_POWER"
13597   "@
13598    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
13599    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
13600   [(set_attr "length" "12")])
13601
13602 (define_insn ""
13603   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13604         (compare:CC
13605          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13606                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13607          (const_int 0)))
13608    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
13609         (le:SI (match_dup 1) (match_dup 2)))
13610    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
13611   "TARGET_POWER"
13612   "@
13613    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
13614    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
13615    #
13616    #"
13617   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
13618    (set_attr "length" "12,12,16,16")])
13619
13620 (define_split
13621   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13622         (compare:CC
13623          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13624                 (match_operand:SI 2 "reg_or_short_operand" ""))
13625          (const_int 0)))
13626    (set (match_operand:SI 0 "gpc_reg_operand" "")
13627         (le:SI (match_dup 1) (match_dup 2)))
13628    (clobber (match_scratch:SI 3 ""))]
13629   "TARGET_POWER && reload_completed"
13630   [(parallel [(set (match_dup 0)
13631         (le:SI (match_dup 1) (match_dup 2)))
13632    (clobber (match_dup 3))])
13633    (set (match_dup 4)
13634         (compare:CC (match_dup 0)
13635                     (const_int 0)))]
13636   "")
13637
13638 (define_insn ""
13639   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13640         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13641                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
13642                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
13643   "TARGET_POWER"
13644   "@
13645    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13646    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
13647   [(set_attr "length" "12")])
13648
13649 (define_insn ""
13650   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13651         (compare:CC
13652          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13653                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13654                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13655          (const_int 0)))
13656    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13657   "TARGET_POWER"
13658   "@
13659    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13660    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
13661    #
13662    #"
13663   [(set_attr "type" "compare")
13664    (set_attr "length" "12,12,16,16")])
13665
13666 (define_split
13667   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13668         (compare:CC
13669          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13670                          (match_operand:SI 2 "reg_or_short_operand" ""))
13671                   (match_operand:SI 3 "gpc_reg_operand" ""))
13672          (const_int 0)))
13673    (clobber (match_scratch:SI 4 ""))]
13674   "TARGET_POWER && reload_completed"
13675   [(set (match_dup 4)
13676         (plus:SI (le:SI (match_dup 1) (match_dup 2))
13677                  (match_dup 3)))
13678    (set (match_dup 0)
13679         (compare:CC (match_dup 4)
13680                     (const_int 0)))]
13681   "")
13682
13683 (define_insn ""
13684   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13685         (compare:CC
13686          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13687                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13688                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13689          (const_int 0)))
13690    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13691         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13692   "TARGET_POWER"
13693   "@
13694    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13695    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
13696    #
13697    #"
13698   [(set_attr "type" "compare")
13699    (set_attr "length" "12,12,16,16")])
13700
13701 (define_split
13702   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13703         (compare:CC
13704          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13705                          (match_operand:SI 2 "reg_or_short_operand" ""))
13706                   (match_operand:SI 3 "gpc_reg_operand" ""))
13707          (const_int 0)))
13708    (set (match_operand:SI 0 "gpc_reg_operand" "")
13709         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13710   "TARGET_POWER && reload_completed"
13711   [(set (match_dup 0)
13712         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13713    (set (match_dup 4)
13714         (compare:CC (match_dup 0)
13715                     (const_int 0)))]
13716   "")
13717
13718 (define_insn ""
13719   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13720         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13721                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
13722   "TARGET_POWER"
13723   "@
13724    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
13725    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
13726   [(set_attr "length" "12")])
13727
13728 (define_insn "*leu<mode>"
13729   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13730         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13731                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13732   ""
13733   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
13734   [(set_attr "type" "three")
13735    (set_attr "length" "12")])
13736
13737 (define_insn "*leu<mode>_compare"
13738   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13739         (compare:CC
13740          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13741                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13742          (const_int 0)))
13743    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13744         (leu:P (match_dup 1) (match_dup 2)))]
13745   ""
13746   "@
13747    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
13748    #"
13749   [(set_attr "type" "compare")
13750    (set_attr "length" "12,16")])
13751
13752 (define_split
13753   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13754         (compare:CC
13755          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
13756                 (match_operand:P 2 "reg_or_short_operand" ""))
13757          (const_int 0)))
13758    (set (match_operand:P 0 "gpc_reg_operand" "")
13759         (leu:P (match_dup 1) (match_dup 2)))]
13760   "reload_completed"
13761   [(set (match_dup 0)
13762         (leu:P (match_dup 1) (match_dup 2)))
13763    (set (match_dup 3)
13764         (compare:CC (match_dup 0)
13765                     (const_int 0)))]
13766   "")
13767
13768 (define_insn "*plus_leu<mode>"
13769   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13770         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13771                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13772                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13773   ""
13774   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
13775   [(set_attr "type" "two")
13776    (set_attr "length" "8")])
13777
13778 (define_insn ""
13779   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13780         (compare:CC
13781          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13782                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13783                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13784          (const_int 0)))
13785    (clobber (match_scratch:SI 4 "=&r,&r"))]
13786   "TARGET_32BIT"
13787   "@
13788    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
13789    #"
13790   [(set_attr "type" "compare")
13791    (set_attr "length" "8,12")])
13792
13793 (define_split
13794   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13795         (compare:CC
13796          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13797                           (match_operand:SI 2 "reg_or_short_operand" ""))
13798                   (match_operand:SI 3 "gpc_reg_operand" ""))
13799          (const_int 0)))
13800    (clobber (match_scratch:SI 4 ""))]
13801   "TARGET_32BIT && reload_completed"
13802   [(set (match_dup 4)
13803         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
13804                   (match_dup 3)))
13805    (set (match_dup 0)
13806         (compare:CC (match_dup 4)
13807                     (const_int 0)))]
13808   "")
13809
13810 (define_insn ""
13811   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13812         (compare:CC
13813          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13814                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13815                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13816          (const_int 0)))
13817    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13818         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13819   "TARGET_32BIT"
13820   "@
13821    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
13822    #"
13823   [(set_attr "type" "compare")
13824    (set_attr "length" "8,12")])
13825
13826 (define_split
13827   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13828         (compare:CC
13829          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13830                           (match_operand:SI 2 "reg_or_short_operand" ""))
13831                   (match_operand:SI 3 "gpc_reg_operand" ""))
13832          (const_int 0)))
13833    (set (match_operand:SI 0 "gpc_reg_operand" "")
13834         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13835   "TARGET_32BIT && reload_completed"
13836   [(set (match_dup 0)
13837         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13838    (set (match_dup 4)
13839         (compare:CC (match_dup 0)
13840                     (const_int 0)))]
13841   "")
13842
13843 (define_insn "*neg_leu<mode>"
13844   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13845         (neg:P (leu: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\;nand %0,%0,%0"
13849    [(set_attr "type" "three")
13850     (set_attr "length" "12")])
13851
13852 (define_insn "*and_neg_leu<mode>"
13853   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13854         (and:P (neg:P
13855                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13856                         (match_operand:P 2 "reg_or_short_operand" "rI")))
13857                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13858   ""
13859   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
13860   [(set_attr "type" "three")
13861    (set_attr "length" "12")])
13862
13863 (define_insn ""
13864   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13865         (compare:CC
13866          (and:SI (neg:SI
13867                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13868                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13869                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13870          (const_int 0)))
13871    (clobber (match_scratch:SI 4 "=&r,&r"))]
13872   "TARGET_32BIT"
13873   "@
13874    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13875    #"
13876   [(set_attr "type" "compare")
13877    (set_attr "length" "12,16")])
13878
13879 (define_split
13880   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13881         (compare:CC
13882          (and:SI (neg:SI
13883                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13884                           (match_operand:SI 2 "reg_or_short_operand" "")))
13885                  (match_operand:SI 3 "gpc_reg_operand" ""))
13886          (const_int 0)))
13887    (clobber (match_scratch:SI 4 ""))]
13888   "TARGET_32BIT && reload_completed"
13889   [(set (match_dup 4)
13890         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13891                 (match_dup 3)))
13892    (set (match_dup 0)
13893         (compare:CC (match_dup 4)
13894                     (const_int 0)))]
13895   "")
13896
13897 (define_insn ""
13898   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13899         (compare:CC
13900          (and:SI (neg:SI
13901                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13902                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13903                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13904          (const_int 0)))
13905    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13906         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13907   "TARGET_32BIT"
13908   "@
13909    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13910    #"
13911   [(set_attr "type" "compare")
13912    (set_attr "length" "12,16")])
13913
13914 (define_split
13915   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13916         (compare:CC
13917          (and:SI (neg:SI
13918                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13919                           (match_operand:SI 2 "reg_or_short_operand" "")))
13920                  (match_operand:SI 3 "gpc_reg_operand" ""))
13921          (const_int 0)))
13922    (set (match_operand:SI 0 "gpc_reg_operand" "")
13923         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13924   "TARGET_32BIT && reload_completed"
13925   [(set (match_dup 0)
13926         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13927                 (match_dup 3)))
13928    (set (match_dup 4)
13929         (compare:CC (match_dup 0)
13930                     (const_int 0)))]
13931   "")
13932
13933 (define_insn ""
13934   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13935         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13936                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13937   "TARGET_POWER"
13938   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13939    [(set_attr "length" "12")])
13940
13941 (define_insn ""
13942   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13943         (compare:CC
13944          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13945                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13946          (const_int 0)))
13947    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13948         (lt:SI (match_dup 1) (match_dup 2)))]
13949   "TARGET_POWER"
13950   "@
13951    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13952    #"
13953   [(set_attr "type" "delayed_compare")
13954    (set_attr "length" "12,16")])
13955
13956 (define_split
13957   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13958         (compare:CC
13959          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13960                 (match_operand:SI 2 "reg_or_short_operand" ""))
13961          (const_int 0)))
13962    (set (match_operand:SI 0 "gpc_reg_operand" "")
13963         (lt:SI (match_dup 1) (match_dup 2)))]
13964   "TARGET_POWER && reload_completed"
13965   [(set (match_dup 0)
13966         (lt:SI (match_dup 1) (match_dup 2)))
13967    (set (match_dup 3)
13968         (compare:CC (match_dup 0)
13969                     (const_int 0)))]
13970   "")
13971
13972 (define_insn ""
13973   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13974         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13975                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
13976                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13977   "TARGET_POWER"
13978   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13979   [(set_attr "length" "12")])
13980
13981 (define_insn ""
13982   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13983         (compare:CC
13984          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13985                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13986                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13987          (const_int 0)))
13988    (clobber (match_scratch:SI 4 "=&r,&r"))]
13989   "TARGET_POWER"
13990   "@
13991    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13992    #"
13993   [(set_attr "type" "compare")
13994    (set_attr "length" "12,16")])
13995
13996 (define_split
13997   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13998         (compare:CC
13999          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14000                          (match_operand:SI 2 "reg_or_short_operand" ""))
14001                   (match_operand:SI 3 "gpc_reg_operand" ""))
14002          (const_int 0)))
14003    (clobber (match_scratch:SI 4 ""))]
14004   "TARGET_POWER && reload_completed"
14005   [(set (match_dup 4)
14006         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
14007                  (match_dup 3)))
14008    (set (match_dup 0)
14009         (compare:CC (match_dup 4)
14010                     (const_int 0)))]
14011   "")
14012
14013 (define_insn ""
14014   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14015         (compare:CC
14016          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14017                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14018                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14019          (const_int 0)))
14020    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14021         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14022   "TARGET_POWER"
14023   "@
14024    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
14025    #"
14026   [(set_attr "type" "compare")
14027    (set_attr "length" "12,16")])
14028
14029 (define_split
14030   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14031         (compare:CC
14032          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14033                          (match_operand:SI 2 "reg_or_short_operand" ""))
14034                   (match_operand:SI 3 "gpc_reg_operand" ""))
14035          (const_int 0)))
14036    (set (match_operand:SI 0 "gpc_reg_operand" "")
14037         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14038   "TARGET_POWER && reload_completed"
14039   [(set (match_dup 0)
14040         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14041    (set (match_dup 4)
14042         (compare:CC (match_dup 0)
14043                     (const_int 0)))]
14044   "")
14045
14046 (define_insn ""
14047   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14048         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14049                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14050   "TARGET_POWER"
14051   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
14052   [(set_attr "length" "12")])
14053
14054 (define_insn_and_split "*ltu<mode>"
14055   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14056         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14057                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14058   ""
14059   "#"
14060   ""
14061   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14062    (set (match_dup 0) (neg:P (match_dup 0)))]
14063   "")
14064
14065 (define_insn_and_split "*ltu<mode>_compare"
14066   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14067         (compare:CC
14068          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14069                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14070          (const_int 0)))
14071    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14072         (ltu:P (match_dup 1) (match_dup 2)))]
14073   ""
14074   "#"
14075   ""
14076   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14077    (parallel [(set (match_dup 3)
14078                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14079               (set (match_dup 0) (neg:P (match_dup 0)))])]
14080   "")
14081
14082 (define_insn_and_split "*plus_ltu<mode>"
14083   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
14084         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14085                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14086                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
14087   ""
14088   "#"
14089   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14090   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14091    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14092   "")
14093
14094 (define_insn_and_split "*plus_ltu<mode>_compare"
14095   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14096         (compare:CC
14097          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14098                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14099                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14100          (const_int 0)))
14101    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14102         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14103   ""
14104   "#"
14105   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14106   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14107    (parallel [(set (match_dup 4)
14108                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14109                                (const_int 0)))
14110               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14111   "")
14112
14113 (define_insn "*neg_ltu<mode>"
14114   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14115         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14116                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
14117   ""
14118   "@
14119    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
14120    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
14121   [(set_attr "type" "two")
14122    (set_attr "length" "8")])
14123
14124 (define_insn ""
14125   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14126         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14127                (match_operand:SI 2 "reg_or_short_operand" "rI")))
14128    (clobber (match_scratch:SI 3 "=r"))]
14129   "TARGET_POWER"
14130   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
14131    [(set_attr "length" "12")])
14132
14133 (define_insn ""
14134   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14135         (compare:CC
14136          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14137                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14138          (const_int 0)))
14139    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14140         (ge:SI (match_dup 1) (match_dup 2)))
14141    (clobber (match_scratch:SI 3 "=r,r"))]
14142   "TARGET_POWER"
14143   "@
14144    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14145    #"
14146   [(set_attr "type" "compare")
14147    (set_attr "length" "12,16")])
14148
14149 (define_split
14150   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14151         (compare:CC
14152          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14153                 (match_operand:SI 2 "reg_or_short_operand" ""))
14154          (const_int 0)))
14155    (set (match_operand:SI 0 "gpc_reg_operand" "")
14156         (ge:SI (match_dup 1) (match_dup 2)))
14157    (clobber (match_scratch:SI 3 ""))]
14158   "TARGET_POWER && reload_completed"
14159   [(parallel [(set (match_dup 0)
14160                    (ge:SI (match_dup 1) (match_dup 2)))
14161               (clobber (match_dup 3))])
14162    (set (match_dup 4)
14163         (compare:CC (match_dup 0)
14164                     (const_int 0)))]
14165   "")
14166
14167 (define_insn ""
14168   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14169         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14170                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14171                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14172   "TARGET_POWER"
14173   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
14174   [(set_attr "length" "12")])
14175
14176 (define_insn ""
14177   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14178         (compare:CC
14179          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14180                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14181                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14182          (const_int 0)))
14183    (clobber (match_scratch:SI 4 "=&r,&r"))]
14184   "TARGET_POWER"
14185   "@
14186    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14187    #"
14188   [(set_attr "type" "compare")
14189    (set_attr "length" "12,16")])
14190
14191 (define_split
14192   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14193         (compare:CC
14194          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14195                          (match_operand:SI 2 "reg_or_short_operand" ""))
14196                   (match_operand:SI 3 "gpc_reg_operand" ""))
14197          (const_int 0)))
14198    (clobber (match_scratch:SI 4 ""))]
14199   "TARGET_POWER && reload_completed"
14200   [(set (match_dup 4)
14201         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
14202                  (match_dup 3)))
14203    (set (match_dup 0)
14204         (compare:CC (match_dup 4)
14205                     (const_int 0)))]
14206   "")
14207
14208 (define_insn ""
14209   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14210         (compare:CC
14211          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14212                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14213                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14214          (const_int 0)))
14215    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14216         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14217   "TARGET_POWER"
14218   "@
14219    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14220    #"
14221   [(set_attr "type" "compare")
14222    (set_attr "length" "12,16")])
14223
14224 (define_split
14225   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14226         (compare:CC
14227          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14228                          (match_operand:SI 2 "reg_or_short_operand" ""))
14229                   (match_operand:SI 3 "gpc_reg_operand" ""))
14230          (const_int 0)))
14231    (set (match_operand:SI 0 "gpc_reg_operand" "")
14232         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14233   "TARGET_POWER && reload_completed"
14234   [(set (match_dup 0)
14235         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14236    (set (match_dup 4)
14237         (compare:CC (match_dup 0)
14238                     (const_int 0)))]
14239   "")
14240
14241 (define_insn ""
14242   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14243         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14244                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14245   "TARGET_POWER"
14246   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
14247   [(set_attr "length" "12")])
14248
14249 (define_insn "*geu<mode>"
14250   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14251         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14252                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14253   ""
14254   "@
14255    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
14256    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14257   [(set_attr "type" "three")
14258    (set_attr "length" "12")])
14259
14260 (define_insn "*geu<mode>_compare"
14261   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14262         (compare:CC
14263          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14264                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14265          (const_int 0)))
14266    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14267         (geu:P (match_dup 1) (match_dup 2)))]
14268   ""
14269   "@
14270    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14271    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14272    #
14273    #"
14274   [(set_attr "type" "compare")
14275    (set_attr "length" "12,12,16,16")])
14276
14277 (define_split
14278   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14279         (compare:CC
14280          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
14281                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
14282          (const_int 0)))
14283    (set (match_operand:P 0 "gpc_reg_operand" "")
14284         (geu:P (match_dup 1) (match_dup 2)))]
14285   "reload_completed"
14286   [(set (match_dup 0)
14287         (geu:P (match_dup 1) (match_dup 2)))
14288    (set (match_dup 3)
14289         (compare:CC (match_dup 0)
14290                     (const_int 0)))]
14291   "")
14292
14293 (define_insn "*plus_geu<mode>"
14294   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14295         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14296                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14297                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14298   ""
14299   "@
14300    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
14301    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
14302   [(set_attr "type" "two")
14303    (set_attr "length" "8")])
14304
14305 (define_insn ""
14306   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14307         (compare:CC
14308          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14309                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14310                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14311          (const_int 0)))
14312    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14313   "TARGET_32BIT"
14314   "@
14315    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
14316    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
14317    #
14318    #"
14319   [(set_attr "type" "compare")
14320    (set_attr "length" "8,8,12,12")])
14321
14322 (define_split
14323   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14324         (compare:CC
14325          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14326                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14327                   (match_operand:SI 3 "gpc_reg_operand" ""))
14328          (const_int 0)))
14329    (clobber (match_scratch:SI 4 ""))]
14330   "TARGET_32BIT && reload_completed"
14331   [(set (match_dup 4)
14332         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
14333                   (match_dup 3)))
14334    (set (match_dup 0)
14335         (compare:CC (match_dup 4)
14336                     (const_int 0)))]
14337   "")
14338
14339 (define_insn ""
14340   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14341         (compare:CC
14342          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14343                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14344                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14345          (const_int 0)))
14346    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14347         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14348   "TARGET_32BIT"
14349   "@
14350    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
14351    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
14352    #
14353    #"
14354   [(set_attr "type" "compare")
14355    (set_attr "length" "8,8,12,12")])
14356
14357 (define_split
14358   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14359         (compare:CC
14360          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14361                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14362                   (match_operand:SI 3 "gpc_reg_operand" ""))
14363          (const_int 0)))
14364    (set (match_operand:SI 0 "gpc_reg_operand" "")
14365         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14366   "TARGET_32BIT && reload_completed"
14367   [(set (match_dup 0)
14368         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14369    (set (match_dup 4)
14370         (compare:CC (match_dup 0)
14371                     (const_int 0)))]
14372   "")
14373
14374 (define_insn "*neg_geu<mode>"
14375   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14376         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14377                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
14378   ""
14379   "@
14380    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
14381    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
14382   [(set_attr "type" "three")
14383    (set_attr "length" "12")])
14384
14385 (define_insn "*and_neg_geu<mode>"
14386   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14387         (and:P (neg:P
14388                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14389                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
14390                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14391   ""
14392   "@
14393    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
14394    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
14395   [(set_attr "type" "three")
14396    (set_attr "length" "12")])
14397
14398 (define_insn ""
14399   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14400         (compare:CC
14401          (and:SI (neg:SI
14402                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14403                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14404                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14405          (const_int 0)))
14406    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14407   "TARGET_32BIT"
14408   "@
14409    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14410    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14411    #
14412    #"
14413   [(set_attr "type" "compare")
14414    (set_attr "length" "12,12,16,16")])
14415
14416 (define_split
14417   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14418         (compare:CC
14419          (and:SI (neg:SI
14420                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14421                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14422                  (match_operand:SI 3 "gpc_reg_operand" ""))
14423          (const_int 0)))
14424    (clobber (match_scratch:SI 4 ""))]
14425   "TARGET_32BIT && reload_completed"
14426   [(set (match_dup 4)
14427         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
14428                 (match_dup 3)))
14429    (set (match_dup 0)
14430         (compare:CC (match_dup 4)
14431                     (const_int 0)))]
14432   "")
14433
14434 (define_insn ""
14435   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14436         (compare:CC
14437          (and:SI (neg:SI
14438                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14439                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14440                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14441          (const_int 0)))
14442    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14443         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14444   "TARGET_32BIT"
14445   "@
14446    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14447    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14448    #
14449    #"
14450   [(set_attr "type" "compare")
14451    (set_attr "length" "12,12,16,16")])
14452
14453 (define_split
14454   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14455         (compare:CC
14456          (and:SI (neg:SI
14457                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14458                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14459                  (match_operand:SI 3 "gpc_reg_operand" ""))
14460          (const_int 0)))
14461    (set (match_operand:SI 0 "gpc_reg_operand" "")
14462         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14463   "TARGET_32BIT && reload_completed"
14464   [(set (match_dup 0)
14465         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
14466    (set (match_dup 4)
14467         (compare:CC (match_dup 0)
14468                     (const_int 0)))]
14469   "")
14470
14471 (define_insn ""
14472   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14473         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14474                (match_operand:SI 2 "reg_or_short_operand" "r")))]
14475   "TARGET_POWER"
14476   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
14477   [(set_attr "length" "12")])
14478
14479 (define_insn ""
14480   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14481         (compare:CC
14482          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14483                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14484          (const_int 0)))
14485    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14486         (gt:SI (match_dup 1) (match_dup 2)))]
14487   "TARGET_POWER"
14488   "@
14489    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
14490    #"
14491   [(set_attr "type" "delayed_compare")
14492    (set_attr "length" "12,16")])
14493
14494 (define_split
14495   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14496         (compare:CC
14497          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14498                 (match_operand:SI 2 "reg_or_short_operand" ""))
14499          (const_int 0)))
14500    (set (match_operand:SI 0 "gpc_reg_operand" "")
14501         (gt:SI (match_dup 1) (match_dup 2)))]
14502   "TARGET_POWER && reload_completed"
14503   [(set (match_dup 0)
14504         (gt:SI (match_dup 1) (match_dup 2)))
14505    (set (match_dup 3)
14506         (compare:CC (match_dup 0)
14507                     (const_int 0)))]
14508   "")
14509
14510 (define_insn "*plus_gt0<mode>"
14511   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14512         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
14513                       (const_int 0))
14514                  (match_operand:P 2 "gpc_reg_operand" "r")))]
14515   ""
14516   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
14517   [(set_attr "type" "three")
14518    (set_attr "length" "12")])
14519
14520 (define_insn ""
14521   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14522         (compare:CC
14523          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14524                          (const_int 0))
14525                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14526          (const_int 0)))
14527    (clobber (match_scratch:SI 3 "=&r,&r"))]
14528   "TARGET_32BIT"
14529   "@
14530    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
14531    #"
14532   [(set_attr "type" "compare")
14533    (set_attr "length" "12,16")])
14534
14535 (define_split
14536   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14537         (compare:CC
14538          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14539                          (const_int 0))
14540                   (match_operand:SI 2 "gpc_reg_operand" ""))
14541          (const_int 0)))
14542    (clobber (match_scratch:SI 3 ""))]
14543   "TARGET_32BIT && reload_completed"
14544   [(set (match_dup 3)
14545         (plus:SI (gt:SI (match_dup 1) (const_int 0))
14546                   (match_dup 2)))
14547    (set (match_dup 0)
14548         (compare:CC (match_dup 3)
14549                     (const_int 0)))]
14550   "")
14551
14552 (define_insn ""
14553   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14554         (compare:CC
14555          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14556                          (const_int 0))
14557                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14558          (const_int 0)))
14559    (clobber (match_scratch:DI 3 "=&r,&r"))]
14560   "TARGET_64BIT"
14561   "@
14562    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14563    #"
14564   [(set_attr "type" "compare")
14565    (set_attr "length" "12,16")])
14566
14567 (define_split
14568   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14569         (compare:CC
14570          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14571                          (const_int 0))
14572                   (match_operand:DI 2 "gpc_reg_operand" ""))
14573          (const_int 0)))
14574    (clobber (match_scratch:DI 3 ""))]
14575   "TARGET_64BIT && reload_completed"
14576   [(set (match_dup 3)
14577         (plus:DI (gt:DI (match_dup 1) (const_int 0))
14578                  (match_dup 2)))
14579    (set (match_dup 0)
14580         (compare:CC (match_dup 3)
14581                     (const_int 0)))]
14582   "")
14583
14584 (define_insn ""
14585   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14586         (compare:CC
14587          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14588                          (const_int 0))
14589                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14590          (const_int 0)))
14591    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14592         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14593   "TARGET_32BIT"
14594   "@
14595    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
14596    #"
14597   [(set_attr "type" "compare")
14598    (set_attr "length" "12,16")])
14599
14600 (define_split
14601   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14602         (compare:CC
14603          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14604                          (const_int 0))
14605                   (match_operand:SI 2 "gpc_reg_operand" ""))
14606          (const_int 0)))
14607    (set (match_operand:SI 0 "gpc_reg_operand" "")
14608         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14609   "TARGET_32BIT && reload_completed"
14610   [(set (match_dup 0)
14611         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
14612    (set (match_dup 3)
14613         (compare:CC (match_dup 0)
14614                     (const_int 0)))]
14615   "")
14616
14617 (define_insn ""
14618   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14619         (compare:CC
14620          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14621                          (const_int 0))
14622                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14623          (const_int 0)))
14624    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
14625         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14626   "TARGET_64BIT"
14627   "@
14628    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14629    #"
14630   [(set_attr "type" "compare")
14631    (set_attr "length" "12,16")])
14632
14633 (define_split
14634   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14635         (compare:CC
14636          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14637                          (const_int 0))
14638                   (match_operand:DI 2 "gpc_reg_operand" ""))
14639          (const_int 0)))
14640    (set (match_operand:DI 0 "gpc_reg_operand" "")
14641         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14642   "TARGET_64BIT && reload_completed"
14643   [(set (match_dup 0)
14644         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
14645    (set (match_dup 3)
14646         (compare:CC (match_dup 0)
14647                     (const_int 0)))]
14648   "")
14649
14650 (define_insn ""
14651   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14652         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14653                         (match_operand:SI 2 "reg_or_short_operand" "r"))
14654                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14655   "TARGET_POWER"
14656   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
14657   [(set_attr "length" "12")])
14658
14659 (define_insn ""
14660   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14661         (compare:CC
14662          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14663                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14664                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14665          (const_int 0)))
14666    (clobber (match_scratch:SI 4 "=&r,&r"))]
14667   "TARGET_POWER"
14668   "@
14669    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
14670    #"
14671   [(set_attr "type" "compare")
14672    (set_attr "length" "12,16")])
14673
14674 (define_split
14675   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14676         (compare:CC
14677          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14678                          (match_operand:SI 2 "reg_or_short_operand" ""))
14679                   (match_operand:SI 3 "gpc_reg_operand" ""))
14680          (const_int 0)))
14681    (clobber (match_scratch:SI 4 ""))]
14682   "TARGET_POWER && reload_completed"
14683   [(set (match_dup 4)
14684         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14685    (set (match_dup 0)
14686         (compare:CC (match_dup 4)
14687                     (const_int 0)))]
14688   "")
14689
14690 (define_insn ""
14691   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14692         (compare:CC
14693          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14694                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14695                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14696          (const_int 0)))
14697    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14698         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14699   "TARGET_POWER"
14700   "@
14701    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
14702    #"
14703   [(set_attr "type" "compare")
14704    (set_attr "length" "12,16")])
14705
14706 (define_split
14707   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14708         (compare:CC
14709          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14710                          (match_operand:SI 2 "reg_or_short_operand" ""))
14711                   (match_operand:SI 3 "gpc_reg_operand" ""))
14712          (const_int 0)))
14713    (set (match_operand:SI 0 "gpc_reg_operand" "")
14714         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14715   "TARGET_POWER && reload_completed"
14716   [(set (match_dup 0)
14717         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14718    (set (match_dup 4)
14719         (compare:CC (match_dup 0)
14720                     (const_int 0)))]
14721   "")
14722
14723 (define_insn ""
14724   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14725         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14726                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
14727   "TARGET_POWER"
14728   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
14729   [(set_attr "length" "12")])
14730
14731 (define_insn_and_split "*gtu<mode>"
14732   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14733         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14734                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14735   ""
14736   "#"
14737   ""
14738   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14739    (set (match_dup 0) (neg:P (match_dup 0)))]
14740   "")
14741
14742 (define_insn_and_split "*gtu<mode>_compare"
14743   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14744         (compare:CC
14745          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14746                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14747          (const_int 0)))
14748    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14749         (gtu:P (match_dup 1) (match_dup 2)))]
14750   ""
14751   "#"
14752   ""
14753   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14754    (parallel [(set (match_dup 3)
14755                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14756               (set (match_dup 0) (neg:P (match_dup 0)))])]
14757   "")
14758
14759 (define_insn_and_split "*plus_gtu<mode>"
14760   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14761         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14762                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14763                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
14764   ""
14765   "#"
14766   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14767   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14768    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14769   "")
14770
14771 (define_insn_and_split "*plus_gtu<mode>_compare"
14772   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14773         (compare:CC
14774          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14775                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
14776                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14777          (const_int 0)))
14778    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14779         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14780   ""
14781   "#"
14782   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14783   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14784    (parallel [(set (match_dup 4)
14785                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14786                                (const_int 0)))
14787               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14788   "")
14789
14790 (define_insn "*neg_gtu<mode>"
14791   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14792         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14793                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14794   ""
14795   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
14796   [(set_attr "type" "two")
14797    (set_attr "length" "8")])
14798
14799 \f
14800 ;; Define both directions of branch and return.  If we need a reload
14801 ;; register, we'd rather use CR0 since it is much easier to copy a
14802 ;; register CC value to there.
14803
14804 (define_insn ""
14805   [(set (pc)
14806         (if_then_else (match_operator 1 "branch_comparison_operator"
14807                                       [(match_operand 2
14808                                                       "cc_reg_operand" "y")
14809                                        (const_int 0)])
14810                       (label_ref (match_operand 0 "" ""))
14811                       (pc)))]
14812   ""
14813   "*
14814 {
14815   return output_cbranch (operands[1], \"%l0\", 0, insn);
14816 }"
14817   [(set_attr "type" "branch")])
14818
14819 (define_insn ""
14820   [(set (pc)
14821         (if_then_else (match_operator 0 "branch_comparison_operator"
14822                                       [(match_operand 1
14823                                                       "cc_reg_operand" "y")
14824                                        (const_int 0)])
14825                       (return)
14826                       (pc)))]
14827   "direct_return ()"
14828   "*
14829 {
14830   return output_cbranch (operands[0], NULL, 0, insn);
14831 }"
14832   [(set_attr "type" "jmpreg")
14833    (set_attr "length" "4")])
14834
14835 (define_insn ""
14836   [(set (pc)
14837         (if_then_else (match_operator 1 "branch_comparison_operator"
14838                                       [(match_operand 2
14839                                                       "cc_reg_operand" "y")
14840                                        (const_int 0)])
14841                       (pc)
14842                       (label_ref (match_operand 0 "" ""))))]
14843   ""
14844   "*
14845 {
14846   return output_cbranch (operands[1], \"%l0\", 1, insn);
14847 }"
14848   [(set_attr "type" "branch")])
14849
14850 (define_insn ""
14851   [(set (pc)
14852         (if_then_else (match_operator 0 "branch_comparison_operator"
14853                                       [(match_operand 1
14854                                                       "cc_reg_operand" "y")
14855                                        (const_int 0)])
14856                       (pc)
14857                       (return)))]
14858   "direct_return ()"
14859   "*
14860 {
14861   return output_cbranch (operands[0], NULL, 1, insn);
14862 }"
14863   [(set_attr "type" "jmpreg")
14864    (set_attr "length" "4")])
14865
14866 ;; Logic on condition register values.
14867
14868 ; This pattern matches things like
14869 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
14870 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
14871 ;                                  (const_int 1)))
14872 ; which are generated by the branch logic.
14873 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
14874
14875 (define_insn "*cceq_ior_compare"
14876   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14877         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
14878                         [(match_operator:SI 2
14879                                       "branch_positive_comparison_operator"
14880                                       [(match_operand 3
14881                                                       "cc_reg_operand" "y,y")
14882                                        (const_int 0)])
14883                          (match_operator:SI 4
14884                                       "branch_positive_comparison_operator"
14885                                       [(match_operand 5
14886                                                       "cc_reg_operand" "0,y")
14887                                        (const_int 0)])])
14888                       (const_int 1)))]
14889   ""
14890   "cr%q1 %E0,%j2,%j4"
14891   [(set_attr "type" "cr_logical,delayed_cr")])
14892
14893 ; Why is the constant -1 here, but 1 in the previous pattern?
14894 ; Because ~1 has all but the low bit set.
14895 (define_insn ""
14896   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14897         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
14898                         [(not:SI (match_operator:SI 2
14899                                       "branch_positive_comparison_operator"
14900                                       [(match_operand 3
14901                                                       "cc_reg_operand" "y,y")
14902                                        (const_int 0)]))
14903                          (match_operator:SI 4
14904                                 "branch_positive_comparison_operator"
14905                                 [(match_operand 5
14906                                                 "cc_reg_operand" "0,y")
14907                                  (const_int 0)])])
14908                       (const_int -1)))]
14909   ""
14910   "cr%q1 %E0,%j2,%j4"
14911   [(set_attr "type" "cr_logical,delayed_cr")])
14912
14913 (define_insn "*cceq_rev_compare"
14914   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14915         (compare:CCEQ (match_operator:SI 1
14916                                       "branch_positive_comparison_operator"
14917                                       [(match_operand 2
14918                                                       "cc_reg_operand" "0,y")
14919                                        (const_int 0)])
14920                       (const_int 0)))]
14921   ""
14922   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
14923   [(set_attr "type" "cr_logical,delayed_cr")])
14924
14925 ;; If we are comparing the result of two comparisons, this can be done
14926 ;; using creqv or crxor.
14927
14928 (define_insn_and_split ""
14929   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
14930         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
14931                               [(match_operand 2 "cc_reg_operand" "y")
14932                                (const_int 0)])
14933                       (match_operator 3 "branch_comparison_operator"
14934                               [(match_operand 4 "cc_reg_operand" "y")
14935                                (const_int 0)])))]
14936   ""
14937   "#"
14938   ""
14939   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
14940                                     (match_dup 5)))]
14941   "
14942 {
14943   int positive_1, positive_2;
14944
14945   positive_1 = branch_positive_comparison_operator (operands[1],
14946                                                     GET_MODE (operands[1]));
14947   positive_2 = branch_positive_comparison_operator (operands[3],
14948                                                     GET_MODE (operands[3]));
14949
14950   if (! positive_1)
14951     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
14952                                                             GET_CODE (operands[1])),
14953                                   SImode,
14954                                   operands[2], const0_rtx);
14955   else if (GET_MODE (operands[1]) != SImode)
14956     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
14957                                   operands[2], const0_rtx);
14958
14959   if (! positive_2)
14960     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
14961                                                             GET_CODE (operands[3])),
14962                                   SImode,
14963                                   operands[4], const0_rtx);
14964   else if (GET_MODE (operands[3]) != SImode)
14965     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
14966                                   operands[4], const0_rtx);
14967
14968   if (positive_1 == positive_2)
14969     {
14970       operands[1] = gen_rtx_NOT (SImode, operands[1]);
14971       operands[5] = constm1_rtx;
14972     }
14973   else
14974     {
14975       operands[5] = const1_rtx;
14976     }
14977 }")
14978
14979 ;; Unconditional branch and return.
14980
14981 (define_insn "jump"
14982   [(set (pc)
14983         (label_ref (match_operand 0 "" "")))]
14984   ""
14985   "b %l0"
14986   [(set_attr "type" "branch")])
14987
14988 (define_insn "return"
14989   [(return)]
14990   "direct_return ()"
14991   "{br|blr}"
14992   [(set_attr "type" "jmpreg")])
14993
14994 (define_expand "indirect_jump"
14995   [(set (pc) (match_operand 0 "register_operand" ""))])
14996
14997 (define_insn "*indirect_jump<mode>"
14998   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
14999   ""
15000   "@
15001    bctr
15002    {br|blr}"
15003   [(set_attr "type" "jmpreg")])
15004
15005 ;; Table jump for switch statements:
15006 (define_expand "tablejump"
15007   [(use (match_operand 0 "" ""))
15008    (use (label_ref (match_operand 1 "" "")))]
15009   ""
15010   "
15011 {
15012   if (TARGET_32BIT)
15013     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
15014   else
15015     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
15016   DONE;
15017 }")
15018
15019 (define_expand "tablejumpsi"
15020   [(set (match_dup 3)
15021         (plus:SI (match_operand:SI 0 "" "")
15022                  (match_dup 2)))
15023    (parallel [(set (pc) (match_dup 3))
15024               (use (label_ref (match_operand 1 "" "")))])]
15025   "TARGET_32BIT"
15026   "
15027 { operands[0] = force_reg (SImode, operands[0]);
15028   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
15029   operands[3] = gen_reg_rtx (SImode);
15030 }")
15031
15032 (define_expand "tablejumpdi"
15033   [(set (match_dup 4)
15034         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
15035    (set (match_dup 3)
15036         (plus:DI (match_dup 4)
15037                  (match_dup 2)))
15038    (parallel [(set (pc) (match_dup 3))
15039               (use (label_ref (match_operand 1 "" "")))])]
15040   "TARGET_64BIT"
15041   "
15042 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
15043   operands[3] = gen_reg_rtx (DImode);
15044   operands[4] = gen_reg_rtx (DImode);
15045 }")
15046
15047 (define_insn "*tablejump<mode>_internal1"
15048   [(set (pc)
15049         (match_operand:P 0 "register_operand" "c,*l"))
15050    (use (label_ref (match_operand 1 "" "")))]
15051   ""
15052   "@
15053    bctr
15054    {br|blr}"
15055   [(set_attr "type" "jmpreg")])
15056
15057 (define_insn "nop"
15058   [(const_int 0)]
15059   ""
15060   "{cror 0,0,0|nop}")
15061 \f
15062 ;; Define the subtract-one-and-jump insns, starting with the template
15063 ;; so loop.c knows what to generate.
15064
15065 (define_expand "doloop_end"
15066   [(use (match_operand 0 "" ""))        ; loop pseudo
15067    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
15068    (use (match_operand 2 "" ""))        ; max iterations
15069    (use (match_operand 3 "" ""))        ; loop level
15070    (use (match_operand 4 "" ""))]       ; label
15071   ""
15072   "
15073 {
15074   /* Only use this on innermost loops.  */
15075   if (INTVAL (operands[3]) > 1)
15076     FAIL;
15077   if (TARGET_64BIT)
15078     {
15079       if (GET_MODE (operands[0]) != DImode)
15080         FAIL;
15081       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
15082     }
15083   else
15084     {
15085       if (GET_MODE (operands[0]) != SImode)
15086         FAIL;
15087       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
15088     }
15089   DONE;
15090 }")
15091
15092 (define_expand "ctr<mode>"
15093   [(parallel [(set (pc)
15094                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
15095                                      (const_int 1))
15096                                  (label_ref (match_operand 1 "" ""))
15097                                  (pc)))
15098               (set (match_dup 0)
15099                    (plus:P (match_dup 0)
15100                             (const_int -1)))
15101               (clobber (match_scratch:CC 2 ""))
15102               (clobber (match_scratch:P 3 ""))])]
15103   ""
15104   "")
15105
15106 ;; We need to be able to do this for any operand, including MEM, or we
15107 ;; will cause reload to blow up since we don't allow output reloads on
15108 ;; JUMP_INSNs.
15109 ;; For the length attribute to be calculated correctly, the
15110 ;; label MUST be operand 0.
15111
15112 (define_insn "*ctr<mode>_internal1"
15113   [(set (pc)
15114         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15115                           (const_int 1))
15116                       (label_ref (match_operand 0 "" ""))
15117                       (pc)))
15118    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15119         (plus:P (match_dup 1)
15120                  (const_int -1)))
15121    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15122    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15123   ""
15124   "*
15125 {
15126   if (which_alternative != 0)
15127     return \"#\";
15128   else if (get_attr_length (insn) == 4)
15129     return \"{bdn|bdnz} %l0\";
15130   else
15131     return \"bdz $+8\;b %l0\";
15132 }"
15133   [(set_attr "type" "branch")
15134    (set_attr "length" "*,12,16,16")])
15135
15136 (define_insn "*ctr<mode>_internal2"
15137   [(set (pc)
15138         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15139                           (const_int 1))
15140                       (pc)
15141                       (label_ref (match_operand 0 "" ""))))
15142    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15143         (plus:P (match_dup 1)
15144                  (const_int -1)))
15145    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15146    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15147   ""
15148   "*
15149 {
15150   if (which_alternative != 0)
15151     return \"#\";
15152   else if (get_attr_length (insn) == 4)
15153     return \"bdz %l0\";
15154   else
15155     return \"{bdn|bdnz} $+8\;b %l0\";
15156 }"
15157   [(set_attr "type" "branch")
15158    (set_attr "length" "*,12,16,16")])
15159
15160 ;; Similar but use EQ
15161
15162 (define_insn "*ctr<mode>_internal5"
15163   [(set (pc)
15164         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15165                           (const_int 1))
15166                       (label_ref (match_operand 0 "" ""))
15167                       (pc)))
15168    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15169         (plus:P (match_dup 1)
15170                  (const_int -1)))
15171    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15172    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15173   ""
15174   "*
15175 {
15176   if (which_alternative != 0)
15177     return \"#\";
15178   else if (get_attr_length (insn) == 4)
15179     return \"bdz %l0\";
15180   else
15181     return \"{bdn|bdnz} $+8\;b %l0\";
15182 }"
15183   [(set_attr "type" "branch")
15184    (set_attr "length" "*,12,16,16")])
15185
15186 (define_insn "*ctr<mode>_internal6"
15187   [(set (pc)
15188         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15189                           (const_int 1))
15190                       (pc)
15191                       (label_ref (match_operand 0 "" ""))))
15192    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15193         (plus:P (match_dup 1)
15194                  (const_int -1)))
15195    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15196    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15197   ""
15198   "*
15199 {
15200   if (which_alternative != 0)
15201     return \"#\";
15202   else if (get_attr_length (insn) == 4)
15203     return \"{bdn|bdnz} %l0\";
15204   else
15205     return \"bdz $+8\;b %l0\";
15206 }"
15207   [(set_attr "type" "branch")
15208    (set_attr "length" "*,12,16,16")])
15209
15210 ;; Now the splitters if we could not allocate the CTR register
15211
15212 (define_split
15213   [(set (pc)
15214         (if_then_else (match_operator 2 "comparison_operator"
15215                                       [(match_operand:P 1 "gpc_reg_operand" "")
15216                                        (const_int 1)])
15217                       (match_operand 5 "" "")
15218                       (match_operand 6 "" "")))
15219    (set (match_operand:P 0 "gpc_reg_operand" "")
15220         (plus:P (match_dup 1) (const_int -1)))
15221    (clobber (match_scratch:CC 3 ""))
15222    (clobber (match_scratch:P 4 ""))]
15223   "reload_completed"
15224   [(parallel [(set (match_dup 3)
15225                    (compare:CC (plus:P (match_dup 1)
15226                                         (const_int -1))
15227                                (const_int 0)))
15228               (set (match_dup 0)
15229                    (plus:P (match_dup 1)
15230                             (const_int -1)))])
15231    (set (pc) (if_then_else (match_dup 7)
15232                            (match_dup 5)
15233                            (match_dup 6)))]
15234   "
15235 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15236                                 operands[3], const0_rtx); }")
15237
15238 (define_split
15239   [(set (pc)
15240         (if_then_else (match_operator 2 "comparison_operator"
15241                                       [(match_operand:P 1 "gpc_reg_operand" "")
15242                                        (const_int 1)])
15243                       (match_operand 5 "" "")
15244                       (match_operand 6 "" "")))
15245    (set (match_operand:P 0 "nonimmediate_operand" "")
15246         (plus:P (match_dup 1) (const_int -1)))
15247    (clobber (match_scratch:CC 3 ""))
15248    (clobber (match_scratch:P 4 ""))]
15249   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
15250   [(parallel [(set (match_dup 3)
15251                    (compare:CC (plus:P (match_dup 1)
15252                                         (const_int -1))
15253                                (const_int 0)))
15254               (set (match_dup 4)
15255                    (plus:P (match_dup 1)
15256                             (const_int -1)))])
15257    (set (match_dup 0)
15258         (match_dup 4))
15259    (set (pc) (if_then_else (match_dup 7)
15260                            (match_dup 5)
15261                            (match_dup 6)))]
15262   "
15263 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15264                                 operands[3], const0_rtx); }")
15265 \f
15266 (define_insn "trap"
15267   [(trap_if (const_int 1) (const_int 0))]
15268   ""
15269   "{t 31,0,0|trap}"
15270   [(set_attr "type" "trap")])
15271
15272 (define_expand "ctrap<mode>4"
15273   [(trap_if (match_operator 0 "ordered_comparison_operator"
15274                             [(match_operand:GPR 1 "register_operand")
15275                              (match_operand:GPR 2 "reg_or_short_operand")])
15276             (match_operand 3 "zero_constant" ""))]
15277   ""
15278   "")
15279
15280 (define_insn ""
15281   [(trap_if (match_operator 0 "ordered_comparison_operator"
15282                             [(match_operand:GPR 1 "register_operand" "r")
15283                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
15284             (const_int 0))]
15285   ""
15286   "{t|t<wd>}%V0%I2 %1,%2"
15287   [(set_attr "type" "trap")])
15288 \f
15289 ;; Insns related to generating the function prologue and epilogue.
15290
15291 (define_expand "prologue"
15292   [(use (const_int 0))]
15293   "TARGET_SCHED_PROLOG"
15294   "
15295 {
15296       rs6000_emit_prologue ();
15297       DONE;
15298 }")
15299
15300 (define_insn "*movesi_from_cr_one"
15301   [(match_parallel 0 "mfcr_operation"
15302                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15303                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
15304                                      (match_operand 3 "immediate_operand" "n")]
15305                           UNSPEC_MOVESI_FROM_CR))])]
15306   "TARGET_MFCRF"
15307   "*
15308 {
15309   int mask = 0;
15310   int i;
15311   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15312   {
15313     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15314     operands[4] = GEN_INT (mask);
15315     output_asm_insn (\"mfcr %1,%4\", operands);
15316   }
15317   return \"\";
15318 }"
15319   [(set_attr "type" "mfcrf")])
15320
15321 (define_insn "movesi_from_cr"
15322   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15323         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
15324                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
15325                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
15326                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
15327                    UNSPEC_MOVESI_FROM_CR))]
15328   ""
15329   "mfcr %0"
15330   [(set_attr "type" "mfcr")])
15331
15332 (define_insn "*stmw"
15333   [(match_parallel 0 "stmw_operation"
15334                    [(set (match_operand:SI 1 "memory_operand" "=m")
15335                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
15336   "TARGET_MULTIPLE"
15337   "{stm|stmw} %2,%1"
15338   [(set_attr "type" "store_ux")])
15339
15340 (define_insn "*save_gpregs_<mode>"
15341   [(match_parallel 0 "any_parallel_operand"
15342                    [(clobber (reg:P 65))
15343                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15344                     (use (match_operand:P 2 "gpc_reg_operand" "r"))
15345                     (set (match_operand:P 3 "memory_operand" "=m")
15346                          (match_operand:P 4 "gpc_reg_operand" "r"))])]
15347   ""
15348   "bl %1"
15349   [(set_attr "type" "branch")
15350    (set_attr "length" "4")])
15351
15352 (define_insn "*save_fpregs_<mode>"
15353   [(match_parallel 0 "any_parallel_operand"
15354                    [(clobber (reg:P 65))
15355                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15356                     (use (match_operand:P 2 "gpc_reg_operand" "r"))
15357                     (set (match_operand:DF 3 "memory_operand" "=m")
15358                          (match_operand:DF 4 "gpc_reg_operand" "d"))])]
15359   ""
15360   "bl %1"
15361   [(set_attr "type" "branch")
15362    (set_attr "length" "4")])
15363
15364 ; These are to explain that changes to the stack pointer should
15365 ; not be moved over stores to stack memory.
15366 (define_insn "stack_tie"
15367   [(set (match_operand:BLK 0 "memory_operand" "+m")
15368         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
15369   ""
15370   ""
15371   [(set_attr "length" "0")])
15372
15373
15374 (define_expand "epilogue"
15375   [(use (const_int 0))]
15376   "TARGET_SCHED_PROLOG"
15377   "
15378 {
15379       rs6000_emit_epilogue (FALSE);
15380       DONE;
15381 }")
15382
15383 ; On some processors, doing the mtcrf one CC register at a time is
15384 ; faster (like on the 604e).  On others, doing them all at once is
15385 ; faster; for instance, on the 601 and 750.
15386
15387 (define_expand "movsi_to_cr_one"
15388   [(set (match_operand:CC 0 "cc_reg_operand" "")
15389         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
15390                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
15391   ""
15392   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
15393
15394 (define_insn "*movsi_to_cr"
15395   [(match_parallel 0 "mtcrf_operation"
15396                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
15397                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
15398                                      (match_operand 3 "immediate_operand" "n")]
15399                                     UNSPEC_MOVESI_TO_CR))])]
15400  ""
15401  "*
15402 {
15403   int mask = 0;
15404   int i;
15405   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15406     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15407   operands[4] = GEN_INT (mask);
15408   return \"mtcrf %4,%2\";
15409 }"
15410   [(set_attr "type" "mtcr")])
15411
15412 (define_insn "*mtcrfsi"
15413   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
15414         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15415                     (match_operand 2 "immediate_operand" "n")]
15416                    UNSPEC_MOVESI_TO_CR))]
15417   "GET_CODE (operands[0]) == REG
15418    && CR_REGNO_P (REGNO (operands[0]))
15419    && GET_CODE (operands[2]) == CONST_INT
15420    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
15421   "mtcrf %R0,%1"
15422   [(set_attr "type" "mtcr")])
15423
15424 ; The load-multiple instructions have similar properties.
15425 ; Note that "load_multiple" is a name known to the machine-independent
15426 ; code that actually corresponds to the PowerPC load-string.
15427
15428 (define_insn "*lmw"
15429   [(match_parallel 0 "lmw_operation"
15430                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15431                          (match_operand:SI 2 "memory_operand" "m"))])]
15432   "TARGET_MULTIPLE"
15433   "{lm|lmw} %1,%2"
15434   [(set_attr "type" "load_ux")
15435    (set_attr "cell_micro" "always")])
15436
15437 (define_insn "*return_internal_<mode>"
15438   [(return)
15439    (use (match_operand:P 0 "register_operand" "lc"))]
15440   ""
15441   "b%T0"
15442   [(set_attr "type" "jmpreg")])
15443
15444 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
15445 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
15446
15447 (define_insn "*restore_gpregs_<mode>"
15448  [(match_parallel 0 "any_parallel_operand"
15449                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15450                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15451                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15452                    (set (match_operand:P 4 "gpc_reg_operand" "=r")
15453                         (match_operand:P 5 "memory_operand" "m"))])]
15454  ""
15455  "bl %2"
15456  [(set_attr "type" "branch")
15457   (set_attr "length" "4")])
15458
15459 (define_insn "*return_and_restore_gpregs_<mode>"
15460  [(match_parallel 0 "any_parallel_operand"
15461                   [(return)
15462                    (clobber (match_operand:P 1 "register_operand" "=l"))
15463                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15464                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15465                    (set (match_operand:P 4 "gpc_reg_operand" "=r")
15466                         (match_operand:P 5 "memory_operand" "m"))])]
15467  ""
15468  "b %2"
15469  [(set_attr "type" "branch")
15470   (set_attr "length" "4")])
15471
15472 (define_insn "*return_and_restore_fpregs_<mode>"
15473  [(match_parallel 0 "any_parallel_operand"
15474                   [(return)
15475                    (clobber (match_operand:P 1 "register_operand" "=l"))
15476                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15477                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15478                    (set (match_operand:DF 4 "gpc_reg_operand" "=d")
15479                         (match_operand:DF 5 "memory_operand" "m"))])]
15480  ""
15481  "b %2"
15482  [(set_attr "type" "branch")
15483   (set_attr "length" "4")])
15484
15485 (define_insn "*return_and_restore_fpregs_aix_<mode>"
15486  [(match_parallel 0 "any_parallel_operand"
15487                   [(return)
15488                    (use (match_operand:P 1 "register_operand" "l"))
15489                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15490                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15491                    (set (match_operand:DF 4 "gpc_reg_operand" "=d")
15492                         (match_operand:DF 5 "memory_operand" "m"))])]
15493  ""
15494  "b %2"
15495  [(set_attr "type" "branch")
15496   (set_attr "length" "4")])
15497
15498 ; This is used in compiling the unwind routines.
15499 (define_expand "eh_return"
15500   [(use (match_operand 0 "general_operand" ""))]
15501   ""
15502   "
15503 {
15504   if (TARGET_32BIT)
15505     emit_insn (gen_eh_set_lr_si (operands[0]));
15506   else
15507     emit_insn (gen_eh_set_lr_di (operands[0]));
15508   DONE;
15509 }")
15510
15511 ; We can't expand this before we know where the link register is stored.
15512 (define_insn "eh_set_lr_<mode>"
15513   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
15514                     UNSPECV_EH_RR)
15515    (clobber (match_scratch:P 1 "=&b"))]
15516   ""
15517   "#")
15518
15519 (define_split
15520   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
15521    (clobber (match_scratch 1 ""))]
15522   "reload_completed"
15523   [(const_int 0)]
15524   "
15525 {
15526   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
15527   DONE;
15528 }")
15529
15530 (define_insn "prefetch"
15531   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
15532              (match_operand:SI 1 "const_int_operand" "n")
15533              (match_operand:SI 2 "const_int_operand" "n"))]
15534   "TARGET_POWERPC"
15535   "*
15536 {
15537   if (GET_CODE (operands[0]) == REG)
15538     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
15539   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
15540 }"
15541   [(set_attr "type" "load")])
15542 \f
15543 (define_insn "bpermd_<mode>"
15544   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15545         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
15546                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
15547   "TARGET_POPCNTD"
15548   "bpermd %0,%1,%2"
15549   [(set_attr "type" "integer")])
15550
15551 \f
15552
15553 (include "sync.md")
15554 (include "vector.md")
15555 (include "vsx.md")
15556 (include "altivec.md")
15557 (include "spe.md")
15558 (include "dfp.md")
15559 (include "paired.md")