OSDN Git Service

PR target/44067
[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, 2010
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    (CA_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; and the size used for arithmetic carries.
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 ; These modes do not fit in integer registers in 32-bit mode.
221 ; but on e500v2, the gpr are 64 bit registers
222 (define_mode_iterator DIFD [DI (DF "!TARGET_E500_DOUBLE") DD])
223
224 ;; Iterator for reciprocal estimate instructions
225 (define_mode_iterator RECIPF [SF DF V4SF V2DF])
226
227 ; Various instructions that come in SI and DI forms.
228 ; A generic w/d attribute, for things like cmpw/cmpd.
229 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
230
231 ; DImode bits
232 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
233
234 ;; ISEL/ISEL64 target selection
235 (define_mode_attr sel [(SI "") (DI "64")])
236
237 ;; Suffix for reload patterns
238 (define_mode_attr ptrsize [(SI "32bit")
239                            (DI "64bit")])
240
241 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
242                             (DI "TARGET_64BIT")])
243
244 (define_mode_attr mptrsize [(SI "si")
245                             (DI "di")])
246
247 (define_mode_attr rreg [(SF   "f")
248                         (DF   "Ws")
249                         (V4SF "Wf")
250                         (V2DF "Wd")])
251
252 \f
253 ;; Start with fixed-point load and store insns.  Here we put only the more
254 ;; complex forms.  Basic data transfer is done later.
255
256 (define_expand "zero_extend<mode>di2"
257   [(set (match_operand:DI 0 "gpc_reg_operand" "")
258         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
259   "TARGET_POWERPC64"
260   "")
261
262 (define_insn "*zero_extend<mode>di2_internal1"
263   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
264         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
265   "TARGET_POWERPC64"
266   "@
267    l<wd>z%U1%X1 %0,%1
268    rldicl %0,%1,0,<dbits>"
269   [(set_attr "type" "load,*")])
270
271 (define_insn "*zero_extend<mode>di2_internal2"
272   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
273         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
274                     (const_int 0)))
275    (clobber (match_scratch:DI 2 "=r,r"))]
276   "TARGET_64BIT"
277   "@
278    rldicl. %2,%1,0,<dbits>
279    #"
280   [(set_attr "type" "compare")
281    (set_attr "length" "4,8")])
282
283 (define_split
284   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
285         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
286                     (const_int 0)))
287    (clobber (match_scratch:DI 2 ""))]
288   "TARGET_POWERPC64 && reload_completed"
289   [(set (match_dup 2)
290         (zero_extend:DI (match_dup 1)))
291    (set (match_dup 0)
292         (compare:CC (match_dup 2)
293                     (const_int 0)))]
294   "")
295
296 (define_insn "*zero_extend<mode>di2_internal3"
297   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
298         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
299                     (const_int 0)))
300    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
301         (zero_extend:DI (match_dup 1)))]
302   "TARGET_64BIT"
303   "@
304    rldicl. %0,%1,0,<dbits>
305    #"
306   [(set_attr "type" "compare")
307    (set_attr "length" "4,8")])
308
309 (define_split
310   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
311         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
312                     (const_int 0)))
313    (set (match_operand:DI 0 "gpc_reg_operand" "")
314         (zero_extend:DI (match_dup 1)))]
315   "TARGET_POWERPC64 && reload_completed"
316   [(set (match_dup 0)
317         (zero_extend:DI (match_dup 1)))
318    (set (match_dup 2)
319         (compare:CC (match_dup 0)
320                     (const_int 0)))]
321   "")
322
323 (define_insn "extendqidi2"
324   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
325         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
326   "TARGET_POWERPC64"
327   "extsb %0,%1"
328   [(set_attr "type" "exts")])
329
330 (define_insn ""
331   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
332         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
333                     (const_int 0)))
334    (clobber (match_scratch:DI 2 "=r,r"))]
335   "TARGET_64BIT"
336   "@
337    extsb. %2,%1
338    #"
339   [(set_attr "type" "compare")
340    (set_attr "length" "4,8")])
341
342 (define_split
343   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
344         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
345                     (const_int 0)))
346    (clobber (match_scratch:DI 2 ""))]
347   "TARGET_POWERPC64 && reload_completed"
348   [(set (match_dup 2)
349         (sign_extend:DI (match_dup 1)))
350    (set (match_dup 0)
351         (compare:CC (match_dup 2)
352                     (const_int 0)))]
353   "")
354
355 (define_insn ""
356   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
357         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
358                     (const_int 0)))
359    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
360         (sign_extend:DI (match_dup 1)))]
361   "TARGET_64BIT"
362   "@
363    extsb. %0,%1
364    #"
365   [(set_attr "type" "compare")
366    (set_attr "length" "4,8")])
367
368 (define_split
369   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
370         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
371                     (const_int 0)))
372    (set (match_operand:DI 0 "gpc_reg_operand" "")
373         (sign_extend:DI (match_dup 1)))]
374   "TARGET_POWERPC64 && reload_completed"
375   [(set (match_dup 0)
376         (sign_extend:DI (match_dup 1)))
377    (set (match_dup 2)
378         (compare:CC (match_dup 0)
379                     (const_int 0)))]
380   "")
381
382 (define_expand "extendhidi2"
383   [(set (match_operand:DI 0 "gpc_reg_operand" "")
384         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
385   "TARGET_POWERPC64"
386   "")
387
388 (define_insn ""
389   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
390         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
391   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
392   "@
393    lha%U1%X1 %0,%1
394    extsh %0,%1"
395   [(set_attr "type" "load_ext,exts")])
396
397 (define_insn ""
398   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
399         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
400   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
401   "extsh %0,%1"
402   [(set_attr "type" "exts")])
403
404 (define_insn ""
405   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
406         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
407                     (const_int 0)))
408    (clobber (match_scratch:DI 2 "=r,r"))]
409   "TARGET_64BIT"
410   "@
411    extsh. %2,%1
412    #"
413   [(set_attr "type" "compare")
414    (set_attr "length" "4,8")])
415
416 (define_split
417   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
418         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
419                     (const_int 0)))
420    (clobber (match_scratch:DI 2 ""))]
421   "TARGET_POWERPC64 && reload_completed"
422   [(set (match_dup 2)
423         (sign_extend:DI (match_dup 1)))
424    (set (match_dup 0)
425         (compare:CC (match_dup 2)
426                     (const_int 0)))]
427   "")
428
429 (define_insn ""
430   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
431         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
432                     (const_int 0)))
433    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
434         (sign_extend:DI (match_dup 1)))]
435   "TARGET_64BIT"
436   "@
437    extsh. %0,%1
438    #"
439   [(set_attr "type" "compare")
440    (set_attr "length" "4,8")])
441
442 (define_split
443   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
444         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
445                     (const_int 0)))
446    (set (match_operand:DI 0 "gpc_reg_operand" "")
447         (sign_extend:DI (match_dup 1)))]
448   "TARGET_POWERPC64 && reload_completed"
449   [(set (match_dup 0)
450         (sign_extend:DI (match_dup 1)))
451    (set (match_dup 2)
452         (compare:CC (match_dup 0)
453                     (const_int 0)))]
454   "")
455
456 (define_expand "extendsidi2"
457   [(set (match_operand:DI 0 "gpc_reg_operand" "")
458         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
459   "TARGET_POWERPC64"
460   "")
461
462 (define_insn ""
463   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
464         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
465   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
466   "@
467    lwa%U1%X1 %0,%1
468    extsw %0,%1"
469   [(set_attr "type" "load_ext,exts")])
470
471 (define_insn ""
472   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
473         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
474   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
475   "extsw %0,%1"
476   [(set_attr "type" "exts")])
477
478 (define_insn ""
479   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
480         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
481                     (const_int 0)))
482    (clobber (match_scratch:DI 2 "=r,r"))]
483   "TARGET_64BIT"
484   "@
485    extsw. %2,%1
486    #"
487   [(set_attr "type" "compare")
488    (set_attr "length" "4,8")])
489
490 (define_split
491   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
492         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
493                     (const_int 0)))
494    (clobber (match_scratch:DI 2 ""))]
495   "TARGET_POWERPC64 && reload_completed"
496   [(set (match_dup 2)
497         (sign_extend:DI (match_dup 1)))
498    (set (match_dup 0)
499         (compare:CC (match_dup 2)
500                     (const_int 0)))]
501   "")
502
503 (define_insn ""
504   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
505         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
506                     (const_int 0)))
507    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
508         (sign_extend:DI (match_dup 1)))]
509   "TARGET_64BIT"
510   "@
511    extsw. %0,%1
512    #"
513   [(set_attr "type" "compare")
514    (set_attr "length" "4,8")])
515
516 (define_split
517   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
518         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
519                     (const_int 0)))
520    (set (match_operand:DI 0 "gpc_reg_operand" "")
521         (sign_extend:DI (match_dup 1)))]
522   "TARGET_POWERPC64 && reload_completed"
523   [(set (match_dup 0)
524         (sign_extend:DI (match_dup 1)))
525    (set (match_dup 2)
526         (compare:CC (match_dup 0)
527                     (const_int 0)))]
528   "")
529
530 (define_expand "zero_extendqisi2"
531   [(set (match_operand:SI 0 "gpc_reg_operand" "")
532         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
533   ""
534   "")
535
536 (define_insn ""
537   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
538         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
539   ""
540   "@
541    lbz%U1%X1 %0,%1
542    {rlinm|rlwinm} %0,%1,0,0xff"
543   [(set_attr "type" "load,*")])
544
545 (define_insn ""
546   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
547         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
548                     (const_int 0)))
549    (clobber (match_scratch:SI 2 "=r,r"))]
550   ""
551   "@
552    {andil.|andi.} %2,%1,0xff
553    #"
554   [(set_attr "type" "fast_compare,compare")
555    (set_attr "length" "4,8")])
556
557 (define_split
558   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
559         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
560                     (const_int 0)))
561    (clobber (match_scratch:SI 2 ""))]
562   "reload_completed"
563   [(set (match_dup 2)
564         (zero_extend:SI (match_dup 1)))
565    (set (match_dup 0)
566         (compare:CC (match_dup 2)
567                     (const_int 0)))]
568   "")
569
570 (define_insn ""
571   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
572         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
573                     (const_int 0)))
574    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
575         (zero_extend:SI (match_dup 1)))]
576   ""
577   "@
578    {andil.|andi.} %0,%1,0xff
579    #"
580   [(set_attr "type" "fast_compare,compare")
581    (set_attr "length" "4,8")])
582
583 (define_split
584   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
585         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
586                     (const_int 0)))
587    (set (match_operand:SI 0 "gpc_reg_operand" "")
588         (zero_extend:SI (match_dup 1)))]
589   "reload_completed"
590   [(set (match_dup 0)
591         (zero_extend:SI (match_dup 1)))
592    (set (match_dup 2)
593         (compare:CC (match_dup 0)
594                     (const_int 0)))]
595   "")
596
597 (define_expand "extendqisi2"
598   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
599    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
600   ""
601   "
602 {
603   if (TARGET_POWERPC)
604     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
605   else if (TARGET_POWER)
606     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
607   else
608     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
609   DONE;
610 }")
611
612 (define_insn "extendqisi2_ppc"
613   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
614         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
615   "TARGET_POWERPC"
616   "extsb %0,%1"
617   [(set_attr "type" "exts")])
618
619 (define_insn ""
620   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
621         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
622                     (const_int 0)))
623    (clobber (match_scratch:SI 2 "=r,r"))]
624   "TARGET_POWERPC"
625   "@
626    extsb. %2,%1
627    #"
628   [(set_attr "type" "compare")
629    (set_attr "length" "4,8")])
630
631 (define_split
632   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
633         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
634                     (const_int 0)))
635    (clobber (match_scratch:SI 2 ""))]
636   "TARGET_POWERPC && reload_completed"
637   [(set (match_dup 2)
638         (sign_extend:SI (match_dup 1)))
639    (set (match_dup 0)
640         (compare:CC (match_dup 2)
641                     (const_int 0)))]
642   "")
643
644 (define_insn ""
645   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
646         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
647                     (const_int 0)))
648    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
649         (sign_extend:SI (match_dup 1)))]
650   "TARGET_POWERPC"
651   "@
652    extsb. %0,%1
653    #"
654   [(set_attr "type" "compare")
655    (set_attr "length" "4,8")])
656
657 (define_split
658   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
659         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
660                     (const_int 0)))
661    (set (match_operand:SI 0 "gpc_reg_operand" "")
662         (sign_extend:SI (match_dup 1)))]
663   "TARGET_POWERPC && reload_completed"
664   [(set (match_dup 0)
665         (sign_extend:SI (match_dup 1)))
666    (set (match_dup 2)
667         (compare:CC (match_dup 0)
668                     (const_int 0)))]
669   "")
670
671 (define_expand "extendqisi2_power"
672   [(parallel [(set (match_dup 2)
673                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
674                               (const_int 24)))
675               (clobber (scratch:SI))])
676    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
677                    (ashiftrt:SI (match_dup 2)
678                                 (const_int 24)))
679               (clobber (scratch:SI))])]
680   "TARGET_POWER"
681   "
682 { operands[1] = gen_lowpart (SImode, operands[1]);
683   operands[2] = gen_reg_rtx (SImode); }")
684
685 (define_expand "extendqisi2_no_power"
686   [(set (match_dup 2)
687         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
688                    (const_int 24)))
689    (set (match_operand:SI 0 "gpc_reg_operand" "")
690         (ashiftrt:SI (match_dup 2)
691                      (const_int 24)))]
692   "! TARGET_POWER && ! TARGET_POWERPC"
693   "
694 { operands[1] = gen_lowpart (SImode, operands[1]);
695   operands[2] = gen_reg_rtx (SImode); }")
696
697 (define_expand "zero_extendqihi2"
698   [(set (match_operand:HI 0 "gpc_reg_operand" "")
699         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
700   ""
701   "")
702
703 (define_insn ""
704   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
705         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
706   ""
707   "@
708    lbz%U1%X1 %0,%1
709    {rlinm|rlwinm} %0,%1,0,0xff"
710   [(set_attr "type" "load,*")])
711
712 (define_insn ""
713   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
714         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
715                     (const_int 0)))
716    (clobber (match_scratch:HI 2 "=r,r"))]
717   ""
718   "@
719    {andil.|andi.} %2,%1,0xff
720    #"
721   [(set_attr "type" "fast_compare,compare")
722    (set_attr "length" "4,8")])
723
724 (define_split
725   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
726         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
727                     (const_int 0)))
728    (clobber (match_scratch:HI 2 ""))]
729   "reload_completed"
730   [(set (match_dup 2)
731         (zero_extend:HI (match_dup 1)))
732    (set (match_dup 0)
733         (compare:CC (match_dup 2)
734                     (const_int 0)))]
735   "")
736
737 (define_insn ""
738   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
739         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
740                     (const_int 0)))
741    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
742         (zero_extend:HI (match_dup 1)))]
743   ""
744   "@
745    {andil.|andi.} %0,%1,0xff
746    #"
747   [(set_attr "type" "fast_compare,compare")
748    (set_attr "length" "4,8")])
749
750 (define_split
751   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
752         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
753                     (const_int 0)))
754    (set (match_operand:HI 0 "gpc_reg_operand" "")
755         (zero_extend:HI (match_dup 1)))]
756   "reload_completed"
757   [(set (match_dup 0)
758         (zero_extend:HI (match_dup 1)))
759    (set (match_dup 2)
760         (compare:CC (match_dup 0)
761                     (const_int 0)))]
762   "")
763
764 (define_expand "extendqihi2"
765   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
766    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
767   ""
768   "
769 {
770   if (TARGET_POWERPC)
771     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
772   else if (TARGET_POWER)
773     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
774   else
775     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
776   DONE;
777 }")
778
779 (define_insn "extendqihi2_ppc"
780   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
781         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
782   "TARGET_POWERPC"
783   "extsb %0,%1"
784   [(set_attr "type" "exts")])
785
786 (define_insn ""
787   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
788         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
789                     (const_int 0)))
790    (clobber (match_scratch:HI 2 "=r,r"))]
791   "TARGET_POWERPC"
792   "@
793    extsb. %2,%1
794    #"
795   [(set_attr "type" "compare")
796    (set_attr "length" "4,8")])
797
798 (define_split
799   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
800         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
801                     (const_int 0)))
802    (clobber (match_scratch:HI 2 ""))]
803   "TARGET_POWERPC && reload_completed"
804   [(set (match_dup 2)
805         (sign_extend:HI (match_dup 1)))
806    (set (match_dup 0)
807         (compare:CC (match_dup 2)
808                     (const_int 0)))]
809   "")
810
811 (define_insn ""
812   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
813         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
814                     (const_int 0)))
815    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
816         (sign_extend:HI (match_dup 1)))]
817   "TARGET_POWERPC"
818   "@
819    extsb. %0,%1
820    #"
821   [(set_attr "type" "compare")
822    (set_attr "length" "4,8")])
823
824 (define_split
825   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
826         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
827                     (const_int 0)))
828    (set (match_operand:HI 0 "gpc_reg_operand" "")
829         (sign_extend:HI (match_dup 1)))]
830   "TARGET_POWERPC && reload_completed"
831   [(set (match_dup 0)
832         (sign_extend:HI (match_dup 1)))
833    (set (match_dup 2)
834         (compare:CC (match_dup 0)
835                     (const_int 0)))]
836   "")
837
838 (define_expand "extendqihi2_power"
839   [(parallel [(set (match_dup 2)
840                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
841                               (const_int 24)))
842               (clobber (scratch:SI))])
843    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
844                    (ashiftrt:SI (match_dup 2)
845                                 (const_int 24)))
846               (clobber (scratch:SI))])]
847   "TARGET_POWER"
848   "
849 { operands[0] = gen_lowpart (SImode, operands[0]);
850   operands[1] = gen_lowpart (SImode, operands[1]);
851   operands[2] = gen_reg_rtx (SImode); }")
852
853 (define_expand "extendqihi2_no_power"
854   [(set (match_dup 2)
855         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
856                    (const_int 24)))
857    (set (match_operand:HI 0 "gpc_reg_operand" "")
858         (ashiftrt:SI (match_dup 2)
859                      (const_int 24)))]
860   "! TARGET_POWER && ! TARGET_POWERPC"
861   "
862 { operands[0] = gen_lowpart (SImode, operands[0]);
863   operands[1] = gen_lowpart (SImode, operands[1]);
864   operands[2] = gen_reg_rtx (SImode); }")
865
866 (define_expand "zero_extendhisi2"
867   [(set (match_operand:SI 0 "gpc_reg_operand" "")
868         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
869   ""
870   "")
871
872 (define_insn ""
873   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
874         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
875   ""
876   "@
877    lhz%U1%X1 %0,%1
878    {rlinm|rlwinm} %0,%1,0,0xffff"
879   [(set_attr "type" "load,*")])
880
881 (define_insn ""
882   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
883         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
884                     (const_int 0)))
885    (clobber (match_scratch:SI 2 "=r,r"))]
886   ""
887   "@
888    {andil.|andi.} %2,%1,0xffff
889    #"
890   [(set_attr "type" "fast_compare,compare")
891    (set_attr "length" "4,8")])
892
893 (define_split
894   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
895         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
896                     (const_int 0)))
897    (clobber (match_scratch:SI 2 ""))]
898   "reload_completed"
899   [(set (match_dup 2)
900         (zero_extend:SI (match_dup 1)))
901    (set (match_dup 0)
902         (compare:CC (match_dup 2)
903                     (const_int 0)))]
904   "")
905
906 (define_insn ""
907   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
908         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
909                     (const_int 0)))
910    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
911         (zero_extend:SI (match_dup 1)))]
912   ""
913   "@
914    {andil.|andi.} %0,%1,0xffff
915    #"
916   [(set_attr "type" "fast_compare,compare")
917    (set_attr "length" "4,8")])
918
919 (define_split
920   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
921         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
922                     (const_int 0)))
923    (set (match_operand:SI 0 "gpc_reg_operand" "")
924         (zero_extend:SI (match_dup 1)))]
925   "reload_completed"
926   [(set (match_dup 0)
927         (zero_extend:SI (match_dup 1)))
928    (set (match_dup 2)
929         (compare:CC (match_dup 0)
930                     (const_int 0)))]
931   "")
932
933 (define_expand "extendhisi2"
934   [(set (match_operand:SI 0 "gpc_reg_operand" "")
935         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
936   ""
937   "")
938
939 (define_insn ""
940   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
941         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
942   "rs6000_gen_cell_microcode"
943   "@
944    lha%U1%X1 %0,%1
945    {exts|extsh} %0,%1"
946   [(set_attr "type" "load_ext,exts")])
947
948 (define_insn ""
949   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
950         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
951   "!rs6000_gen_cell_microcode"
952   "{exts|extsh} %0,%1"
953   [(set_attr "type" "exts")])
954
955 (define_insn ""
956   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
957         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
958                     (const_int 0)))
959    (clobber (match_scratch:SI 2 "=r,r"))]
960   ""
961   "@
962    {exts.|extsh.} %2,%1
963    #"
964   [(set_attr "type" "compare")
965    (set_attr "length" "4,8")])
966
967 (define_split
968   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
969         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
970                     (const_int 0)))
971    (clobber (match_scratch:SI 2 ""))]
972   "reload_completed"
973   [(set (match_dup 2)
974         (sign_extend:SI (match_dup 1)))
975    (set (match_dup 0)
976         (compare:CC (match_dup 2)
977                     (const_int 0)))]
978   "")
979
980 (define_insn ""
981   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
982         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
983                     (const_int 0)))
984    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
985         (sign_extend:SI (match_dup 1)))]
986   ""
987   "@
988    {exts.|extsh.} %0,%1
989    #"
990   [(set_attr "type" "compare")
991    (set_attr "length" "4,8")])
992 \f
993 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
994
995 (define_insn "*macchwc"
996   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
997         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
998                                        (match_operand:SI 2 "gpc_reg_operand" "r")
999                                        (const_int 16))
1000                                       (sign_extend:SI
1001                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1002                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1003                     (const_int 0)))
1004    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1005         (plus:SI (mult:SI (ashiftrt:SI
1006                            (match_dup 2)
1007                            (const_int 16))
1008                           (sign_extend:SI
1009                            (match_dup 1)))
1010                  (match_dup 4)))]
1011   "TARGET_MULHW"
1012   "macchw. %0, %1, %2"
1013   [(set_attr "type" "imul3")])
1014
1015 (define_insn "*macchw"
1016   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1017         (plus:SI (mult:SI (ashiftrt:SI
1018                            (match_operand:SI 2 "gpc_reg_operand" "r")
1019                            (const_int 16))
1020                           (sign_extend:SI
1021                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1022                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1023   "TARGET_MULHW"
1024   "macchw %0, %1, %2"
1025   [(set_attr "type" "imul3")])
1026
1027 (define_insn "*macchwuc"
1028   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1029         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1030                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1031                                        (const_int 16))
1032                                       (zero_extend:SI
1033                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1034                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1035                     (const_int 0)))
1036    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1037         (plus:SI (mult:SI (lshiftrt:SI
1038                            (match_dup 2)
1039                            (const_int 16))
1040                           (zero_extend:SI
1041                            (match_dup 1)))
1042                  (match_dup 4)))]
1043   "TARGET_MULHW"
1044   "macchwu. %0, %1, %2"
1045   [(set_attr "type" "imul3")])
1046
1047 (define_insn "*macchwu"
1048   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1049         (plus:SI (mult:SI (lshiftrt:SI
1050                            (match_operand:SI 2 "gpc_reg_operand" "r")
1051                            (const_int 16))
1052                           (zero_extend:SI
1053                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1054                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1055   "TARGET_MULHW"
1056   "macchwu %0, %1, %2"
1057   [(set_attr "type" "imul3")])
1058
1059 (define_insn "*machhwc"
1060   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1061         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1062                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1063                                        (const_int 16))
1064                                       (ashiftrt:SI
1065                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1066                                        (const_int 16)))
1067                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1068                     (const_int 0)))
1069    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1070         (plus:SI (mult:SI (ashiftrt:SI
1071                            (match_dup 1)
1072                            (const_int 16))
1073                           (ashiftrt:SI
1074                            (match_dup 2)
1075                            (const_int 16)))
1076                  (match_dup 4)))]
1077   "TARGET_MULHW"
1078   "machhw. %0, %1, %2"
1079   [(set_attr "type" "imul3")])
1080
1081 (define_insn "*machhw"
1082   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1083         (plus:SI (mult:SI (ashiftrt:SI
1084                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1085                            (const_int 16))
1086                           (ashiftrt:SI
1087                            (match_operand:SI 2 "gpc_reg_operand" "r")
1088                            (const_int 16)))
1089                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1090   "TARGET_MULHW"
1091   "machhw %0, %1, %2"
1092   [(set_attr "type" "imul3")])
1093
1094 (define_insn "*machhwuc"
1095   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1096         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1097                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1098                                        (const_int 16))
1099                                       (lshiftrt:SI
1100                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1101                                        (const_int 16)))
1102                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1103                     (const_int 0)))
1104    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1105         (plus:SI (mult:SI (lshiftrt:SI
1106                            (match_dup 1)
1107                            (const_int 16))
1108                           (lshiftrt:SI
1109                            (match_dup 2)
1110                            (const_int 16)))
1111                  (match_dup 4)))]
1112   "TARGET_MULHW"
1113   "machhwu. %0, %1, %2"
1114   [(set_attr "type" "imul3")])
1115
1116 (define_insn "*machhwu"
1117   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1118         (plus:SI (mult:SI (lshiftrt:SI
1119                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1120                            (const_int 16))
1121                           (lshiftrt:SI
1122                            (match_operand:SI 2 "gpc_reg_operand" "r")
1123                            (const_int 16)))
1124                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1125   "TARGET_MULHW"
1126   "machhwu %0, %1, %2"
1127   [(set_attr "type" "imul3")])
1128
1129 (define_insn "*maclhwc"
1130   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1131         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1132                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1133                                       (sign_extend:SI
1134                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1135                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1136                     (const_int 0)))
1137    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1138         (plus:SI (mult:SI (sign_extend:SI
1139                            (match_dup 1))
1140                           (sign_extend:SI
1141                            (match_dup 2)))
1142                  (match_dup 4)))]
1143   "TARGET_MULHW"
1144   "maclhw. %0, %1, %2"
1145   [(set_attr "type" "imul3")])
1146
1147 (define_insn "*maclhw"
1148   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1149         (plus:SI (mult:SI (sign_extend:SI
1150                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1151                           (sign_extend:SI
1152                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1153                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1154   "TARGET_MULHW"
1155   "maclhw %0, %1, %2"
1156   [(set_attr "type" "imul3")])
1157
1158 (define_insn "*maclhwuc"
1159   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1160         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1161                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1162                                       (zero_extend:SI
1163                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1164                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1165                     (const_int 0)))
1166    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1167         (plus:SI (mult:SI (zero_extend:SI
1168                            (match_dup 1))
1169                           (zero_extend:SI
1170                            (match_dup 2)))
1171                  (match_dup 4)))]
1172   "TARGET_MULHW"
1173   "maclhwu. %0, %1, %2"
1174   [(set_attr "type" "imul3")])
1175
1176 (define_insn "*maclhwu"
1177   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1178         (plus:SI (mult:SI (zero_extend:SI
1179                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1180                           (zero_extend:SI
1181                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1182                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1183   "TARGET_MULHW"
1184   "maclhwu %0, %1, %2"
1185   [(set_attr "type" "imul3")])
1186
1187 (define_insn "*nmacchwc"
1188   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1189         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1190                               (mult:SI (ashiftrt:SI
1191                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1192                                         (const_int 16))
1193                                        (sign_extend:SI
1194                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1195                     (const_int 0)))
1196    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1197         (minus:SI (match_dup 4)
1198                   (mult:SI (ashiftrt:SI
1199                             (match_dup 2)
1200                             (const_int 16))
1201                            (sign_extend:SI
1202                             (match_dup 1)))))]
1203   "TARGET_MULHW"
1204   "nmacchw. %0, %1, %2"
1205   [(set_attr "type" "imul3")])
1206
1207 (define_insn "*nmacchw"
1208   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1209         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1210                   (mult:SI (ashiftrt:SI
1211                             (match_operand:SI 2 "gpc_reg_operand" "r")
1212                             (const_int 16))
1213                            (sign_extend:SI
1214                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1215   "TARGET_MULHW"
1216   "nmacchw %0, %1, %2"
1217   [(set_attr "type" "imul3")])
1218
1219 (define_insn "*nmachhwc"
1220   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1221         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1222                               (mult:SI (ashiftrt:SI
1223                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1224                                         (const_int 16))
1225                                        (ashiftrt:SI
1226                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1227                                         (const_int 16))))
1228                     (const_int 0)))
1229    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1230         (minus:SI (match_dup 4)
1231                   (mult:SI (ashiftrt:SI
1232                             (match_dup 1)
1233                             (const_int 16))
1234                            (ashiftrt:SI
1235                             (match_dup 2)
1236                             (const_int 16)))))]
1237   "TARGET_MULHW"
1238   "nmachhw. %0, %1, %2"
1239   [(set_attr "type" "imul3")])
1240
1241 (define_insn "*nmachhw"
1242   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1243         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1244                   (mult:SI (ashiftrt:SI
1245                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1246                             (const_int 16))
1247                            (ashiftrt:SI
1248                             (match_operand:SI 2 "gpc_reg_operand" "r")
1249                             (const_int 16)))))]
1250   "TARGET_MULHW"
1251   "nmachhw %0, %1, %2"
1252   [(set_attr "type" "imul3")])
1253
1254 (define_insn "*nmaclhwc"
1255   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1256         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1257                               (mult:SI (sign_extend:SI
1258                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1259                                        (sign_extend:SI
1260                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1261                     (const_int 0)))
1262    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1263         (minus:SI (match_dup 4)
1264                   (mult:SI (sign_extend:SI
1265                             (match_dup 1))
1266                            (sign_extend:SI
1267                             (match_dup 2)))))]
1268   "TARGET_MULHW"
1269   "nmaclhw. %0, %1, %2"
1270   [(set_attr "type" "imul3")])
1271
1272 (define_insn "*nmaclhw"
1273   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1274         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1275                   (mult:SI (sign_extend:SI
1276                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1277                            (sign_extend:SI
1278                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1279   "TARGET_MULHW"
1280   "nmaclhw %0, %1, %2"
1281   [(set_attr "type" "imul3")])
1282
1283 (define_insn "*mulchwc"
1284   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1285         (compare:CC (mult:SI (ashiftrt:SI
1286                               (match_operand:SI 2 "gpc_reg_operand" "r")
1287                               (const_int 16))
1288                              (sign_extend:SI
1289                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1290                     (const_int 0)))
1291    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1292         (mult:SI (ashiftrt:SI
1293                   (match_dup 2)
1294                   (const_int 16))
1295                  (sign_extend:SI
1296                   (match_dup 1))))]
1297   "TARGET_MULHW"
1298   "mulchw. %0, %1, %2"
1299   [(set_attr "type" "imul3")])
1300
1301 (define_insn "*mulchw"
1302   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1303         (mult:SI (ashiftrt:SI
1304                   (match_operand:SI 2 "gpc_reg_operand" "r")
1305                   (const_int 16))
1306                  (sign_extend:SI
1307                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1308   "TARGET_MULHW"
1309   "mulchw %0, %1, %2"
1310   [(set_attr "type" "imul3")])
1311
1312 (define_insn "*mulchwuc"
1313   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1314         (compare:CC (mult:SI (lshiftrt:SI
1315                               (match_operand:SI 2 "gpc_reg_operand" "r")
1316                               (const_int 16))
1317                              (zero_extend:SI
1318                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1319                     (const_int 0)))
1320    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1321         (mult:SI (lshiftrt:SI
1322                   (match_dup 2)
1323                   (const_int 16))
1324                  (zero_extend:SI
1325                   (match_dup 1))))]
1326   "TARGET_MULHW"
1327   "mulchwu. %0, %1, %2"
1328   [(set_attr "type" "imul3")])
1329
1330 (define_insn "*mulchwu"
1331   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1332         (mult:SI (lshiftrt:SI
1333                   (match_operand:SI 2 "gpc_reg_operand" "r")
1334                   (const_int 16))
1335                  (zero_extend:SI
1336                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1337   "TARGET_MULHW"
1338   "mulchwu %0, %1, %2"
1339   [(set_attr "type" "imul3")])
1340
1341 (define_insn "*mulhhwc"
1342   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1343         (compare:CC (mult:SI (ashiftrt:SI
1344                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1345                               (const_int 16))
1346                              (ashiftrt:SI
1347                               (match_operand:SI 2 "gpc_reg_operand" "r")
1348                               (const_int 16)))
1349                     (const_int 0)))
1350    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1351         (mult:SI (ashiftrt:SI
1352                   (match_dup 1)
1353                   (const_int 16))
1354                  (ashiftrt:SI
1355                   (match_dup 2)
1356                   (const_int 16))))]
1357   "TARGET_MULHW"
1358   "mulhhw. %0, %1, %2"
1359   [(set_attr "type" "imul3")])
1360
1361 (define_insn "*mulhhw"
1362   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1363         (mult:SI (ashiftrt:SI
1364                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1365                   (const_int 16))
1366                  (ashiftrt:SI
1367                   (match_operand:SI 2 "gpc_reg_operand" "r")
1368                   (const_int 16))))]
1369   "TARGET_MULHW"
1370   "mulhhw %0, %1, %2"
1371   [(set_attr "type" "imul3")])
1372
1373 (define_insn "*mulhhwuc"
1374   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1375         (compare:CC (mult:SI (lshiftrt:SI
1376                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1377                               (const_int 16))
1378                              (lshiftrt:SI
1379                               (match_operand:SI 2 "gpc_reg_operand" "r")
1380                               (const_int 16)))
1381                     (const_int 0)))
1382    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1383         (mult:SI (lshiftrt:SI
1384                   (match_dup 1)
1385                   (const_int 16))
1386                  (lshiftrt:SI
1387                   (match_dup 2)
1388                   (const_int 16))))]
1389   "TARGET_MULHW"
1390   "mulhhwu. %0, %1, %2"
1391   [(set_attr "type" "imul3")])
1392
1393 (define_insn "*mulhhwu"
1394   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1395         (mult:SI (lshiftrt:SI
1396                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1397                   (const_int 16))
1398                  (lshiftrt:SI
1399                   (match_operand:SI 2 "gpc_reg_operand" "r")
1400                   (const_int 16))))]
1401   "TARGET_MULHW"
1402   "mulhhwu %0, %1, %2"
1403   [(set_attr "type" "imul3")])
1404
1405 (define_insn "*mullhwc"
1406   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1407         (compare:CC (mult:SI (sign_extend:SI
1408                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1409                              (sign_extend:SI
1410                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1411                     (const_int 0)))
1412    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1413         (mult:SI (sign_extend:SI
1414                   (match_dup 1))
1415                  (sign_extend:SI
1416                   (match_dup 2))))]
1417   "TARGET_MULHW"
1418   "mullhw. %0, %1, %2"
1419   [(set_attr "type" "imul3")])
1420
1421 (define_insn "*mullhw"
1422   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1423         (mult:SI (sign_extend:SI
1424                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1425                  (sign_extend:SI
1426                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1427   "TARGET_MULHW"
1428   "mullhw %0, %1, %2"
1429   [(set_attr "type" "imul3")])
1430
1431 (define_insn "*mullhwuc"
1432   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1433         (compare:CC (mult:SI (zero_extend:SI
1434                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1435                              (zero_extend:SI
1436                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1437                     (const_int 0)))
1438    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1439         (mult:SI (zero_extend:SI
1440                   (match_dup 1))
1441                  (zero_extend:SI
1442                   (match_dup 2))))]
1443   "TARGET_MULHW"
1444   "mullhwu. %0, %1, %2"
1445   [(set_attr "type" "imul3")])
1446
1447 (define_insn "*mullhwu"
1448   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1449         (mult:SI (zero_extend:SI
1450                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1451                  (zero_extend:SI
1452                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1453   "TARGET_MULHW"
1454   "mullhwu %0, %1, %2"
1455   [(set_attr "type" "imul3")])
1456 \f
1457 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1458 (define_insn "dlmzb"
1459   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1460         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1461                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1462                    UNSPEC_DLMZB_CR))
1463    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1464         (unspec:SI [(match_dup 1)
1465                     (match_dup 2)]
1466                    UNSPEC_DLMZB))]
1467   "TARGET_DLMZB"
1468   "dlmzb. %0, %1, %2")
1469
1470 (define_expand "strlensi"
1471   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1472         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1473                     (match_operand:QI 2 "const_int_operand" "")
1474                     (match_operand 3 "const_int_operand" "")]
1475                    UNSPEC_DLMZB_STRLEN))
1476    (clobber (match_scratch:CC 4 "=x"))]
1477   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1478 {
1479   rtx result = operands[0];
1480   rtx src = operands[1];
1481   rtx search_char = operands[2];
1482   rtx align = operands[3];
1483   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1484   rtx loop_label, end_label, mem, cr0, cond;
1485   if (search_char != const0_rtx
1486       || GET_CODE (align) != CONST_INT
1487       || INTVAL (align) < 8)
1488         FAIL;
1489   word1 = gen_reg_rtx (SImode);
1490   word2 = gen_reg_rtx (SImode);
1491   scratch_dlmzb = gen_reg_rtx (SImode);
1492   scratch_string = gen_reg_rtx (Pmode);
1493   loop_label = gen_label_rtx ();
1494   end_label = gen_label_rtx ();
1495   addr = force_reg (Pmode, XEXP (src, 0));
1496   emit_move_insn (scratch_string, addr);
1497   emit_label (loop_label);
1498   mem = change_address (src, SImode, scratch_string);
1499   emit_move_insn (word1, mem);
1500   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1501   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1502   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1503   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1504   emit_jump_insn (gen_rtx_SET (VOIDmode,
1505                                pc_rtx,
1506                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1507                                                      cond,
1508                                                      gen_rtx_LABEL_REF
1509                                                        (VOIDmode,
1510                                                         end_label),
1511                                                      pc_rtx)));
1512   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1513   emit_jump_insn (gen_rtx_SET (VOIDmode,
1514                                pc_rtx,
1515                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1516   emit_barrier ();
1517   emit_label (end_label);
1518   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1519   emit_insn (gen_subsi3 (result, scratch_string, addr));
1520   emit_insn (gen_subsi3 (result, result, const1_rtx));
1521   DONE;
1522 })
1523 \f
1524 (define_split
1525   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1526         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1527                     (const_int 0)))
1528    (set (match_operand:SI 0 "gpc_reg_operand" "")
1529         (sign_extend:SI (match_dup 1)))]
1530   "reload_completed"
1531   [(set (match_dup 0)
1532         (sign_extend:SI (match_dup 1)))
1533    (set (match_dup 2)
1534         (compare:CC (match_dup 0)
1535                     (const_int 0)))]
1536   "")
1537
1538 ;; Fixed-point arithmetic insns.
1539
1540 (define_expand "add<mode>3"
1541   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1542         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1543                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1544   ""
1545 {
1546   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1547     {
1548       if (non_short_cint_operand (operands[2], DImode))
1549         FAIL;
1550     }
1551   else if (GET_CODE (operands[2]) == CONST_INT
1552            && ! add_operand (operands[2], <MODE>mode))
1553     {
1554       rtx tmp = ((!can_create_pseudo_p ()
1555                   || rtx_equal_p (operands[0], operands[1]))
1556                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1557
1558       HOST_WIDE_INT val = INTVAL (operands[2]);
1559       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1560       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1561
1562       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1563         FAIL;
1564
1565       /* The ordering here is important for the prolog expander.
1566          When space is allocated from the stack, adding 'low' first may
1567          produce a temporary deallocation (which would be bad).  */
1568       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1569       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1570       DONE;
1571     }
1572 })
1573
1574 ;; Discourage ai/addic because of carry but provide it in an alternative
1575 ;; allowing register zero as source.
1576 (define_insn "*add<mode>3_internal1"
1577   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1578         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1579                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1580   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1581   "@
1582    {cax|add} %0,%1,%2
1583    {cal %0,%2(%1)|addi %0,%1,%2}
1584    {ai|addic} %0,%1,%2
1585    {cau|addis} %0,%1,%v2"
1586   [(set_attr "length" "4,4,4,4")])
1587
1588 (define_insn "addsi3_high"
1589   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1590         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1591                  (high:SI (match_operand 2 "" ""))))]
1592   "TARGET_MACHO && !TARGET_64BIT"
1593   "{cau|addis} %0,%1,ha16(%2)"
1594   [(set_attr "length" "4")])
1595
1596 (define_insn "*add<mode>3_internal2"
1597   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1598         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1599                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1600                     (const_int 0)))
1601    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1602   ""
1603   "@
1604    {cax.|add.} %3,%1,%2
1605    {ai.|addic.} %3,%1,%2
1606    #
1607    #"
1608   [(set_attr "type" "fast_compare,compare,compare,compare")
1609    (set_attr "length" "4,4,8,8")])
1610
1611 (define_split
1612   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1613         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1614                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1615                     (const_int 0)))
1616    (clobber (match_scratch:GPR 3 ""))]
1617   "reload_completed"
1618   [(set (match_dup 3)
1619         (plus:GPR (match_dup 1)
1620                  (match_dup 2)))
1621    (set (match_dup 0)
1622         (compare:CC (match_dup 3)
1623                     (const_int 0)))]
1624   "")
1625
1626 (define_insn "*add<mode>3_internal3"
1627   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1628         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1629                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1630                     (const_int 0)))
1631    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1632         (plus:P (match_dup 1)
1633                 (match_dup 2)))]
1634   ""
1635   "@
1636    {cax.|add.} %0,%1,%2
1637    {ai.|addic.} %0,%1,%2
1638    #
1639    #"
1640   [(set_attr "type" "fast_compare,compare,compare,compare")
1641    (set_attr "length" "4,4,8,8")])
1642
1643 (define_split
1644   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1645         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1646                             (match_operand:P 2 "reg_or_short_operand" ""))
1647                     (const_int 0)))
1648    (set (match_operand:P 0 "gpc_reg_operand" "")
1649         (plus:P (match_dup 1) (match_dup 2)))]
1650   "reload_completed"
1651   [(set (match_dup 0)
1652         (plus:P (match_dup 1)
1653                 (match_dup 2)))
1654    (set (match_dup 3)
1655         (compare:CC (match_dup 0)
1656                     (const_int 0)))]
1657   "")
1658
1659 ;; Split an add that we can't do in one insn into two insns, each of which
1660 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1661 ;; add should be last in case the result gets used in an address.
1662
1663 (define_split
1664   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1665         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1666                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1667   ""
1668   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1669    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1670 {
1671   HOST_WIDE_INT val = INTVAL (operands[2]);
1672   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1673   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1674
1675   operands[4] = GEN_INT (low);
1676   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1677     operands[3] = GEN_INT (rest);
1678   else if (can_create_pseudo_p ())
1679     {
1680       operands[3] = gen_reg_rtx (DImode);
1681       emit_move_insn (operands[3], operands[2]);
1682       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1683       DONE;
1684     }
1685   else
1686     FAIL;
1687 })
1688
1689 (define_insn "one_cmpl<mode>2"
1690   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1691         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1692   ""
1693   "nor %0,%1,%1")
1694
1695 (define_insn ""
1696   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1697         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1698                     (const_int 0)))
1699    (clobber (match_scratch:P 2 "=r,r"))]
1700   ""
1701   "@
1702    nor. %2,%1,%1
1703    #"
1704   [(set_attr "type" "fast_compare,compare")
1705    (set_attr "length" "4,8")])
1706
1707 (define_split
1708   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1709         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1710                     (const_int 0)))
1711    (clobber (match_scratch:P 2 ""))]
1712   "reload_completed"
1713   [(set (match_dup 2)
1714         (not:P (match_dup 1)))
1715    (set (match_dup 0)
1716         (compare:CC (match_dup 2)
1717                     (const_int 0)))]
1718   "")
1719
1720 (define_insn ""
1721   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1722         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1723                     (const_int 0)))
1724    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1725         (not:P (match_dup 1)))]
1726   ""
1727   "@
1728    nor. %0,%1,%1
1729    #"
1730   [(set_attr "type" "fast_compare,compare")
1731    (set_attr "length" "4,8")])
1732
1733 (define_split
1734   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1735         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1736                     (const_int 0)))
1737    (set (match_operand:P 0 "gpc_reg_operand" "")
1738         (not:P (match_dup 1)))]
1739   "reload_completed"
1740   [(set (match_dup 0)
1741         (not:P (match_dup 1)))
1742    (set (match_dup 2)
1743         (compare:CC (match_dup 0)
1744                     (const_int 0)))]
1745   "")
1746
1747 (define_insn ""
1748   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1749         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1750                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1751   "! TARGET_POWERPC"
1752   "{sf%I1|subf%I1c} %0,%2,%1")
1753
1754 (define_insn ""
1755   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1756         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1757                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1758   "TARGET_POWERPC"
1759   "@
1760    subf %0,%2,%1
1761    subfic %0,%2,%1")
1762
1763 (define_insn ""
1764   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1765         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1766                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1767                     (const_int 0)))
1768    (clobber (match_scratch:SI 3 "=r,r"))]
1769   "! TARGET_POWERPC"
1770   "@
1771    {sf.|subfc.} %3,%2,%1
1772    #"
1773   [(set_attr "type" "compare")
1774    (set_attr "length" "4,8")])
1775
1776 (define_insn ""
1777   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1778         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1779                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1780                     (const_int 0)))
1781    (clobber (match_scratch:P 3 "=r,r"))]
1782   "TARGET_POWERPC"
1783   "@
1784    subf. %3,%2,%1
1785    #"
1786   [(set_attr "type" "fast_compare")
1787    (set_attr "length" "4,8")])
1788
1789 (define_split
1790   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1791         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1792                              (match_operand:P 2 "gpc_reg_operand" ""))
1793                     (const_int 0)))
1794    (clobber (match_scratch:P 3 ""))]
1795   "reload_completed"
1796   [(set (match_dup 3)
1797         (minus:P (match_dup 1)
1798                   (match_dup 2)))
1799    (set (match_dup 0)
1800         (compare:CC (match_dup 3)
1801                     (const_int 0)))]
1802   "")
1803
1804 (define_insn ""
1805   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1806         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1807                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1808                     (const_int 0)))
1809    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1810         (minus:SI (match_dup 1) (match_dup 2)))]
1811   "! TARGET_POWERPC"
1812   "@
1813    {sf.|subfc.} %0,%2,%1
1814    #"
1815   [(set_attr "type" "compare")
1816    (set_attr "length" "4,8")])
1817
1818 (define_insn ""
1819   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1820         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1821                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1822                     (const_int 0)))
1823    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1824         (minus:P (match_dup 1)
1825                   (match_dup 2)))]
1826   "TARGET_POWERPC"
1827   "@
1828    subf. %0,%2,%1
1829    #"
1830   [(set_attr "type" "fast_compare")
1831    (set_attr "length" "4,8")])
1832
1833 (define_split
1834   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1835         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1836                              (match_operand:P 2 "gpc_reg_operand" ""))
1837                     (const_int 0)))
1838    (set (match_operand:P 0 "gpc_reg_operand" "")
1839         (minus:P (match_dup 1)
1840                   (match_dup 2)))]
1841   "reload_completed"
1842   [(set (match_dup 0)
1843         (minus:P (match_dup 1)
1844                   (match_dup 2)))
1845    (set (match_dup 3)
1846         (compare:CC (match_dup 0)
1847                     (const_int 0)))]
1848   "")
1849
1850 (define_expand "sub<mode>3"
1851   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1852         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1853                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1854   ""
1855   "
1856 {
1857   if (GET_CODE (operands[2]) == CONST_INT)
1858     {
1859       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1860                                  negate_rtx (<MODE>mode, operands[2])));
1861       DONE;
1862     }
1863 }")
1864
1865 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1866 ;; instruction and some auxiliary computations.  Then we just have a single
1867 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1868 ;; combine.
1869
1870 (define_expand "sminsi3"
1871   [(set (match_dup 3)
1872         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1873                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1874                          (const_int 0)
1875                          (minus:SI (match_dup 2) (match_dup 1))))
1876    (set (match_operand:SI 0 "gpc_reg_operand" "")
1877         (minus:SI (match_dup 2) (match_dup 3)))]
1878   "TARGET_POWER || TARGET_ISEL"
1879   "
1880 {
1881   if (TARGET_ISEL)
1882     {
1883       operands[2] = force_reg (SImode, operands[2]);
1884       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1885       DONE;
1886     }
1887
1888   operands[3] = gen_reg_rtx (SImode);
1889 }")
1890
1891 (define_split
1892   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1893         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1894                  (match_operand:SI 2 "reg_or_short_operand" "")))
1895    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1896   "TARGET_POWER"
1897   [(set (match_dup 3)
1898         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1899                          (const_int 0)
1900                          (minus:SI (match_dup 2) (match_dup 1))))
1901    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1902   "")
1903
1904 (define_expand "smaxsi3"
1905   [(set (match_dup 3)
1906         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1907                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1908                          (const_int 0)
1909                          (minus:SI (match_dup 2) (match_dup 1))))
1910    (set (match_operand:SI 0 "gpc_reg_operand" "")
1911         (plus:SI (match_dup 3) (match_dup 1)))]
1912   "TARGET_POWER || TARGET_ISEL"
1913   "
1914 {
1915   if (TARGET_ISEL)
1916     {
1917       operands[2] = force_reg (SImode, operands[2]);
1918       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1919       DONE;
1920     }
1921   operands[3] = gen_reg_rtx (SImode);
1922 }")
1923
1924 (define_split
1925   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1926         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1927                  (match_operand:SI 2 "reg_or_short_operand" "")))
1928    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1929   "TARGET_POWER"
1930   [(set (match_dup 3)
1931         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1932                          (const_int 0)
1933                          (minus:SI (match_dup 2) (match_dup 1))))
1934    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1935   "")
1936
1937 (define_expand "uminsi3"
1938   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1939                               (match_dup 5)))
1940    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1941                               (match_dup 5)))
1942    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1943                                        (const_int 0)
1944                                        (minus:SI (match_dup 4) (match_dup 3))))
1945    (set (match_operand:SI 0 "gpc_reg_operand" "")
1946         (minus:SI (match_dup 2) (match_dup 3)))]
1947   "TARGET_POWER || TARGET_ISEL"
1948   "
1949 {
1950   if (TARGET_ISEL)
1951     {
1952       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1953       DONE;
1954     }
1955   operands[3] = gen_reg_rtx (SImode);
1956   operands[4] = gen_reg_rtx (SImode);
1957   operands[5] = GEN_INT (-2147483647 - 1);
1958 }")
1959
1960 (define_expand "umaxsi3"
1961   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1962                               (match_dup 5)))
1963    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1964                               (match_dup 5)))
1965    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1966                                        (const_int 0)
1967                                        (minus:SI (match_dup 4) (match_dup 3))))
1968    (set (match_operand:SI 0 "gpc_reg_operand" "")
1969         (plus:SI (match_dup 3) (match_dup 1)))]
1970   "TARGET_POWER || TARGET_ISEL"
1971   "
1972 {
1973   if (TARGET_ISEL)
1974     {
1975       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1976       DONE;
1977     }
1978   operands[3] = gen_reg_rtx (SImode);
1979   operands[4] = gen_reg_rtx (SImode);
1980   operands[5] = GEN_INT (-2147483647 - 1);
1981 }")
1982
1983 (define_insn ""
1984   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1985         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1986                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1987                          (const_int 0)
1988                          (minus:SI (match_dup 2) (match_dup 1))))]
1989   "TARGET_POWER"
1990   "doz%I2 %0,%1,%2")
1991
1992 (define_insn ""
1993   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1994         (compare:CC
1995          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1996                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1997                           (const_int 0)
1998                           (minus:SI (match_dup 2) (match_dup 1)))
1999          (const_int 0)))
2000    (clobber (match_scratch:SI 3 "=r,r"))]
2001   "TARGET_POWER"
2002   "@
2003    doz%I2. %3,%1,%2
2004    #"
2005   [(set_attr "type" "delayed_compare")
2006    (set_attr "length" "4,8")])
2007
2008 (define_split
2009   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2010         (compare:CC
2011          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2012                               (match_operand:SI 2 "reg_or_short_operand" ""))
2013                           (const_int 0)
2014                           (minus:SI (match_dup 2) (match_dup 1)))
2015          (const_int 0)))
2016    (clobber (match_scratch:SI 3 ""))]
2017   "TARGET_POWER && reload_completed"
2018   [(set (match_dup 3)
2019         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2020                           (const_int 0)
2021                           (minus:SI (match_dup 2) (match_dup 1))))
2022    (set (match_dup 0)
2023         (compare:CC (match_dup 3)
2024                     (const_int 0)))]
2025   "")
2026
2027 (define_insn ""
2028   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2029         (compare:CC
2030          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2031                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2032                           (const_int 0)
2033                           (minus:SI (match_dup 2) (match_dup 1)))
2034          (const_int 0)))
2035    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2036         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2037                          (const_int 0)
2038                          (minus:SI (match_dup 2) (match_dup 1))))]
2039   "TARGET_POWER"
2040   "@
2041    doz%I2. %0,%1,%2
2042    #"
2043   [(set_attr "type" "delayed_compare")
2044    (set_attr "length" "4,8")])
2045
2046 (define_split
2047   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2048         (compare:CC
2049          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2050                               (match_operand:SI 2 "reg_or_short_operand" ""))
2051                           (const_int 0)
2052                           (minus:SI (match_dup 2) (match_dup 1)))
2053          (const_int 0)))
2054    (set (match_operand:SI 0 "gpc_reg_operand" "")
2055         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2056                          (const_int 0)
2057                          (minus:SI (match_dup 2) (match_dup 1))))]
2058   "TARGET_POWER && reload_completed"
2059   [(set (match_dup 0)
2060         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2061                          (const_int 0)
2062                          (minus:SI (match_dup 2) (match_dup 1))))
2063    (set (match_dup 3)
2064         (compare:CC (match_dup 0)
2065                     (const_int 0)))]
2066   "")
2067
2068 ;; We don't need abs with condition code because such comparisons should
2069 ;; never be done.
2070 (define_expand "abssi2"
2071   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2072         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2073   ""
2074   "
2075 {
2076   if (TARGET_ISEL)
2077     {
2078       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
2079       DONE;
2080     }
2081   else if (! TARGET_POWER)
2082     {
2083       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
2084       DONE;
2085     }
2086 }")
2087
2088 (define_insn "*abssi2_power"
2089   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2090         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2091   "TARGET_POWER"
2092   "abs %0,%1")
2093
2094 (define_insn_and_split "abs<mode>2_isel"
2095   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2096         (abs:GPR (match_operand:GPR 1 "gpc_reg_operand" "b")))
2097    (clobber (match_scratch:GPR 2 "=&b"))
2098    (clobber (match_scratch:CC 3 "=y"))]
2099   "TARGET_ISEL"
2100   "#"
2101   "&& reload_completed"
2102   [(set (match_dup 2) (neg:GPR (match_dup 1)))
2103    (set (match_dup 3)
2104         (compare:CC (match_dup 1)
2105                     (const_int 0)))
2106    (set (match_dup 0)
2107         (if_then_else:GPR (ge (match_dup 3)
2108                               (const_int 0))
2109                           (match_dup 1)
2110                           (match_dup 2)))]
2111   "")
2112
2113 (define_insn_and_split "nabs<mode>2_isel"
2114   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2115         (neg:GPR (abs:GPR (match_operand:GPR 1 "gpc_reg_operand" "b"))))
2116    (clobber (match_scratch:GPR 2 "=&b"))
2117    (clobber (match_scratch:CC 3 "=y"))]
2118   "TARGET_ISEL"
2119   "#"
2120   "&& reload_completed"
2121   [(set (match_dup 2) (neg:GPR (match_dup 1)))
2122    (set (match_dup 3)
2123         (compare:CC (match_dup 1)
2124                     (const_int 0)))
2125    (set (match_dup 0)
2126         (if_then_else:GPR (ge (match_dup 3)
2127                               (const_int 0))
2128                           (match_dup 2)
2129                           (match_dup 1)))]
2130   "")
2131
2132 (define_insn_and_split "abssi2_nopower"
2133   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2134         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2135    (clobber (match_scratch:SI 2 "=&r,&r"))]
2136   "! TARGET_POWER && ! TARGET_ISEL"
2137   "#"
2138   "&& reload_completed"
2139   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2140    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2141    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2142   "")
2143
2144 (define_insn "*nabs_power"
2145   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2146         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2147   "TARGET_POWER"
2148   "nabs %0,%1")
2149
2150 (define_insn_and_split "*nabs_nopower"
2151   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2152         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2153    (clobber (match_scratch:SI 2 "=&r,&r"))]
2154   "! TARGET_POWER"
2155   "#"
2156   "&& reload_completed"
2157   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2158    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2159    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2160   "")
2161
2162 (define_expand "neg<mode>2"
2163   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2164         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2165   ""
2166   "")
2167
2168 (define_insn "*neg<mode>2_internal"
2169   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2170         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2171   ""
2172   "neg %0,%1")
2173
2174 (define_insn ""
2175   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2176         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2177                     (const_int 0)))
2178    (clobber (match_scratch:P 2 "=r,r"))]
2179   ""
2180   "@
2181    neg. %2,%1
2182    #"
2183   [(set_attr "type" "fast_compare")
2184    (set_attr "length" "4,8")])
2185
2186 (define_split
2187   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2188         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2189                     (const_int 0)))
2190    (clobber (match_scratch:P 2 ""))]
2191   "reload_completed"
2192   [(set (match_dup 2)
2193         (neg:P (match_dup 1)))
2194    (set (match_dup 0)
2195         (compare:CC (match_dup 2)
2196                     (const_int 0)))]
2197   "")
2198
2199 (define_insn ""
2200   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2201         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2202                     (const_int 0)))
2203    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2204         (neg:P (match_dup 1)))]
2205   ""
2206   "@
2207    neg. %0,%1
2208    #"
2209   [(set_attr "type" "fast_compare")
2210    (set_attr "length" "4,8")])
2211
2212 (define_split
2213   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2214         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2215                     (const_int 0)))
2216    (set (match_operand:P 0 "gpc_reg_operand" "")
2217         (neg:P (match_dup 1)))]
2218   "reload_completed"
2219   [(set (match_dup 0)
2220         (neg:P (match_dup 1)))
2221    (set (match_dup 2)
2222         (compare:CC (match_dup 0)
2223                     (const_int 0)))]
2224   "")
2225
2226 (define_insn "clz<mode>2"
2227   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2228         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2229   ""
2230   "{cntlz|cntlz<wd>} %0,%1"
2231   [(set_attr "type" "cntlz")])
2232
2233 (define_expand "ctz<mode>2"
2234   [(set (match_dup 2)
2235         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2236    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2237                                           (match_dup 2)))
2238               (clobber (scratch:CC))])
2239    (set (match_dup 4) (clz:GPR (match_dup 3)))
2240    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2241         (minus:GPR (match_dup 5) (match_dup 4)))]
2242   ""
2243   {
2244      operands[2] = gen_reg_rtx (<MODE>mode);
2245      operands[3] = gen_reg_rtx (<MODE>mode);
2246      operands[4] = gen_reg_rtx (<MODE>mode);
2247      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2248   })
2249
2250 (define_expand "ffs<mode>2"
2251   [(set (match_dup 2)
2252         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2253    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2254                                           (match_dup 2)))
2255               (clobber (scratch:CC))])
2256    (set (match_dup 4) (clz:GPR (match_dup 3)))
2257    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2258         (minus:GPR (match_dup 5) (match_dup 4)))]
2259   ""
2260   {
2261      operands[2] = gen_reg_rtx (<MODE>mode);
2262      operands[3] = gen_reg_rtx (<MODE>mode);
2263      operands[4] = gen_reg_rtx (<MODE>mode);
2264      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2265   })
2266
2267 (define_insn "popcntb<mode>2"
2268   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2269         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2270                      UNSPEC_POPCNTB))]
2271   "TARGET_POPCNTB"
2272   "popcntb %0,%1")
2273
2274 (define_insn "popcntwsi2"
2275   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2276         (popcount:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2277   "TARGET_POPCNTD"
2278   "popcntw %0,%1")
2279
2280 (define_insn "popcntddi2"
2281   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2282         (popcount:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
2283   "TARGET_POPCNTD && TARGET_POWERPC64"
2284   "popcntd %0,%1")
2285
2286 (define_expand "popcount<mode>2"
2287   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2288         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2289   "TARGET_POPCNTB || TARGET_POPCNTD"
2290   {
2291     rs6000_emit_popcount (operands[0], operands[1]);
2292     DONE;
2293   })
2294
2295 (define_expand "parity<mode>2"
2296   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2297         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2298   "TARGET_POPCNTB"
2299   {
2300     rs6000_emit_parity (operands[0], operands[1]);
2301     DONE;
2302   })
2303
2304 ;; Since the hardware zeros the upper part of the register, save generating the
2305 ;; AND immediate if we are converting to unsigned
2306 (define_insn "*bswaphi2_extenddi"
2307   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2308         (zero_extend:DI
2309          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2310   "TARGET_POWERPC64"
2311   "lhbrx %0,%y1"
2312   [(set_attr "length" "4")
2313    (set_attr "type" "load")])
2314
2315 (define_insn "*bswaphi2_extendsi"
2316   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2317         (zero_extend:SI
2318          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2319   "TARGET_POWERPC"
2320   "lhbrx %0,%y1"
2321   [(set_attr "length" "4")
2322    (set_attr "type" "load")])
2323
2324 (define_expand "bswaphi2"
2325   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
2326                    (bswap:HI
2327                     (match_operand:HI 1 "reg_or_mem_operand" "")))
2328               (clobber (match_scratch:SI 2 ""))])]
2329   ""
2330 {
2331   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2332     operands[1] = force_reg (HImode, operands[1]);
2333 })
2334
2335 (define_insn "bswaphi2_internal"
2336   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
2337         (bswap:HI
2338          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
2339    (clobber (match_scratch:SI 2 "=X,X,&r"))]
2340   "TARGET_POWERPC"
2341   "@
2342    lhbrx %0,%y1
2343    sthbrx %1,%y0
2344    #"
2345   [(set_attr "length" "4,4,12")
2346    (set_attr "type" "load,store,*")])
2347
2348 (define_split
2349   [(set (match_operand:HI 0 "gpc_reg_operand" "")
2350         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
2351    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2352   "TARGET_POWERPC && reload_completed"
2353   [(set (match_dup 3)
2354         (zero_extract:SI (match_dup 4)
2355                          (const_int 8)
2356                          (const_int 16)))
2357    (set (match_dup 2)
2358         (and:SI (ashift:SI (match_dup 4)
2359                            (const_int 8))
2360                 (const_int 65280)))             ;; 0xff00
2361    (set (match_dup 3)
2362         (ior:SI (match_dup 3)
2363                 (match_dup 2)))]
2364   "
2365 {
2366   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2367   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2368 }")
2369
2370 (define_insn "*bswapsi2_extenddi"
2371   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2372         (zero_extend:DI
2373          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2374   "TARGET_POWERPC64"
2375   "lwbrx %0,%y1"
2376   [(set_attr "length" "4")
2377    (set_attr "type" "load")])
2378
2379 (define_expand "bswapsi2"
2380   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2381         (bswap:SI
2382          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2383   ""
2384 {
2385   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2386     operands[1] = force_reg (SImode, operands[1]);
2387 })
2388
2389 (define_insn "*bswapsi2_internal"
2390   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2391         (bswap:SI
2392          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2393   ""
2394   "@
2395    {lbrx|lwbrx} %0,%y1
2396    {stbrx|stwbrx} %1,%y0
2397    #"
2398   [(set_attr "length" "4,4,12")
2399    (set_attr "type" "load,store,*")])
2400
2401 (define_split
2402   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2403         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2404   "reload_completed"
2405   [(set (match_dup 0)
2406         (rotate:SI (match_dup 1) (const_int 8)))
2407    (set (zero_extract:SI (match_dup 0)
2408                          (const_int 8)
2409                          (const_int 0))
2410         (match_dup 1))
2411    (set (zero_extract:SI (match_dup 0)
2412                          (const_int 8)
2413                          (const_int 16))
2414         (rotate:SI (match_dup 1)
2415                    (const_int 16)))]
2416   "")
2417
2418 (define_expand "bswapdi2"
2419   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2420                    (bswap:DI
2421                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2422               (clobber (match_scratch:DI 2 ""))
2423               (clobber (match_scratch:DI 3 ""))
2424               (clobber (match_scratch:DI 4 ""))])]
2425   ""
2426 {
2427   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2428     operands[1] = force_reg (DImode, operands[1]);
2429
2430   if (!TARGET_POWERPC64)
2431     {
2432       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2433          that uses 64-bit registers needs the same scratch registers as 64-bit
2434          mode.  */
2435       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2436       DONE;
2437     }
2438 })
2439
2440 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2441 (define_insn "*bswapdi2_ldbrx"
2442   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2443         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2444    (clobber (match_scratch:DI 2 "=X,X,&r"))
2445    (clobber (match_scratch:DI 3 "=X,X,&r"))
2446    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2447   "TARGET_POWERPC64 && TARGET_LDBRX
2448    && (REG_P (operands[0]) || REG_P (operands[1]))"
2449   "@
2450    ldbrx %0,%y1
2451    stdbrx %1,%y0
2452    #"
2453   [(set_attr "length" "4,4,36")
2454    (set_attr "type" "load,store,*")])
2455
2456 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2457 (define_insn "*bswapdi2_64bit"
2458   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2459         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2460    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2461    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2462    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2463   "TARGET_POWERPC64 && !TARGET_LDBRX
2464    && (REG_P (operands[0]) || REG_P (operands[1]))"
2465   "#"
2466   [(set_attr "length" "16,12,36")])
2467
2468 (define_split
2469   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2470         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2471    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2472    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2473    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2474   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2475   [(const_int 0)]
2476   "
2477 {
2478   rtx dest   = operands[0];
2479   rtx src    = operands[1];
2480   rtx op2    = operands[2];
2481   rtx op3    = operands[3];
2482   rtx op4    = operands[4];
2483   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode, 4);
2484   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode, 4);
2485   rtx addr1;
2486   rtx addr2;
2487   rtx word_high;
2488   rtx word_low;
2489
2490   addr1 = XEXP (src, 0);
2491   if (GET_CODE (addr1) == PLUS)
2492     {
2493       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2494       addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2495     }
2496   else
2497     {
2498       emit_move_insn (op2, GEN_INT (4));
2499       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2500     }
2501
2502   if (BYTES_BIG_ENDIAN)
2503     {
2504       word_high = change_address (src, SImode, addr1);
2505       word_low  = change_address (src, SImode, addr2);
2506     }
2507   else
2508     {
2509       word_high = change_address (src, SImode, addr2);
2510       word_low  = change_address (src, SImode, addr1);
2511     }
2512
2513   emit_insn (gen_bswapsi2 (op3_32, word_low));
2514   emit_insn (gen_bswapsi2 (op4_32, word_high));
2515   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2516   emit_insn (gen_iordi3 (dest, dest, op4));
2517 }")
2518
2519 (define_split
2520   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2521         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2522    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2523    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2524    (clobber (match_operand:DI 4 "" ""))]
2525   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2526   [(const_int 0)]
2527   "
2528 {
2529   rtx dest   = operands[0];
2530   rtx src    = operands[1];
2531   rtx op2    = operands[2];
2532   rtx op3    = operands[3];
2533   rtx src_si = simplify_gen_subreg (SImode, src, DImode, 4);
2534   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode, 4);
2535   rtx addr1;
2536   rtx addr2;
2537   rtx word_high;
2538   rtx word_low;
2539
2540   addr1 = XEXP (dest, 0);
2541   if (GET_CODE (addr1) == PLUS)
2542     {
2543       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2544       addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2545     }
2546   else
2547     {
2548       emit_move_insn (op2, GEN_INT (4));
2549       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2550     }
2551
2552   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2553   if (BYTES_BIG_ENDIAN)
2554     {
2555       word_high = change_address (dest, SImode, addr1);
2556       word_low  = change_address (dest, SImode, addr2);
2557       emit_insn (gen_bswapsi2 (word_high, src_si));
2558       emit_insn (gen_bswapsi2 (word_low, op3_si));
2559     }
2560   else
2561     {
2562       word_high = change_address (dest, SImode, addr2);
2563       word_low  = change_address (dest, SImode, addr1);
2564       emit_insn (gen_bswapsi2 (word_low, src_si));
2565       emit_insn (gen_bswapsi2 (word_high, op3_si));
2566     }
2567 }")
2568
2569 (define_split
2570   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2571         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2572    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2573    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2574    (clobber (match_operand:DI 4 "" ""))]
2575   "TARGET_POWERPC64 && reload_completed"
2576   [(const_int 0)]
2577   "
2578 {
2579   rtx dest    = operands[0];
2580   rtx src     = operands[1];
2581   rtx op2     = operands[2];
2582   rtx op3     = operands[3];
2583   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, 4);
2584   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, 4);
2585   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, 4);
2586   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, 4);
2587
2588   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2589   emit_insn (gen_bswapsi2 (dest_si, src_si));
2590   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2591   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2592   emit_insn (gen_iordi3 (dest, dest, op3));
2593 }")
2594
2595 (define_insn "bswapdi2_32bit"
2596   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2597         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2598    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2599   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2600   "#"
2601   [(set_attr "length" "16,12,36")])
2602
2603 (define_split
2604   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2605         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2606    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2607   "!TARGET_POWERPC64 && reload_completed"
2608   [(const_int 0)]
2609   "
2610 {
2611   rtx dest   = operands[0];
2612   rtx src    = operands[1];
2613   rtx op2    = operands[2];
2614   rtx dest_hi = simplify_gen_subreg (SImode, dest, DImode, 0);
2615   rtx dest_lo = simplify_gen_subreg (SImode, dest, DImode, 4);
2616   rtx addr1;
2617   rtx addr2;
2618   rtx word_high;
2619   rtx word_low;
2620
2621   addr1 = XEXP (src, 0);
2622   if (GET_CODE (addr1) == PLUS)
2623     {
2624       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2625       addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2626     }
2627   else
2628     {
2629       emit_move_insn (op2, GEN_INT (4));
2630       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2631     }
2632
2633   if (BYTES_BIG_ENDIAN)
2634     {
2635       word_high = change_address (src, SImode, addr1);
2636       word_low  = change_address (src, SImode, addr2);
2637     }
2638   else
2639     {
2640       word_high = change_address (src, SImode, addr2);
2641       word_low  = change_address (src, SImode, addr1);
2642     }
2643
2644   emit_insn (gen_bswapsi2 (dest_hi, word_low));
2645   emit_insn (gen_bswapsi2 (dest_lo, word_high));
2646 }")
2647
2648 (define_split
2649   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2650         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2651    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2652   "!TARGET_POWERPC64 && reload_completed"
2653   [(const_int 0)]
2654   "
2655 {
2656   rtx dest     = operands[0];
2657   rtx src      = operands[1];
2658   rtx op2      = operands[2];
2659   rtx src_high = simplify_gen_subreg (SImode, src, DImode, 0);
2660   rtx src_low  = simplify_gen_subreg (SImode, src, DImode, 4);
2661   rtx addr1;
2662   rtx addr2;
2663   rtx word_high;
2664   rtx word_low;
2665
2666   addr1 = XEXP (dest, 0);
2667   if (GET_CODE (addr1) == PLUS)
2668     {
2669       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2670       addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2671     }
2672   else
2673     {
2674       emit_move_insn (op2, GEN_INT (4));
2675       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2676     }
2677
2678   if (BYTES_BIG_ENDIAN)
2679     {
2680       word_high = change_address (dest, SImode, addr1);
2681       word_low  = change_address (dest, SImode, addr2);
2682     }
2683   else
2684     {
2685       word_high = change_address (dest, SImode, addr2);
2686       word_low  = change_address (dest, SImode, addr1);
2687     }
2688
2689   emit_insn (gen_bswapsi2 (word_high, src_low));
2690   emit_insn (gen_bswapsi2 (word_low, src_high));
2691 }")
2692
2693 (define_split
2694   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2695         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2696    (clobber (match_operand:SI 2 "" ""))]
2697   "!TARGET_POWERPC64 && reload_completed"
2698   [(const_int 0)]
2699   "
2700 {
2701   rtx dest      = operands[0];
2702   rtx src       = operands[1];
2703   rtx src_high  = simplify_gen_subreg (SImode, src, DImode, 0);
2704   rtx src_low   = simplify_gen_subreg (SImode, src, DImode, 4);
2705   rtx dest_high = simplify_gen_subreg (SImode, dest, DImode, 0);
2706   rtx dest_low  = simplify_gen_subreg (SImode, dest, DImode, 4);
2707
2708   emit_insn (gen_bswapsi2 (dest_high, src_low));
2709   emit_insn (gen_bswapsi2 (dest_low, src_high));
2710 }")
2711
2712 (define_expand "mulsi3"
2713   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2714    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2715    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2716   ""
2717   "
2718 {
2719   if (TARGET_POWER)
2720     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2721   else
2722     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2723   DONE;
2724 }")
2725
2726 (define_insn "mulsi3_mq"
2727   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2728         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2729                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2730    (clobber (match_scratch:SI 3 "=q,q"))]
2731   "TARGET_POWER"
2732   "@
2733    {muls|mullw} %0,%1,%2
2734    {muli|mulli} %0,%1,%2"
2735    [(set (attr "type")
2736       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2737                 (const_string "imul3")
2738              (match_operand:SI 2 "short_cint_operand" "")
2739                 (const_string "imul2")]
2740         (const_string "imul")))])
2741
2742 (define_insn "mulsi3_no_mq"
2743   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2744         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2745                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2746   "! TARGET_POWER"
2747   "@
2748    {muls|mullw} %0,%1,%2
2749    {muli|mulli} %0,%1,%2"
2750    [(set (attr "type")
2751       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2752                 (const_string "imul3")
2753              (match_operand:SI 2 "short_cint_operand" "")
2754                 (const_string "imul2")]
2755         (const_string "imul")))])
2756
2757 (define_insn "*mulsi3_mq_internal1"
2758   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2759         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2760                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2761                     (const_int 0)))
2762    (clobber (match_scratch:SI 3 "=r,r"))
2763    (clobber (match_scratch:SI 4 "=q,q"))]
2764   "TARGET_POWER"
2765   "@
2766    {muls.|mullw.} %3,%1,%2
2767    #"
2768   [(set_attr "type" "imul_compare")
2769    (set_attr "length" "4,8")])
2770
2771 (define_split
2772   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2773         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2774                              (match_operand:SI 2 "gpc_reg_operand" ""))
2775                     (const_int 0)))
2776    (clobber (match_scratch:SI 3 ""))
2777    (clobber (match_scratch:SI 4 ""))]
2778   "TARGET_POWER && reload_completed"
2779   [(parallel [(set (match_dup 3)
2780         (mult:SI (match_dup 1) (match_dup 2)))
2781    (clobber (match_dup 4))])
2782    (set (match_dup 0)
2783         (compare:CC (match_dup 3)
2784                     (const_int 0)))]
2785   "")
2786
2787 (define_insn "*mulsi3_no_mq_internal1"
2788   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2789         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2790                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2791                     (const_int 0)))
2792    (clobber (match_scratch:SI 3 "=r,r"))]
2793   "! TARGET_POWER"
2794   "@
2795    {muls.|mullw.} %3,%1,%2
2796    #"
2797   [(set_attr "type" "imul_compare")
2798    (set_attr "length" "4,8")])
2799
2800 (define_split
2801   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2802         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2803                              (match_operand:SI 2 "gpc_reg_operand" ""))
2804                     (const_int 0)))
2805    (clobber (match_scratch:SI 3 ""))]
2806   "! TARGET_POWER && reload_completed"
2807   [(set (match_dup 3)
2808         (mult:SI (match_dup 1) (match_dup 2)))
2809    (set (match_dup 0)
2810         (compare:CC (match_dup 3)
2811                     (const_int 0)))]
2812   "")
2813
2814 (define_insn "*mulsi3_mq_internal2"
2815   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2816         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2817                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2818                     (const_int 0)))
2819    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2820         (mult:SI (match_dup 1) (match_dup 2)))
2821    (clobber (match_scratch:SI 4 "=q,q"))]
2822   "TARGET_POWER"
2823   "@
2824    {muls.|mullw.} %0,%1,%2
2825    #"
2826   [(set_attr "type" "imul_compare")
2827    (set_attr "length" "4,8")])
2828
2829 (define_split
2830   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2831         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2832                              (match_operand:SI 2 "gpc_reg_operand" ""))
2833                     (const_int 0)))
2834    (set (match_operand:SI 0 "gpc_reg_operand" "")
2835         (mult:SI (match_dup 1) (match_dup 2)))
2836    (clobber (match_scratch:SI 4 ""))]
2837   "TARGET_POWER && reload_completed"
2838   [(parallel [(set (match_dup 0)
2839         (mult:SI (match_dup 1) (match_dup 2)))
2840    (clobber (match_dup 4))])
2841    (set (match_dup 3)
2842         (compare:CC (match_dup 0)
2843                     (const_int 0)))]
2844   "")
2845
2846 (define_insn "*mulsi3_no_mq_internal2"
2847   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2848         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2849                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2850                     (const_int 0)))
2851    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2852         (mult:SI (match_dup 1) (match_dup 2)))]
2853   "! TARGET_POWER"
2854   "@
2855    {muls.|mullw.} %0,%1,%2
2856    #"
2857   [(set_attr "type" "imul_compare")
2858    (set_attr "length" "4,8")])
2859
2860 (define_split
2861   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2862         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2863                              (match_operand:SI 2 "gpc_reg_operand" ""))
2864                     (const_int 0)))
2865    (set (match_operand:SI 0 "gpc_reg_operand" "")
2866         (mult:SI (match_dup 1) (match_dup 2)))]
2867   "! TARGET_POWER && reload_completed"
2868   [(set (match_dup 0)
2869         (mult:SI (match_dup 1) (match_dup 2)))
2870    (set (match_dup 3)
2871         (compare:CC (match_dup 0)
2872                     (const_int 0)))]
2873   "")
2874
2875 ;; Operand 1 is divided by operand 2; quotient goes to operand
2876 ;; 0 and remainder to operand 3.
2877 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2878
2879 (define_expand "divmodsi4"
2880   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2881                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2882                            (match_operand:SI 2 "gpc_reg_operand" "")))
2883               (set (match_operand:SI 3 "register_operand" "")
2884                    (mod:SI (match_dup 1) (match_dup 2)))])]
2885   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2886   "
2887 {
2888   if (! TARGET_POWER && ! TARGET_POWERPC)
2889     {
2890       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2891       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2892       emit_insn (gen_divss_call ());
2893       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2894       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2895       DONE;
2896     }
2897 }")
2898
2899 (define_insn "*divmodsi4_internal"
2900   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2901         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2902                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2903    (set (match_operand:SI 3 "register_operand" "=q")
2904         (mod:SI (match_dup 1) (match_dup 2)))]
2905   "TARGET_POWER"
2906   "divs %0,%1,%2"
2907   [(set_attr "type" "idiv")])
2908
2909 (define_expand "udiv<mode>3"
2910   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2911         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2912                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2913   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2914   "
2915 {
2916   if (! TARGET_POWER && ! TARGET_POWERPC)
2917     {
2918       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2919       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2920       emit_insn (gen_quous_call ());
2921       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2922       DONE;
2923     }
2924   else if (TARGET_POWER)
2925     {
2926       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2927       DONE;
2928     }
2929 }")
2930
2931 (define_insn "udivsi3_mq"
2932   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2933         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2934                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2935    (clobber (match_scratch:SI 3 "=q"))]
2936   "TARGET_POWERPC && TARGET_POWER"
2937   "divwu %0,%1,%2"
2938   [(set_attr "type" "idiv")])
2939
2940 (define_insn "*udivsi3_no_mq"
2941   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2942         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2943                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2944   "TARGET_POWERPC && ! TARGET_POWER"
2945   "div<wd>u %0,%1,%2"
2946    [(set (attr "type")
2947       (cond [(match_operand:SI 0 "" "")
2948                 (const_string "idiv")]
2949         (const_string "ldiv")))])
2950
2951
2952 ;; For powers of two we can do srai/aze for divide and then adjust for
2953 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2954 ;; used; for PowerPC, force operands into register and do a normal divide;
2955 ;; for AIX common-mode, use quoss call on register operands.
2956 (define_expand "div<mode>3"
2957   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2958         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2959                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2960   ""
2961   "
2962 {
2963   if (GET_CODE (operands[2]) == CONST_INT
2964       && INTVAL (operands[2]) > 0
2965       && exact_log2 (INTVAL (operands[2])) >= 0)
2966     ;
2967   else if (TARGET_POWERPC)
2968     {
2969       operands[2] = force_reg (<MODE>mode, operands[2]);
2970       if (TARGET_POWER)
2971         {
2972           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2973           DONE;
2974         }
2975     }
2976   else if (TARGET_POWER)
2977     FAIL;
2978   else
2979     {
2980       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2981       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2982       emit_insn (gen_quoss_call ());
2983       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2984       DONE;
2985     }
2986 }")
2987
2988 (define_insn "divsi3_mq"
2989   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2990         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2991                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2992    (clobber (match_scratch:SI 3 "=q"))]
2993   "TARGET_POWERPC && TARGET_POWER"
2994   "divw %0,%1,%2"
2995   [(set_attr "type" "idiv")])
2996
2997 (define_insn "*div<mode>3_no_mq"
2998   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2999         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3000                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
3001   "TARGET_POWERPC && ! TARGET_POWER"
3002   "div<wd> %0,%1,%2"
3003   [(set (attr "type")
3004      (cond [(match_operand:SI 0 "" "")
3005                 (const_string "idiv")]
3006         (const_string "ldiv")))])
3007
3008 (define_expand "mod<mode>3"
3009   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
3010    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
3011    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
3012   ""
3013   "
3014 {
3015   int i;
3016   rtx temp1;
3017   rtx temp2;
3018
3019   if (GET_CODE (operands[2]) != CONST_INT
3020       || INTVAL (operands[2]) <= 0
3021       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
3022     FAIL;
3023
3024   temp1 = gen_reg_rtx (<MODE>mode);
3025   temp2 = gen_reg_rtx (<MODE>mode);
3026
3027   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
3028   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
3029   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
3030   DONE;
3031 }")
3032
3033 (define_insn ""
3034   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3035         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3036                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
3037   ""
3038   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
3039   [(set_attr "type" "two")
3040    (set_attr "length" "8")])
3041
3042 (define_insn ""
3043   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3044         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
3045                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
3046                     (const_int 0)))
3047    (clobber (match_scratch:P 3 "=r,r"))]
3048   ""
3049   "@
3050    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
3051    #"
3052   [(set_attr "type" "compare")
3053    (set_attr "length" "8,12")
3054    (set_attr "cell_micro" "not")])
3055
3056 (define_split
3057   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3058         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3059                              (match_operand:GPR 2 "exact_log2_cint_operand"
3060                               ""))
3061                     (const_int 0)))
3062    (clobber (match_scratch:GPR 3 ""))]
3063   "reload_completed"
3064   [(set (match_dup 3)
3065         (div:<MODE> (match_dup 1) (match_dup 2)))
3066    (set (match_dup 0)
3067         (compare:CC (match_dup 3)
3068                     (const_int 0)))]
3069   "")
3070
3071 (define_insn ""
3072   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3073         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
3074                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
3075                     (const_int 0)))
3076    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
3077         (div:P (match_dup 1) (match_dup 2)))]
3078   ""
3079   "@
3080    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
3081    #"
3082   [(set_attr "type" "compare")
3083    (set_attr "length" "8,12")
3084    (set_attr "cell_micro" "not")])
3085
3086 (define_split
3087   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3088         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3089                              (match_operand:GPR 2 "exact_log2_cint_operand"
3090                               ""))
3091                     (const_int 0)))
3092    (set (match_operand:GPR 0 "gpc_reg_operand" "")
3093         (div:GPR (match_dup 1) (match_dup 2)))]
3094   "reload_completed"
3095   [(set (match_dup 0)
3096         (div:<MODE> (match_dup 1) (match_dup 2)))
3097    (set (match_dup 3)
3098         (compare:CC (match_dup 0)
3099                     (const_int 0)))]
3100   "")
3101
3102 (define_insn ""
3103   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3104         (udiv:SI
3105          (plus:DI (ashift:DI
3106                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
3107                    (const_int 32))
3108                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
3109          (match_operand:SI 3 "gpc_reg_operand" "r")))
3110    (set (match_operand:SI 2 "register_operand" "=*q")
3111         (umod:SI
3112          (plus:DI (ashift:DI
3113                    (zero_extend:DI (match_dup 1)) (const_int 32))
3114                   (zero_extend:DI (match_dup 4)))
3115          (match_dup 3)))]
3116   "TARGET_POWER"
3117   "div %0,%1,%3"
3118   [(set_attr "type" "idiv")])
3119
3120 ;; To do unsigned divide we handle the cases of the divisor looking like a
3121 ;; negative number.  If it is a constant that is less than 2**31, we don't
3122 ;; have to worry about the branches.  So make a few subroutines here.
3123 ;;
3124 ;; First comes the normal case.
3125 (define_expand "udivmodsi4_normal"
3126   [(set (match_dup 4) (const_int 0))
3127    (parallel [(set (match_operand:SI 0 "" "")
3128                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
3129                                                 (const_int 32))
3130                                      (zero_extend:DI (match_operand:SI 1 "" "")))
3131                             (match_operand:SI 2 "" "")))
3132               (set (match_operand:SI 3 "" "")
3133                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
3134                                                 (const_int 32))
3135                                      (zero_extend:DI (match_dup 1)))
3136                             (match_dup 2)))])]
3137   "TARGET_POWER"
3138   "
3139 { operands[4] = gen_reg_rtx (SImode); }")
3140
3141 ;; This handles the branches.
3142 (define_expand "udivmodsi4_tests"
3143   [(set (match_operand:SI 0 "" "") (const_int 0))
3144    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
3145    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
3146    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
3147                            (label_ref (match_operand:SI 4 "" "")) (pc)))
3148    (set (match_dup 0) (const_int 1))
3149    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
3150    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
3151    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
3152                            (label_ref (match_dup 4)) (pc)))]
3153   "TARGET_POWER"
3154   "
3155 { operands[5] = gen_reg_rtx (CCUNSmode);
3156   operands[6] = gen_reg_rtx (CCmode);
3157 }")
3158
3159 (define_expand "udivmodsi4"
3160   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
3161                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
3162                             (match_operand:SI 2 "reg_or_cint_operand" "")))
3163               (set (match_operand:SI 3 "gpc_reg_operand" "")
3164                    (umod:SI (match_dup 1) (match_dup 2)))])]
3165   ""
3166   "
3167 {
3168   rtx label = 0;
3169
3170   if (! TARGET_POWER)
3171     {
3172       if (! TARGET_POWERPC)
3173         {
3174           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
3175           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
3176           emit_insn (gen_divus_call ());
3177           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
3178           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
3179           DONE;
3180         }
3181       else
3182         FAIL;
3183     }
3184
3185   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
3186     {
3187       operands[2] = force_reg (SImode, operands[2]);
3188       label = gen_label_rtx ();
3189       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
3190                                   operands[3], label));
3191     }
3192   else
3193     operands[2] = force_reg (SImode, operands[2]);
3194
3195   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
3196                                operands[3]));
3197   if (label)
3198     emit_label (label);
3199
3200   DONE;
3201 }")
3202
3203 ;; AIX architecture-independent common-mode multiply (DImode),
3204 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
3205 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
3206 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
3207 ;; assumed unused if generating common-mode, so ignore.
3208 (define_insn "mulh_call"
3209   [(set (reg:SI 3)
3210         (truncate:SI
3211          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
3212                                (sign_extend:DI (reg:SI 4)))
3213                       (const_int 32))))
3214    (clobber (reg:SI LR_REGNO))]
3215   "! TARGET_POWER && ! TARGET_POWERPC"
3216   "bla __mulh"
3217   [(set_attr "type" "imul")])
3218
3219 (define_insn "mull_call"
3220   [(set (reg:DI 3)
3221         (mult:DI (sign_extend:DI (reg:SI 3))
3222                  (sign_extend:DI (reg:SI 4))))
3223    (clobber (reg:SI LR_REGNO))
3224    (clobber (reg:SI 0))]
3225   "! TARGET_POWER && ! TARGET_POWERPC"
3226   "bla __mull"
3227   [(set_attr "type" "imul")])
3228
3229 (define_insn "divss_call"
3230   [(set (reg:SI 3)
3231         (div:SI (reg:SI 3) (reg:SI 4)))
3232    (set (reg:SI 4)
3233         (mod:SI (reg:SI 3) (reg:SI 4)))
3234    (clobber (reg:SI LR_REGNO))
3235    (clobber (reg:SI 0))]
3236   "! TARGET_POWER && ! TARGET_POWERPC"
3237   "bla __divss"
3238   [(set_attr "type" "idiv")])
3239
3240 (define_insn "divus_call"
3241   [(set (reg:SI 3)
3242         (udiv:SI (reg:SI 3) (reg:SI 4)))
3243    (set (reg:SI 4)
3244         (umod:SI (reg:SI 3) (reg:SI 4)))
3245    (clobber (reg:SI LR_REGNO))
3246    (clobber (reg:SI 0))
3247    (clobber (match_scratch:CC 0 "=x"))
3248    (clobber (reg:CC CR1_REGNO))]
3249   "! TARGET_POWER && ! TARGET_POWERPC"
3250   "bla __divus"
3251   [(set_attr "type" "idiv")])
3252
3253 (define_insn "quoss_call"
3254   [(set (reg:SI 3)
3255         (div:SI (reg:SI 3) (reg:SI 4)))
3256    (clobber (reg:SI LR_REGNO))]
3257   "! TARGET_POWER && ! TARGET_POWERPC"
3258   "bla __quoss"
3259   [(set_attr "type" "idiv")])
3260
3261 (define_insn "quous_call"
3262   [(set (reg:SI 3)
3263         (udiv:SI (reg:SI 3) (reg:SI 4)))
3264    (clobber (reg:SI LR_REGNO))
3265    (clobber (reg:SI 0))
3266    (clobber (match_scratch:CC 0 "=x"))
3267    (clobber (reg:CC CR1_REGNO))]
3268   "! TARGET_POWER && ! TARGET_POWERPC"
3269   "bla __quous"
3270   [(set_attr "type" "idiv")])
3271 \f
3272 ;; Logical instructions
3273 ;; The logical instructions are mostly combined by using match_operator,
3274 ;; but the plain AND insns are somewhat different because there is no
3275 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
3276 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
3277
3278 (define_expand "andsi3"
3279   [(parallel
3280     [(set (match_operand:SI 0 "gpc_reg_operand" "")
3281           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3282                   (match_operand:SI 2 "and_operand" "")))
3283      (clobber (match_scratch:CC 3 ""))])]
3284   ""
3285   "")
3286
3287 (define_insn "andsi3_mc"
3288   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3289         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
3290                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
3291    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
3292   "rs6000_gen_cell_microcode"
3293   "@
3294    and %0,%1,%2
3295    {rlinm|rlwinm} %0,%1,0,%m2,%M2
3296    {andil.|andi.} %0,%1,%b2
3297    {andiu.|andis.} %0,%1,%u2"
3298   [(set_attr "type" "*,*,fast_compare,fast_compare")])
3299
3300 (define_insn "andsi3_nomc"
3301   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3302         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
3303                 (match_operand:SI 2 "and_operand" "?r,T")))
3304    (clobber (match_scratch:CC 3 "=X,X"))]
3305   "!rs6000_gen_cell_microcode"
3306   "@
3307    and %0,%1,%2
3308    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
3309
3310 (define_insn "andsi3_internal0_nomc"
3311   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3312         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
3313                 (match_operand:SI 2 "and_operand" "?r,T")))]
3314   "!rs6000_gen_cell_microcode"
3315   "@
3316    and %0,%1,%2
3317    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
3318
3319
3320 ;; Note to set cr's other than cr0 we do the and immediate and then
3321 ;; the test again -- this avoids a mfcr which on the higher end
3322 ;; machines causes an execution serialization
3323
3324 (define_insn "*andsi3_internal2_mc"
3325   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3326         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3327                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3328                     (const_int 0)))
3329    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
3330    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3331   "TARGET_32BIT && rs6000_gen_cell_microcode"
3332   "@
3333    and. %3,%1,%2
3334    {andil.|andi.} %3,%1,%b2
3335    {andiu.|andis.} %3,%1,%u2
3336    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
3337    #
3338    #
3339    #
3340    #"
3341   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
3342                      compare,compare,compare,compare")
3343    (set_attr "length" "4,4,4,4,8,8,8,8")])
3344
3345 (define_insn "*andsi3_internal3_mc"
3346   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3347         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3348                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3349                     (const_int 0)))
3350    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
3351    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3352   "TARGET_64BIT && rs6000_gen_cell_microcode"
3353   "@
3354    #
3355    {andil.|andi.} %3,%1,%b2
3356    {andiu.|andis.} %3,%1,%u2
3357    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
3358    #
3359    #
3360    #
3361    #"
3362   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
3363                      compare,compare,compare")
3364    (set_attr "length" "8,4,4,4,8,8,8,8")])
3365
3366 (define_split
3367   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3368         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3369                              (match_operand:GPR 2 "and_operand" ""))
3370                     (const_int 0)))
3371    (clobber (match_scratch:GPR 3 ""))
3372    (clobber (match_scratch:CC 4 ""))]
3373   "reload_completed"
3374   [(parallel [(set (match_dup 3)
3375                    (and:<MODE> (match_dup 1)
3376                                (match_dup 2)))
3377               (clobber (match_dup 4))])
3378    (set (match_dup 0)
3379         (compare:CC (match_dup 3)
3380                     (const_int 0)))]
3381   "")
3382
3383 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
3384 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
3385
3386 (define_split
3387   [(set (match_operand:CC 0 "cc_reg_operand" "")
3388         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3389                             (match_operand:SI 2 "gpc_reg_operand" ""))
3390                     (const_int 0)))
3391    (clobber (match_scratch:SI 3 ""))
3392    (clobber (match_scratch:CC 4 ""))]
3393   "TARGET_POWERPC64 && reload_completed"
3394   [(parallel [(set (match_dup 3)
3395                    (and:SI (match_dup 1)
3396                            (match_dup 2)))
3397               (clobber (match_dup 4))])
3398    (set (match_dup 0)
3399         (compare:CC (match_dup 3)
3400                     (const_int 0)))]
3401   "")
3402
3403 (define_insn "*andsi3_internal4"
3404   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3405         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3406                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3407                     (const_int 0)))
3408    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3409         (and:SI (match_dup 1)
3410                 (match_dup 2)))
3411    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3412   "TARGET_32BIT && rs6000_gen_cell_microcode"
3413   "@
3414    and. %0,%1,%2
3415    {andil.|andi.} %0,%1,%b2
3416    {andiu.|andis.} %0,%1,%u2
3417    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3418    #
3419    #
3420    #
3421    #"
3422   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
3423                      compare,compare,compare,compare")
3424    (set_attr "length" "4,4,4,4,8,8,8,8")])
3425
3426 (define_insn "*andsi3_internal5_mc"
3427   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3428         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3429                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3430                     (const_int 0)))
3431    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3432         (and:SI (match_dup 1)
3433                 (match_dup 2)))
3434    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3435   "TARGET_64BIT && rs6000_gen_cell_microcode"
3436   "@
3437    #
3438    {andil.|andi.} %0,%1,%b2
3439    {andiu.|andis.} %0,%1,%u2
3440    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3441    #
3442    #
3443    #
3444    #"
3445   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
3446                      compare,compare,compare")
3447    (set_attr "length" "8,4,4,4,8,8,8,8")])
3448
3449 (define_split
3450   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3451         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3452                             (match_operand:SI 2 "and_operand" ""))
3453                     (const_int 0)))
3454    (set (match_operand:SI 0 "gpc_reg_operand" "")
3455         (and:SI (match_dup 1)
3456                 (match_dup 2)))
3457    (clobber (match_scratch:CC 4 ""))]
3458   "reload_completed"
3459   [(parallel [(set (match_dup 0)
3460                    (and:SI (match_dup 1)
3461                            (match_dup 2)))
3462               (clobber (match_dup 4))])
3463    (set (match_dup 3)
3464         (compare:CC (match_dup 0)
3465                     (const_int 0)))]
3466   "")
3467
3468 (define_split
3469   [(set (match_operand:CC 3 "cc_reg_operand" "")
3470         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3471                             (match_operand:SI 2 "gpc_reg_operand" ""))
3472                     (const_int 0)))
3473    (set (match_operand:SI 0 "gpc_reg_operand" "")
3474         (and:SI (match_dup 1)
3475                 (match_dup 2)))
3476    (clobber (match_scratch:CC 4 ""))]
3477   "TARGET_POWERPC64 && reload_completed"
3478   [(parallel [(set (match_dup 0)
3479                    (and:SI (match_dup 1)
3480                            (match_dup 2)))
3481               (clobber (match_dup 4))])
3482    (set (match_dup 3)
3483         (compare:CC (match_dup 0)
3484                     (const_int 0)))]
3485   "")
3486
3487 ;; Handle the PowerPC64 rlwinm corner case
3488
3489 (define_insn_and_split "*andsi3_internal6"
3490   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3491         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3492                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3493   "TARGET_POWERPC64"
3494   "#"
3495   "TARGET_POWERPC64"
3496   [(set (match_dup 0)
3497         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3498                 (match_dup 4)))
3499    (set (match_dup 0)
3500         (rotate:SI (match_dup 0) (match_dup 5)))]
3501   "
3502 {
3503   int mb = extract_MB (operands[2]);
3504   int me = extract_ME (operands[2]);
3505   operands[3] = GEN_INT (me + 1);
3506   operands[5] = GEN_INT (32 - (me + 1));
3507   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3508 }"
3509   [(set_attr "length" "8")])
3510
3511 (define_expand "iorsi3"
3512   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3513         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3514                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3515   ""
3516   "
3517 {
3518   if (GET_CODE (operands[2]) == CONST_INT
3519       && ! logical_operand (operands[2], SImode))
3520     {
3521       HOST_WIDE_INT value = INTVAL (operands[2]);
3522       rtx tmp = ((!can_create_pseudo_p ()
3523                   || rtx_equal_p (operands[0], operands[1]))
3524                  ? operands[0] : gen_reg_rtx (SImode));
3525
3526       emit_insn (gen_iorsi3 (tmp, operands[1],
3527                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3528       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3529       DONE;
3530     }
3531 }")
3532
3533 (define_expand "xorsi3"
3534   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3535         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3536                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3537   ""
3538   "
3539 {
3540   if (GET_CODE (operands[2]) == CONST_INT
3541       && ! logical_operand (operands[2], SImode))
3542     {
3543       HOST_WIDE_INT value = INTVAL (operands[2]);
3544       rtx tmp = ((!can_create_pseudo_p ()
3545                   || rtx_equal_p (operands[0], operands[1]))
3546                  ? operands[0] : gen_reg_rtx (SImode));
3547
3548       emit_insn (gen_xorsi3 (tmp, operands[1],
3549                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3550       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3551       DONE;
3552     }
3553 }")
3554
3555 (define_insn "*boolsi3_internal1"
3556   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3557         (match_operator:SI 3 "boolean_or_operator"
3558          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3559           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3560   ""
3561   "@
3562    %q3 %0,%1,%2
3563    {%q3il|%q3i} %0,%1,%b2
3564    {%q3iu|%q3is} %0,%1,%u2")
3565
3566 (define_insn "*boolsi3_internal2"
3567   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3568         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3569          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3570           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3571          (const_int 0)))
3572    (clobber (match_scratch:SI 3 "=r,r"))]
3573   "TARGET_32BIT"
3574   "@
3575    %q4. %3,%1,%2
3576    #"
3577   [(set_attr "type" "fast_compare,compare")
3578    (set_attr "length" "4,8")])
3579
3580 (define_split
3581   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3582         (compare:CC (match_operator:SI 4 "boolean_operator"
3583          [(match_operand:SI 1 "gpc_reg_operand" "")
3584           (match_operand:SI 2 "gpc_reg_operand" "")])
3585          (const_int 0)))
3586    (clobber (match_scratch:SI 3 ""))]
3587   "TARGET_32BIT && reload_completed"
3588   [(set (match_dup 3) (match_dup 4))
3589    (set (match_dup 0)
3590         (compare:CC (match_dup 3)
3591                     (const_int 0)))]
3592   "")
3593
3594 (define_insn "*boolsi3_internal3"
3595   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3596         (compare:CC (match_operator:SI 4 "boolean_operator"
3597          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3598           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3599          (const_int 0)))
3600    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3601         (match_dup 4))]
3602   "TARGET_32BIT"
3603   "@
3604    %q4. %0,%1,%2
3605    #"
3606   [(set_attr "type" "fast_compare,compare")
3607    (set_attr "length" "4,8")])
3608
3609 (define_split
3610   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3611         (compare:CC (match_operator:SI 4 "boolean_operator"
3612          [(match_operand:SI 1 "gpc_reg_operand" "")
3613           (match_operand:SI 2 "gpc_reg_operand" "")])
3614          (const_int 0)))
3615    (set (match_operand:SI 0 "gpc_reg_operand" "")
3616         (match_dup 4))]
3617   "TARGET_32BIT && reload_completed"
3618   [(set (match_dup 0) (match_dup 4))
3619    (set (match_dup 3)
3620         (compare:CC (match_dup 0)
3621                     (const_int 0)))]
3622   "")
3623
3624 ;; Split a logical operation that we can't do in one insn into two insns,
3625 ;; each of which does one 16-bit part.  This is used by combine.
3626
3627 (define_split
3628   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3629         (match_operator:SI 3 "boolean_or_operator"
3630          [(match_operand:SI 1 "gpc_reg_operand" "")
3631           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3632   ""
3633   [(set (match_dup 0) (match_dup 4))
3634    (set (match_dup 0) (match_dup 5))]
3635 "
3636 {
3637   rtx i;
3638   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3639   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3640                                 operands[1], i);
3641   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3642   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3643                                 operands[0], i);
3644 }")
3645
3646 (define_insn "*boolcsi3_internal1"
3647   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3648         (match_operator:SI 3 "boolean_operator"
3649          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3650           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3651   ""
3652   "%q3 %0,%2,%1")
3653
3654 (define_insn "*boolcsi3_internal2"
3655   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3656         (compare:CC (match_operator:SI 4 "boolean_operator"
3657          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3658           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3659          (const_int 0)))
3660    (clobber (match_scratch:SI 3 "=r,r"))]
3661   "TARGET_32BIT"
3662   "@
3663    %q4. %3,%2,%1
3664    #"
3665   [(set_attr "type" "compare")
3666    (set_attr "length" "4,8")])
3667
3668 (define_split
3669   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3670         (compare:CC (match_operator:SI 4 "boolean_operator"
3671          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3672           (match_operand:SI 2 "gpc_reg_operand" "")])
3673          (const_int 0)))
3674    (clobber (match_scratch:SI 3 ""))]
3675   "TARGET_32BIT && reload_completed"
3676   [(set (match_dup 3) (match_dup 4))
3677    (set (match_dup 0)
3678         (compare:CC (match_dup 3)
3679                     (const_int 0)))]
3680   "")
3681
3682 (define_insn "*boolcsi3_internal3"
3683   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3684         (compare:CC (match_operator:SI 4 "boolean_operator"
3685          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3686           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3687          (const_int 0)))
3688    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3689         (match_dup 4))]
3690   "TARGET_32BIT"
3691   "@
3692    %q4. %0,%2,%1
3693    #"
3694   [(set_attr "type" "compare")
3695    (set_attr "length" "4,8")])
3696
3697 (define_split
3698   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3699         (compare:CC (match_operator:SI 4 "boolean_operator"
3700          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3701           (match_operand:SI 2 "gpc_reg_operand" "")])
3702          (const_int 0)))
3703    (set (match_operand:SI 0 "gpc_reg_operand" "")
3704         (match_dup 4))]
3705   "TARGET_32BIT && reload_completed"
3706   [(set (match_dup 0) (match_dup 4))
3707    (set (match_dup 3)
3708         (compare:CC (match_dup 0)
3709                     (const_int 0)))]
3710   "")
3711
3712 (define_insn "*boolccsi3_internal1"
3713   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3714         (match_operator:SI 3 "boolean_operator"
3715          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3716           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3717   ""
3718   "%q3 %0,%1,%2")
3719
3720 (define_insn "*boolccsi3_internal2"
3721   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3722         (compare:CC (match_operator:SI 4 "boolean_operator"
3723          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3724           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3725          (const_int 0)))
3726    (clobber (match_scratch:SI 3 "=r,r"))]
3727   "TARGET_32BIT"
3728   "@
3729    %q4. %3,%1,%2
3730    #"
3731   [(set_attr "type" "fast_compare,compare")
3732    (set_attr "length" "4,8")])
3733
3734 (define_split
3735   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3736         (compare:CC (match_operator:SI 4 "boolean_operator"
3737          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3738           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3739          (const_int 0)))
3740    (clobber (match_scratch:SI 3 ""))]
3741   "TARGET_32BIT && reload_completed"
3742   [(set (match_dup 3) (match_dup 4))
3743    (set (match_dup 0)
3744         (compare:CC (match_dup 3)
3745                     (const_int 0)))]
3746   "")
3747
3748 (define_insn "*boolccsi3_internal3"
3749   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3750         (compare:CC (match_operator:SI 4 "boolean_operator"
3751          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3752           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3753          (const_int 0)))
3754    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3755         (match_dup 4))]
3756   "TARGET_32BIT"
3757   "@
3758    %q4. %0,%1,%2
3759    #"
3760   [(set_attr "type" "fast_compare,compare")
3761    (set_attr "length" "4,8")])
3762
3763 (define_split
3764   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3765         (compare:CC (match_operator:SI 4 "boolean_operator"
3766          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3767           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3768          (const_int 0)))
3769    (set (match_operand:SI 0 "gpc_reg_operand" "")
3770         (match_dup 4))]
3771   "TARGET_32BIT && reload_completed"
3772   [(set (match_dup 0) (match_dup 4))
3773    (set (match_dup 3)
3774         (compare:CC (match_dup 0)
3775                     (const_int 0)))]
3776   "")
3777
3778 ;; maskir insn.  We need four forms because things might be in arbitrary
3779 ;; orders.  Don't define forms that only set CR fields because these
3780 ;; would modify an input register.
3781
3782 (define_insn "*maskir_internal1"
3783   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3784         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3785                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3786                 (and:SI (match_dup 2)
3787                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3788   "TARGET_POWER"
3789   "maskir %0,%3,%2")
3790
3791 (define_insn "*maskir_internal2"
3792   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3793         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3794                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3795                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3796                         (match_dup 2))))]
3797   "TARGET_POWER"
3798   "maskir %0,%3,%2")
3799
3800 (define_insn "*maskir_internal3"
3801   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3802         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3803                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3804                 (and:SI (not:SI (match_dup 2))
3805                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3806   "TARGET_POWER"
3807   "maskir %0,%3,%2")
3808
3809 (define_insn "*maskir_internal4"
3810   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3811         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3812                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3813                 (and:SI (not:SI (match_dup 2))
3814                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3815   "TARGET_POWER"
3816   "maskir %0,%3,%2")
3817
3818 (define_insn "*maskir_internal5"
3819   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3820         (compare:CC
3821          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3822                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3823                  (and:SI (match_dup 2)
3824                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3825          (const_int 0)))
3826    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3827         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3828                 (and:SI (match_dup 2) (match_dup 3))))]
3829   "TARGET_POWER"
3830   "@
3831    maskir. %0,%3,%2
3832    #"
3833   [(set_attr "type" "compare")
3834    (set_attr "length" "4,8")])
3835
3836 (define_split
3837   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3838         (compare:CC
3839          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3840                          (match_operand:SI 1 "gpc_reg_operand" ""))
3841                  (and:SI (match_dup 2)
3842                          (match_operand:SI 3 "gpc_reg_operand" "")))
3843          (const_int 0)))
3844    (set (match_operand:SI 0 "gpc_reg_operand" "")
3845         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3846                 (and:SI (match_dup 2) (match_dup 3))))]
3847   "TARGET_POWER && reload_completed"
3848   [(set (match_dup 0)
3849         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3850                 (and:SI (match_dup 2) (match_dup 3))))
3851    (set (match_dup 4)
3852         (compare:CC (match_dup 0)
3853                     (const_int 0)))]
3854   "")
3855
3856 (define_insn "*maskir_internal6"
3857   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3858         (compare:CC
3859          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3860                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3861                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3862                          (match_dup 2)))
3863          (const_int 0)))
3864    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3865         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3866                 (and:SI (match_dup 3) (match_dup 2))))]
3867   "TARGET_POWER"
3868   "@
3869    maskir. %0,%3,%2
3870    #"
3871   [(set_attr "type" "compare")
3872    (set_attr "length" "4,8")])
3873
3874 (define_split
3875   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3876         (compare:CC
3877          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3878                          (match_operand:SI 1 "gpc_reg_operand" ""))
3879                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3880                          (match_dup 2)))
3881          (const_int 0)))
3882    (set (match_operand:SI 0 "gpc_reg_operand" "")
3883         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3884                 (and:SI (match_dup 3) (match_dup 2))))]
3885   "TARGET_POWER && reload_completed"
3886   [(set (match_dup 0)
3887         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3888                 (and:SI (match_dup 3) (match_dup 2))))
3889    (set (match_dup 4)
3890         (compare:CC (match_dup 0)
3891                     (const_int 0)))]
3892   "")
3893
3894 (define_insn "*maskir_internal7"
3895   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3896         (compare:CC
3897          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3898                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3899                  (and:SI (not:SI (match_dup 2))
3900                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3901          (const_int 0)))
3902    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3903         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3904                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3905   "TARGET_POWER"
3906   "@
3907    maskir. %0,%3,%2
3908    #"
3909   [(set_attr "type" "compare")
3910    (set_attr "length" "4,8")])
3911
3912 (define_split
3913   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3914         (compare:CC
3915          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3916                          (match_operand:SI 3 "gpc_reg_operand" ""))
3917                  (and:SI (not:SI (match_dup 2))
3918                          (match_operand:SI 1 "gpc_reg_operand" "")))
3919          (const_int 0)))
3920    (set (match_operand:SI 0 "gpc_reg_operand" "")
3921         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3922                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3923   "TARGET_POWER && reload_completed"
3924   [(set (match_dup 0)
3925         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3926                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3927    (set (match_dup 4)
3928         (compare:CC (match_dup 0)
3929                     (const_int 0)))]
3930   "")
3931
3932 (define_insn "*maskir_internal8"
3933   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3934         (compare:CC
3935          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3936                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3937                  (and:SI (not:SI (match_dup 2))
3938                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3939          (const_int 0)))
3940    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3941         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3942                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3943   "TARGET_POWER"
3944   "@
3945    maskir. %0,%3,%2
3946    #"
3947   [(set_attr "type" "compare")
3948    (set_attr "length" "4,8")])
3949
3950 (define_split
3951   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3952         (compare:CC
3953          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3954                          (match_operand:SI 2 "gpc_reg_operand" ""))
3955                  (and:SI (not:SI (match_dup 2))
3956                          (match_operand:SI 1 "gpc_reg_operand" "")))
3957          (const_int 0)))
3958    (set (match_operand:SI 0 "gpc_reg_operand" "")
3959         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3960                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3961   "TARGET_POWER && reload_completed"
3962   [(set (match_dup 0)
3963         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3964                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3965    (set (match_dup 4)
3966         (compare:CC (match_dup 0)
3967                     (const_int 0)))]
3968   "")
3969 \f
3970 ;; Rotate and shift insns, in all their variants.  These support shifts,
3971 ;; field inserts and extracts, and various combinations thereof.
3972 (define_expand "insv"
3973   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3974                        (match_operand:SI 1 "const_int_operand" "")
3975                        (match_operand:SI 2 "const_int_operand" ""))
3976         (match_operand 3 "gpc_reg_operand" ""))]
3977   ""
3978   "
3979 {
3980   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3981      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3982      compiler if the address of the structure is taken later.  Likewise, do
3983      not handle invalid E500 subregs.  */
3984   if (GET_CODE (operands[0]) == SUBREG
3985       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3986           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3987               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3988     FAIL;
3989
3990   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3991     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
3992   else
3993     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
3994   DONE;
3995 }")
3996
3997 (define_insn "insvsi"
3998   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3999                          (match_operand:SI 1 "const_int_operand" "i")
4000                          (match_operand:SI 2 "const_int_operand" "i"))
4001         (match_operand:SI 3 "gpc_reg_operand" "r"))]
4002   ""
4003   "*
4004 {
4005   int start = INTVAL (operands[2]) & 31;
4006   int size = INTVAL (operands[1]) & 31;
4007
4008   operands[4] = GEN_INT (32 - start - size);
4009   operands[1] = GEN_INT (start + size - 1);
4010   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4011 }"
4012   [(set_attr "type" "insert_word")])
4013
4014 (define_insn "*insvsi_internal1"
4015   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4016                          (match_operand:SI 1 "const_int_operand" "i")
4017                          (match_operand:SI 2 "const_int_operand" "i"))
4018         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4019                    (match_operand:SI 4 "const_int_operand" "i")))]
4020   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4021   "*
4022 {
4023   int shift = INTVAL (operands[4]) & 31;
4024   int start = INTVAL (operands[2]) & 31;
4025   int size = INTVAL (operands[1]) & 31;
4026
4027   operands[4] = GEN_INT (shift - start - size);
4028   operands[1] = GEN_INT (start + size - 1);
4029   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4030 }"
4031   [(set_attr "type" "insert_word")])
4032
4033 (define_insn "*insvsi_internal2"
4034   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4035                          (match_operand:SI 1 "const_int_operand" "i")
4036                          (match_operand:SI 2 "const_int_operand" "i"))
4037         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4038                      (match_operand:SI 4 "const_int_operand" "i")))]
4039   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4040   "*
4041 {
4042   int shift = INTVAL (operands[4]) & 31;
4043   int start = INTVAL (operands[2]) & 31;
4044   int size = INTVAL (operands[1]) & 31;
4045
4046   operands[4] = GEN_INT (32 - shift - start - size);
4047   operands[1] = GEN_INT (start + size - 1);
4048   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4049 }"
4050   [(set_attr "type" "insert_word")])
4051
4052 (define_insn "*insvsi_internal3"
4053   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4054                          (match_operand:SI 1 "const_int_operand" "i")
4055                          (match_operand:SI 2 "const_int_operand" "i"))
4056         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4057                      (match_operand:SI 4 "const_int_operand" "i")))]
4058   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4059   "*
4060 {
4061   int shift = INTVAL (operands[4]) & 31;
4062   int start = INTVAL (operands[2]) & 31;
4063   int size = INTVAL (operands[1]) & 31;
4064
4065   operands[4] = GEN_INT (32 - shift - start - size);
4066   operands[1] = GEN_INT (start + size - 1);
4067   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4068 }"
4069   [(set_attr "type" "insert_word")])
4070
4071 (define_insn "*insvsi_internal4"
4072   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4073                          (match_operand:SI 1 "const_int_operand" "i")
4074                          (match_operand:SI 2 "const_int_operand" "i"))
4075         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4076                          (match_operand:SI 4 "const_int_operand" "i")
4077                          (match_operand:SI 5 "const_int_operand" "i")))]
4078   "INTVAL (operands[4]) >= INTVAL (operands[1])"
4079   "*
4080 {
4081   int extract_start = INTVAL (operands[5]) & 31;
4082   int extract_size = INTVAL (operands[4]) & 31;
4083   int insert_start = INTVAL (operands[2]) & 31;
4084   int insert_size = INTVAL (operands[1]) & 31;
4085
4086 /* Align extract field with insert field */
4087   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
4088   operands[1] = GEN_INT (insert_start + insert_size - 1);
4089   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
4090 }"
4091   [(set_attr "type" "insert_word")])
4092
4093 ;; combine patterns for rlwimi
4094 (define_insn "*insvsi_internal5"
4095   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4096         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
4097                         (match_operand:SI 1 "mask_operand" "i"))
4098                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4099                                      (match_operand:SI 2 "const_int_operand" "i"))
4100                         (match_operand:SI 5 "mask_operand" "i"))))]
4101   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
4102   "*
4103 {
4104  int me = extract_ME(operands[5]);
4105  int mb = extract_MB(operands[5]);
4106  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
4107  operands[2] = GEN_INT(mb);
4108  operands[1] = GEN_INT(me);
4109  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4110 }"
4111   [(set_attr "type" "insert_word")])
4112
4113 (define_insn "*insvsi_internal6"
4114   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4115         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4116                                      (match_operand:SI 2 "const_int_operand" "i"))
4117                         (match_operand:SI 5 "mask_operand" "i"))
4118                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
4119                         (match_operand:SI 1 "mask_operand" "i"))))]
4120   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
4121   "*
4122 {
4123  int me = extract_ME(operands[5]);
4124  int mb = extract_MB(operands[5]);
4125  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
4126  operands[2] = GEN_INT(mb);
4127  operands[1] = GEN_INT(me);
4128  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4129 }"
4130   [(set_attr "type" "insert_word")])
4131
4132 (define_insn "insvdi"
4133   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4134                          (match_operand:SI 1 "const_int_operand" "i")
4135                          (match_operand:SI 2 "const_int_operand" "i"))
4136         (match_operand:DI 3 "gpc_reg_operand" "r"))]
4137   "TARGET_POWERPC64"
4138   "*
4139 {
4140   int start = INTVAL (operands[2]) & 63;
4141   int size = INTVAL (operands[1]) & 63;
4142
4143   operands[1] = GEN_INT (64 - start - size);
4144   return \"rldimi %0,%3,%H1,%H2\";
4145 }"
4146   [(set_attr "type" "insert_dword")])
4147
4148 (define_insn "*insvdi_internal2"
4149   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4150                          (match_operand:SI 1 "const_int_operand" "i")
4151                          (match_operand:SI 2 "const_int_operand" "i"))
4152         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4153                      (match_operand:SI 4 "const_int_operand" "i")))]
4154   "TARGET_POWERPC64
4155    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
4156   "*
4157 {
4158   int shift = INTVAL (operands[4]) & 63;
4159   int start = (INTVAL (operands[2]) & 63) - 32;
4160   int size = INTVAL (operands[1]) & 63;
4161
4162   operands[4] = GEN_INT (64 - shift - start - size);
4163   operands[2] = GEN_INT (start);
4164   operands[1] = GEN_INT (start + size - 1);
4165   return \"rlwimi %0,%3,%h4,%h2,%h1\";
4166 }")
4167
4168 (define_insn "*insvdi_internal3"
4169   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4170                          (match_operand:SI 1 "const_int_operand" "i")
4171                          (match_operand:SI 2 "const_int_operand" "i"))
4172         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4173                      (match_operand:SI 4 "const_int_operand" "i")))]
4174   "TARGET_POWERPC64
4175    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
4176   "*
4177 {
4178   int shift = INTVAL (operands[4]) & 63;
4179   int start = (INTVAL (operands[2]) & 63) - 32;
4180   int size = INTVAL (operands[1]) & 63;
4181
4182   operands[4] = GEN_INT (64 - shift - start - size);
4183   operands[2] = GEN_INT (start);
4184   operands[1] = GEN_INT (start + size - 1);
4185   return \"rlwimi %0,%3,%h4,%h2,%h1\";
4186 }")
4187
4188 (define_expand "extzv"
4189   [(set (match_operand 0 "gpc_reg_operand" "")
4190         (zero_extract (match_operand 1 "gpc_reg_operand" "")
4191                        (match_operand:SI 2 "const_int_operand" "")
4192                        (match_operand:SI 3 "const_int_operand" "")))]
4193   ""
4194   "
4195 {
4196   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
4197      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
4198      compiler if the address of the structure is taken later.  */
4199   if (GET_CODE (operands[0]) == SUBREG
4200       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
4201     FAIL;
4202
4203   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
4204     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
4205   else
4206     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
4207   DONE;
4208 }")
4209
4210 (define_insn "extzvsi"
4211   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4212         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4213                          (match_operand:SI 2 "const_int_operand" "i")
4214                          (match_operand:SI 3 "const_int_operand" "i")))]
4215   ""
4216   "*
4217 {
4218   int start = INTVAL (operands[3]) & 31;
4219   int size = INTVAL (operands[2]) & 31;
4220
4221   if (start + size >= 32)
4222     operands[3] = const0_rtx;
4223   else
4224     operands[3] = GEN_INT (start + size);
4225   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
4226 }")
4227
4228 (define_insn "*extzvsi_internal1"
4229   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4230         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4231                          (match_operand:SI 2 "const_int_operand" "i,i")
4232                          (match_operand:SI 3 "const_int_operand" "i,i"))
4233                     (const_int 0)))
4234    (clobber (match_scratch:SI 4 "=r,r"))]
4235   ""
4236   "*
4237 {
4238   int start = INTVAL (operands[3]) & 31;
4239   int size = INTVAL (operands[2]) & 31;
4240
4241   /* Force split for non-cc0 compare.  */
4242   if (which_alternative == 1)
4243      return \"#\";
4244
4245   /* If the bit-field being tested fits in the upper or lower half of a
4246      word, it is possible to use andiu. or andil. to test it.  This is
4247      useful because the condition register set-use delay is smaller for
4248      andi[ul]. than for rlinm.  This doesn't work when the starting bit
4249      position is 0 because the LT and GT bits may be set wrong.  */
4250
4251   if ((start > 0 && start + size <= 16) || start >= 16)
4252     {
4253       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
4254                               - (1 << (16 - (start & 15) - size))));
4255       if (start < 16)
4256         return \"{andiu.|andis.} %4,%1,%3\";
4257       else
4258         return \"{andil.|andi.} %4,%1,%3\";
4259     }
4260
4261   if (start + size >= 32)
4262     operands[3] = const0_rtx;
4263   else
4264     operands[3] = GEN_INT (start + size);
4265   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
4266 }"
4267   [(set_attr "type" "delayed_compare")
4268    (set_attr "length" "4,8")])
4269
4270 (define_split
4271   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4272         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
4273                          (match_operand:SI 2 "const_int_operand" "")
4274                          (match_operand:SI 3 "const_int_operand" ""))
4275                     (const_int 0)))
4276    (clobber (match_scratch:SI 4 ""))]
4277   "reload_completed"
4278   [(set (match_dup 4)
4279         (zero_extract:SI (match_dup 1) (match_dup 2)
4280                          (match_dup 3)))
4281    (set (match_dup 0)
4282         (compare:CC (match_dup 4)
4283                     (const_int 0)))]
4284   "")
4285
4286 (define_insn "*extzvsi_internal2"
4287   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4288         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4289                          (match_operand:SI 2 "const_int_operand" "i,i")
4290                          (match_operand:SI 3 "const_int_operand" "i,i"))
4291                     (const_int 0)))
4292    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4293         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
4294   ""
4295   "*
4296 {
4297   int start = INTVAL (operands[3]) & 31;
4298   int size = INTVAL (operands[2]) & 31;
4299
4300   /* Force split for non-cc0 compare.  */
4301   if (which_alternative == 1)
4302      return \"#\";
4303
4304   /* Since we are using the output value, we can't ignore any need for
4305      a shift.  The bit-field must end at the LSB.  */
4306   if (start >= 16 && start + size == 32)
4307     {
4308       operands[3] = GEN_INT ((1 << size) - 1);
4309       return \"{andil.|andi.} %0,%1,%3\";
4310     }
4311
4312   if (start + size >= 32)
4313     operands[3] = const0_rtx;
4314   else
4315     operands[3] = GEN_INT (start + size);
4316   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
4317 }"
4318   [(set_attr "type" "delayed_compare")
4319    (set_attr "length" "4,8")])
4320
4321 (define_split
4322   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4323         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
4324                          (match_operand:SI 2 "const_int_operand" "")
4325                          (match_operand:SI 3 "const_int_operand" ""))
4326                     (const_int 0)))
4327    (set (match_operand:SI 0 "gpc_reg_operand" "")
4328         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
4329   "reload_completed"
4330   [(set (match_dup 0)
4331         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
4332    (set (match_dup 4)
4333         (compare:CC (match_dup 0)
4334                     (const_int 0)))]
4335   "")
4336
4337 (define_insn "extzvdi"
4338   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4339         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4340                          (match_operand:SI 2 "const_int_operand" "i")
4341                          (match_operand:SI 3 "const_int_operand" "i")))]
4342   "TARGET_POWERPC64"
4343   "*
4344 {
4345   int start = INTVAL (operands[3]) & 63;
4346   int size = INTVAL (operands[2]) & 63;
4347
4348   if (start + size >= 64)
4349     operands[3] = const0_rtx;
4350   else
4351     operands[3] = GEN_INT (start + size);
4352   operands[2] = GEN_INT (64 - size);
4353   return \"rldicl %0,%1,%3,%2\";
4354 }")
4355
4356 (define_insn "*extzvdi_internal1"
4357   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
4358         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4359                          (match_operand:SI 2 "const_int_operand" "i")
4360                          (match_operand:SI 3 "const_int_operand" "i"))
4361                     (const_int 0)))
4362    (clobber (match_scratch:DI 4 "=r"))]
4363   "TARGET_64BIT && rs6000_gen_cell_microcode"
4364   "*
4365 {
4366   int start = INTVAL (operands[3]) & 63;
4367   int size = INTVAL (operands[2]) & 63;
4368
4369   if (start + size >= 64)
4370     operands[3] = const0_rtx;
4371   else
4372     operands[3] = GEN_INT (start + size);
4373   operands[2] = GEN_INT (64 - size);
4374   return \"rldicl. %4,%1,%3,%2\";
4375 }"
4376   [(set_attr "type" "compare")])
4377
4378 (define_insn "*extzvdi_internal2"
4379   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
4380         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4381                          (match_operand:SI 2 "const_int_operand" "i")
4382                          (match_operand:SI 3 "const_int_operand" "i"))
4383                     (const_int 0)))
4384    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4385         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
4386   "TARGET_64BIT && rs6000_gen_cell_microcode"
4387   "*
4388 {
4389   int start = INTVAL (operands[3]) & 63;
4390   int size = INTVAL (operands[2]) & 63;
4391
4392   if (start + size >= 64)
4393     operands[3] = const0_rtx;
4394   else
4395     operands[3] = GEN_INT (start + size);
4396   operands[2] = GEN_INT (64 - size);
4397   return \"rldicl. %0,%1,%3,%2\";
4398 }"
4399   [(set_attr "type" "compare")])
4400
4401 (define_insn "rotlsi3"
4402   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4403         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4404                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4405   ""
4406   "@
4407    {rlnm|rlwnm} %0,%1,%2,0xffffffff
4408    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
4409   [(set_attr "type" "var_shift_rotate,integer")])
4410
4411 (define_insn "*rotlsi3_64"
4412   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4413         (zero_extend:DI
4414             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4415                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4416   "TARGET_64BIT"
4417   "@
4418    {rlnm|rlwnm} %0,%1,%2,0xffffffff
4419    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
4420   [(set_attr "type" "var_shift_rotate,integer")])
4421
4422 (define_insn "*rotlsi3_internal2"
4423   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4424         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4425                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4426                     (const_int 0)))
4427    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4428   ""
4429   "@
4430    {rlnm.|rlwnm.} %3,%1,%2,0xffffffff
4431    {rlinm.|rlwinm.} %3,%1,%h2,0xffffffff
4432    #
4433    #"
4434   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4435    (set_attr "length" "4,4,8,8")])
4436
4437 (define_split
4438   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4439         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4440                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4441                     (const_int 0)))
4442    (clobber (match_scratch:SI 3 ""))]
4443   "reload_completed"
4444   [(set (match_dup 3)
4445         (rotate:SI (match_dup 1) (match_dup 2)))
4446    (set (match_dup 0)
4447         (compare:CC (match_dup 3)
4448                     (const_int 0)))]
4449   "")
4450
4451 (define_insn "*rotlsi3_internal3"
4452   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4453         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4454                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4455                     (const_int 0)))
4456    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4457         (rotate:SI (match_dup 1) (match_dup 2)))]
4458   ""
4459   "@
4460    {rlnm.|rlwnm.} %0,%1,%2,0xffffffff
4461    {rlinm.|rlwinm.} %0,%1,%h2,0xffffffff
4462    #
4463    #"
4464   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4465    (set_attr "length" "4,4,8,8")])
4466
4467 (define_split
4468   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4469         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4470                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4471                     (const_int 0)))
4472    (set (match_operand:SI 0 "gpc_reg_operand" "")
4473         (rotate:SI (match_dup 1) (match_dup 2)))]
4474   "reload_completed"
4475   [(set (match_dup 0)
4476         (rotate:SI (match_dup 1) (match_dup 2)))
4477    (set (match_dup 3)
4478         (compare:CC (match_dup 0)
4479                     (const_int 0)))]
4480   "")
4481
4482 (define_insn "*rotlsi3_internal4"
4483   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4484         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4485                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
4486                 (match_operand:SI 3 "mask_operand" "n,n")))]
4487   ""
4488   "@
4489    {rlnm|rlwnm} %0,%1,%2,%m3,%M3
4490    {rlinm|rlwinm} %0,%1,%h2,%m3,%M3"
4491   [(set_attr "type" "var_shift_rotate,integer")])
4492
4493 (define_insn "*rotlsi3_internal5"
4494   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4495         (compare:CC (and:SI
4496                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4497                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4498                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4499                     (const_int 0)))
4500    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
4501   ""
4502   "@
4503    {rlnm.|rlwnm.} %4,%1,%2,%m3,%M3
4504    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4505    #
4506    #"
4507   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4508    (set_attr "length" "4,4,8,8")])
4509
4510 (define_split
4511   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4512         (compare:CC (and:SI
4513                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4514                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4515                      (match_operand:SI 3 "mask_operand" ""))
4516                     (const_int 0)))
4517    (clobber (match_scratch:SI 4 ""))]
4518   "reload_completed"
4519   [(set (match_dup 4)
4520         (and:SI (rotate:SI (match_dup 1)
4521                                 (match_dup 2))
4522                      (match_dup 3)))
4523    (set (match_dup 0)
4524         (compare:CC (match_dup 4)
4525                     (const_int 0)))]
4526   "")
4527
4528 (define_insn "*rotlsi3_internal6"
4529   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
4530         (compare:CC (and:SI
4531                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4532                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4533                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4534                     (const_int 0)))
4535    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4536         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4537   ""
4538   "@
4539    {rlnm.|rlwnm.} %0,%1,%2,%m3,%M3
4540    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4541    #
4542    #"
4543   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4544    (set_attr "length" "4,4,8,8")])
4545
4546 (define_split
4547   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4548         (compare:CC (and:SI
4549                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4550                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4551                      (match_operand:SI 3 "mask_operand" ""))
4552                     (const_int 0)))
4553    (set (match_operand:SI 0 "gpc_reg_operand" "")
4554         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4555   "reload_completed"
4556   [(set (match_dup 0)
4557         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4558    (set (match_dup 4)
4559         (compare:CC (match_dup 0)
4560                     (const_int 0)))]
4561   "")
4562
4563 (define_insn "*rotlsi3_internal7"
4564   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4565         (zero_extend:SI
4566          (subreg:QI
4567           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4568                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4569   ""
4570   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff"
4571   [(set (attr "cell_micro")
4572      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4573         (const_string "not")
4574         (const_string "always")))])
4575
4576 (define_insn "*rotlsi3_internal8"
4577   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4578         (compare:CC (zero_extend:SI
4579                      (subreg:QI
4580                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4581                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4582                     (const_int 0)))
4583    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4584   ""
4585   "@
4586    {rlnm.|rlwnm.} %3,%1,%2,0xff
4587    {rlinm.|rlwinm.} %3,%1,%h2,0xff
4588    #
4589    #"
4590   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4591    (set_attr "length" "4,4,8,8")])
4592
4593 (define_split
4594   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4595         (compare:CC (zero_extend:SI
4596                      (subreg:QI
4597                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4598                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4599                     (const_int 0)))
4600    (clobber (match_scratch:SI 3 ""))]
4601   "reload_completed"
4602   [(set (match_dup 3)
4603         (zero_extend:SI (subreg:QI
4604                       (rotate:SI (match_dup 1)
4605                                  (match_dup 2)) 0)))
4606    (set (match_dup 0)
4607         (compare:CC (match_dup 3)
4608                     (const_int 0)))]
4609   "")
4610
4611 (define_insn "*rotlsi3_internal9"
4612   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4613         (compare:CC (zero_extend:SI
4614                      (subreg:QI
4615                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4616                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4617                     (const_int 0)))
4618    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4619         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4620   ""
4621   "@
4622    {rlnm.|rlwnm.} %0,%1,%2,0xff
4623    {rlinm.|rlwinm.} %0,%1,%h2,0xff
4624    #
4625    #"
4626   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4627    (set_attr "length" "4,4,8,8")])
4628
4629 (define_split
4630   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4631         (compare:CC (zero_extend:SI
4632                      (subreg:QI
4633                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4634                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4635                     (const_int 0)))
4636    (set (match_operand:SI 0 "gpc_reg_operand" "")
4637         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4638   "reload_completed"
4639   [(set (match_dup 0)
4640         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4641    (set (match_dup 3)
4642         (compare:CC (match_dup 0)
4643                     (const_int 0)))]
4644   "")
4645
4646 (define_insn "*rotlsi3_internal10"
4647   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4648         (zero_extend:SI
4649          (subreg:HI
4650           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4651                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4652   ""
4653   "@
4654    {rlnm|rlwnm} %0,%1,%2,0xffff
4655    {rlinm|rlwinm} %0,%1,%h2,0xffff"
4656   [(set_attr "type" "var_shift_rotate,integer")])
4657
4658
4659 (define_insn "*rotlsi3_internal11"
4660   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4661         (compare:CC (zero_extend:SI
4662                      (subreg:HI
4663                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4664                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4665                     (const_int 0)))
4666    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4667   ""
4668   "@
4669    {rlnm.|rlwnm.} %3,%1,%2,0xffff
4670    {rlinm.|rlwinm.} %3,%1,%h2,0xffff
4671    #
4672    #"
4673   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4674    (set_attr "length" "4,4,8,8")])
4675
4676 (define_split
4677   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4678         (compare:CC (zero_extend:SI
4679                      (subreg:HI
4680                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4681                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4682                     (const_int 0)))
4683    (clobber (match_scratch:SI 3 ""))]
4684   "reload_completed"
4685   [(set (match_dup 3)
4686         (zero_extend:SI (subreg:HI
4687                       (rotate:SI (match_dup 1)
4688                                  (match_dup 2)) 0)))
4689    (set (match_dup 0)
4690         (compare:CC (match_dup 3)
4691                     (const_int 0)))]
4692   "")
4693
4694 (define_insn "*rotlsi3_internal12"
4695   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4696         (compare:CC (zero_extend:SI
4697                      (subreg:HI
4698                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4699                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4700                     (const_int 0)))
4701    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4702         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4703   ""
4704   "@
4705    {rlnm.|rlwnm.} %0,%1,%2,0xffff
4706    {rlinm.|rlwinm.} %0,%1,%h2,0xffff
4707    #
4708    #"
4709   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4710    (set_attr "length" "4,4,8,8")])
4711
4712 (define_split
4713   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4714         (compare:CC (zero_extend:SI
4715                      (subreg:HI
4716                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4717                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4718                     (const_int 0)))
4719    (set (match_operand:SI 0 "gpc_reg_operand" "")
4720         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4721   "reload_completed"
4722   [(set (match_dup 0)
4723         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4724    (set (match_dup 3)
4725         (compare:CC (match_dup 0)
4726                     (const_int 0)))]
4727   "")
4728
4729 ;; Note that we use "sle." instead of "sl." so that we can set
4730 ;; SHIFT_COUNT_TRUNCATED.
4731
4732 (define_expand "ashlsi3"
4733   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4734    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4735    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4736   ""
4737   "
4738 {
4739   if (TARGET_POWER)
4740     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4741   else
4742     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4743   DONE;
4744 }")
4745
4746 (define_insn "ashlsi3_power"
4747   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4748         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4749                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4750    (clobber (match_scratch:SI 3 "=q,X"))]
4751   "TARGET_POWER"
4752   "@
4753    sle %0,%1,%2
4754    {sli|slwi} %0,%1,%h2")
4755
4756 (define_insn "ashlsi3_no_power"
4757   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4758         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4759                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4760   "! TARGET_POWER"
4761   "@
4762    {sl|slw} %0,%1,%2
4763    {sli|slwi} %0,%1,%h2"
4764   [(set_attr "type" "var_shift_rotate,shift")])
4765
4766 (define_insn "*ashlsi3_64"
4767   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4768         (zero_extend:DI
4769             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4770                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4771   "TARGET_POWERPC64"
4772   "@
4773    {sl|slw} %0,%1,%2
4774    {sli|slwi} %0,%1,%h2"
4775   [(set_attr "type" "var_shift_rotate,shift")])
4776
4777 (define_insn ""
4778   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4779         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4780                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4781                     (const_int 0)))
4782    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4783    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4784   "TARGET_POWER"
4785   "@
4786    sle. %3,%1,%2
4787    {sli.|slwi.} %3,%1,%h2
4788    #
4789    #"
4790   [(set_attr "type" "delayed_compare")
4791    (set_attr "length" "4,4,8,8")])
4792
4793 (define_split
4794   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4795         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4796                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4797                     (const_int 0)))
4798    (clobber (match_scratch:SI 3 ""))
4799    (clobber (match_scratch:SI 4 ""))]
4800   "TARGET_POWER && reload_completed"
4801   [(parallel [(set (match_dup 3)
4802         (ashift:SI (match_dup 1) (match_dup 2)))
4803    (clobber (match_dup 4))])
4804    (set (match_dup 0)
4805         (compare:CC (match_dup 3)
4806                     (const_int 0)))]
4807   "")
4808
4809 (define_insn ""
4810   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4811         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4812                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4813                     (const_int 0)))
4814    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4815   "! TARGET_POWER && TARGET_32BIT"
4816   "@
4817    {sl.|slw.} %3,%1,%2
4818    {sli.|slwi.} %3,%1,%h2
4819    #
4820    #"
4821   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4822    (set_attr "length" "4,4,8,8")])
4823
4824 (define_split
4825   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4826         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4827                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4828                     (const_int 0)))
4829    (clobber (match_scratch:SI 3 ""))]
4830   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4831   [(set (match_dup 3)
4832         (ashift:SI (match_dup 1) (match_dup 2)))
4833    (set (match_dup 0)
4834         (compare:CC (match_dup 3)
4835                     (const_int 0)))]
4836   "")
4837
4838 (define_insn ""
4839   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4840         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4841                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4842                     (const_int 0)))
4843    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4844         (ashift:SI (match_dup 1) (match_dup 2)))
4845    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4846   "TARGET_POWER"
4847   "@
4848    sle. %0,%1,%2
4849    {sli.|slwi.} %0,%1,%h2
4850    #
4851    #"
4852   [(set_attr "type" "delayed_compare")
4853    (set_attr "length" "4,4,8,8")])
4854
4855 (define_split
4856   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4857         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4858                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4859                     (const_int 0)))
4860    (set (match_operand:SI 0 "gpc_reg_operand" "")
4861         (ashift:SI (match_dup 1) (match_dup 2)))
4862    (clobber (match_scratch:SI 4 ""))]
4863   "TARGET_POWER && reload_completed"
4864   [(parallel [(set (match_dup 0)
4865         (ashift:SI (match_dup 1) (match_dup 2)))
4866    (clobber (match_dup 4))])
4867    (set (match_dup 3)
4868         (compare:CC (match_dup 0)
4869                     (const_int 0)))]
4870   "")
4871
4872 (define_insn ""
4873   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4874         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4875                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4876                     (const_int 0)))
4877    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4878         (ashift:SI (match_dup 1) (match_dup 2)))]
4879   "! TARGET_POWER && TARGET_32BIT"
4880   "@
4881    {sl.|slw.} %0,%1,%2
4882    {sli.|slwi.} %0,%1,%h2
4883    #
4884    #"
4885   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4886    (set_attr "length" "4,4,8,8")])
4887
4888 (define_split
4889   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4890         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4891                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4892                     (const_int 0)))
4893    (set (match_operand:SI 0 "gpc_reg_operand" "")
4894         (ashift:SI (match_dup 1) (match_dup 2)))]
4895   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4896   [(set (match_dup 0)
4897         (ashift:SI (match_dup 1) (match_dup 2)))
4898    (set (match_dup 3)
4899         (compare:CC (match_dup 0)
4900                     (const_int 0)))]
4901   "")
4902
4903 (define_insn "rlwinm"
4904   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4905         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4906                            (match_operand:SI 2 "const_int_operand" "i"))
4907                 (match_operand:SI 3 "mask_operand" "n")))]
4908   "includes_lshift_p (operands[2], operands[3])"
4909   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4910
4911 (define_insn ""
4912   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4913         (compare:CC
4914          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4915                             (match_operand:SI 2 "const_int_operand" "i,i"))
4916                  (match_operand:SI 3 "mask_operand" "n,n"))
4917          (const_int 0)))
4918    (clobber (match_scratch:SI 4 "=r,r"))]
4919   "includes_lshift_p (operands[2], operands[3])"
4920   "@
4921    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4922    #"
4923   [(set_attr "type" "delayed_compare")
4924    (set_attr "length" "4,8")])
4925
4926 (define_split
4927   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4928         (compare:CC
4929          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4930                             (match_operand:SI 2 "const_int_operand" ""))
4931                  (match_operand:SI 3 "mask_operand" ""))
4932          (const_int 0)))
4933    (clobber (match_scratch:SI 4 ""))]
4934   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4935   [(set (match_dup 4)
4936         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4937                  (match_dup 3)))
4938    (set (match_dup 0)
4939         (compare:CC (match_dup 4)
4940                     (const_int 0)))]
4941   "")
4942
4943 (define_insn ""
4944   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4945         (compare:CC
4946          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4947                             (match_operand:SI 2 "const_int_operand" "i,i"))
4948                  (match_operand:SI 3 "mask_operand" "n,n"))
4949          (const_int 0)))
4950    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4951         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4952   "includes_lshift_p (operands[2], operands[3])"
4953   "@
4954    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4955    #"
4956   [(set_attr "type" "delayed_compare")
4957    (set_attr "length" "4,8")])
4958
4959 (define_split
4960   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4961         (compare:CC
4962          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4963                             (match_operand:SI 2 "const_int_operand" ""))
4964                  (match_operand:SI 3 "mask_operand" ""))
4965          (const_int 0)))
4966    (set (match_operand:SI 0 "gpc_reg_operand" "")
4967         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4968   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4969   [(set (match_dup 0)
4970         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4971    (set (match_dup 4)
4972         (compare:CC (match_dup 0)
4973                     (const_int 0)))]
4974   "")
4975
4976 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
4977 ;; "sli x,x,0".
4978 (define_expand "lshrsi3"
4979   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4980    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4981    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4982   ""
4983   "
4984 {
4985   if (TARGET_POWER)
4986     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
4987   else
4988     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
4989   DONE;
4990 }")
4991
4992 (define_insn "lshrsi3_power"
4993   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4994         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4995                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
4996    (clobber (match_scratch:SI 3 "=q,X,X"))]
4997   "TARGET_POWER"
4998   "@
4999   sre %0,%1,%2
5000   mr %0,%1
5001   {s%A2i|s%A2wi} %0,%1,%h2")
5002
5003 (define_insn "lshrsi3_no_power"
5004   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
5005         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
5006                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
5007   "! TARGET_POWER"
5008   "@
5009   mr %0,%1
5010   {sr|srw} %0,%1,%2
5011   {sri|srwi} %0,%1,%h2"
5012   [(set_attr "type" "integer,var_shift_rotate,shift")])
5013
5014 (define_insn "*lshrsi3_64"
5015   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5016         (zero_extend:DI
5017             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5018                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5019   "TARGET_POWERPC64"
5020   "@
5021   {sr|srw} %0,%1,%2
5022   {sri|srwi} %0,%1,%h2"
5023   [(set_attr "type" "var_shift_rotate,shift")])
5024
5025 (define_insn ""
5026   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5027         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5028                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
5029                     (const_int 0)))
5030    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
5031    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
5032   "TARGET_POWER"
5033   "@
5034   sre. %3,%1,%2
5035   mr. %1,%1
5036   {s%A2i.|s%A2wi.} %3,%1,%h2
5037   #
5038   #
5039   #"
5040   [(set_attr "type" "delayed_compare")
5041    (set_attr "length" "4,4,4,8,8,8")])
5042
5043 (define_split
5044   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5045         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5046                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5047                     (const_int 0)))
5048    (clobber (match_scratch:SI 3 ""))
5049    (clobber (match_scratch:SI 4 ""))]
5050   "TARGET_POWER && reload_completed"
5051   [(parallel [(set (match_dup 3)
5052         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5053    (clobber (match_dup 4))])
5054    (set (match_dup 0)
5055         (compare:CC (match_dup 3)
5056                     (const_int 0)))]
5057   "")
5058
5059 (define_insn ""
5060   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5061         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5062                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
5063                     (const_int 0)))
5064    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
5065   "! TARGET_POWER && TARGET_32BIT"
5066   "@
5067    mr. %1,%1
5068    {sr.|srw.} %3,%1,%2
5069    {sri.|srwi.} %3,%1,%h2
5070    #
5071    #
5072    #"
5073   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5074    (set_attr "length" "4,4,4,8,8,8")])
5075
5076 (define_split
5077   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5078         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5079                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5080                     (const_int 0)))
5081    (clobber (match_scratch:SI 3 ""))]
5082   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5083   [(set (match_dup 3)
5084         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5085    (set (match_dup 0)
5086         (compare:CC (match_dup 3)
5087                     (const_int 0)))]
5088   "")
5089
5090 (define_insn ""
5091   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5092         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5093                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
5094                     (const_int 0)))
5095    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
5096         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5097    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
5098   "TARGET_POWER"
5099   "@
5100   sre. %0,%1,%2
5101   mr. %0,%1
5102   {s%A2i.|s%A2wi.} %0,%1,%h2
5103   #
5104   #
5105   #"
5106   [(set_attr "type" "delayed_compare")
5107    (set_attr "length" "4,4,4,8,8,8")])
5108
5109 (define_split
5110   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5111         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5112                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5113                     (const_int 0)))
5114    (set (match_operand:SI 0 "gpc_reg_operand" "")
5115         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5116    (clobber (match_scratch:SI 4 ""))]
5117   "TARGET_POWER && reload_completed"
5118   [(parallel [(set (match_dup 0)
5119         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5120    (clobber (match_dup 4))])
5121    (set (match_dup 3)
5122         (compare:CC (match_dup 0)
5123                     (const_int 0)))]
5124   "")
5125
5126 (define_insn ""
5127   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5128         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5129                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
5130                     (const_int 0)))
5131    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
5132         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
5133   "! TARGET_POWER && TARGET_32BIT"
5134   "@
5135    mr. %0,%1
5136    {sr.|srw.} %0,%1,%2
5137    {sri.|srwi.} %0,%1,%h2
5138    #
5139    #
5140    #"
5141   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5142    (set_attr "length" "4,4,4,8,8,8")])
5143
5144 (define_split
5145   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5146         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5147                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5148                     (const_int 0)))
5149    (set (match_operand:SI 0 "gpc_reg_operand" "")
5150         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
5151   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5152   [(set (match_dup 0)
5153         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5154    (set (match_dup 3)
5155         (compare:CC (match_dup 0)
5156                     (const_int 0)))]
5157   "")
5158
5159 (define_insn ""
5160   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5161         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5162                              (match_operand:SI 2 "const_int_operand" "i"))
5163                 (match_operand:SI 3 "mask_operand" "n")))]
5164   "includes_rshift_p (operands[2], operands[3])"
5165   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
5166
5167 (define_insn ""
5168   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5169         (compare:CC
5170          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5171                               (match_operand:SI 2 "const_int_operand" "i,i"))
5172                  (match_operand:SI 3 "mask_operand" "n,n"))
5173          (const_int 0)))
5174    (clobber (match_scratch:SI 4 "=r,r"))]
5175   "includes_rshift_p (operands[2], operands[3])"
5176   "@
5177    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
5178    #"
5179   [(set_attr "type" "delayed_compare")
5180    (set_attr "length" "4,8")])
5181
5182 (define_split
5183   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5184         (compare:CC
5185          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5186                               (match_operand:SI 2 "const_int_operand" ""))
5187                  (match_operand:SI 3 "mask_operand" ""))
5188          (const_int 0)))
5189    (clobber (match_scratch:SI 4 ""))]
5190   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
5191   [(set (match_dup 4)
5192         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
5193                  (match_dup 3)))
5194    (set (match_dup 0)
5195         (compare:CC (match_dup 4)
5196                     (const_int 0)))]
5197   "")
5198
5199 (define_insn ""
5200   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
5201         (compare:CC
5202          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5203                               (match_operand:SI 2 "const_int_operand" "i,i"))
5204                  (match_operand:SI 3 "mask_operand" "n,n"))
5205          (const_int 0)))
5206    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5207         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5208   "includes_rshift_p (operands[2], operands[3])"
5209   "@
5210    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
5211    #"
5212   [(set_attr "type" "delayed_compare")
5213    (set_attr "length" "4,8")])
5214
5215 (define_split
5216   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
5217         (compare:CC
5218          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5219                               (match_operand:SI 2 "const_int_operand" ""))
5220                  (match_operand:SI 3 "mask_operand" ""))
5221          (const_int 0)))
5222    (set (match_operand:SI 0 "gpc_reg_operand" "")
5223         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5224   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
5225   [(set (match_dup 0)
5226         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
5227    (set (match_dup 4)
5228         (compare:CC (match_dup 0)
5229                     (const_int 0)))]
5230   "")
5231
5232 (define_insn ""
5233   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5234         (zero_extend:SI
5235          (subreg:QI
5236           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5237                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
5238   "includes_rshift_p (operands[2], GEN_INT (255))"
5239   "{rlinm|rlwinm} %0,%1,%s2,0xff")
5240
5241 (define_insn ""
5242   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5243         (compare:CC
5244          (zero_extend:SI
5245           (subreg:QI
5246            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5247                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5248          (const_int 0)))
5249    (clobber (match_scratch:SI 3 "=r,r"))]
5250   "includes_rshift_p (operands[2], GEN_INT (255))"
5251   "@
5252    {rlinm.|rlwinm.} %3,%1,%s2,0xff
5253    #"
5254   [(set_attr "type" "delayed_compare")
5255    (set_attr "length" "4,8")])
5256
5257 (define_split
5258   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5259         (compare:CC
5260          (zero_extend:SI
5261           (subreg:QI
5262            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5263                         (match_operand:SI 2 "const_int_operand" "")) 0))
5264          (const_int 0)))
5265    (clobber (match_scratch:SI 3 ""))]
5266   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
5267   [(set (match_dup 3)
5268         (zero_extend:SI (subreg:QI
5269            (lshiftrt:SI (match_dup 1)
5270                         (match_dup 2)) 0)))
5271    (set (match_dup 0)
5272         (compare:CC (match_dup 3)
5273                     (const_int 0)))]
5274   "")
5275
5276 (define_insn ""
5277   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5278         (compare:CC
5279          (zero_extend:SI
5280           (subreg:QI
5281            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5282                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5283          (const_int 0)))
5284    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5285         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5286   "includes_rshift_p (operands[2], GEN_INT (255))"
5287   "@
5288    {rlinm.|rlwinm.} %0,%1,%s2,0xff
5289    #"
5290   [(set_attr "type" "delayed_compare")
5291    (set_attr "length" "4,8")])
5292
5293 (define_split
5294   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5295         (compare:CC
5296          (zero_extend:SI
5297           (subreg:QI
5298            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5299                         (match_operand:SI 2 "const_int_operand" "")) 0))
5300          (const_int 0)))
5301    (set (match_operand:SI 0 "gpc_reg_operand" "")
5302         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5303   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
5304   [(set (match_dup 0)
5305         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5306    (set (match_dup 3)
5307         (compare:CC (match_dup 0)
5308                     (const_int 0)))]
5309   "")
5310
5311 (define_insn ""
5312   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5313         (zero_extend:SI
5314          (subreg:HI
5315           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5316                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
5317   "includes_rshift_p (operands[2], GEN_INT (65535))"
5318   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
5319
5320 (define_insn ""
5321   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5322         (compare:CC
5323          (zero_extend:SI
5324           (subreg:HI
5325            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5326                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5327          (const_int 0)))
5328    (clobber (match_scratch:SI 3 "=r,r"))]
5329   "includes_rshift_p (operands[2], GEN_INT (65535))"
5330   "@
5331    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
5332    #"
5333   [(set_attr "type" "delayed_compare")
5334    (set_attr "length" "4,8")])
5335
5336 (define_split
5337   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5338         (compare:CC
5339          (zero_extend:SI
5340           (subreg:HI
5341            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5342                         (match_operand:SI 2 "const_int_operand" "")) 0))
5343          (const_int 0)))
5344    (clobber (match_scratch:SI 3 ""))]
5345   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5346   [(set (match_dup 3)
5347         (zero_extend:SI (subreg:HI
5348            (lshiftrt:SI (match_dup 1)
5349                         (match_dup 2)) 0)))
5350    (set (match_dup 0)
5351         (compare:CC (match_dup 3)
5352                     (const_int 0)))]
5353   "")
5354
5355 (define_insn ""
5356   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5357         (compare:CC
5358          (zero_extend:SI
5359           (subreg:HI
5360            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5361                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5362          (const_int 0)))
5363    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5364         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5365   "includes_rshift_p (operands[2], GEN_INT (65535))"
5366   "@
5367    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
5368    #"
5369   [(set_attr "type" "delayed_compare")
5370    (set_attr "length" "4,8")])
5371
5372 (define_split
5373   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5374         (compare:CC
5375          (zero_extend:SI
5376           (subreg:HI
5377            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5378                         (match_operand:SI 2 "const_int_operand" "")) 0))
5379          (const_int 0)))
5380    (set (match_operand:SI 0 "gpc_reg_operand" "")
5381         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5382   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5383   [(set (match_dup 0)
5384         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5385    (set (match_dup 3)
5386         (compare:CC (match_dup 0)
5387                     (const_int 0)))]
5388   "")
5389
5390 (define_insn ""
5391   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5392                          (const_int 1)
5393                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5394         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5395                      (const_int 31)))]
5396   "TARGET_POWER"
5397   "rrib %0,%1,%2")
5398
5399 (define_insn ""
5400   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5401                          (const_int 1)
5402                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5403         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5404                      (const_int 31)))]
5405   "TARGET_POWER"
5406   "rrib %0,%1,%2")
5407
5408 (define_insn ""
5409   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5410                          (const_int 1)
5411                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5412         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5413                          (const_int 1)
5414                          (const_int 0)))]
5415   "TARGET_POWER"
5416   "rrib %0,%1,%2")
5417
5418 (define_expand "ashrsi3"
5419   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5420         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5421                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
5422   ""
5423   "
5424 {
5425   if (TARGET_POWER)
5426     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
5427   else
5428     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
5429   DONE;
5430 }")
5431
5432 (define_insn "ashrsi3_power"
5433   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5434         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5435                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
5436    (clobber (match_scratch:SI 3 "=q,X"))]
5437   "TARGET_POWER"
5438   "@
5439    srea %0,%1,%2
5440    {srai|srawi} %0,%1,%h2"
5441   [(set_attr "type" "shift")])
5442
5443 (define_insn "ashrsi3_no_power"
5444   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5445         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5446                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
5447   "! TARGET_POWER"
5448   "@
5449    {sra|sraw} %0,%1,%2
5450    {srai|srawi} %0,%1,%h2"
5451   [(set_attr "type" "var_shift_rotate,shift")])
5452
5453 (define_insn "*ashrsi3_64"
5454   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5455         (sign_extend:DI
5456             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5457                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5458   "TARGET_POWERPC64"
5459   "@
5460    {sra|sraw} %0,%1,%2
5461    {srai|srawi} %0,%1,%h2"
5462   [(set_attr "type" "var_shift_rotate,shift")])
5463
5464 (define_insn ""
5465   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5466         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5467                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5468                     (const_int 0)))
5469    (clobber (match_scratch:SI 3 "=r,r,r,r"))
5470    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5471   "TARGET_POWER"
5472   "@
5473    srea. %3,%1,%2
5474    {srai.|srawi.} %3,%1,%h2
5475    #
5476    #"
5477   [(set_attr "type" "delayed_compare")
5478    (set_attr "length" "4,4,8,8")])
5479
5480 (define_split
5481   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5482         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5483                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5484                     (const_int 0)))
5485    (clobber (match_scratch:SI 3 ""))
5486    (clobber (match_scratch:SI 4 ""))]
5487   "TARGET_POWER && reload_completed"
5488   [(parallel [(set (match_dup 3)
5489         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5490    (clobber (match_dup 4))])
5491    (set (match_dup 0)
5492         (compare:CC (match_dup 3)
5493                     (const_int 0)))]
5494   "")
5495
5496 (define_insn ""
5497   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5498         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5499                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5500                     (const_int 0)))
5501    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
5502   "! TARGET_POWER"
5503   "@
5504    {sra.|sraw.} %3,%1,%2
5505    {srai.|srawi.} %3,%1,%h2
5506    #
5507    #"
5508   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5509    (set_attr "length" "4,4,8,8")])
5510
5511 (define_split
5512   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5513         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5514                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5515                     (const_int 0)))
5516    (clobber (match_scratch:SI 3 ""))]
5517   "! TARGET_POWER && reload_completed"
5518   [(set (match_dup 3)
5519         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5520    (set (match_dup 0)
5521         (compare:CC (match_dup 3)
5522                     (const_int 0)))]
5523   "")
5524
5525 (define_insn ""
5526   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5527         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5528                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5529                     (const_int 0)))
5530    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5531         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5532    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5533   "TARGET_POWER"
5534   "@
5535    srea. %0,%1,%2
5536    {srai.|srawi.} %0,%1,%h2
5537    #
5538    #"
5539   [(set_attr "type" "delayed_compare")
5540    (set_attr "length" "4,4,8,8")])
5541
5542 (define_split
5543   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5544         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5545                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5546                     (const_int 0)))
5547    (set (match_operand:SI 0 "gpc_reg_operand" "")
5548         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5549    (clobber (match_scratch:SI 4 ""))]
5550   "TARGET_POWER && reload_completed"
5551   [(parallel [(set (match_dup 0)
5552         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5553    (clobber (match_dup 4))])
5554    (set (match_dup 3)
5555         (compare:CC (match_dup 0)
5556                     (const_int 0)))]
5557   "")
5558
5559 (define_insn ""
5560   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5561         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5562                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5563                     (const_int 0)))
5564    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5565         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5566   "! TARGET_POWER"
5567   "@
5568    {sra.|sraw.} %0,%1,%2
5569    {srai.|srawi.} %0,%1,%h2
5570    #
5571    #"
5572   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5573    (set_attr "length" "4,4,8,8")])
5574 \f
5575 ;; Builtins to replace a division to generate FRE reciprocal estimate
5576 ;; instructions and the necessary fixup instructions
5577 (define_expand "recip<mode>3"
5578   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5579    (match_operand:RECIPF 1 "gpc_reg_operand" "")
5580    (match_operand:RECIPF 2 "gpc_reg_operand" "")]
5581   "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
5582 {
5583    rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
5584    DONE;
5585 })
5586
5587 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
5588 ;; hardware division.  This is only done before register allocation and with
5589 ;; -ffast-math.  This must appear before the divsf3/divdf3 insns.
5590 (define_split
5591   [(set (match_operand:RECIPF 0 "gpc_reg_operand" "")
5592         (div:RECIPF (match_operand 1 "gpc_reg_operand" "")
5593                     (match_operand 2 "gpc_reg_operand" "")))]
5594   "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
5595    && can_create_pseudo_p () && optimize_insn_for_speed_p ()
5596    && flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math"
5597   [(const_int 0)]
5598 {
5599   rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
5600   DONE;
5601 })
5602
5603 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
5604 ;; appropriate fixup.
5605 (define_expand "rsqrt<mode>2"
5606   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5607    (match_operand:RECIPF 1 "gpc_reg_operand" "")]
5608   "RS6000_RECIP_HAVE_RSQRT_P (<MODE>mode)"
5609 {
5610   rs6000_emit_swrsqrt (operands[0], operands[1]);
5611   DONE;
5612 })
5613 \f
5614 (define_split
5615   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5616         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5617                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5618                     (const_int 0)))
5619    (set (match_operand:SI 0 "gpc_reg_operand" "")
5620         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5621   "! TARGET_POWER && reload_completed"
5622   [(set (match_dup 0)
5623         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5624    (set (match_dup 3)
5625         (compare:CC (match_dup 0)
5626                     (const_int 0)))]
5627   "")
5628
5629 ;; Floating-point insns, excluding normal data motion.
5630 ;;
5631 ;; PowerPC has a full set of single-precision floating point instructions.
5632 ;;
5633 ;; For the POWER architecture, we pretend that we have both SFmode and
5634 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
5635 ;; The only conversions we will do will be when storing to memory.  In that
5636 ;; case, we will use the "frsp" instruction before storing.
5637 ;;
5638 ;; Note that when we store into a single-precision memory location, we need to
5639 ;; use the frsp insn first.  If the register being stored isn't dead, we
5640 ;; need a scratch register for the frsp.  But this is difficult when the store
5641 ;; is done by reload.  It is not incorrect to do the frsp on the register in
5642 ;; this case, we just lose precision that we would have otherwise gotten but
5643 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
5644
5645 (define_expand "extendsfdf2"
5646   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5647         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5648   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5649   "")
5650
5651 (define_insn_and_split "*extendsfdf2_fpr"
5652   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d")
5653         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
5654   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5655   "@
5656    #
5657    fmr %0,%1
5658    lfs%U1%X1 %0,%1"
5659   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5660   [(const_int 0)]
5661 {
5662   emit_note (NOTE_INSN_DELETED);
5663   DONE;
5664 }
5665   [(set_attr "type" "fp,fp,fpload")])
5666
5667 (define_expand "truncdfsf2"
5668   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5669         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5670   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5671   "")
5672
5673 (define_insn "*truncdfsf2_fpr"
5674   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5675         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5676   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5677   "frsp %0,%1"
5678   [(set_attr "type" "fp")])
5679
5680 (define_insn "aux_truncdfsf2"
5681   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5682         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
5683   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5684   "frsp %0,%1"
5685   [(set_attr "type" "fp")])
5686
5687 (define_expand "negsf2"
5688   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5689         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5690   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5691   "")
5692
5693 (define_insn "*negsf2"
5694   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5695         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5696   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5697   "fneg %0,%1"
5698   [(set_attr "type" "fp")])
5699
5700 (define_expand "abssf2"
5701   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5702         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5703   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5704   "")
5705
5706 (define_insn "*abssf2"
5707   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5708         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5709   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5710   "fabs %0,%1"
5711   [(set_attr "type" "fp")])
5712
5713 (define_insn ""
5714   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5715         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
5716   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5717   "fnabs %0,%1"
5718   [(set_attr "type" "fp")])
5719
5720 (define_expand "addsf3"
5721   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5722         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5723                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5724   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5725   "")
5726
5727 (define_insn ""
5728   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5729         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5730                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5731   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5732   "fadds %0,%1,%2"
5733   [(set_attr "type" "fp")
5734    (set_attr "fp_type" "fp_addsub_s")])
5735
5736 (define_insn ""
5737   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5738         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5739                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5740   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5741   "{fa|fadd} %0,%1,%2"
5742   [(set_attr "type" "fp")])
5743
5744 (define_expand "subsf3"
5745   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5746         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5747                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5748   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5749   "")
5750
5751 (define_insn ""
5752   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5753         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5754                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5755   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5756   "fsubs %0,%1,%2"
5757   [(set_attr "type" "fp")
5758    (set_attr "fp_type" "fp_addsub_s")])
5759
5760 (define_insn ""
5761   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5762         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5763                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5764   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5765   "{fs|fsub} %0,%1,%2"
5766   [(set_attr "type" "fp")])
5767
5768 (define_expand "mulsf3"
5769   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5770         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5771                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5772   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5773   "")
5774
5775 (define_insn ""
5776   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5777         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5778                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5779   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5780   "fmuls %0,%1,%2"
5781   [(set_attr "type" "fp")
5782    (set_attr "fp_type" "fp_mul_s")])
5783
5784 (define_insn ""
5785   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5786         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5787                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5788   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5789   "{fm|fmul} %0,%1,%2"
5790   [(set_attr "type" "dmul")])
5791
5792 (define_expand "divsf3"
5793   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5794         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5795                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5796   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5797   "")
5798
5799 (define_insn ""
5800   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5801         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5802                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5803   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS 
5804    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5805   "fdivs %0,%1,%2"
5806   [(set_attr "type" "sdiv")])
5807
5808 (define_insn ""
5809   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5810         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5811                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5812   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS 
5813    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5814   "{fd|fdiv} %0,%1,%2"
5815   [(set_attr "type" "ddiv")])
5816
5817 (define_insn "fres"
5818   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5819         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5820   "TARGET_FRES"
5821   "fres %0,%1"
5822   [(set_attr "type" "fp")])
5823
5824 (define_insn "*fmaddsf4_powerpc"
5825   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5826         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5827                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5828                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5829   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS
5830    && TARGET_SINGLE_FLOAT && TARGET_FUSED_MADD"
5831   "fmadds %0,%1,%2,%3"
5832   [(set_attr "type" "fp")
5833    (set_attr "fp_type" "fp_maddsub_s")])
5834
5835 (define_insn "*fmaddsf4_power"
5836   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5837         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5838                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5839                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5840   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5841   "{fma|fmadd} %0,%1,%2,%3"
5842   [(set_attr "type" "dmul")])
5843
5844 (define_insn "*fmsubsf4_powerpc"
5845   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5846         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5847                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5848                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5849   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS
5850    && TARGET_SINGLE_FLOAT && TARGET_FUSED_MADD"
5851   "fmsubs %0,%1,%2,%3"
5852   [(set_attr "type" "fp")
5853    (set_attr "fp_type" "fp_maddsub_s")])
5854
5855 (define_insn "*fmsubsf4_power"
5856   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5857         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5858                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5859                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5860   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5861   "{fms|fmsub} %0,%1,%2,%3"
5862   [(set_attr "type" "dmul")])
5863
5864 (define_insn "*fnmaddsf4_powerpc_1"
5865   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5866         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5867                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5868                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5869   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5870    && TARGET_SINGLE_FLOAT"
5871   "fnmadds %0,%1,%2,%3"
5872   [(set_attr "type" "fp")
5873    (set_attr "fp_type" "fp_maddsub_s")])
5874
5875 (define_insn "*fnmaddsf4_powerpc_2"
5876   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5877         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5878                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5879                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5880   "TARGET_POWERPC && TARGET_SINGLE_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5881    && ! HONOR_SIGNED_ZEROS (SFmode)"
5882   "fnmadds %0,%1,%2,%3"
5883   [(set_attr "type" "fp")
5884    (set_attr "fp_type" "fp_maddsub_s")])
5885
5886 (define_insn "*fnmaddsf4_power_1"
5887   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5888         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5889                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5890                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5891   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5892   "{fnma|fnmadd} %0,%1,%2,%3"
5893   [(set_attr "type" "dmul")])
5894
5895 (define_insn "*fnmaddsf4_power_2"
5896   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5897         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5898                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5899                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5900   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5901    && ! HONOR_SIGNED_ZEROS (SFmode)"
5902   "{fnma|fnmadd} %0,%1,%2,%3"
5903   [(set_attr "type" "dmul")])
5904
5905 (define_insn "*fnmsubsf4_powerpc_1"
5906   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5907         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5908                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5909                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5910   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5911    && TARGET_SINGLE_FLOAT"
5912   "fnmsubs %0,%1,%2,%3"
5913   [(set_attr "type" "fp")
5914    (set_attr "fp_type" "fp_maddsub_s")])
5915
5916 (define_insn "*fnmsubsf4_powerpc_2"
5917   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5918         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5919                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5920                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5921   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5922    && TARGET_SINGLE_FLOAT && ! HONOR_SIGNED_ZEROS (SFmode)"
5923   "fnmsubs %0,%1,%2,%3"
5924   [(set_attr "type" "fp")
5925    (set_attr "fp_type" "fp_maddsub_s")])
5926
5927 (define_insn "*fnmsubsf4_power_1"
5928   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5929         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5930                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5931                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5932   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5933   "{fnms|fnmsub} %0,%1,%2,%3"
5934   [(set_attr "type" "dmul")])
5935
5936 (define_insn "*fnmsubsf4_power_2"
5937   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5938         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5939                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5940                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5941   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5942    && ! HONOR_SIGNED_ZEROS (SFmode)"
5943   "{fnms|fnmsub} %0,%1,%2,%3"
5944   [(set_attr "type" "dmul")])
5945
5946 (define_expand "sqrtsf2"
5947   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5948         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5949   "(TARGET_PPC_GPOPT || TARGET_POWER2 || TARGET_XILINX_FPU)
5950    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5951    && !TARGET_SIMPLE_FPU"
5952   "")
5953
5954 (define_insn ""
5955   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5956         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5957   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU) && TARGET_HARD_FLOAT
5958    && TARGET_FPRS && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5959   "fsqrts %0,%1"
5960   [(set_attr "type" "ssqrt")])
5961
5962 (define_insn ""
5963   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5964         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5965   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS 
5966    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5967   "fsqrt %0,%1"
5968   [(set_attr "type" "dsqrt")])
5969
5970 (define_insn "*rsqrtsf_internal1"
5971   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5972         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
5973                    UNSPEC_RSQRT))]
5974   "TARGET_FRSQRTES"
5975   "frsqrtes %0,%1"
5976   [(set_attr "type" "fp")])
5977
5978 (define_expand "copysignsf3"
5979   [(set (match_dup 3)
5980         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
5981    (set (match_dup 4)
5982         (neg:SF (abs:SF (match_dup 1))))
5983    (set (match_operand:SF 0 "gpc_reg_operand" "")
5984         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
5985                              (match_dup 5))
5986                          (match_dup 3)
5987                          (match_dup 4)))]
5988   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5989    && ((TARGET_PPC_GFXOPT
5990         && !HONOR_NANS (SFmode)
5991         && !HONOR_SIGNED_ZEROS (SFmode))
5992        || VECTOR_UNIT_VSX_P (DFmode))"
5993   {
5994      if (VECTOR_UNIT_VSX_P (DFmode))
5995        {
5996          emit_insn (gen_vsx_copysignsf3 (operands[0], operands[1], operands[2],
5997                                          CONST0_RTX (SFmode)));
5998          DONE;
5999        }
6000      operands[3] = gen_reg_rtx (SFmode);
6001      operands[4] = gen_reg_rtx (SFmode);
6002      operands[5] = CONST0_RTX (SFmode);
6003   })
6004
6005 (define_expand "copysigndf3"
6006   [(set (match_dup 3)
6007         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
6008    (set (match_dup 4)
6009         (neg:DF (abs:DF (match_dup 1))))
6010    (set (match_operand:DF 0 "gpc_reg_operand" "")
6011         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
6012                              (match_dup 5))
6013                          (match_dup 3)
6014                          (match_dup 4)))]
6015   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6016    && ((TARGET_PPC_GFXOPT
6017         && !HONOR_NANS (DFmode)
6018         && !HONOR_SIGNED_ZEROS (DFmode))
6019        || VECTOR_UNIT_VSX_P (DFmode))"
6020   {
6021      if (VECTOR_UNIT_VSX_P (DFmode))
6022        {
6023          emit_insn (gen_vsx_copysigndf3 (operands[0], operands[1],
6024                                          operands[2], CONST0_RTX (DFmode)));
6025          DONE;
6026        }
6027      operands[3] = gen_reg_rtx (DFmode);
6028      operands[4] = gen_reg_rtx (DFmode);
6029      operands[5] = CONST0_RTX (DFmode);
6030   })
6031
6032 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
6033 ;; fsel instruction and some auxiliary computations.  Then we just have a
6034 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
6035 ;; combine.
6036 (define_expand "smaxsf3"
6037   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6038         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
6039                              (match_operand:SF 2 "gpc_reg_operand" ""))
6040                          (match_dup 1)
6041                          (match_dup 2)))]
6042   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6043    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6044   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
6045
6046 (define_expand "sminsf3"
6047   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6048         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
6049                              (match_operand:SF 2 "gpc_reg_operand" ""))
6050                          (match_dup 2)
6051                          (match_dup 1)))]
6052   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6053    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6054   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
6055
6056 (define_split
6057   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6058         (match_operator:SF 3 "min_max_operator"
6059          [(match_operand:SF 1 "gpc_reg_operand" "")
6060           (match_operand:SF 2 "gpc_reg_operand" "")]))]
6061   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6062    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6063   [(const_int 0)]
6064   "
6065 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
6066                       operands[1], operands[2]);
6067   DONE;
6068 }")
6069
6070 (define_expand "mov<mode>cc"
6071    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
6072          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
6073                            (match_operand:GPR 2 "gpc_reg_operand" "")
6074                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
6075   "TARGET_ISEL<sel>"
6076   "
6077 {
6078   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6079     DONE;
6080   else
6081     FAIL;
6082 }")
6083
6084 ;; We use the BASE_REGS for the isel input operands because, if rA is
6085 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
6086 ;; because we may switch the operands and rB may end up being rA.
6087 ;;
6088 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
6089 ;; leave out the mode in operand 4 and use one pattern, but reload can
6090 ;; change the mode underneath our feet and then gets confused trying
6091 ;; to reload the value.
6092 (define_insn "isel_signed_<mode>"
6093   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
6094         (if_then_else:GPR
6095          (match_operator 1 "comparison_operator"
6096                          [(match_operand:CC 4 "cc_reg_operand" "y")
6097                           (const_int 0)])
6098          (match_operand:GPR 2 "gpc_reg_operand" "b")
6099          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
6100   "TARGET_ISEL<sel>"
6101   "*
6102 { return output_isel (operands); }"
6103   [(set_attr "type" "isel")
6104    (set_attr "length" "4")])
6105
6106 (define_insn "isel_unsigned_<mode>"
6107   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
6108         (if_then_else:GPR
6109          (match_operator 1 "comparison_operator"
6110                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
6111                           (const_int 0)])
6112          (match_operand:GPR 2 "gpc_reg_operand" "b")
6113          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
6114   "TARGET_ISEL<sel>"
6115   "*
6116 { return output_isel (operands); }"
6117   [(set_attr "type" "isel")
6118    (set_attr "length" "4")])
6119
6120 (define_expand "movsfcc"
6121    [(set (match_operand:SF 0 "gpc_reg_operand" "")
6122          (if_then_else:SF (match_operand 1 "comparison_operator" "")
6123                           (match_operand:SF 2 "gpc_reg_operand" "")
6124                           (match_operand:SF 3 "gpc_reg_operand" "")))]
6125   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6126   "
6127 {
6128   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6129     DONE;
6130   else
6131     FAIL;
6132 }")
6133
6134 (define_insn "*fselsfsf4"
6135   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6136         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
6137                              (match_operand:SF 4 "zero_fp_constant" "F"))
6138                          (match_operand:SF 2 "gpc_reg_operand" "f")
6139                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
6140   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6141   "fsel %0,%1,%2,%3"
6142   [(set_attr "type" "fp")])
6143
6144 (define_insn "*fseldfsf4"
6145   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6146         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
6147                              (match_operand:DF 4 "zero_fp_constant" "F"))
6148                          (match_operand:SF 2 "gpc_reg_operand" "f")
6149                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
6150   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
6151   "fsel %0,%1,%2,%3"
6152   [(set_attr "type" "fp")])
6153
6154 (define_expand "negdf2"
6155   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6156         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6157   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6158   "")
6159
6160 (define_insn "*negdf2_fpr"
6161   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6162         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6163   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6164    && !VECTOR_UNIT_VSX_P (DFmode)"
6165   "fneg %0,%1"
6166   [(set_attr "type" "fp")])
6167
6168 (define_expand "absdf2"
6169   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6170         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6171   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6172   "")
6173
6174 (define_insn "*absdf2_fpr"
6175   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6176         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6177   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6178    && !VECTOR_UNIT_VSX_P (DFmode)"
6179   "fabs %0,%1"
6180   [(set_attr "type" "fp")])
6181
6182 (define_insn "*nabsdf2_fpr"
6183   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6184         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d"))))]
6185   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6186    && !VECTOR_UNIT_VSX_P (DFmode)"
6187   "fnabs %0,%1"
6188   [(set_attr "type" "fp")])
6189
6190 (define_expand "adddf3"
6191   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6192         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
6193                  (match_operand:DF 2 "gpc_reg_operand" "")))]
6194   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6195   "")
6196
6197 (define_insn "*adddf3_fpr"
6198   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6199         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6200                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
6201   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6202    && !VECTOR_UNIT_VSX_P (DFmode)"
6203   "{fa|fadd} %0,%1,%2"
6204   [(set_attr "type" "fp")
6205    (set_attr "fp_type" "fp_addsub_d")])
6206
6207 (define_expand "subdf3"
6208   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6209         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
6210                   (match_operand:DF 2 "gpc_reg_operand" "")))]
6211   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6212   "")
6213
6214 (define_insn "*subdf3_fpr"
6215   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6216         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "d")
6217                   (match_operand:DF 2 "gpc_reg_operand" "d")))]
6218   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6219    && !VECTOR_UNIT_VSX_P (DFmode)"
6220   "{fs|fsub} %0,%1,%2"
6221   [(set_attr "type" "fp")
6222    (set_attr "fp_type" "fp_addsub_d")])
6223
6224 (define_expand "muldf3"
6225   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6226         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
6227                  (match_operand:DF 2 "gpc_reg_operand" "")))]
6228   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6229   "")
6230
6231 (define_insn "*muldf3_fpr"
6232   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6233         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6234                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
6235   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6236    && !VECTOR_UNIT_VSX_P (DFmode)"
6237   "{fm|fmul} %0,%1,%2"
6238   [(set_attr "type" "dmul")
6239    (set_attr "fp_type" "fp_mul_d")])
6240
6241 (define_expand "divdf3"
6242   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6243         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
6244                 (match_operand:DF 2 "gpc_reg_operand" "")))]
6245   "TARGET_HARD_FLOAT
6246    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)
6247    && !TARGET_SIMPLE_FPU"
6248   "")
6249
6250 (define_insn "*divdf3_fpr"
6251   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6252         (div:DF (match_operand:DF 1 "gpc_reg_operand" "d")
6253                 (match_operand:DF 2 "gpc_reg_operand" "d")))]
6254   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && !TARGET_SIMPLE_FPU
6255    && !VECTOR_UNIT_VSX_P (DFmode)"
6256   "{fd|fdiv} %0,%1,%2"
6257   [(set_attr "type" "ddiv")])
6258
6259 (define_insn "*fred_fpr"
6260   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6261         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
6262   "TARGET_FRE && !VECTOR_UNIT_VSX_P (DFmode)"
6263   "fre %0,%1"
6264   [(set_attr "type" "fp")])
6265
6266 (define_insn "*rsqrtdf_internal1"
6267   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6268         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")]
6269                    UNSPEC_RSQRT))]
6270   "TARGET_FRSQRTE && !VECTOR_UNIT_VSX_P (DFmode)"
6271   "frsqrte %0,%1"
6272   [(set_attr "type" "fp")])
6273
6274 (define_insn "*fmadddf4_fpr"
6275   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6276         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6277                           (match_operand:DF 2 "gpc_reg_operand" "d"))
6278                  (match_operand:DF 3 "gpc_reg_operand" "d")))]
6279   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6280    && VECTOR_UNIT_NONE_P (DFmode)"
6281   "{fma|fmadd} %0,%1,%2,%3"
6282   [(set_attr "type" "dmul")
6283    (set_attr "fp_type" "fp_maddsub_d")])
6284
6285 (define_insn "*fmsubdf4_fpr"
6286   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6287         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6288                            (match_operand:DF 2 "gpc_reg_operand" "d"))
6289                   (match_operand:DF 3 "gpc_reg_operand" "d")))]
6290   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6291    && VECTOR_UNIT_NONE_P (DFmode)"
6292   "{fms|fmsub} %0,%1,%2,%3"
6293   [(set_attr "type" "dmul")
6294    (set_attr "fp_type" "fp_maddsub_d")])
6295
6296 (define_insn "*fnmadddf4_fpr_1"
6297   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6298         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6299                                   (match_operand:DF 2 "gpc_reg_operand" "d"))
6300                          (match_operand:DF 3 "gpc_reg_operand" "d"))))]
6301   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6302    && VECTOR_UNIT_NONE_P (DFmode)"
6303   "{fnma|fnmadd} %0,%1,%2,%3"
6304   [(set_attr "type" "dmul")
6305    (set_attr "fp_type" "fp_maddsub_d")])
6306
6307 (define_insn "*fnmadddf4_fpr_2"
6308   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6309         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d"))
6310                            (match_operand:DF 2 "gpc_reg_operand" "d"))
6311                   (match_operand:DF 3 "gpc_reg_operand" "d")))]
6312   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6313    && ! HONOR_SIGNED_ZEROS (DFmode) && VECTOR_UNIT_NONE_P (DFmode)"
6314   "{fnma|fnmadd} %0,%1,%2,%3"
6315   [(set_attr "type" "dmul")
6316    (set_attr "fp_type" "fp_maddsub_d")])
6317
6318 (define_insn "*fnmsubdf4_fpr_1"
6319   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6320         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6321                                    (match_operand:DF 2 "gpc_reg_operand" "d"))
6322                           (match_operand:DF 3 "gpc_reg_operand" "d"))))]
6323   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6324    && VECTOR_UNIT_NONE_P (DFmode)"
6325   "{fnms|fnmsub} %0,%1,%2,%3"
6326   [(set_attr "type" "dmul")
6327    (set_attr "fp_type" "fp_maddsub_d")])
6328
6329 (define_insn "*fnmsubdf4_fpr_2"
6330   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6331         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "d")
6332                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6333                            (match_operand:DF 2 "gpc_reg_operand" "d"))))]
6334   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6335    && ! HONOR_SIGNED_ZEROS (DFmode) && VECTOR_UNIT_NONE_P (DFmode)"
6336   "{fnms|fnmsub} %0,%1,%2,%3"
6337   [(set_attr "type" "dmul")
6338    (set_attr "fp_type" "fp_maddsub_d")])
6339
6340 (define_expand "sqrtdf2"
6341   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6342         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6343   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS 
6344    && TARGET_DOUBLE_FLOAT"
6345   "")
6346
6347 (define_insn "*sqrtdf2_fpr"
6348   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6349         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6350   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS 
6351    && TARGET_DOUBLE_FLOAT
6352    && !VECTOR_UNIT_VSX_P (DFmode)"
6353   "fsqrt %0,%1"
6354   [(set_attr "type" "dsqrt")])
6355
6356 ;; The conditional move instructions allow us to perform max and min
6357 ;; operations even when
6358
6359 (define_expand "smaxdf3"
6360   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6361         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
6362                              (match_operand:DF 2 "gpc_reg_operand" ""))
6363                          (match_dup 1)
6364                          (match_dup 2)))]
6365   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6366    && !flag_trapping_math"
6367   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
6368
6369 (define_expand "smindf3"
6370   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6371         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
6372                              (match_operand:DF 2 "gpc_reg_operand" ""))
6373                          (match_dup 2)
6374                          (match_dup 1)))]
6375   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6376    && !flag_trapping_math"
6377   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
6378
6379 (define_split
6380   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6381         (match_operator:DF 3 "min_max_operator"
6382          [(match_operand:DF 1 "gpc_reg_operand" "")
6383           (match_operand:DF 2 "gpc_reg_operand" "")]))]
6384   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6385    && !flag_trapping_math"
6386   [(const_int 0)]
6387   "
6388 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
6389                       operands[1], operands[2]);
6390   DONE;
6391 }")
6392
6393 (define_expand "movdfcc"
6394    [(set (match_operand:DF 0 "gpc_reg_operand" "")
6395          (if_then_else:DF (match_operand 1 "comparison_operator" "")
6396                           (match_operand:DF 2 "gpc_reg_operand" "")
6397                           (match_operand:DF 3 "gpc_reg_operand" "")))]
6398   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6399   "
6400 {
6401   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6402     DONE;
6403   else
6404     FAIL;
6405 }")
6406
6407 (define_insn "*fseldfdf4"
6408   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6409         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
6410                              (match_operand:DF 4 "zero_fp_constant" "F"))
6411                          (match_operand:DF 2 "gpc_reg_operand" "d")
6412                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
6413   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6414   "fsel %0,%1,%2,%3"
6415   [(set_attr "type" "fp")])
6416
6417 (define_insn "*fselsfdf4"
6418   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6419         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
6420                              (match_operand:SF 4 "zero_fp_constant" "F"))
6421                          (match_operand:DF 2 "gpc_reg_operand" "d")
6422                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
6423   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
6424   "fsel %0,%1,%2,%3"
6425   [(set_attr "type" "fp")])
6426 \f
6427 ;; Conversions to and from floating-point.
6428
6429 (define_expand "fixuns_truncsfsi2"
6430   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6431         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
6432   "TARGET_HARD_FLOAT && !TARGET_FPRS && TARGET_SINGLE_FLOAT"
6433   "")
6434
6435 (define_expand "fix_truncsfsi2"
6436  [(set (match_operand:SI 0 "gpc_reg_operand" "")
6437       (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
6438  "TARGET_HARD_FLOAT && !TARGET_FPRS && TARGET_SINGLE_FLOAT"
6439  "")
6440
6441 (define_expand "fixuns_truncdfsi2"
6442   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6443         (unsigned_fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
6444   "TARGET_HARD_FLOAT && TARGET_E500_DOUBLE"
6445   "")
6446
6447 (define_expand "fixuns_truncdfdi2"
6448   [(set (match_operand:DI 0 "register_operand" "")
6449         (unsigned_fix:DI (match_operand:DF 1 "register_operand" "")))]
6450   "TARGET_HARD_FLOAT && TARGET_VSX"
6451   "")
6452
6453 ; For each of these conversions, there is a define_expand, a define_insn
6454 ; with a '#' template, and a define_split (with C code).  The idea is
6455 ; to allow constant folding with the template of the define_insn,
6456 ; then to have the insns split later (between sched1 and final).
6457
6458 (define_expand "floatsidf2"
6459   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
6460                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
6461               (use (match_dup 2))
6462               (use (match_dup 3))
6463               (clobber (match_dup 4))
6464               (clobber (match_dup 5))
6465               (clobber (match_dup 6))])]
6466   "TARGET_HARD_FLOAT 
6467    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6468   "
6469 {
6470   if (TARGET_E500_DOUBLE)
6471     {
6472       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
6473       DONE;
6474     }
6475   if (TARGET_POWERPC64)
6476     {
6477       rtx x = convert_to_mode (DImode, operands[1], 0);
6478       emit_insn (gen_floatdidf2 (operands[0], x));
6479       DONE;
6480     }
6481
6482   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6483   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
6484   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
6485   operands[5] = gen_reg_rtx (DFmode);
6486   operands[6] = gen_reg_rtx (SImode);
6487 }")
6488
6489 (define_insn_and_split "*floatsidf2_internal"
6490   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6491         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6492    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6493    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6494    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6495    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
6496    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
6497   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6498   "#"
6499   ""
6500   [(pc)]
6501   "
6502 {
6503   rtx lowword, highword;
6504   gcc_assert (MEM_P (operands[4]));
6505   highword = adjust_address (operands[4], SImode, 0);
6506   lowword = adjust_address (operands[4], SImode, 4);
6507   if (! WORDS_BIG_ENDIAN)
6508     {
6509       rtx tmp;
6510       tmp = highword; highword = lowword; lowword = tmp;
6511     }
6512
6513   emit_insn (gen_xorsi3 (operands[6], operands[1],
6514                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
6515   emit_move_insn (lowword, operands[6]);
6516   emit_move_insn (highword, operands[2]);
6517   emit_move_insn (operands[5], operands[4]);
6518   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6519   DONE;
6520 }"
6521   [(set_attr "length" "24")])
6522
6523 (define_expand "floatunssisf2"
6524   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6525         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
6526   "TARGET_HARD_FLOAT && !TARGET_FPRS && TARGET_SINGLE_FLOAT"
6527   "")
6528
6529 (define_expand "floatunssidf2"
6530   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
6531                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
6532               (use (match_dup 2))
6533               (use (match_dup 3))
6534               (clobber (match_dup 4))
6535               (clobber (match_dup 5))])]
6536   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6537   "
6538 {
6539   if (TARGET_E500_DOUBLE)
6540     {
6541       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
6542       DONE;
6543     }
6544   if (TARGET_POWERPC64)
6545     {
6546       rtx x = convert_to_mode (DImode, operands[1], 1);
6547       emit_insn (gen_floatdidf2 (operands[0], x));
6548       DONE;
6549     }
6550
6551   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6552   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
6553   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
6554   operands[5] = gen_reg_rtx (DFmode);
6555 }")
6556
6557 (define_insn_and_split "*floatunssidf2_internal"
6558   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6559         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6560    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6561    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6562    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6563    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
6564   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6565   "#"
6566   ""
6567   [(pc)]
6568   "
6569 {
6570   rtx lowword, highword;
6571   gcc_assert (MEM_P (operands[4]));
6572   highword = adjust_address (operands[4], SImode, 0);
6573   lowword = adjust_address (operands[4], SImode, 4);
6574   if (! WORDS_BIG_ENDIAN)
6575     {
6576       rtx tmp;
6577       tmp = highword; highword = lowword; lowword = tmp;
6578     }
6579
6580   emit_move_insn (lowword, operands[1]);
6581   emit_move_insn (highword, operands[2]);
6582   emit_move_insn (operands[5], operands[4]);
6583   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6584   DONE;
6585 }"
6586   [(set_attr "length" "20")])
6587
6588 (define_expand "fix_truncdfsi2"
6589   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
6590                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
6591               (clobber (match_dup 2))
6592               (clobber (match_dup 3))])]
6593   "(TARGET_POWER2 || TARGET_POWERPC)
6594    && TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6595   "
6596 {
6597   if (TARGET_E500_DOUBLE)
6598     {
6599      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
6600      DONE;
6601     }
6602   operands[2] = gen_reg_rtx (DImode);
6603   if (TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
6604       && gpc_reg_operand(operands[0], GET_MODE (operands[0])))
6605     {
6606       operands[3] = gen_reg_rtx (DImode);
6607       emit_insn (gen_fix_truncdfsi2_mfpgpr (operands[0], operands[1],
6608                                             operands[2], operands[3]));
6609       DONE;
6610     }
6611   if (TARGET_PPC_GFXOPT)
6612     {
6613       rtx orig_dest = operands[0];
6614       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
6615         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
6616       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
6617                                                      operands[2]));
6618       if (operands[0] != orig_dest)
6619         emit_move_insn (orig_dest, operands[0]);
6620       DONE;
6621     }
6622   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
6623 }")
6624
6625 (define_insn_and_split "*fix_truncdfsi2_internal"
6626   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6627         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "d")))
6628    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))
6629    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o"))]
6630   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
6631    && TARGET_DOUBLE_FLOAT"
6632   "#"
6633   ""
6634   [(pc)]
6635   "
6636 {
6637   rtx lowword;
6638   gcc_assert (MEM_P (operands[3]));
6639   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6640
6641   emit_insn (gen_fctiwz (operands[2], operands[1]));
6642   emit_move_insn (operands[3], operands[2]);
6643   emit_move_insn (operands[0], lowword);
6644   DONE;
6645 }"
6646   [(set_attr "length" "16")])
6647
6648 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
6649   [(set (match_operand:SI 0 "memory_operand" "=Z")
6650         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "d")))
6651    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))]
6652   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
6653    && TARGET_DOUBLE_FLOAT 
6654    && TARGET_PPC_GFXOPT"
6655   "#"
6656   "&& 1"
6657   [(pc)]
6658   "
6659 {
6660   emit_insn (gen_fctiwz (operands[2], operands[1]));
6661   emit_insn (gen_stfiwx (operands[0], operands[2]));
6662   DONE;
6663 }"
6664   [(set_attr "length" "16")])
6665
6666 (define_insn_and_split "fix_truncdfsi2_mfpgpr"
6667   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6668         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "d")))
6669    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))
6670    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))]
6671   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
6672    && TARGET_DOUBLE_FLOAT"
6673   "#"
6674   "&& 1"
6675   [(set (match_dup 2) (unspec:DI [(fix:SI (match_dup 1))] UNSPEC_FCTIWZ))
6676    (set (match_dup 3) (match_dup 2))
6677    (set (match_dup 0) (subreg:SI (match_dup 3) 4))]
6678   ""
6679   [(set_attr "length" "12")])
6680
6681 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6682 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
6683 ; because the first makes it clear that operand 0 is not live
6684 ; before the instruction.
6685 (define_insn "fctiwz"
6686   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6687         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "d"))]
6688                    UNSPEC_FCTIWZ))]
6689   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
6690    && TARGET_DOUBLE_FLOAT"
6691   "{fcirz|fctiwz} %0,%1"
6692   [(set_attr "type" "fp")])
6693
6694 (define_expand "btruncdf2"
6695   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6696         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRIZ))]
6697   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6698   "")
6699
6700 (define_insn "*btruncdf2_fpr"
6701   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6702         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
6703   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6704    && !VECTOR_UNIT_VSX_P (DFmode)"
6705   "friz %0,%1"
6706   [(set_attr "type" "fp")])
6707
6708 (define_insn "btruncsf2"
6709   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6710         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
6711   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6712   "friz %0,%1"
6713   [(set_attr "type" "fp")])
6714
6715 (define_expand "ceildf2"
6716   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6717         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "")] UNSPEC_FRIP))]
6718   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6719   "")
6720
6721 (define_insn "*ceildf2_fpr"
6722   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6723         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRIP))]
6724   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6725    && !VECTOR_UNIT_VSX_P (DFmode)"
6726   "frip %0,%1"
6727   [(set_attr "type" "fp")])
6728
6729 (define_insn "ceilsf2"
6730  [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6731         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
6732   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT "
6733   "frip %0,%1"
6734   [(set_attr "type" "fp")])
6735
6736 (define_expand "floordf2"
6737   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6738         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "")] UNSPEC_FRIM))]
6739   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6740   "")
6741
6742 (define_insn "*floordf2_fpr"
6743   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6744         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRIM))]
6745   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6746    && !VECTOR_UNIT_VSX_P (DFmode)"
6747   "frim %0,%1"
6748   [(set_attr "type" "fp")])
6749
6750 (define_insn "floorsf2"
6751   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6752         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
6753   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT "
6754   "frim %0,%1"
6755   [(set_attr "type" "fp")])
6756
6757 ;; No VSX equivalent to frin
6758 (define_insn "rounddf2"
6759   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6760         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")] UNSPEC_FRIN))]
6761   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6762   "frin %0,%1"
6763   [(set_attr "type" "fp")])
6764
6765 (define_insn "roundsf2"
6766   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6767         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
6768   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT "
6769   "frin %0,%1"
6770   [(set_attr "type" "fp")])
6771
6772 (define_expand "ftruncdf2"
6773   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6774         (fix:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6775   "VECTOR_UNIT_VSX_P (DFmode)"
6776   "")
6777
6778 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6779 (define_insn "stfiwx"
6780   [(set (match_operand:SI 0 "memory_operand" "=Z")
6781         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
6782                    UNSPEC_STFIWX))]
6783   "TARGET_PPC_GFXOPT"
6784   "stfiwx %1,%y0"
6785   [(set_attr "type" "fpstore")])
6786
6787 (define_expand "floatsisf2"
6788   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6789         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
6790   "TARGET_HARD_FLOAT && !TARGET_FPRS"
6791   "")
6792
6793 (define_expand "floatdidf2"
6794   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6795         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
6796   "(TARGET_POWERPC64 || TARGET_XILINX_FPU || VECTOR_UNIT_VSX_P (DFmode))
6797    && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
6798   "")
6799
6800 (define_insn "*floatdidf2_fpr"
6801   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6802         (float:DF (match_operand:DI 1 "gpc_reg_operand" "!d#r")))]
6803   "(TARGET_POWERPC64 || TARGET_XILINX_FPU)
6804    && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6805    && !VECTOR_UNIT_VSX_P (DFmode)"
6806   "fcfid %0,%1"
6807   [(set_attr "type" "fp")])
6808
6809 (define_expand "floatunsdidf2"
6810   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6811         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
6812   "TARGET_VSX"
6813   "")
6814
6815 (define_expand "fix_truncdfdi2"
6816   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6817         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "")))]
6818   "(TARGET_POWERPC64 || TARGET_XILINX_FPU || VECTOR_UNIT_VSX_P (DFmode))
6819     && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
6820   "")
6821
6822 (define_insn "*fix_truncdfdi2_fpr"
6823   [(set (match_operand:DI 0 "gpc_reg_operand" "=!d#r")
6824         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d")))]
6825   "(TARGET_POWERPC64 || TARGET_XILINX_FPU)
6826     && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6827     && !VECTOR_UNIT_VSX_P (DFmode)"
6828   "fctidz %0,%1"
6829   [(set_attr "type" "fp")])
6830
6831 (define_expand "floatdisf2"
6832   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6833         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6834   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT "
6835   "
6836 {
6837   rtx val = operands[1];
6838   if (!flag_unsafe_math_optimizations)
6839     {
6840       rtx label = gen_label_rtx ();
6841       val = gen_reg_rtx (DImode);
6842       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
6843       emit_label (label);
6844     }
6845   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
6846   DONE;
6847 }")
6848
6849 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6850 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6851 ;; from double rounding.
6852 (define_insn_and_split "floatdisf2_internal1"
6853   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6854         (float:SF (match_operand:DI 1 "gpc_reg_operand" "!d#r")))
6855    (clobber (match_scratch:DF 2 "=d"))]
6856   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6857   "#"
6858   "&& reload_completed"
6859   [(set (match_dup 2)
6860         (float:DF (match_dup 1)))
6861    (set (match_dup 0)
6862         (float_truncate:SF (match_dup 2)))]
6863   "")
6864
6865 ;; Twiddles bits to avoid double rounding.
6866 ;; Bits that might be truncated when converting to DFmode are replaced
6867 ;; by a bit that won't be lost at that stage, but is below the SFmode
6868 ;; rounding position.
6869 (define_expand "floatdisf2_internal2"
6870   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6871                                    (const_int 53)))
6872    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6873                                                       (const_int 2047)))
6874               (clobber (scratch:CC))])
6875    (set (match_dup 3) (plus:DI (match_dup 3)
6876                                (const_int 1)))
6877    (set (match_dup 0) (plus:DI (match_dup 0)
6878                                (const_int 2047)))
6879    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6880                                      (const_int 2)))
6881    (set (match_dup 0) (ior:DI (match_dup 0)
6882                               (match_dup 1)))
6883    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6884                                          (const_int -2048)))
6885               (clobber (scratch:CC))])
6886    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6887                            (label_ref (match_operand:DI 2 "" ""))
6888                            (pc)))
6889    (set (match_dup 0) (match_dup 1))]
6890   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6891   "
6892 {
6893   operands[3] = gen_reg_rtx (DImode);
6894   operands[4] = gen_reg_rtx (CCUNSmode);
6895 }")
6896 \f
6897 ;; Define the DImode operations that can be done in a small number
6898 ;; of instructions.  The & constraints are to prevent the register
6899 ;; allocator from allocating registers that overlap with the inputs
6900 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6901 ;; also allow for the output being the same as one of the inputs.
6902
6903 (define_insn "*adddi3_noppc64"
6904   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6905         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6906                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6907   "! TARGET_POWERPC64"
6908   "*
6909 {
6910   if (WORDS_BIG_ENDIAN)
6911     return (GET_CODE (operands[2])) != CONST_INT
6912             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
6913             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
6914   else
6915     return (GET_CODE (operands[2])) != CONST_INT
6916             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
6917             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
6918 }"
6919   [(set_attr "type" "two")
6920    (set_attr "length" "8")])
6921
6922 (define_insn "*subdi3_noppc64"
6923   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6924         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6925                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6926   "! TARGET_POWERPC64"
6927   "*
6928 {
6929   if (WORDS_BIG_ENDIAN)
6930     return (GET_CODE (operands[1]) != CONST_INT)
6931             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
6932             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
6933   else
6934     return (GET_CODE (operands[1]) != CONST_INT)
6935             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
6936             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
6937 }"
6938   [(set_attr "type" "two")
6939    (set_attr "length" "8")])
6940
6941 (define_insn "*negdi2_noppc64"
6942   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6943         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6944   "! TARGET_POWERPC64"
6945   "*
6946 {
6947   return (WORDS_BIG_ENDIAN)
6948     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
6949     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
6950 }"
6951   [(set_attr "type" "two")
6952    (set_attr "length" "8")])
6953
6954 (define_expand "mulsidi3"
6955   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6956         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6957                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6958   "! TARGET_POWERPC64"
6959   "
6960 {
6961   if (! TARGET_POWER && ! TARGET_POWERPC)
6962     {
6963       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6964       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6965       emit_insn (gen_mull_call ());
6966       if (WORDS_BIG_ENDIAN)
6967         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
6968       else
6969         {
6970           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
6971                           gen_rtx_REG (SImode, 3));
6972           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
6973                           gen_rtx_REG (SImode, 4));
6974         }
6975       DONE;
6976     }
6977   else if (TARGET_POWER)
6978     {
6979       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
6980       DONE;
6981     }
6982 }")
6983
6984 (define_insn "mulsidi3_mq"
6985   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6986         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6987                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6988    (clobber (match_scratch:SI 3 "=q"))]
6989   "TARGET_POWER"
6990   "mul %0,%1,%2\;mfmq %L0"
6991   [(set_attr "type" "imul")
6992    (set_attr "length" "8")])
6993
6994 (define_insn "*mulsidi3_no_mq"
6995   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6996         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6997                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6998   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6999   "*
7000 {
7001   return (WORDS_BIG_ENDIAN)
7002     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
7003     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
7004 }"
7005   [(set_attr "type" "imul")
7006    (set_attr "length" "8")])
7007
7008 (define_split
7009   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7010         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7011                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7012   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
7013   [(set (match_dup 3)
7014         (truncate:SI
7015          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
7016                                (sign_extend:DI (match_dup 2)))
7017                       (const_int 32))))
7018    (set (match_dup 4)
7019         (mult:SI (match_dup 1)
7020                  (match_dup 2)))]
7021   "
7022 {
7023   int endian = (WORDS_BIG_ENDIAN == 0);
7024   operands[3] = operand_subword (operands[0], endian, 0, DImode);
7025   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
7026 }")
7027
7028 (define_expand "umulsidi3"
7029   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7030         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7031                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7032   "TARGET_POWERPC && ! TARGET_POWERPC64"
7033   "
7034 {
7035   if (TARGET_POWER)
7036     {
7037       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
7038       DONE;
7039     }
7040 }")
7041
7042 (define_insn "umulsidi3_mq"
7043   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7044         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7045                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
7046    (clobber (match_scratch:SI 3 "=q"))]
7047   "TARGET_POWERPC && TARGET_POWER"
7048   "*
7049 {
7050   return (WORDS_BIG_ENDIAN)
7051     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
7052     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
7053 }"
7054   [(set_attr "type" "imul")
7055    (set_attr "length" "8")])
7056
7057 (define_insn "*umulsidi3_no_mq"
7058   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7059         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7060                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
7061   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
7062   "*
7063 {
7064   return (WORDS_BIG_ENDIAN)
7065     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
7066     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
7067 }"
7068   [(set_attr "type" "imul")
7069    (set_attr "length" "8")])
7070
7071 (define_split
7072   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7073         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7074                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7075   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
7076   [(set (match_dup 3)
7077         (truncate:SI
7078          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
7079                                (zero_extend:DI (match_dup 2)))
7080                       (const_int 32))))
7081    (set (match_dup 4)
7082         (mult:SI (match_dup 1)
7083                  (match_dup 2)))]
7084   "
7085 {
7086   int endian = (WORDS_BIG_ENDIAN == 0);
7087   operands[3] = operand_subword (operands[0], endian, 0, DImode);
7088   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
7089 }")
7090
7091 (define_expand "smulsi3_highpart"
7092   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7093         (truncate:SI
7094          (lshiftrt:DI (mult:DI (sign_extend:DI
7095                                 (match_operand:SI 1 "gpc_reg_operand" ""))
7096                                (sign_extend:DI
7097                                 (match_operand:SI 2 "gpc_reg_operand" "")))
7098                       (const_int 32))))]
7099   ""
7100   "
7101 {
7102   if (! TARGET_POWER && ! TARGET_POWERPC)
7103     {
7104       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
7105       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
7106       emit_insn (gen_mulh_call ());
7107       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
7108       DONE;
7109     }
7110   else if (TARGET_POWER)
7111     {
7112       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
7113       DONE;
7114     }
7115 }")
7116
7117 (define_insn "smulsi3_highpart_mq"
7118   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7119         (truncate:SI
7120          (lshiftrt:DI (mult:DI (sign_extend:DI
7121                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7122                                (sign_extend:DI
7123                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7124                       (const_int 32))))
7125    (clobber (match_scratch:SI 3 "=q"))]
7126   "TARGET_POWER"
7127   "mul %0,%1,%2"
7128   [(set_attr "type" "imul")])
7129
7130 (define_insn "*smulsi3_highpart_no_mq"
7131   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7132         (truncate:SI
7133          (lshiftrt:DI (mult:DI (sign_extend:DI
7134                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7135                                (sign_extend:DI
7136                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7137                       (const_int 32))))]
7138   "TARGET_POWERPC && ! TARGET_POWER"
7139   "mulhw %0,%1,%2"
7140   [(set_attr "type" "imul")])
7141
7142 (define_expand "umulsi3_highpart"
7143   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7144         (truncate:SI
7145          (lshiftrt:DI (mult:DI (zero_extend:DI
7146                                 (match_operand:SI 1 "gpc_reg_operand" ""))
7147                                (zero_extend:DI
7148                                 (match_operand:SI 2 "gpc_reg_operand" "")))
7149                       (const_int 32))))]
7150   "TARGET_POWERPC"
7151   "
7152 {
7153   if (TARGET_POWER)
7154     {
7155       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
7156       DONE;
7157     }
7158 }")
7159
7160 (define_insn "umulsi3_highpart_mq"
7161   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7162         (truncate:SI
7163          (lshiftrt:DI (mult:DI (zero_extend:DI
7164                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7165                                (zero_extend:DI
7166                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7167                       (const_int 32))))
7168    (clobber (match_scratch:SI 3 "=q"))]
7169   "TARGET_POWERPC && TARGET_POWER"
7170   "mulhwu %0,%1,%2"
7171   [(set_attr "type" "imul")])
7172
7173 (define_insn "*umulsi3_highpart_no_mq"
7174   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7175         (truncate:SI
7176          (lshiftrt:DI (mult:DI (zero_extend:DI
7177                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7178                                (zero_extend:DI
7179                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7180                       (const_int 32))))]
7181   "TARGET_POWERPC && ! TARGET_POWER"
7182   "mulhwu %0,%1,%2"
7183   [(set_attr "type" "imul")])
7184
7185 ;; If operands 0 and 2 are in the same register, we have a problem.  But
7186 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
7187 ;; why we have the strange constraints below.
7188 (define_insn "ashldi3_power"
7189   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
7190         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
7191                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
7192    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
7193   "TARGET_POWER"
7194   "@
7195    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
7196    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
7197    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
7198    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
7199   [(set_attr "length" "8")])
7200
7201 (define_insn "lshrdi3_power"
7202   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
7203         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
7204                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
7205    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
7206   "TARGET_POWER"
7207   "@
7208    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
7209    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
7210    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
7211    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
7212   [(set_attr "length" "8")])
7213
7214 ;; Shift by a variable amount is too complex to be worth open-coding.  We
7215 ;; just handle shifts by constants.
7216 (define_insn "ashrdi3_power"
7217   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7218         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7219                      (match_operand:SI 2 "const_int_operand" "M,i")))
7220    (clobber (match_scratch:SI 3 "=X,q"))]
7221   "TARGET_POWER"
7222   "@
7223    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
7224    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
7225   [(set_attr "type" "shift")
7226    (set_attr "length" "8")])
7227
7228 (define_insn "ashrdi3_no_power"
7229   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
7230         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7231                      (match_operand:SI 2 "const_int_operand" "M,i")))]
7232   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
7233   "@
7234    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
7235    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
7236   [(set_attr "type" "two,three")
7237    (set_attr "length" "8,12")])
7238
7239 (define_insn "*ashrdisi3_noppc64"
7240   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7241         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7242                                 (const_int 32)) 4))]
7243   "TARGET_32BIT && !TARGET_POWERPC64"
7244   "*
7245 {
7246   if (REGNO (operands[0]) == REGNO (operands[1]))
7247     return \"\";
7248   else
7249     return \"mr %0,%1\";
7250 }"
7251    [(set_attr "length" "4")])
7252
7253 \f
7254 ;; PowerPC64 DImode operations.
7255
7256 (define_expand "absdi2"
7257   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7258         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
7259   "TARGET_POWERPC64"
7260   "
7261 {
7262   if (TARGET_ISEL)
7263     emit_insn (gen_absdi2_isel (operands[0], operands[1]));
7264   else
7265     emit_insn (gen_absdi2_internal (operands[0], operands[1]));
7266   DONE;
7267 }")
7268
7269 (define_insn_and_split "absdi2_internal"
7270   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7271         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
7272    (clobber (match_scratch:DI 2 "=&r,&r"))]
7273   "TARGET_POWERPC64 && !TARGET_ISEL"
7274   "#"
7275   "&& reload_completed"
7276   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
7277    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
7278    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
7279   "")
7280
7281 (define_insn_and_split "*nabsdi2"
7282   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7283         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
7284    (clobber (match_scratch:DI 2 "=&r,&r"))]
7285   "TARGET_POWERPC64 && !TARGET_ISEL"
7286   "#"
7287   "&& reload_completed"
7288   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
7289    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
7290    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
7291   "")
7292
7293 (define_insn "muldi3"
7294   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7295         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7296                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
7297   "TARGET_POWERPC64"
7298   "@
7299    mulld %0,%1,%2
7300    mulli %0,%1,%2"
7301    [(set (attr "type")
7302       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
7303                 (const_string "imul3")
7304              (match_operand:SI 2 "short_cint_operand" "")
7305                 (const_string "imul2")]
7306         (const_string "lmul")))])
7307
7308 (define_insn "*muldi3_internal1"
7309   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7310         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7311                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
7312                     (const_int 0)))
7313    (clobber (match_scratch:DI 3 "=r,r"))]
7314   "TARGET_POWERPC64"
7315   "@
7316    mulld. %3,%1,%2
7317    #"
7318   [(set_attr "type" "lmul_compare")
7319    (set_attr "length" "4,8")])
7320
7321 (define_split
7322   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7323         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
7324                              (match_operand:DI 2 "gpc_reg_operand" ""))
7325                     (const_int 0)))
7326    (clobber (match_scratch:DI 3 ""))]
7327   "TARGET_POWERPC64 && reload_completed"
7328   [(set (match_dup 3)
7329         (mult:DI (match_dup 1) (match_dup 2)))
7330    (set (match_dup 0)
7331         (compare:CC (match_dup 3)
7332                     (const_int 0)))]
7333   "")
7334
7335 (define_insn "*muldi3_internal2"
7336   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7337         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7338                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
7339                     (const_int 0)))
7340    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7341         (mult:DI (match_dup 1) (match_dup 2)))]
7342   "TARGET_POWERPC64"
7343   "@
7344    mulld. %0,%1,%2
7345    #"
7346   [(set_attr "type" "lmul_compare")
7347    (set_attr "length" "4,8")])
7348
7349 (define_split
7350   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7351         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
7352                              (match_operand:DI 2 "gpc_reg_operand" ""))
7353                     (const_int 0)))
7354    (set (match_operand:DI 0 "gpc_reg_operand" "")
7355         (mult:DI (match_dup 1) (match_dup 2)))]
7356   "TARGET_POWERPC64 && reload_completed"
7357   [(set (match_dup 0)
7358         (mult:DI (match_dup 1) (match_dup 2)))
7359    (set (match_dup 3)
7360         (compare:CC (match_dup 0)
7361                     (const_int 0)))]
7362   "")
7363
7364 (define_insn "smuldi3_highpart"
7365   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7366         (truncate:DI
7367          (lshiftrt:TI (mult:TI (sign_extend:TI
7368                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
7369                                (sign_extend:TI
7370                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
7371                       (const_int 64))))]
7372   "TARGET_POWERPC64"
7373   "mulhd %0,%1,%2"
7374   [(set_attr "type" "lmul")])
7375
7376 (define_insn "umuldi3_highpart"
7377   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7378         (truncate:DI
7379          (lshiftrt:TI (mult:TI (zero_extend:TI
7380                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
7381                                (zero_extend:TI
7382                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
7383                       (const_int 64))))]
7384   "TARGET_POWERPC64"
7385   "mulhdu %0,%1,%2"
7386   [(set_attr "type" "lmul")])
7387
7388 (define_insn "rotldi3"
7389   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7390         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7391                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
7392   "TARGET_POWERPC64"
7393   "@
7394    rldcl %0,%1,%2,0
7395    rldicl %0,%1,%H2,0"
7396   [(set_attr "type" "var_shift_rotate,integer")])
7397
7398 (define_insn "*rotldi3_internal2"
7399   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7400         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7401                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7402                     (const_int 0)))
7403    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7404   "TARGET_64BIT"
7405   "@
7406    rldcl. %3,%1,%2,0
7407    rldicl. %3,%1,%H2,0
7408    #
7409    #"
7410   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7411    (set_attr "length" "4,4,8,8")])
7412
7413 (define_split
7414   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7415         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7416                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7417                     (const_int 0)))
7418    (clobber (match_scratch:DI 3 ""))]
7419   "TARGET_POWERPC64 && reload_completed"
7420   [(set (match_dup 3)
7421         (rotate:DI (match_dup 1) (match_dup 2)))
7422    (set (match_dup 0)
7423         (compare:CC (match_dup 3)
7424                     (const_int 0)))]
7425   "")
7426
7427 (define_insn "*rotldi3_internal3"
7428   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7429         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7430                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7431                     (const_int 0)))
7432    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7433         (rotate:DI (match_dup 1) (match_dup 2)))]
7434   "TARGET_64BIT"
7435   "@
7436    rldcl. %0,%1,%2,0
7437    rldicl. %0,%1,%H2,0
7438    #
7439    #"
7440   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7441    (set_attr "length" "4,4,8,8")])
7442
7443 (define_split
7444   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7445         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7446                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7447                     (const_int 0)))
7448    (set (match_operand:DI 0 "gpc_reg_operand" "")
7449         (rotate:DI (match_dup 1) (match_dup 2)))]
7450   "TARGET_POWERPC64 && reload_completed"
7451   [(set (match_dup 0)
7452         (rotate:DI (match_dup 1) (match_dup 2)))
7453    (set (match_dup 3)
7454         (compare:CC (match_dup 0)
7455                     (const_int 0)))]
7456   "")
7457
7458 (define_insn "*rotldi3_internal4"
7459   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7460         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7461                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
7462                 (match_operand:DI 3 "mask64_operand" "n,n")))]
7463   "TARGET_POWERPC64"
7464   "@
7465    rldc%B3 %0,%1,%2,%S3
7466    rldic%B3 %0,%1,%H2,%S3"
7467   [(set_attr "type" "var_shift_rotate,integer")])
7468
7469 (define_insn "*rotldi3_internal5"
7470   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7471         (compare:CC (and:DI
7472                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7473                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7474                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7475                     (const_int 0)))
7476    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
7477   "TARGET_64BIT"
7478   "@
7479    rldc%B3. %4,%1,%2,%S3
7480    rldic%B3. %4,%1,%H2,%S3
7481    #
7482    #"
7483   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7484    (set_attr "length" "4,4,8,8")])
7485
7486 (define_split
7487   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7488         (compare:CC (and:DI
7489                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7490                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7491                      (match_operand:DI 3 "mask64_operand" ""))
7492                     (const_int 0)))
7493    (clobber (match_scratch:DI 4 ""))]
7494   "TARGET_POWERPC64 && reload_completed"
7495   [(set (match_dup 4)
7496         (and:DI (rotate:DI (match_dup 1)
7497                                 (match_dup 2))
7498                      (match_dup 3)))
7499    (set (match_dup 0)
7500         (compare:CC (match_dup 4)
7501                     (const_int 0)))]
7502   "")
7503
7504 (define_insn "*rotldi3_internal6"
7505   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
7506         (compare:CC (and:DI
7507                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7508                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7509                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7510                     (const_int 0)))
7511    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7512         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7513   "TARGET_64BIT"
7514   "@
7515    rldc%B3. %0,%1,%2,%S3
7516    rldic%B3. %0,%1,%H2,%S3
7517    #
7518    #"
7519   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7520    (set_attr "length" "4,4,8,8")])
7521
7522 (define_split
7523   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7524         (compare:CC (and:DI
7525                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7526                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7527                      (match_operand:DI 3 "mask64_operand" ""))
7528                     (const_int 0)))
7529    (set (match_operand:DI 0 "gpc_reg_operand" "")
7530         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7531   "TARGET_POWERPC64 && reload_completed"
7532   [(set (match_dup 0)
7533         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
7534    (set (match_dup 4)
7535         (compare:CC (match_dup 0)
7536                     (const_int 0)))]
7537   "")
7538
7539 (define_insn "*rotldi3_internal7"
7540   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7541         (zero_extend:DI
7542          (subreg:QI
7543           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7544                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7545   "TARGET_POWERPC64"
7546   "@
7547    rldcl %0,%1,%2,56
7548    rldicl %0,%1,%H2,56"
7549   [(set_attr "type" "var_shift_rotate,integer")])
7550
7551 (define_insn "*rotldi3_internal8"
7552   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7553         (compare:CC (zero_extend:DI
7554                      (subreg:QI
7555                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7556                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7557                     (const_int 0)))
7558    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7559   "TARGET_64BIT"
7560   "@
7561    rldcl. %3,%1,%2,56
7562    rldicl. %3,%1,%H2,56
7563    #
7564    #"
7565   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7566    (set_attr "length" "4,4,8,8")])
7567
7568 (define_split
7569   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7570         (compare:CC (zero_extend:DI
7571                      (subreg:QI
7572                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7573                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7574                     (const_int 0)))
7575    (clobber (match_scratch:DI 3 ""))]
7576   "TARGET_POWERPC64 && reload_completed"
7577   [(set (match_dup 3)
7578         (zero_extend:DI (subreg:QI
7579                       (rotate:DI (match_dup 1)
7580                                  (match_dup 2)) 0)))
7581    (set (match_dup 0)
7582         (compare:CC (match_dup 3)
7583                     (const_int 0)))]
7584   "")
7585
7586 (define_insn "*rotldi3_internal9"
7587   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7588         (compare:CC (zero_extend:DI
7589                      (subreg:QI
7590                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7591                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7592                     (const_int 0)))
7593    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7594         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7595   "TARGET_64BIT"
7596   "@
7597    rldcl. %0,%1,%2,56
7598    rldicl. %0,%1,%H2,56
7599    #
7600    #"
7601   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7602    (set_attr "length" "4,4,8,8")])
7603
7604 (define_split
7605   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7606         (compare:CC (zero_extend:DI
7607                      (subreg:QI
7608                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7609                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7610                     (const_int 0)))
7611    (set (match_operand:DI 0 "gpc_reg_operand" "")
7612         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7613   "TARGET_POWERPC64 && reload_completed"
7614   [(set (match_dup 0)
7615         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7616    (set (match_dup 3)
7617         (compare:CC (match_dup 0)
7618                     (const_int 0)))]
7619   "")
7620
7621 (define_insn "*rotldi3_internal10"
7622   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7623         (zero_extend:DI
7624          (subreg:HI
7625           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7626                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7627   "TARGET_POWERPC64"
7628   "@
7629    rldcl %0,%1,%2,48
7630    rldicl %0,%1,%H2,48"
7631   [(set_attr "type" "var_shift_rotate,integer")])
7632
7633 (define_insn "*rotldi3_internal11"
7634   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7635         (compare:CC (zero_extend:DI
7636                      (subreg:HI
7637                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7638                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7639                     (const_int 0)))
7640    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7641   "TARGET_64BIT"
7642   "@
7643    rldcl. %3,%1,%2,48
7644    rldicl. %3,%1,%H2,48
7645    #
7646    #"
7647   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7648    (set_attr "length" "4,4,8,8")])
7649
7650 (define_split
7651   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7652         (compare:CC (zero_extend:DI
7653                      (subreg:HI
7654                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7655                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7656                     (const_int 0)))
7657    (clobber (match_scratch:DI 3 ""))]
7658   "TARGET_POWERPC64 && reload_completed"
7659   [(set (match_dup 3)
7660         (zero_extend:DI (subreg:HI
7661                       (rotate:DI (match_dup 1)
7662                                  (match_dup 2)) 0)))
7663    (set (match_dup 0)
7664         (compare:CC (match_dup 3)
7665                     (const_int 0)))]
7666   "")
7667
7668 (define_insn "*rotldi3_internal12"
7669   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7670         (compare:CC (zero_extend:DI
7671                      (subreg:HI
7672                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7673                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7674                     (const_int 0)))
7675    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7676         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7677   "TARGET_64BIT"
7678   "@
7679    rldcl. %0,%1,%2,48
7680    rldicl. %0,%1,%H2,48
7681    #
7682    #"
7683   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7684    (set_attr "length" "4,4,8,8")])
7685
7686 (define_split
7687   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7688         (compare:CC (zero_extend:DI
7689                      (subreg:HI
7690                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7691                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7692                     (const_int 0)))
7693    (set (match_operand:DI 0 "gpc_reg_operand" "")
7694         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7695   "TARGET_POWERPC64 && reload_completed"
7696   [(set (match_dup 0)
7697         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7698    (set (match_dup 3)
7699         (compare:CC (match_dup 0)
7700                     (const_int 0)))]
7701   "")
7702
7703 (define_insn "*rotldi3_internal13"
7704   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7705         (zero_extend:DI
7706          (subreg:SI
7707           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7708                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7709   "TARGET_POWERPC64"
7710   "@
7711    rldcl %0,%1,%2,32
7712    rldicl %0,%1,%H2,32"
7713   [(set_attr "type" "var_shift_rotate,integer")])
7714
7715 (define_insn "*rotldi3_internal14"
7716   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7717         (compare:CC (zero_extend:DI
7718                      (subreg:SI
7719                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7720                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7721                     (const_int 0)))
7722    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7723   "TARGET_64BIT"
7724   "@
7725    rldcl. %3,%1,%2,32
7726    rldicl. %3,%1,%H2,32
7727    #
7728    #"
7729   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7730    (set_attr "length" "4,4,8,8")])
7731
7732 (define_split
7733   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7734         (compare:CC (zero_extend:DI
7735                      (subreg:SI
7736                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7737                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7738                     (const_int 0)))
7739    (clobber (match_scratch:DI 3 ""))]
7740   "TARGET_POWERPC64 && reload_completed"
7741   [(set (match_dup 3)
7742         (zero_extend:DI (subreg:SI
7743                       (rotate:DI (match_dup 1)
7744                                  (match_dup 2)) 0)))
7745    (set (match_dup 0)
7746         (compare:CC (match_dup 3)
7747                     (const_int 0)))]
7748   "")
7749
7750 (define_insn "*rotldi3_internal15"
7751   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7752         (compare:CC (zero_extend:DI
7753                      (subreg:SI
7754                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7755                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7756                     (const_int 0)))
7757    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7758         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7759   "TARGET_64BIT"
7760   "@
7761    rldcl. %0,%1,%2,32
7762    rldicl. %0,%1,%H2,32
7763    #
7764    #"
7765   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7766    (set_attr "length" "4,4,8,8")])
7767
7768 (define_split
7769   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7770         (compare:CC (zero_extend:DI
7771                      (subreg:SI
7772                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7773                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7774                     (const_int 0)))
7775    (set (match_operand:DI 0 "gpc_reg_operand" "")
7776         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7777   "TARGET_POWERPC64 && reload_completed"
7778   [(set (match_dup 0)
7779         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7780    (set (match_dup 3)
7781         (compare:CC (match_dup 0)
7782                     (const_int 0)))]
7783   "")
7784
7785 (define_expand "ashldi3"
7786   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7787         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7788                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
7789   "TARGET_POWERPC64 || TARGET_POWER"
7790   "
7791 {
7792   if (TARGET_POWERPC64)
7793     ;
7794   else if (TARGET_POWER)
7795     {
7796       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
7797       DONE;
7798     }
7799   else
7800     FAIL;
7801 }")
7802
7803 (define_insn "*ashldi3_internal1"
7804   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7805         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7806                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7807   "TARGET_POWERPC64"
7808   "@
7809    sld %0,%1,%2
7810    sldi %0,%1,%H2"
7811   [(set_attr "type" "var_shift_rotate,shift")])
7812
7813 (define_insn "*ashldi3_internal2"
7814   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7815         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7816                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7817                     (const_int 0)))
7818    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7819   "TARGET_64BIT"
7820   "@
7821    sld. %3,%1,%2
7822    sldi. %3,%1,%H2
7823    #
7824    #"
7825   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7826    (set_attr "length" "4,4,8,8")])
7827
7828 (define_split
7829   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7830         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7831                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7832                     (const_int 0)))
7833    (clobber (match_scratch:DI 3 ""))]
7834   "TARGET_POWERPC64 && reload_completed"
7835   [(set (match_dup 3)
7836         (ashift:DI (match_dup 1) (match_dup 2)))
7837    (set (match_dup 0)
7838         (compare:CC (match_dup 3)
7839                     (const_int 0)))]
7840   "")
7841
7842 (define_insn "*ashldi3_internal3"
7843   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7844         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7845                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7846                     (const_int 0)))
7847    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7848         (ashift:DI (match_dup 1) (match_dup 2)))]
7849   "TARGET_64BIT"
7850   "@
7851    sld. %0,%1,%2
7852    sldi. %0,%1,%H2
7853    #
7854    #"
7855   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7856    (set_attr "length" "4,4,8,8")])
7857
7858 (define_split
7859   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7860         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7861                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7862                     (const_int 0)))
7863    (set (match_operand:DI 0 "gpc_reg_operand" "")
7864         (ashift:DI (match_dup 1) (match_dup 2)))]
7865   "TARGET_POWERPC64 && reload_completed"
7866   [(set (match_dup 0)
7867         (ashift:DI (match_dup 1) (match_dup 2)))
7868    (set (match_dup 3)
7869         (compare:CC (match_dup 0)
7870                     (const_int 0)))]
7871   "")
7872
7873 (define_insn "*ashldi3_internal4"
7874   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7875         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7876                            (match_operand:SI 2 "const_int_operand" "i"))
7877                 (match_operand:DI 3 "const_int_operand" "n")))]
7878   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7879   "rldic %0,%1,%H2,%W3")
7880
7881 (define_insn "ashldi3_internal5"
7882   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7883         (compare:CC
7884          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7885                             (match_operand:SI 2 "const_int_operand" "i,i"))
7886                  (match_operand:DI 3 "const_int_operand" "n,n"))
7887          (const_int 0)))
7888    (clobber (match_scratch:DI 4 "=r,r"))]
7889   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7890   "@
7891    rldic. %4,%1,%H2,%W3
7892    #"
7893   [(set_attr "type" "compare")
7894    (set_attr "length" "4,8")])
7895
7896 (define_split
7897   [(set (match_operand:CC 0 "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    (clobber (match_scratch:DI 4 ""))]
7904   "TARGET_POWERPC64 && reload_completed
7905    && includes_rldic_lshift_p (operands[2], operands[3])"
7906   [(set (match_dup 4)
7907         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7908                 (match_dup 3)))
7909    (set (match_dup 0)
7910         (compare:CC (match_dup 4)
7911                     (const_int 0)))]
7912   "")
7913
7914 (define_insn "*ashldi3_internal6"
7915   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7916         (compare:CC
7917          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7918                             (match_operand:SI 2 "const_int_operand" "i,i"))
7919                     (match_operand:DI 3 "const_int_operand" "n,n"))
7920          (const_int 0)))
7921    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7922         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7923   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7924   "@
7925    rldic. %0,%1,%H2,%W3
7926    #"
7927   [(set_attr "type" "compare")
7928    (set_attr "length" "4,8")])
7929
7930 (define_split
7931   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7932         (compare:CC
7933          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7934                             (match_operand:SI 2 "const_int_operand" ""))
7935                  (match_operand:DI 3 "const_int_operand" ""))
7936          (const_int 0)))
7937    (set (match_operand:DI 0 "gpc_reg_operand" "")
7938         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7939   "TARGET_POWERPC64 && reload_completed
7940    && includes_rldic_lshift_p (operands[2], operands[3])"
7941   [(set (match_dup 0)
7942         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7943                 (match_dup 3)))
7944    (set (match_dup 4)
7945         (compare:CC (match_dup 0)
7946                     (const_int 0)))]
7947   "")
7948
7949 (define_insn "*ashldi3_internal7"
7950   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7951         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7952                            (match_operand:SI 2 "const_int_operand" "i"))
7953                 (match_operand:DI 3 "mask64_operand" "n")))]
7954   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7955   "rldicr %0,%1,%H2,%S3")
7956
7957 (define_insn "ashldi3_internal8"
7958   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7959         (compare:CC
7960          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7961                             (match_operand:SI 2 "const_int_operand" "i,i"))
7962                  (match_operand:DI 3 "mask64_operand" "n,n"))
7963          (const_int 0)))
7964    (clobber (match_scratch:DI 4 "=r,r"))]
7965   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7966   "@
7967    rldicr. %4,%1,%H2,%S3
7968    #"
7969   [(set_attr "type" "compare")
7970    (set_attr "length" "4,8")])
7971
7972 (define_split
7973   [(set (match_operand:CC 0 "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    (clobber (match_scratch:DI 4 ""))]
7980   "TARGET_POWERPC64 && reload_completed
7981    && includes_rldicr_lshift_p (operands[2], operands[3])"
7982   [(set (match_dup 4)
7983         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7984                 (match_dup 3)))
7985    (set (match_dup 0)
7986         (compare:CC (match_dup 4)
7987                     (const_int 0)))]
7988   "")
7989
7990 (define_insn "*ashldi3_internal9"
7991   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7992         (compare:CC
7993          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7994                             (match_operand:SI 2 "const_int_operand" "i,i"))
7995                     (match_operand:DI 3 "mask64_operand" "n,n"))
7996          (const_int 0)))
7997    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7998         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7999   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
8000   "@
8001    rldicr. %0,%1,%H2,%S3
8002    #"
8003   [(set_attr "type" "compare")
8004    (set_attr "length" "4,8")])
8005
8006 (define_split
8007   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
8008         (compare:CC
8009          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8010                             (match_operand:SI 2 "const_int_operand" ""))
8011                  (match_operand:DI 3 "mask64_operand" ""))
8012          (const_int 0)))
8013    (set (match_operand:DI 0 "gpc_reg_operand" "")
8014         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8015   "TARGET_POWERPC64 && reload_completed
8016    && includes_rldicr_lshift_p (operands[2], operands[3])"
8017   [(set (match_dup 0)
8018         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8019                 (match_dup 3)))
8020    (set (match_dup 4)
8021         (compare:CC (match_dup 0)
8022                     (const_int 0)))]
8023   "")
8024
8025 (define_expand "lshrdi3"
8026   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8027         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8028                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
8029   "TARGET_POWERPC64 || TARGET_POWER"
8030   "
8031 {
8032   if (TARGET_POWERPC64)
8033     ;
8034   else if (TARGET_POWER)
8035     {
8036       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
8037       DONE;
8038     }
8039   else
8040     FAIL;
8041 }")
8042
8043 (define_insn "*lshrdi3_internal1"
8044   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8045         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8046                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8047   "TARGET_POWERPC64"
8048   "@
8049    srd %0,%1,%2
8050    srdi %0,%1,%H2"
8051   [(set_attr "type" "var_shift_rotate,shift")])
8052
8053 (define_insn "*lshrdi3_internal2"
8054   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8055         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8056                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8057                     (const_int 0)))
8058    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8059   "TARGET_64BIT "
8060   "@
8061    srd. %3,%1,%2
8062    srdi. %3,%1,%H2
8063    #
8064    #"
8065   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8066    (set_attr "length" "4,4,8,8")])
8067
8068 (define_split
8069   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8070         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8071                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8072                     (const_int 0)))
8073    (clobber (match_scratch:DI 3 ""))]
8074   "TARGET_POWERPC64 && reload_completed"
8075   [(set (match_dup 3)
8076         (lshiftrt:DI (match_dup 1) (match_dup 2)))
8077    (set (match_dup 0)
8078         (compare:CC (match_dup 3)
8079                     (const_int 0)))]
8080   "")
8081
8082 (define_insn "*lshrdi3_internal3"
8083   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8084         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8085                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8086                     (const_int 0)))
8087    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8088         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
8089   "TARGET_64BIT"
8090   "@
8091    srd. %0,%1,%2
8092    srdi. %0,%1,%H2
8093    #
8094    #"
8095   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8096    (set_attr "length" "4,4,8,8")])
8097
8098 (define_split
8099   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8100         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8101                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8102                     (const_int 0)))
8103    (set (match_operand:DI 0 "gpc_reg_operand" "")
8104         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
8105   "TARGET_POWERPC64 && reload_completed"
8106   [(set (match_dup 0)
8107         (lshiftrt:DI (match_dup 1) (match_dup 2)))
8108    (set (match_dup 3)
8109         (compare:CC (match_dup 0)
8110                     (const_int 0)))]
8111   "")
8112
8113 (define_expand "ashrdi3"
8114   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8115         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8116                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
8117   "WORDS_BIG_ENDIAN"
8118   "
8119 {
8120   if (TARGET_POWERPC64)
8121     ;
8122   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
8123     {
8124       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
8125       DONE;
8126     }
8127   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
8128            && WORDS_BIG_ENDIAN)
8129     {
8130       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
8131       DONE;
8132     }
8133   else
8134     FAIL;
8135 }")
8136
8137 (define_insn "*ashrdi3_internal1"
8138   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8139         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8140                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8141   "TARGET_POWERPC64"
8142   "@
8143    srad %0,%1,%2
8144    sradi %0,%1,%H2"
8145   [(set_attr "type" "var_shift_rotate,shift")])
8146
8147 (define_insn "*ashrdi3_internal2"
8148   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8149         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8150                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8151                     (const_int 0)))
8152    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8153   "TARGET_64BIT"
8154   "@
8155    srad. %3,%1,%2
8156    sradi. %3,%1,%H2
8157    #
8158    #"
8159   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8160    (set_attr "length" "4,4,8,8")])
8161
8162 (define_split
8163   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
8164         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8165                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8166                     (const_int 0)))
8167    (clobber (match_scratch:DI 3 ""))]
8168   "TARGET_POWERPC64 && reload_completed"
8169   [(set (match_dup 3)
8170         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8171    (set (match_dup 0)
8172         (compare:CC (match_dup 3)
8173                     (const_int 0)))]
8174   "")
8175
8176 (define_insn "*ashrdi3_internal3"
8177   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8178         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8179                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8180                     (const_int 0)))
8181    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8182         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8183   "TARGET_64BIT"
8184   "@
8185    srad. %0,%1,%2
8186    sradi. %0,%1,%H2
8187    #
8188    #"
8189   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8190    (set_attr "length" "4,4,8,8")])
8191
8192 (define_split
8193   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
8194         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8195                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8196                     (const_int 0)))
8197    (set (match_operand:DI 0 "gpc_reg_operand" "")
8198         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8199   "TARGET_POWERPC64 && reload_completed"
8200   [(set (match_dup 0)
8201         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8202    (set (match_dup 3)
8203         (compare:CC (match_dup 0)
8204                     (const_int 0)))]
8205   "")
8206
8207 (define_expand "anddi3"
8208   [(parallel
8209     [(set (match_operand:DI 0 "gpc_reg_operand" "")
8210           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8211                   (match_operand:DI 2 "and64_2_operand" "")))
8212      (clobber (match_scratch:CC 3 ""))])]
8213   "TARGET_POWERPC64"
8214   "")
8215
8216 (define_insn "anddi3_mc"
8217   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
8218         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
8219                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
8220    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
8221   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
8222   "@
8223    and %0,%1,%2
8224    rldic%B2 %0,%1,0,%S2
8225    rlwinm %0,%1,0,%m2,%M2
8226    andi. %0,%1,%b2
8227    andis. %0,%1,%u2
8228    #"
8229   [(set_attr "type" "*,*,*,fast_compare,fast_compare,*")
8230    (set_attr "length" "4,4,4,4,4,8")])
8231
8232 (define_insn "anddi3_nomc"
8233   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8234         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
8235                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
8236    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
8237   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
8238   "@
8239    and %0,%1,%2
8240    rldic%B2 %0,%1,0,%S2
8241    rlwinm %0,%1,0,%m2,%M2
8242    #"
8243   [(set_attr "length" "4,4,4,8")])
8244
8245 (define_split
8246   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8247         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8248                 (match_operand:DI 2 "mask64_2_operand" "")))
8249    (clobber (match_scratch:CC 3 ""))]
8250   "TARGET_POWERPC64
8251     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8252     && !mask_operand (operands[2], DImode)
8253     && !mask64_operand (operands[2], DImode)"
8254   [(set (match_dup 0)
8255         (and:DI (rotate:DI (match_dup 1)
8256                            (match_dup 4))
8257                 (match_dup 5)))
8258    (set (match_dup 0)
8259         (and:DI (rotate:DI (match_dup 0)
8260                            (match_dup 6))
8261                 (match_dup 7)))]
8262 {
8263   build_mask64_2_operands (operands[2], &operands[4]);
8264 })
8265
8266 (define_insn "*anddi3_internal2_mc"
8267   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8268         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8269                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8270                     (const_int 0)))
8271    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
8272    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8273   "TARGET_64BIT && rs6000_gen_cell_microcode"
8274   "@
8275    and. %3,%1,%2
8276    rldic%B2. %3,%1,0,%S2
8277    rlwinm. %3,%1,0,%m2,%M2
8278    andi. %3,%1,%b2
8279    andis. %3,%1,%u2
8280    #
8281    #
8282    #
8283    #
8284    #
8285    #
8286    #"
8287   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8288                      fast_compare,compare,compare,compare,compare,compare,\
8289                      compare,compare")
8290    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8291
8292 (define_split
8293   [(set (match_operand:CC 0 "cc_reg_operand" "")
8294         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8295                             (match_operand:DI 2 "mask64_2_operand" ""))
8296                     (const_int 0)))
8297    (clobber (match_scratch:DI 3 ""))
8298    (clobber (match_scratch:CC 4 ""))]
8299   "TARGET_64BIT && reload_completed
8300     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8301     && !mask_operand (operands[2], DImode)
8302     && !mask64_operand (operands[2], DImode)"
8303   [(set (match_dup 3)
8304         (and:DI (rotate:DI (match_dup 1)
8305                            (match_dup 5))
8306                 (match_dup 6)))
8307    (parallel [(set (match_dup 0)
8308                    (compare:CC (and:DI (rotate:DI (match_dup 3)
8309                                                   (match_dup 7))
8310                                        (match_dup 8))
8311                                (const_int 0)))
8312               (clobber (match_dup 3))])]
8313   "
8314 {
8315   build_mask64_2_operands (operands[2], &operands[5]);
8316 }")
8317
8318 (define_insn "*anddi3_internal3_mc"
8319   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8320         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8321                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8322                     (const_int 0)))
8323    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
8324         (and:DI (match_dup 1) (match_dup 2)))
8325    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8326   "TARGET_64BIT && rs6000_gen_cell_microcode"
8327   "@
8328    and. %0,%1,%2
8329    rldic%B2. %0,%1,0,%S2
8330    rlwinm. %0,%1,0,%m2,%M2
8331    andi. %0,%1,%b2
8332    andis. %0,%1,%u2
8333    #
8334    #
8335    #
8336    #
8337    #
8338    #
8339    #"
8340   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8341                      fast_compare,compare,compare,compare,compare,compare,\
8342                      compare,compare")
8343    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8344
8345 (define_split
8346   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8347         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8348                             (match_operand:DI 2 "and64_2_operand" ""))
8349                     (const_int 0)))
8350    (set (match_operand:DI 0 "gpc_reg_operand" "")
8351         (and:DI (match_dup 1) (match_dup 2)))
8352    (clobber (match_scratch:CC 4 ""))]
8353   "TARGET_64BIT && reload_completed"
8354   [(parallel [(set (match_dup 0)
8355                     (and:DI (match_dup 1) (match_dup 2)))
8356                (clobber (match_dup 4))])
8357    (set (match_dup 3)
8358         (compare:CC (match_dup 0)
8359                     (const_int 0)))]
8360   "")
8361
8362 (define_split
8363   [(set (match_operand:CC 3 "cc_reg_operand" "")
8364         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8365                             (match_operand:DI 2 "mask64_2_operand" ""))
8366                     (const_int 0)))
8367    (set (match_operand:DI 0 "gpc_reg_operand" "")
8368         (and:DI (match_dup 1) (match_dup 2)))
8369    (clobber (match_scratch:CC 4 ""))]
8370   "TARGET_64BIT && reload_completed
8371     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8372     && !mask_operand (operands[2], DImode)
8373     && !mask64_operand (operands[2], DImode)"
8374   [(set (match_dup 0)
8375         (and:DI (rotate:DI (match_dup 1)
8376                            (match_dup 5))
8377                 (match_dup 6)))
8378    (parallel [(set (match_dup 3)
8379                    (compare:CC (and:DI (rotate:DI (match_dup 0)
8380                                                   (match_dup 7))
8381                                        (match_dup 8))
8382                                (const_int 0)))
8383               (set (match_dup 0)
8384                    (and:DI (rotate:DI (match_dup 0)
8385                                       (match_dup 7))
8386                            (match_dup 8)))])]
8387   "
8388 {
8389   build_mask64_2_operands (operands[2], &operands[5]);
8390 }")
8391
8392 (define_expand "iordi3"
8393   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8394         (ior: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_iordi3 (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_iordi3 (tmp, operands[1],
8416                                  immed_double_const (value
8417                                                      & (~ (HOST_WIDE_INT) 0xffff),
8418                                                      0, DImode)));
8419         }
8420
8421       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8422       DONE;
8423     }
8424 }")
8425
8426 (define_expand "xordi3"
8427   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8428         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
8429                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8430   "TARGET_POWERPC64"
8431   "
8432 {
8433   if (non_logical_cint_operand (operands[2], DImode))
8434     {
8435       HOST_WIDE_INT value;
8436       rtx tmp = ((!can_create_pseudo_p ()
8437                   || rtx_equal_p (operands[0], operands[1]))
8438                  ? operands[0] : gen_reg_rtx (DImode));
8439
8440       if (GET_CODE (operands[2]) == CONST_INT)
8441         {
8442           value = INTVAL (operands[2]);
8443           emit_insn (gen_xordi3 (tmp, operands[1],
8444                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8445         }
8446       else
8447         {
8448           value = CONST_DOUBLE_LOW (operands[2]);
8449           emit_insn (gen_xordi3 (tmp, operands[1],
8450                                  immed_double_const (value
8451                                                      & (~ (HOST_WIDE_INT) 0xffff),
8452                                                      0, DImode)));
8453         }
8454
8455       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8456       DONE;
8457     }
8458 }")
8459
8460 (define_insn "*booldi3_internal1"
8461   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
8462         (match_operator:DI 3 "boolean_or_operator"
8463          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
8464           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
8465   "TARGET_POWERPC64"
8466   "@
8467    %q3 %0,%1,%2
8468    %q3i %0,%1,%b2
8469    %q3is %0,%1,%u2")
8470
8471 (define_insn "*booldi3_internal2"
8472   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8473         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8474          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8475           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8476          (const_int 0)))
8477    (clobber (match_scratch:DI 3 "=r,r"))]
8478   "TARGET_64BIT"
8479   "@
8480    %q4. %3,%1,%2
8481    #"
8482   [(set_attr "type" "fast_compare,compare")
8483    (set_attr "length" "4,8")])
8484
8485 (define_split
8486   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8487         (compare:CC (match_operator:DI 4 "boolean_operator"
8488          [(match_operand:DI 1 "gpc_reg_operand" "")
8489           (match_operand:DI 2 "gpc_reg_operand" "")])
8490          (const_int 0)))
8491    (clobber (match_scratch:DI 3 ""))]
8492   "TARGET_POWERPC64 && reload_completed"
8493   [(set (match_dup 3) (match_dup 4))
8494    (set (match_dup 0)
8495         (compare:CC (match_dup 3)
8496                     (const_int 0)))]
8497   "")
8498
8499 (define_insn "*booldi3_internal3"
8500   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8501         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8502          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8503           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8504          (const_int 0)))
8505    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8506         (match_dup 4))]
8507   "TARGET_64BIT"
8508   "@
8509    %q4. %0,%1,%2
8510    #"
8511   [(set_attr "type" "fast_compare,compare")
8512    (set_attr "length" "4,8")])
8513
8514 (define_split
8515   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8516         (compare:CC (match_operator:DI 4 "boolean_operator"
8517          [(match_operand:DI 1 "gpc_reg_operand" "")
8518           (match_operand:DI 2 "gpc_reg_operand" "")])
8519          (const_int 0)))
8520    (set (match_operand:DI 0 "gpc_reg_operand" "")
8521         (match_dup 4))]
8522   "TARGET_POWERPC64 && reload_completed"
8523   [(set (match_dup 0) (match_dup 4))
8524    (set (match_dup 3)
8525         (compare:CC (match_dup 0)
8526                     (const_int 0)))]
8527   "")
8528
8529 ;; Split a logical operation that we can't do in one insn into two insns,
8530 ;; each of which does one 16-bit part.  This is used by combine.
8531
8532 (define_split
8533   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8534         (match_operator:DI 3 "boolean_or_operator"
8535          [(match_operand:DI 1 "gpc_reg_operand" "")
8536           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
8537   "TARGET_POWERPC64"
8538   [(set (match_dup 0) (match_dup 4))
8539    (set (match_dup 0) (match_dup 5))]
8540 "
8541 {
8542   rtx i3,i4;
8543
8544   if (GET_CODE (operands[2]) == CONST_DOUBLE)
8545     {
8546       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
8547       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
8548                                         0, DImode);
8549       i4 = GEN_INT (value & 0xffff);
8550     }
8551   else
8552     {
8553       i3 = GEN_INT (INTVAL (operands[2])
8554                              & (~ (HOST_WIDE_INT) 0xffff));
8555       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
8556     }
8557   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8558                                 operands[1], i3);
8559   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8560                                 operands[0], i4);
8561 }")
8562
8563 (define_insn "*boolcdi3_internal1"
8564   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8565         (match_operator:DI 3 "boolean_operator"
8566          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8567           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
8568   "TARGET_POWERPC64"
8569   "%q3 %0,%2,%1")
8570
8571 (define_insn "*boolcdi3_internal2"
8572   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8573         (compare:CC (match_operator:DI 4 "boolean_operator"
8574          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8575           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8576          (const_int 0)))
8577    (clobber (match_scratch:DI 3 "=r,r"))]
8578   "TARGET_64BIT"
8579   "@
8580    %q4. %3,%2,%1
8581    #"
8582   [(set_attr "type" "fast_compare,compare")
8583    (set_attr "length" "4,8")])
8584
8585 (define_split
8586   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8587         (compare:CC (match_operator:DI 4 "boolean_operator"
8588          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8589           (match_operand:DI 2 "gpc_reg_operand" "")])
8590          (const_int 0)))
8591    (clobber (match_scratch:DI 3 ""))]
8592   "TARGET_POWERPC64 && reload_completed"
8593   [(set (match_dup 3) (match_dup 4))
8594    (set (match_dup 0)
8595         (compare:CC (match_dup 3)
8596                     (const_int 0)))]
8597   "")
8598
8599 (define_insn "*boolcdi3_internal3"
8600   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8601         (compare:CC (match_operator:DI 4 "boolean_operator"
8602          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8603           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8604          (const_int 0)))
8605    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8606         (match_dup 4))]
8607   "TARGET_64BIT"
8608   "@
8609    %q4. %0,%2,%1
8610    #"
8611   [(set_attr "type" "fast_compare,compare")
8612    (set_attr "length" "4,8")])
8613
8614 (define_split
8615   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8616         (compare:CC (match_operator:DI 4 "boolean_operator"
8617          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8618           (match_operand:DI 2 "gpc_reg_operand" "")])
8619          (const_int 0)))
8620    (set (match_operand:DI 0 "gpc_reg_operand" "")
8621         (match_dup 4))]
8622   "TARGET_POWERPC64 && reload_completed"
8623   [(set (match_dup 0) (match_dup 4))
8624    (set (match_dup 3)
8625         (compare:CC (match_dup 0)
8626                     (const_int 0)))]
8627   "")
8628
8629 (define_insn "*boolccdi3_internal1"
8630   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8631         (match_operator:DI 3 "boolean_operator"
8632          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8633           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
8634   "TARGET_POWERPC64"
8635   "%q3 %0,%1,%2")
8636
8637 (define_insn "*boolccdi3_internal2"
8638   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8639         (compare:CC (match_operator:DI 4 "boolean_operator"
8640          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8641           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8642          (const_int 0)))
8643    (clobber (match_scratch:DI 3 "=r,r"))]
8644   "TARGET_64BIT"
8645   "@
8646    %q4. %3,%1,%2
8647    #"
8648   [(set_attr "type" "fast_compare,compare")
8649    (set_attr "length" "4,8")])
8650
8651 (define_split
8652   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8653         (compare:CC (match_operator:DI 4 "boolean_operator"
8654          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8655           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8656          (const_int 0)))
8657    (clobber (match_scratch:DI 3 ""))]
8658   "TARGET_POWERPC64 && reload_completed"
8659   [(set (match_dup 3) (match_dup 4))
8660    (set (match_dup 0)
8661         (compare:CC (match_dup 3)
8662                     (const_int 0)))]
8663   "")
8664
8665 (define_insn "*boolccdi3_internal3"
8666   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8667         (compare:CC (match_operator:DI 4 "boolean_operator"
8668          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8669           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8670          (const_int 0)))
8671    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8672         (match_dup 4))]
8673   "TARGET_64BIT"
8674   "@
8675    %q4. %0,%1,%2
8676    #"
8677   [(set_attr "type" "fast_compare,compare")
8678    (set_attr "length" "4,8")])
8679
8680 (define_split
8681   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8682         (compare:CC (match_operator:DI 4 "boolean_operator"
8683          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8684           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8685          (const_int 0)))
8686    (set (match_operand:DI 0 "gpc_reg_operand" "")
8687         (match_dup 4))]
8688   "TARGET_POWERPC64 && reload_completed"
8689   [(set (match_dup 0) (match_dup 4))
8690    (set (match_dup 3)
8691         (compare:CC (match_dup 0)
8692                     (const_int 0)))]
8693   "")
8694
8695 (define_expand "smindi3"
8696   [(match_operand:DI 0 "gpc_reg_operand" "")
8697    (match_operand:DI 1 "gpc_reg_operand" "")
8698    (match_operand:DI 2 "gpc_reg_operand" "")]
8699   "TARGET_ISEL64"
8700   "
8701 {
8702   rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
8703   DONE;
8704 }")
8705
8706 (define_expand "smaxdi3"
8707   [(match_operand:DI 0 "gpc_reg_operand" "")
8708    (match_operand:DI 1 "gpc_reg_operand" "")
8709    (match_operand:DI 2 "gpc_reg_operand" "")]
8710   "TARGET_ISEL64"
8711   "
8712 {
8713   rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
8714   DONE;
8715 }")
8716
8717 (define_expand "umindi3"
8718   [(match_operand:DI 0 "gpc_reg_operand" "")
8719    (match_operand:DI 1 "gpc_reg_operand" "")
8720    (match_operand:DI 2 "gpc_reg_operand" "")]
8721   "TARGET_ISEL64"
8722   "
8723 {
8724   rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
8725   DONE;
8726 }")
8727
8728 (define_expand "umaxdi3"
8729   [(match_operand:DI 0 "gpc_reg_operand" "")
8730    (match_operand:DI 1 "gpc_reg_operand" "")
8731    (match_operand:DI 2 "gpc_reg_operand" "")]
8732   "TARGET_ISEL64"
8733   "
8734 {
8735   rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
8736   DONE;
8737 }")
8738
8739 \f
8740 ;; Now define ways of moving data around.
8741
8742 ;; Set up a register with a value from the GOT table
8743
8744 (define_expand "movsi_got"
8745   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8746         (unspec:SI [(match_operand:SI 1 "got_operand" "")
8747                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
8748   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8749   "
8750 {
8751   if (GET_CODE (operands[1]) == CONST)
8752     {
8753       rtx offset = const0_rtx;
8754       HOST_WIDE_INT value;
8755
8756       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
8757       value = INTVAL (offset);
8758       if (value != 0)
8759         {
8760           rtx tmp = (!can_create_pseudo_p ()
8761                      ? operands[0]
8762                      : gen_reg_rtx (Pmode));
8763           emit_insn (gen_movsi_got (tmp, operands[1]));
8764           emit_insn (gen_addsi3 (operands[0], tmp, offset));
8765           DONE;
8766         }
8767     }
8768
8769   operands[2] = rs6000_got_register (operands[1]);
8770 }")
8771
8772 (define_insn "*movsi_got_internal"
8773   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8774         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8775                     (match_operand:SI 2 "gpc_reg_operand" "b")]
8776                    UNSPEC_MOVSI_GOT))]
8777   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8778   "{l|lwz} %0,%a1@got(%2)"
8779   [(set_attr "type" "load")])
8780
8781 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
8782 ;; didn't get allocated to a hard register.
8783 (define_split
8784   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8785         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8786                     (match_operand:SI 2 "memory_operand" "")]
8787                    UNSPEC_MOVSI_GOT))]
8788   "DEFAULT_ABI == ABI_V4
8789     && flag_pic == 1
8790     && (reload_in_progress || reload_completed)"
8791   [(set (match_dup 0) (match_dup 2))
8792    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
8793                                  UNSPEC_MOVSI_GOT))]
8794   "")
8795
8796 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8797 ;; do the load 16-bits at a time.  We could do this by loading from memory,
8798 ;; and this is even supposed to be faster, but it is simpler not to get
8799 ;; integers in the TOC.
8800 (define_insn "movsi_low"
8801   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8802         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8803                            (match_operand 2 "" ""))))]
8804   "TARGET_MACHO && ! TARGET_64BIT"
8805   "{l|lwz} %0,lo16(%2)(%1)"
8806   [(set_attr "type" "load")
8807    (set_attr "length" "4")])
8808
8809 (define_insn "*movsi_internal1"
8810   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
8811         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
8812   "!TARGET_SINGLE_FPU &&
8813    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8814   "@
8815    mr %0,%1
8816    {cal|la} %0,%a1
8817    {l%U1%X1|lwz%U1%X1} %0,%1
8818    {st%U0%X0|stw%U0%X0} %1,%0
8819    {lil|li} %0,%1
8820    {liu|lis} %0,%v1
8821    #
8822    {cal|la} %0,%a1
8823    mf%1 %0
8824    mt%0 %1
8825    mt%0 %1
8826    mt%0 %1
8827    {cror 0,0,0|nop}"
8828   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
8829    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
8830
8831 (define_insn "*movsi_internal1_single"
8832   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h,m,*f")
8833         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0,f,m"))]
8834   "TARGET_SINGLE_FPU &&
8835    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8836   "@
8837    mr %0,%1
8838    {cal|la} %0,%a1
8839    {l%U1%X1|lwz%U1%X1} %0,%1
8840    {st%U0%X0|stw%U0%X0} %1,%0
8841    {lil|li} %0,%1
8842    {liu|lis} %0,%v1
8843    #
8844    {cal|la} %0,%a1
8845    mf%1 %0
8846    mt%0 %1
8847    mt%0 %1
8848    mt%0 %1
8849    {cror 0,0,0|nop}
8850    stfs%U0%X0 %1, %0
8851    lfs%U1%X1 %0, %1"
8852   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*,*,*")
8853    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4,4,4")])
8854
8855 ;; Split a load of a large constant into the appropriate two-insn
8856 ;; sequence.
8857
8858 (define_split
8859   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8860         (match_operand:SI 1 "const_int_operand" ""))]
8861   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
8862    && (INTVAL (operands[1]) & 0xffff) != 0"
8863   [(set (match_dup 0)
8864         (match_dup 2))
8865    (set (match_dup 0)
8866         (ior:SI (match_dup 0)
8867                 (match_dup 3)))]
8868   "
8869 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
8870
8871   if (tem == operands[0])
8872     DONE;
8873   else
8874     FAIL;
8875 }")
8876
8877 (define_insn "*mov<mode>_internal2"
8878   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8879         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
8880                     (const_int 0)))
8881    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8882   ""
8883   "@
8884    {cmpi|cmp<wd>i} %2,%0,0
8885    mr. %0,%1
8886    #"
8887   [(set_attr "type" "cmp,compare,cmp")
8888    (set_attr "length" "4,4,8")])
8889
8890 (define_split
8891   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
8892         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
8893                     (const_int 0)))
8894    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
8895   "reload_completed"
8896   [(set (match_dup 0) (match_dup 1))
8897    (set (match_dup 2)
8898         (compare:CC (match_dup 0)
8899                     (const_int 0)))]
8900   "")
8901 \f
8902 (define_insn "*movhi_internal"
8903   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8904         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8905   "gpc_reg_operand (operands[0], HImode)
8906    || gpc_reg_operand (operands[1], HImode)"
8907   "@
8908    mr %0,%1
8909    lhz%U1%X1 %0,%1
8910    sth%U0%X0 %1,%0
8911    {lil|li} %0,%w1
8912    mf%1 %0
8913    mt%0 %1
8914    mt%0 %1
8915    {cror 0,0,0|nop}"
8916   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
8917
8918 (define_expand "mov<mode>"
8919   [(set (match_operand:INT 0 "general_operand" "")
8920         (match_operand:INT 1 "any_operand" ""))]
8921   ""
8922   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8923
8924 (define_insn "*movqi_internal"
8925   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8926         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8927   "gpc_reg_operand (operands[0], QImode)
8928    || gpc_reg_operand (operands[1], QImode)"
8929   "@
8930    mr %0,%1
8931    lbz%U1%X1 %0,%1
8932    stb%U0%X0 %1,%0
8933    {lil|li} %0,%1
8934    mf%1 %0
8935    mt%0 %1
8936    mt%0 %1
8937    {cror 0,0,0|nop}"
8938   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
8939 \f
8940 ;; Here is how to move condition codes around.  When we store CC data in
8941 ;; an integer register or memory, we store just the high-order 4 bits.
8942 ;; This lets us not shift in the most common case of CR0.
8943 (define_expand "movcc"
8944   [(set (match_operand:CC 0 "nonimmediate_operand" "")
8945         (match_operand:CC 1 "nonimmediate_operand" ""))]
8946   ""
8947   "")
8948
8949 (define_insn "*movcc_internal1"
8950   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,q,cl,r,m")
8951         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,r,m,r"))]
8952   "register_operand (operands[0], CCmode)
8953    || register_operand (operands[1], CCmode)"
8954   "@
8955    mcrf %0,%1
8956    mtcrf 128,%1
8957    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
8958    crxor %0,%0,%0
8959    mfcr %0%Q1
8960    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
8961    mr %0,%1
8962    {lil|li} %0,%1
8963    mf%1 %0
8964    mt%0 %1
8965    mt%0 %1
8966    {l%U1%X1|lwz%U1%X1} %0,%1
8967    {st%U0%U1|stw%U0%U1} %1,%0"
8968   [(set (attr "type")
8969      (cond [(eq_attr "alternative" "0,3")
8970                 (const_string "cr_logical")
8971             (eq_attr "alternative" "1,2")
8972                 (const_string "mtcr")
8973             (eq_attr "alternative" "6,7,9")
8974                 (const_string "integer")
8975             (eq_attr "alternative" "8")
8976                 (const_string "mfjmpr")
8977             (eq_attr "alternative" "10")
8978                 (const_string "mtjmpr")
8979             (eq_attr "alternative" "11")
8980                 (const_string "load")
8981             (eq_attr "alternative" "12")
8982                 (const_string "store")
8983             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
8984                 (const_string "mfcrf")
8985            ]
8986         (const_string "mfcr")))
8987    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4,4")])
8988 \f
8989 ;; For floating-point, we normally deal with the floating-point registers
8990 ;; unless -msoft-float is used.  The sole exception is that parameter passing
8991 ;; can produce floating-point values in fixed-point registers.  Unless the
8992 ;; value is a simple constant or already in memory, we deal with this by
8993 ;; allocating memory and copying the value explicitly via that memory location.
8994 (define_expand "movsf"
8995   [(set (match_operand:SF 0 "nonimmediate_operand" "")
8996         (match_operand:SF 1 "any_operand" ""))]
8997   ""
8998   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
8999
9000 (define_split
9001   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9002         (match_operand:SF 1 "const_double_operand" ""))]
9003   "reload_completed
9004    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9005        || (GET_CODE (operands[0]) == SUBREG
9006            && GET_CODE (SUBREG_REG (operands[0])) == REG
9007            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9008   [(set (match_dup 2) (match_dup 3))]
9009   "
9010 {
9011   long l;
9012   REAL_VALUE_TYPE rv;
9013
9014   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9015   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9016
9017   if (! TARGET_POWERPC64)
9018     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
9019   else
9020     operands[2] = gen_lowpart (SImode, operands[0]);
9021
9022   operands[3] = gen_int_mode (l, SImode);
9023 }")
9024
9025 (define_insn "*movsf_hardfloat"
9026   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
9027         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
9028   "(gpc_reg_operand (operands[0], SFmode)
9029    || gpc_reg_operand (operands[1], SFmode))
9030    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
9031   "@
9032    mr %0,%1
9033    {l%U1%X1|lwz%U1%X1} %0,%1
9034    {st%U0%X0|stw%U0%X0} %1,%0
9035    fmr %0,%1
9036    lfs%U1%X1 %0,%1
9037    stfs%U0%X0 %1,%0
9038    mt%0 %1
9039    mt%0 %1
9040    mf%1 %0
9041    {cror 0,0,0|nop}
9042    #
9043    #"
9044   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
9045    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
9046
9047 (define_insn "*movsf_softfloat"
9048   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
9049         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
9050   "(gpc_reg_operand (operands[0], SFmode)
9051    || gpc_reg_operand (operands[1], SFmode))
9052    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
9053   "@
9054    mr %0,%1
9055    mt%0 %1
9056    mt%0 %1
9057    mf%1 %0
9058    {l%U1%X1|lwz%U1%X1} %0,%1
9059    {st%U0%X0|stw%U0%X0} %1,%0
9060    {lil|li} %0,%1
9061    {liu|lis} %0,%v1
9062    {cal|la} %0,%a1
9063    #
9064    #
9065    {cror 0,0,0|nop}"
9066   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
9067    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
9068
9069 \f
9070 (define_expand "movdf"
9071   [(set (match_operand:DF 0 "nonimmediate_operand" "")
9072         (match_operand:DF 1 "any_operand" ""))]
9073   ""
9074   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
9075
9076 (define_split
9077   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9078         (match_operand:DF 1 "const_int_operand" ""))]
9079   "! TARGET_POWERPC64 && reload_completed
9080    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9081        || (GET_CODE (operands[0]) == SUBREG
9082            && GET_CODE (SUBREG_REG (operands[0])) == REG
9083            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9084   [(set (match_dup 2) (match_dup 4))
9085    (set (match_dup 3) (match_dup 1))]
9086   "
9087 {
9088   int endian = (WORDS_BIG_ENDIAN == 0);
9089   HOST_WIDE_INT value = INTVAL (operands[1]);
9090
9091   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
9092   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
9093 #if HOST_BITS_PER_WIDE_INT == 32
9094   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
9095 #else
9096   operands[4] = GEN_INT (value >> 32);
9097   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9098 #endif
9099 }")
9100
9101 (define_split
9102   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9103         (match_operand:DF 1 "const_double_operand" ""))]
9104   "! TARGET_POWERPC64 && reload_completed
9105    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9106        || (GET_CODE (operands[0]) == SUBREG
9107            && GET_CODE (SUBREG_REG (operands[0])) == REG
9108            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9109   [(set (match_dup 2) (match_dup 4))
9110    (set (match_dup 3) (match_dup 5))]
9111   "
9112 {
9113   int endian = (WORDS_BIG_ENDIAN == 0);
9114   long l[2];
9115   REAL_VALUE_TYPE rv;
9116
9117   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9118   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
9119
9120   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
9121   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
9122   operands[4] = gen_int_mode (l[endian], SImode);
9123   operands[5] = gen_int_mode (l[1 - endian], SImode);
9124 }")
9125
9126 (define_split
9127   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9128         (match_operand:DF 1 "const_double_operand" ""))]
9129   "TARGET_POWERPC64 && reload_completed
9130    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9131        || (GET_CODE (operands[0]) == SUBREG
9132            && GET_CODE (SUBREG_REG (operands[0])) == REG
9133            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9134   [(set (match_dup 2) (match_dup 3))]
9135   "
9136 {
9137   int endian = (WORDS_BIG_ENDIAN == 0);
9138   long l[2];
9139   REAL_VALUE_TYPE rv;
9140 #if HOST_BITS_PER_WIDE_INT >= 64
9141   HOST_WIDE_INT val;
9142 #endif
9143
9144   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9145   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
9146
9147   operands[2] = gen_lowpart (DImode, operands[0]);
9148   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
9149 #if HOST_BITS_PER_WIDE_INT >= 64
9150   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
9151          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
9152
9153   operands[3] = gen_int_mode (val, DImode);
9154 #else
9155   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
9156 #endif
9157 }")
9158
9159 ;; Don't have reload use general registers to load a constant.  First,
9160 ;; it might not work if the output operand is the equivalent of
9161 ;; a non-offsettable memref, but also it is less efficient than loading
9162 ;; the constant into an FP register, since it will probably be used there.
9163 ;; The "??" is a kludge until we can figure out a more reasonable way
9164 ;; of handling these non-offsettable values.
9165 (define_insn "*movdf_hardfloat32"
9166   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,ws,?wa,ws,?wa,Z,?Z,d,d,m,wa,!r,!r,!r")
9167         (match_operand:DF 1 "input_operand" "r,m,r,ws,wa,Z,Z,ws,wa,d,m,d,j,G,H,F"))]
9168   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9169    && (gpc_reg_operand (operands[0], DFmode)
9170        || gpc_reg_operand (operands[1], DFmode))"
9171   "*
9172 {
9173   switch (which_alternative)
9174     {
9175     default:
9176       gcc_unreachable ();
9177     case 0:
9178     case 1:
9179     case 2:
9180       return \"#\";
9181     case 3:
9182     case 4:
9183       return \"xxlor %x0,%x1,%x1\";
9184     case 5:
9185     case 6:
9186       return \"lxsd%U1x %x0,%y1\";
9187     case 7:
9188     case 8:
9189       return \"stxsd%U0x %x1,%y0\";
9190     case 9:
9191       return \"fmr %0,%1\";
9192     case 10:
9193       return \"lfd%U1%X1 %0,%1\";
9194     case 11:
9195       return \"stfd%U0%X0 %1,%0\";
9196     case 12:
9197       return \"xxlxor %x0,%x0,%x0\";
9198     case 13:
9199     case 14:
9200     case 15:
9201       return \"#\";
9202     }
9203 }"
9204   [(set_attr "type" "two,load,store,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,*,*,*")
9205    (set_attr "length" "8,16,16,4,4,4,4,4,4,4,4,4,4,8,12,16")])
9206
9207 (define_insn "*movdf_softfloat32"
9208   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
9209         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
9210   "! TARGET_POWERPC64 
9211    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
9212        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
9213    && (gpc_reg_operand (operands[0], DFmode)
9214        || gpc_reg_operand (operands[1], DFmode))"
9215   "#"
9216   [(set_attr "type" "two,load,store,*,*,*")
9217    (set_attr "length" "8,8,8,8,12,16")])
9218
9219 ; ld/std require word-aligned displacements -> 'Y' constraint.
9220 ; List Y->r and r->Y before r->r for reload.
9221 (define_insn "*movdf_hardfloat64_mfpgpr"
9222   [(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")
9223         (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"))]
9224   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
9225    && TARGET_DOUBLE_FLOAT
9226    && (gpc_reg_operand (operands[0], DFmode)
9227        || gpc_reg_operand (operands[1], DFmode))"
9228   "@
9229    std%U0%X0 %1,%0
9230    ld%U1%X1 %0,%1
9231    mr %0,%1
9232    xxlor %x0,%x1,%x1
9233    xxlor %x0,%x1,%x1
9234    lxsd%U1x %x0,%y1
9235    lxsd%U1x %x0,%y1
9236    stxsd%U0x %x1,%y0
9237    stxsd%U0x %x1,%y0
9238    fmr %0,%1
9239    lfd%U1%X1 %0,%1
9240    stfd%U0%X0 %1,%0
9241    xxlxor %x0,%x0,%x0
9242    mt%0 %1
9243    mf%1 %0
9244    {cror 0,0,0|nop}
9245    #
9246    #
9247    #
9248    mftgpr %0,%1
9249    mffgpr %0,%1"
9250   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
9251    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
9252
9253 ; ld/std require word-aligned displacements -> 'Y' constraint.
9254 ; List Y->r and r->Y before r->r for reload.
9255 (define_insn "*movdf_hardfloat64"
9256   [(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")
9257         (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"))]
9258   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
9259    && TARGET_DOUBLE_FLOAT
9260    && (gpc_reg_operand (operands[0], DFmode)
9261        || gpc_reg_operand (operands[1], DFmode))"
9262   "@
9263    std%U0%X0 %1,%0
9264    ld%U1%X1 %0,%1
9265    mr %0,%1
9266    xxlor %x0,%x1,%x1
9267    xxlor %x0,%x1,%x1
9268    lxsd%U1x %x0,%y1
9269    lxsd%U1x %x0,%y1
9270    stxsd%U0x %x1,%y0
9271    stxsd%U0x %x1,%y0
9272    fmr %0,%1
9273    lfd%U1%X1 %0,%1
9274    stfd%U0%X0 %1,%0
9275    xxlxor %x0,%x0,%x0
9276    mt%0 %1
9277    mf%1 %0
9278    {cror 0,0,0|nop}
9279    #
9280    #
9281    #"
9282   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,mtjmpr,mfjmpr,*,*,*,*")
9283    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16")])
9284
9285 (define_insn "*movdf_softfloat64"
9286   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
9287         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
9288   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
9289    && (gpc_reg_operand (operands[0], DFmode)
9290        || gpc_reg_operand (operands[1], DFmode))"
9291   "@
9292    ld%U1%X1 %0,%1
9293    std%U0%X0 %1,%0
9294    mr %0,%1
9295    mt%0 %1
9296    mf%1 %0
9297    #
9298    #
9299    #
9300    {cror 0,0,0|nop}"
9301   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
9302    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
9303 \f
9304 (define_expand "movtf"
9305   [(set (match_operand:TF 0 "general_operand" "")
9306         (match_operand:TF 1 "any_operand" ""))]
9307   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
9308   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
9309
9310 ; It's important to list the o->f and f->o moves before f->f because
9311 ; otherwise reload, given m->f, will try to pick f->f and reload it,
9312 ; which doesn't make progress.  Likewise r->Y must be before r->r.
9313 (define_insn_and_split "*movtf_internal"
9314   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,d,d,r,Y,r")
9315         (match_operand:TF 1 "input_operand"         "d,o,d,YGHF,r,r"))]
9316   "!TARGET_IEEEQUAD
9317    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
9318    && (gpc_reg_operand (operands[0], TFmode)
9319        || gpc_reg_operand (operands[1], TFmode))"
9320   "#"
9321   "&& reload_completed"
9322   [(pc)]
9323 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9324   [(set_attr "length" "8,8,8,20,20,16")])
9325
9326 (define_insn_and_split "*movtf_softfloat"
9327   [(set (match_operand:TF 0 "rs6000_nonimmediate_operand" "=r,Y,r")
9328         (match_operand:TF 1 "input_operand"         "YGHF,r,r"))]
9329   "!TARGET_IEEEQUAD
9330    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
9331    && (gpc_reg_operand (operands[0], TFmode)
9332        || gpc_reg_operand (operands[1], TFmode))"
9333   "#"
9334   "&& reload_completed"
9335   [(pc)]
9336 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9337   [(set_attr "length" "20,20,16")])
9338
9339 (define_expand "extenddftf2"
9340   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9341         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
9342   "!TARGET_IEEEQUAD
9343    && TARGET_HARD_FLOAT
9344    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9345    && TARGET_LONG_DOUBLE_128"
9346 {
9347   if (TARGET_E500_DOUBLE)
9348     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
9349   else
9350     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
9351   DONE;
9352 })
9353
9354 (define_expand "extenddftf2_fprs"
9355   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9356                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
9357               (use (match_dup 2))])]
9358   "!TARGET_IEEEQUAD
9359    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9360    && TARGET_LONG_DOUBLE_128"
9361 {
9362   operands[2] = CONST0_RTX (DFmode);
9363   /* Generate GOT reference early for SVR4 PIC.  */
9364   if (DEFAULT_ABI == ABI_V4 && flag_pic)
9365     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
9366 })
9367
9368 (define_insn_and_split "*extenddftf2_internal"
9369   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,d,&d,r")
9370        (float_extend:TF (match_operand:DF 1 "input_operand" "dr,md,md,rmGHF")))
9371    (use (match_operand:DF 2 "zero_reg_mem_operand" "rd,m,d,n"))]
9372   "!TARGET_IEEEQUAD
9373    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9374    && TARGET_LONG_DOUBLE_128"
9375   "#"
9376   "&& reload_completed"
9377   [(pc)]
9378 {
9379   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
9380   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
9381   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
9382                   operands[1]);
9383   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
9384                   operands[2]);
9385   DONE;
9386 })
9387
9388 (define_expand "extendsftf2"
9389   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9390         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
9391   "!TARGET_IEEEQUAD
9392    && TARGET_HARD_FLOAT
9393    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9394    && TARGET_LONG_DOUBLE_128"
9395 {
9396   rtx tmp = gen_reg_rtx (DFmode);
9397   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
9398   emit_insn (gen_extenddftf2 (operands[0], tmp));
9399   DONE;
9400 })
9401
9402 (define_expand "trunctfdf2"
9403   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9404         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
9405   "!TARGET_IEEEQUAD
9406    && TARGET_HARD_FLOAT
9407    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9408    && TARGET_LONG_DOUBLE_128"
9409   "")
9410
9411 (define_insn_and_split "trunctfdf2_internal1"
9412   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
9413         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
9414   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
9415    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9416   "@
9417    #
9418    fmr %0,%1"
9419   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
9420   [(const_int 0)]
9421 {
9422   emit_note (NOTE_INSN_DELETED);
9423   DONE;
9424 }
9425   [(set_attr "type" "fp")])
9426
9427 (define_insn "trunctfdf2_internal2"
9428   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9429         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9430   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
9431    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9432    && TARGET_LONG_DOUBLE_128"
9433   "fadd %0,%1,%L1"
9434   [(set_attr "type" "fp")
9435    (set_attr "fp_type" "fp_addsub_d")])
9436
9437 (define_expand "trunctfsf2"
9438   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9439         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
9440   "!TARGET_IEEEQUAD
9441    && TARGET_HARD_FLOAT
9442    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9443    && TARGET_LONG_DOUBLE_128"
9444 {
9445   if (TARGET_E500_DOUBLE)
9446     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
9447   else
9448     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
9449   DONE;
9450 })
9451
9452 (define_insn_and_split "trunctfsf2_fprs"
9453   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
9454         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
9455    (clobber (match_scratch:DF 2 "=d"))]
9456   "!TARGET_IEEEQUAD
9457    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
9458    && TARGET_LONG_DOUBLE_128"
9459   "#"
9460   "&& reload_completed"
9461   [(set (match_dup 2)
9462         (float_truncate:DF (match_dup 1)))
9463    (set (match_dup 0)
9464         (float_truncate:SF (match_dup 2)))]
9465   "")
9466
9467 (define_expand "floatsitf2"
9468   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9469         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
9470   "!TARGET_IEEEQUAD
9471    && TARGET_HARD_FLOAT
9472    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9473    && TARGET_LONG_DOUBLE_128"
9474 {
9475   rtx tmp = gen_reg_rtx (DFmode);
9476   expand_float (tmp, operands[1], false);
9477   emit_insn (gen_extenddftf2 (operands[0], tmp));
9478   DONE;
9479 })
9480
9481 ; fadd, but rounding towards zero.
9482 ; This is probably not the optimal code sequence.
9483 (define_insn "fix_trunc_helper"
9484   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9485         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
9486                    UNSPEC_FIX_TRUNC_TF))
9487    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
9488   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
9489   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
9490   [(set_attr "type" "fp")
9491    (set_attr "length" "20")])
9492
9493 (define_expand "fix_trunctfsi2"
9494   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9495         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
9496   "!TARGET_IEEEQUAD
9497    && (TARGET_POWER2 || TARGET_POWERPC)
9498    && TARGET_HARD_FLOAT
9499    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9500    && TARGET_LONG_DOUBLE_128"
9501 {
9502   if (TARGET_E500_DOUBLE)
9503     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
9504   else
9505     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
9506   DONE;
9507 })
9508
9509 (define_expand "fix_trunctfsi2_fprs"
9510   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
9511                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
9512               (clobber (match_dup 2))
9513               (clobber (match_dup 3))
9514               (clobber (match_dup 4))
9515               (clobber (match_dup 5))])]
9516   "!TARGET_IEEEQUAD
9517    && (TARGET_POWER2 || TARGET_POWERPC)
9518    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9519 {
9520   operands[2] = gen_reg_rtx (DFmode);
9521   operands[3] = gen_reg_rtx (DFmode);
9522   operands[4] = gen_reg_rtx (DImode);
9523   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
9524 })
9525
9526 (define_insn_and_split "*fix_trunctfsi2_internal"
9527   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9528         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
9529    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
9530    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
9531    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
9532    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
9533   "!TARGET_IEEEQUAD
9534    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9535   "#"
9536   ""
9537   [(pc)]
9538 {
9539   rtx lowword;
9540   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
9541
9542   gcc_assert (MEM_P (operands[5]));
9543   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
9544
9545   emit_insn (gen_fctiwz (operands[4], operands[2]));
9546   emit_move_insn (operands[5], operands[4]);
9547   emit_move_insn (operands[0], lowword);
9548   DONE;
9549 })
9550
9551 (define_expand "negtf2"
9552   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9553         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9554   "!TARGET_IEEEQUAD
9555    && TARGET_HARD_FLOAT
9556    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9557    && TARGET_LONG_DOUBLE_128"
9558   "")
9559
9560 (define_insn "negtf2_internal"
9561   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
9562         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9563   "!TARGET_IEEEQUAD
9564    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9565   "*
9566 {
9567   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9568     return \"fneg %L0,%L1\;fneg %0,%1\";
9569   else
9570     return \"fneg %0,%1\;fneg %L0,%L1\";
9571 }"
9572   [(set_attr "type" "fp")
9573    (set_attr "length" "8")])
9574
9575 (define_expand "abstf2"
9576   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9577         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9578   "!TARGET_IEEEQUAD
9579    && TARGET_HARD_FLOAT
9580    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9581    && TARGET_LONG_DOUBLE_128"
9582   "
9583 {
9584   rtx label = gen_label_rtx ();
9585   if (TARGET_E500_DOUBLE)
9586     {
9587       if (flag_finite_math_only && !flag_trapping_math)
9588         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
9589       else
9590         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
9591     }
9592   else
9593     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
9594   emit_label (label);
9595   DONE;
9596 }")
9597
9598 (define_expand "abstf2_internal"
9599   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9600         (match_operand:TF 1 "gpc_reg_operand" ""))
9601    (set (match_dup 3) (match_dup 5))
9602    (set (match_dup 5) (abs:DF (match_dup 5)))
9603    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
9604    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
9605                            (label_ref (match_operand 2 "" ""))
9606                            (pc)))
9607    (set (match_dup 6) (neg:DF (match_dup 6)))]
9608   "!TARGET_IEEEQUAD
9609    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9610    && TARGET_LONG_DOUBLE_128"
9611   "
9612 {
9613   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
9614   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
9615   operands[3] = gen_reg_rtx (DFmode);
9616   operands[4] = gen_reg_rtx (CCFPmode);
9617   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
9618   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
9619 }")
9620 \f
9621 ;; Next come the multi-word integer load and store and the load and store
9622 ;; multiple insns.
9623
9624 ; List r->r after r->"o<>", otherwise reload will try to reload a
9625 ; non-offsettable address by using r->r which won't make progress.
9626 (define_insn "*movdi_internal32"
9627   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=o<>,r,r,*d,*d,m,r")
9628         (match_operand:DI 1 "input_operand" "r,r,m,d,m,d,IJKnGHF"))]
9629   "! TARGET_POWERPC64
9630    && (gpc_reg_operand (operands[0], DImode)
9631        || gpc_reg_operand (operands[1], DImode))"
9632   "@
9633    #
9634    #
9635    #
9636    fmr %0,%1
9637    lfd%U1%X1 %0,%1
9638    stfd%U0%X0 %1,%0
9639    #"
9640   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
9641
9642 (define_split
9643   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9644         (match_operand:DI 1 "const_int_operand" ""))]
9645   "! TARGET_POWERPC64 && reload_completed"
9646   [(set (match_dup 2) (match_dup 4))
9647    (set (match_dup 3) (match_dup 1))]
9648   "
9649 {
9650   HOST_WIDE_INT value = INTVAL (operands[1]);
9651   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9652                                        DImode);
9653   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9654                                        DImode);
9655 #if HOST_BITS_PER_WIDE_INT == 32
9656   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
9657 #else
9658   operands[4] = GEN_INT (value >> 32);
9659   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9660 #endif
9661 }")
9662
9663 (define_split
9664   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
9665         (match_operand:DIFD 1 "input_operand" ""))]
9666   "reload_completed && !TARGET_POWERPC64
9667    && gpr_or_gpr_p (operands[0], operands[1])"
9668   [(pc)]
9669 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9670
9671 (define_insn "*movdi_mfpgpr"
9672   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*d,*d,m,r,*h,*h,r,*d")
9673         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,d,m,d,*h,r,0,*d,r"))]
9674   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
9675    && (gpc_reg_operand (operands[0], DImode)
9676        || gpc_reg_operand (operands[1], DImode))"
9677   "@
9678    mr %0,%1
9679    ld%U1%X1 %0,%1
9680    std%U0%X0 %1,%0
9681    li %0,%1
9682    lis %0,%v1
9683    #
9684    {cal|la} %0,%a1
9685    fmr %0,%1
9686    lfd%U1%X1 %0,%1
9687    stfd%U0%X0 %1,%0
9688    mf%1 %0
9689    mt%0 %1
9690    {cror 0,0,0|nop}
9691    mftgpr %0,%1
9692    mffgpr %0,%1"
9693   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*,mftgpr,mffgpr")
9694    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4")])
9695
9696 (define_insn "*movdi_internal64"
9697   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*d,*d,m,r,*h,*h")
9698         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,d,m,d,*h,r,0"))]
9699   "TARGET_POWERPC64 && (!TARGET_MFPGPR || !TARGET_HARD_FLOAT || !TARGET_FPRS)
9700    && (gpc_reg_operand (operands[0], DImode)
9701        || gpc_reg_operand (operands[1], DImode))"
9702   "@
9703    mr %0,%1
9704    ld%U1%X1 %0,%1
9705    std%U0%X0 %1,%0
9706    li %0,%1
9707    lis %0,%v1
9708    #
9709    {cal|la} %0,%a1
9710    fmr %0,%1
9711    lfd%U1%X1 %0,%1
9712    stfd%U0%X0 %1,%0
9713    mf%1 %0
9714    mt%0 %1
9715    {cror 0,0,0|nop}"
9716   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
9717    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
9718
9719 ;; immediate value valid for a single instruction hiding in a const_double
9720 (define_insn ""
9721   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9722         (match_operand:DI 1 "const_double_operand" "F"))]
9723   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
9724    && GET_CODE (operands[1]) == CONST_DOUBLE
9725    && num_insns_constant (operands[1], DImode) == 1"
9726   "*
9727 {
9728   return ((unsigned HOST_WIDE_INT)
9729           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
9730          ? \"li %0,%1\" : \"lis %0,%v1\";
9731 }")
9732
9733 ;; Generate all one-bits and clear left or right.
9734 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
9735 (define_split
9736   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9737         (match_operand:DI 1 "mask64_operand" ""))]
9738   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9739   [(set (match_dup 0) (const_int -1))
9740    (set (match_dup 0)
9741         (and:DI (rotate:DI (match_dup 0)
9742                            (const_int 0))
9743                 (match_dup 1)))]
9744   "")
9745
9746 ;; Split a load of a large constant into the appropriate five-instruction
9747 ;; sequence.  Handle anything in a constant number of insns.
9748 ;; When non-easy constants can go in the TOC, this should use
9749 ;; easy_fp_constant predicate.
9750 (define_split
9751   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9752         (match_operand:DI 1 "const_int_operand" ""))]
9753   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9754   [(set (match_dup 0) (match_dup 2))
9755    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9756   "
9757 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9758
9759   if (tem == operands[0])
9760     DONE;
9761   else
9762     FAIL;
9763 }")
9764
9765 (define_split
9766   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9767         (match_operand:DI 1 "const_double_operand" ""))]
9768   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9769   [(set (match_dup 0) (match_dup 2))
9770    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9771   "
9772 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9773
9774   if (tem == operands[0])
9775     DONE;
9776   else
9777     FAIL;
9778 }")
9779 \f
9780 ;; TImode is similar, except that we usually want to compute the address into
9781 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
9782 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
9783
9784 ;; We say that MQ is clobbered in the last alternative because the first
9785 ;; alternative would never get used otherwise since it would need a reload
9786 ;; while the 2nd alternative would not.  We put memory cases first so they
9787 ;; are preferred.  Otherwise, we'd try to reload the output instead of
9788 ;; giving the SCRATCH mq.
9789
9790 (define_insn "*movti_power"
9791   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
9792         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
9793    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
9794   "TARGET_POWER && ! TARGET_POWERPC64
9795    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9796   "*
9797 {
9798   switch (which_alternative)
9799     {
9800     default:
9801       gcc_unreachable ();
9802
9803     case 0:
9804       if (TARGET_STRING)
9805         return \"{stsi|stswi} %1,%P0,16\";
9806     case 1:
9807     case 2:
9808       return \"#\";
9809     case 3:
9810       /* If the address is not used in the output, we can use lsi.  Otherwise,
9811          fall through to generating four loads.  */
9812       if (TARGET_STRING
9813           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9814         return \"{lsi|lswi} %0,%P1,16\";
9815       /* ... fall through ...  */
9816     case 4:
9817     case 5:
9818       return \"#\";
9819     }
9820 }"
9821   [(set_attr "type" "store,store,*,load,load,*")])
9822
9823 (define_insn "*movti_string"
9824   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
9825         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
9826   "! TARGET_POWER && ! TARGET_POWERPC64
9827    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9828   "*
9829 {
9830   switch (which_alternative)
9831     {
9832     default:
9833       gcc_unreachable ();
9834     case 0:
9835       if (TARGET_STRING)
9836         return \"{stsi|stswi} %1,%P0,16\";
9837     case 1:
9838     case 2:
9839       return \"#\";
9840     case 3:
9841       /* If the address is not used in the output, we can use lsi.  Otherwise,
9842          fall through to generating four loads.  */
9843       if (TARGET_STRING
9844           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9845         return \"{lsi|lswi} %0,%P1,16\";
9846       /* ... fall through ...  */
9847     case 4:
9848     case 5:
9849       return \"#\";
9850     }
9851 }"
9852   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")
9853    (set (attr "cell_micro") (if_then_else (eq (symbol_ref "TARGET_STRING") (const_int 1))
9854                                           (const_string "always")
9855                                           (const_string "conditional")))])
9856
9857 (define_insn "*movti_ppc64"
9858   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
9859         (match_operand:TI 1 "input_operand" "r,r,m"))]
9860   "(TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
9861     || gpc_reg_operand (operands[1], TImode)))
9862    && VECTOR_MEM_NONE_P (TImode)"
9863   "#"
9864   [(set_attr "type" "*,store,load")])
9865
9866 (define_split
9867   [(set (match_operand:TI 0 "gpc_reg_operand" "")
9868         (match_operand:TI 1 "const_double_operand" ""))]
9869   "TARGET_POWERPC64 && VECTOR_MEM_NONE_P (TImode)"
9870   [(set (match_dup 2) (match_dup 4))
9871    (set (match_dup 3) (match_dup 5))]
9872   "
9873 {
9874   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9875                                        TImode);
9876   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9877                                        TImode);
9878   if (GET_CODE (operands[1]) == CONST_DOUBLE)
9879     {
9880       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
9881       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
9882     }
9883   else if (GET_CODE (operands[1]) == CONST_INT)
9884     {
9885       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
9886       operands[5] = operands[1];
9887     }
9888   else
9889     FAIL;
9890 }")
9891
9892 (define_split
9893   [(set (match_operand:TI 0 "nonimmediate_operand" "")
9894         (match_operand:TI 1 "input_operand" ""))]
9895   "reload_completed && VECTOR_MEM_NONE_P (TImode)
9896    && gpr_or_gpr_p (operands[0], operands[1])"
9897   [(pc)]
9898 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9899 \f
9900 (define_expand "load_multiple"
9901   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9902                           (match_operand:SI 1 "" ""))
9903                      (use (match_operand:SI 2 "" ""))])]
9904   "TARGET_STRING && !TARGET_POWERPC64"
9905   "
9906 {
9907   int regno;
9908   int count;
9909   rtx op1;
9910   int i;
9911
9912   /* Support only loading a constant number of fixed-point registers from
9913      memory and only bother with this if more than two; the machine
9914      doesn't support more than eight.  */
9915   if (GET_CODE (operands[2]) != CONST_INT
9916       || INTVAL (operands[2]) <= 2
9917       || INTVAL (operands[2]) > 8
9918       || GET_CODE (operands[1]) != MEM
9919       || GET_CODE (operands[0]) != REG
9920       || REGNO (operands[0]) >= 32)
9921     FAIL;
9922
9923   count = INTVAL (operands[2]);
9924   regno = REGNO (operands[0]);
9925
9926   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
9927   op1 = replace_equiv_address (operands[1],
9928                                force_reg (SImode, XEXP (operands[1], 0)));
9929
9930   for (i = 0; i < count; i++)
9931     XVECEXP (operands[3], 0, i)
9932       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
9933                      adjust_address_nv (op1, SImode, i * 4));
9934 }")
9935
9936 (define_insn "*ldmsi8"
9937   [(match_parallel 0 "load_multiple_operation"
9938     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9939           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9940      (set (match_operand:SI 3 "gpc_reg_operand" "")
9941           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9942      (set (match_operand:SI 4 "gpc_reg_operand" "")
9943           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9944      (set (match_operand:SI 5 "gpc_reg_operand" "")
9945           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9946      (set (match_operand:SI 6 "gpc_reg_operand" "")
9947           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9948      (set (match_operand:SI 7 "gpc_reg_operand" "")
9949           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
9950      (set (match_operand:SI 8 "gpc_reg_operand" "")
9951           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
9952      (set (match_operand:SI 9 "gpc_reg_operand" "")
9953           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
9954   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
9955   "*
9956 { return rs6000_output_load_multiple (operands); }"
9957   [(set_attr "type" "load_ux")
9958    (set_attr "length" "32")])
9959
9960 (define_insn "*ldmsi7"
9961   [(match_parallel 0 "load_multiple_operation"
9962     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9963           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9964      (set (match_operand:SI 3 "gpc_reg_operand" "")
9965           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9966      (set (match_operand:SI 4 "gpc_reg_operand" "")
9967           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9968      (set (match_operand:SI 5 "gpc_reg_operand" "")
9969           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9970      (set (match_operand:SI 6 "gpc_reg_operand" "")
9971           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9972      (set (match_operand:SI 7 "gpc_reg_operand" "")
9973           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
9974      (set (match_operand:SI 8 "gpc_reg_operand" "")
9975           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
9976   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
9977   "*
9978 { return rs6000_output_load_multiple (operands); }"
9979   [(set_attr "type" "load_ux")
9980    (set_attr "length" "32")])
9981
9982 (define_insn "*ldmsi6"
9983   [(match_parallel 0 "load_multiple_operation"
9984     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9985           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9986      (set (match_operand:SI 3 "gpc_reg_operand" "")
9987           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9988      (set (match_operand:SI 4 "gpc_reg_operand" "")
9989           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9990      (set (match_operand:SI 5 "gpc_reg_operand" "")
9991           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9992      (set (match_operand:SI 6 "gpc_reg_operand" "")
9993           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9994      (set (match_operand:SI 7 "gpc_reg_operand" "")
9995           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
9996   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
9997   "*
9998 { return rs6000_output_load_multiple (operands); }"
9999   [(set_attr "type" "load_ux")
10000    (set_attr "length" "32")])
10001
10002 (define_insn "*ldmsi5"
10003   [(match_parallel 0 "load_multiple_operation"
10004     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10005           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10006      (set (match_operand:SI 3 "gpc_reg_operand" "")
10007           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10008      (set (match_operand:SI 4 "gpc_reg_operand" "")
10009           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10010      (set (match_operand:SI 5 "gpc_reg_operand" "")
10011           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10012      (set (match_operand:SI 6 "gpc_reg_operand" "")
10013           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
10014   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10015   "*
10016 { return rs6000_output_load_multiple (operands); }"
10017   [(set_attr "type" "load_ux")
10018    (set_attr "length" "32")])
10019
10020 (define_insn "*ldmsi4"
10021   [(match_parallel 0 "load_multiple_operation"
10022     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10023           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10024      (set (match_operand:SI 3 "gpc_reg_operand" "")
10025           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10026      (set (match_operand:SI 4 "gpc_reg_operand" "")
10027           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10028      (set (match_operand:SI 5 "gpc_reg_operand" "")
10029           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
10030   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10031   "*
10032 { return rs6000_output_load_multiple (operands); }"
10033   [(set_attr "type" "load_ux")
10034    (set_attr "length" "32")])
10035
10036 (define_insn "*ldmsi3"
10037   [(match_parallel 0 "load_multiple_operation"
10038     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10039           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10040      (set (match_operand:SI 3 "gpc_reg_operand" "")
10041           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10042      (set (match_operand:SI 4 "gpc_reg_operand" "")
10043           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
10044   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
10045   "*
10046 { return rs6000_output_load_multiple (operands); }"
10047   [(set_attr "type" "load_ux")
10048    (set_attr "length" "32")])
10049
10050 (define_expand "store_multiple"
10051   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10052                           (match_operand:SI 1 "" ""))
10053                      (clobber (scratch:SI))
10054                      (use (match_operand:SI 2 "" ""))])]
10055   "TARGET_STRING && !TARGET_POWERPC64"
10056   "
10057 {
10058   int regno;
10059   int count;
10060   rtx to;
10061   rtx op0;
10062   int i;
10063
10064   /* Support only storing a constant number of fixed-point registers to
10065      memory and only bother with this if more than two; the machine
10066      doesn't support more than eight.  */
10067   if (GET_CODE (operands[2]) != CONST_INT
10068       || INTVAL (operands[2]) <= 2
10069       || INTVAL (operands[2]) > 8
10070       || GET_CODE (operands[0]) != MEM
10071       || GET_CODE (operands[1]) != REG
10072       || REGNO (operands[1]) >= 32)
10073     FAIL;
10074
10075   count = INTVAL (operands[2]);
10076   regno = REGNO (operands[1]);
10077
10078   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
10079   to = force_reg (SImode, XEXP (operands[0], 0));
10080   op0 = replace_equiv_address (operands[0], to);
10081
10082   XVECEXP (operands[3], 0, 0)
10083     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
10084   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
10085                                                  gen_rtx_SCRATCH (SImode));
10086
10087   for (i = 1; i < count; i++)
10088     XVECEXP (operands[3], 0, i + 1)
10089       = gen_rtx_SET (VOIDmode,
10090                      adjust_address_nv (op0, SImode, i * 4),
10091                      gen_rtx_REG (SImode, regno + i));
10092 }")
10093
10094 (define_insn "*stmsi8"
10095   [(match_parallel 0 "store_multiple_operation"
10096     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10097           (match_operand:SI 2 "gpc_reg_operand" "r"))
10098      (clobber (match_scratch:SI 3 "=X"))
10099      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10100           (match_operand:SI 4 "gpc_reg_operand" "r"))
10101      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10102           (match_operand:SI 5 "gpc_reg_operand" "r"))
10103      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10104           (match_operand:SI 6 "gpc_reg_operand" "r"))
10105      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10106           (match_operand:SI 7 "gpc_reg_operand" "r"))
10107      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10108           (match_operand:SI 8 "gpc_reg_operand" "r"))
10109      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10110           (match_operand:SI 9 "gpc_reg_operand" "r"))
10111      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10112           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10113   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
10114   "{stsi|stswi} %2,%1,%O0"
10115   [(set_attr "type" "store_ux")
10116    (set_attr "cell_micro" "always")])
10117
10118 (define_insn "*stmsi7"
10119   [(match_parallel 0 "store_multiple_operation"
10120     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10121           (match_operand:SI 2 "gpc_reg_operand" "r"))
10122      (clobber (match_scratch:SI 3 "=X"))
10123      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10124           (match_operand:SI 4 "gpc_reg_operand" "r"))
10125      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10126           (match_operand:SI 5 "gpc_reg_operand" "r"))
10127      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10128           (match_operand:SI 6 "gpc_reg_operand" "r"))
10129      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10130           (match_operand:SI 7 "gpc_reg_operand" "r"))
10131      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10132           (match_operand:SI 8 "gpc_reg_operand" "r"))
10133      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10134           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10135   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
10136   "{stsi|stswi} %2,%1,%O0"
10137   [(set_attr "type" "store_ux")
10138    (set_attr "cell_micro" "always")])
10139
10140 (define_insn "*stmsi6"
10141   [(match_parallel 0 "store_multiple_operation"
10142     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10143           (match_operand:SI 2 "gpc_reg_operand" "r"))
10144      (clobber (match_scratch:SI 3 "=X"))
10145      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10146           (match_operand:SI 4 "gpc_reg_operand" "r"))
10147      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10148           (match_operand:SI 5 "gpc_reg_operand" "r"))
10149      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10150           (match_operand:SI 6 "gpc_reg_operand" "r"))
10151      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10152           (match_operand:SI 7 "gpc_reg_operand" "r"))
10153      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10154           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10155   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
10156   "{stsi|stswi} %2,%1,%O0"
10157   [(set_attr "type" "store_ux")
10158    (set_attr "cell_micro" "always")])
10159
10160 (define_insn "*stmsi5"
10161   [(match_parallel 0 "store_multiple_operation"
10162     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10163           (match_operand:SI 2 "gpc_reg_operand" "r"))
10164      (clobber (match_scratch:SI 3 "=X"))
10165      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10166           (match_operand:SI 4 "gpc_reg_operand" "r"))
10167      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10168           (match_operand:SI 5 "gpc_reg_operand" "r"))
10169      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10170           (match_operand:SI 6 "gpc_reg_operand" "r"))
10171      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10172           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10173   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
10174   "{stsi|stswi} %2,%1,%O0"
10175   [(set_attr "type" "store_ux")
10176    (set_attr "cell_micro" "always")])
10177
10178 (define_insn "*stmsi4"
10179   [(match_parallel 0 "store_multiple_operation"
10180     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10181           (match_operand:SI 2 "gpc_reg_operand" "r"))
10182      (clobber (match_scratch:SI 3 "=X"))
10183      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10184           (match_operand:SI 4 "gpc_reg_operand" "r"))
10185      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10186           (match_operand:SI 5 "gpc_reg_operand" "r"))
10187      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10188           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10189   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
10190   "{stsi|stswi} %2,%1,%O0"
10191   [(set_attr "type" "store_ux")
10192    (set_attr "cell_micro" "always")])
10193
10194 (define_insn "*stmsi3"
10195   [(match_parallel 0 "store_multiple_operation"
10196     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10197           (match_operand:SI 2 "gpc_reg_operand" "r"))
10198      (clobber (match_scratch:SI 3 "=X"))
10199      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10200           (match_operand:SI 4 "gpc_reg_operand" "r"))
10201      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10202           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10203   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
10204   "{stsi|stswi} %2,%1,%O0"
10205   [(set_attr "type" "store_ux")
10206    (set_attr "cell_micro" "always")])
10207
10208 (define_insn "*stmsi8_power"
10209   [(match_parallel 0 "store_multiple_operation"
10210     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10211           (match_operand:SI 2 "gpc_reg_operand" "r"))
10212      (clobber (match_scratch:SI 3 "=q"))
10213      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10214           (match_operand:SI 4 "gpc_reg_operand" "r"))
10215      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10216           (match_operand:SI 5 "gpc_reg_operand" "r"))
10217      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10218           (match_operand:SI 6 "gpc_reg_operand" "r"))
10219      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10220           (match_operand:SI 7 "gpc_reg_operand" "r"))
10221      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10222           (match_operand:SI 8 "gpc_reg_operand" "r"))
10223      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10224           (match_operand:SI 9 "gpc_reg_operand" "r"))
10225      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10226           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10227   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 9"
10228   "{stsi|stswi} %2,%1,%O0"
10229   [(set_attr "type" "store_ux")
10230    (set_attr "cell_micro" "always")])
10231
10232 (define_insn "*stmsi7_power"
10233   [(match_parallel 0 "store_multiple_operation"
10234     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10235           (match_operand:SI 2 "gpc_reg_operand" "r"))
10236      (clobber (match_scratch:SI 3 "=q"))
10237      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10238           (match_operand:SI 4 "gpc_reg_operand" "r"))
10239      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10240           (match_operand:SI 5 "gpc_reg_operand" "r"))
10241      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10242           (match_operand:SI 6 "gpc_reg_operand" "r"))
10243      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10244           (match_operand:SI 7 "gpc_reg_operand" "r"))
10245      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10246           (match_operand:SI 8 "gpc_reg_operand" "r"))
10247      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10248           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10249   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 8"
10250   "{stsi|stswi} %2,%1,%O0"
10251   [(set_attr "type" "store_ux")
10252    (set_attr "cell_micro" "always")])
10253
10254 (define_insn "*stmsi6_power"
10255   [(match_parallel 0 "store_multiple_operation"
10256     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10257           (match_operand:SI 2 "gpc_reg_operand" "r"))
10258      (clobber (match_scratch:SI 3 "=q"))
10259      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10260           (match_operand:SI 4 "gpc_reg_operand" "r"))
10261      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10262           (match_operand:SI 5 "gpc_reg_operand" "r"))
10263      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10264           (match_operand:SI 6 "gpc_reg_operand" "r"))
10265      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10266           (match_operand:SI 7 "gpc_reg_operand" "r"))
10267      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10268           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10269   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 7"
10270   "{stsi|stswi} %2,%1,%O0"
10271   [(set_attr "type" "store_ux")
10272    (set_attr "cell_micro" "always")])
10273
10274 (define_insn "*stmsi5_power"
10275   [(match_parallel 0 "store_multiple_operation"
10276     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10277           (match_operand:SI 2 "gpc_reg_operand" "r"))
10278      (clobber (match_scratch:SI 3 "=q"))
10279      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10280           (match_operand:SI 4 "gpc_reg_operand" "r"))
10281      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10282           (match_operand:SI 5 "gpc_reg_operand" "r"))
10283      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10284           (match_operand:SI 6 "gpc_reg_operand" "r"))
10285      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10286           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10287   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 6"
10288   "{stsi|stswi} %2,%1,%O0"
10289   [(set_attr "type" "store_ux")
10290    (set_attr "cell_micro" "always")])
10291
10292 (define_insn "*stmsi4_power"
10293   [(match_parallel 0 "store_multiple_operation"
10294     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10295           (match_operand:SI 2 "gpc_reg_operand" "r"))
10296      (clobber (match_scratch:SI 3 "=q"))
10297      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10298           (match_operand:SI 4 "gpc_reg_operand" "r"))
10299      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10300           (match_operand:SI 5 "gpc_reg_operand" "r"))
10301      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10302           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10303   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 5"
10304   "{stsi|stswi} %2,%1,%O0"
10305   [(set_attr "type" "store_ux")
10306    (set_attr "cell_micro" "always")])
10307
10308 (define_insn "*stmsi3_power"
10309   [(match_parallel 0 "store_multiple_operation"
10310     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10311           (match_operand:SI 2 "gpc_reg_operand" "r"))
10312      (clobber (match_scratch:SI 3 "=q"))
10313      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10314           (match_operand:SI 4 "gpc_reg_operand" "r"))
10315      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10316           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10317   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 4"
10318   "{stsi|stswi} %2,%1,%O0"
10319   [(set_attr "type" "store_ux")
10320    (set_attr "cell_micro" "always")])
10321 \f
10322 (define_expand "setmemsi"
10323   [(parallel [(set (match_operand:BLK 0 "" "")
10324                    (match_operand 2 "const_int_operand" ""))
10325               (use (match_operand:SI 1 "" ""))
10326               (use (match_operand:SI 3 "" ""))])]
10327   ""
10328   "
10329 {
10330   /* If value to set is not zero, use the library routine.  */
10331   if (operands[2] != const0_rtx)
10332     FAIL;
10333
10334   if (expand_block_clear (operands))
10335     DONE;
10336   else
10337     FAIL;
10338 }")
10339
10340 ;; String/block move insn.
10341 ;; Argument 0 is the destination
10342 ;; Argument 1 is the source
10343 ;; Argument 2 is the length
10344 ;; Argument 3 is the alignment
10345
10346 (define_expand "movmemsi"
10347   [(parallel [(set (match_operand:BLK 0 "" "")
10348                    (match_operand:BLK 1 "" ""))
10349               (use (match_operand:SI 2 "" ""))
10350               (use (match_operand:SI 3 "" ""))])]
10351   ""
10352   "
10353 {
10354   if (expand_block_move (operands))
10355     DONE;
10356   else
10357     FAIL;
10358 }")
10359
10360 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
10361 ;; register allocator doesn't have a clue about allocating 8 word registers.
10362 ;; rD/rS = r5 is preferred, efficient form.
10363 (define_expand "movmemsi_8reg"
10364   [(parallel [(set (match_operand 0 "" "")
10365                    (match_operand 1 "" ""))
10366               (use (match_operand 2 "" ""))
10367               (use (match_operand 3 "" ""))
10368               (clobber (reg:SI  5))
10369               (clobber (reg:SI  6))
10370               (clobber (reg:SI  7))
10371               (clobber (reg:SI  8))
10372               (clobber (reg:SI  9))
10373               (clobber (reg:SI 10))
10374               (clobber (reg:SI 11))
10375               (clobber (reg:SI 12))
10376               (clobber (match_scratch:SI 4 ""))])]
10377   "TARGET_STRING"
10378   "")
10379
10380 (define_insn ""
10381   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10382         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10383    (use (match_operand:SI 2 "immediate_operand" "i"))
10384    (use (match_operand:SI 3 "immediate_operand" "i"))
10385    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10386    (clobber (reg:SI  6))
10387    (clobber (reg:SI  7))
10388    (clobber (reg:SI  8))
10389    (clobber (reg:SI  9))
10390    (clobber (reg:SI 10))
10391    (clobber (reg:SI 11))
10392    (clobber (reg:SI 12))
10393    (clobber (match_scratch:SI 5 "=q"))]
10394   "TARGET_STRING && TARGET_POWER
10395    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10396        || INTVAL (operands[2]) == 0)
10397    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10398    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10399    && REGNO (operands[4]) == 5"
10400   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10401   [(set_attr "type" "store_ux")
10402    (set_attr "cell_micro" "always")
10403    (set_attr "length" "8")])
10404
10405 (define_insn ""
10406   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10407         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10408    (use (match_operand:SI 2 "immediate_operand" "i"))
10409    (use (match_operand:SI 3 "immediate_operand" "i"))
10410    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10411    (clobber (reg:SI  6))
10412    (clobber (reg:SI  7))
10413    (clobber (reg:SI  8))
10414    (clobber (reg:SI  9))
10415    (clobber (reg:SI 10))
10416    (clobber (reg:SI 11))
10417    (clobber (reg:SI 12))
10418    (clobber (match_scratch:SI 5 "=X"))]
10419   "TARGET_STRING && ! TARGET_POWER
10420    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10421        || INTVAL (operands[2]) == 0)
10422    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10423    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10424    && REGNO (operands[4]) == 5"
10425   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10426   [(set_attr "type" "store_ux")
10427    (set_attr "cell_micro" "always")
10428    (set_attr "length" "8")])
10429
10430 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
10431 ;; register allocator doesn't have a clue about allocating 6 word registers.
10432 ;; rD/rS = r5 is preferred, efficient form.
10433 (define_expand "movmemsi_6reg"
10434   [(parallel [(set (match_operand 0 "" "")
10435                    (match_operand 1 "" ""))
10436               (use (match_operand 2 "" ""))
10437               (use (match_operand 3 "" ""))
10438               (clobber (reg:SI  5))
10439               (clobber (reg:SI  6))
10440               (clobber (reg:SI  7))
10441               (clobber (reg:SI  8))
10442               (clobber (reg:SI  9))
10443               (clobber (reg:SI 10))
10444               (clobber (match_scratch:SI 4 ""))])]
10445   "TARGET_STRING"
10446   "")
10447
10448 (define_insn ""
10449   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10450         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10451    (use (match_operand:SI 2 "immediate_operand" "i"))
10452    (use (match_operand:SI 3 "immediate_operand" "i"))
10453    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10454    (clobber (reg:SI  6))
10455    (clobber (reg:SI  7))
10456    (clobber (reg:SI  8))
10457    (clobber (reg:SI  9))
10458    (clobber (reg:SI 10))
10459    (clobber (match_scratch:SI 5 "=q"))]
10460   "TARGET_STRING && TARGET_POWER
10461    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
10462    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10463    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10464    && REGNO (operands[4]) == 5"
10465   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10466   [(set_attr "type" "store_ux")
10467    (set_attr "cell_micro" "always")
10468    (set_attr "length" "8")])
10469
10470 (define_insn ""
10471   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10472         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10473    (use (match_operand:SI 2 "immediate_operand" "i"))
10474    (use (match_operand:SI 3 "immediate_operand" "i"))
10475    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10476    (clobber (reg:SI  6))
10477    (clobber (reg:SI  7))
10478    (clobber (reg:SI  8))
10479    (clobber (reg:SI  9))
10480    (clobber (reg:SI 10))
10481    (clobber (match_scratch:SI 5 "=X"))]
10482   "TARGET_STRING && ! TARGET_POWER
10483    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
10484    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10485    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10486    && REGNO (operands[4]) == 5"
10487   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10488   [(set_attr "type" "store_ux")
10489    (set_attr "cell_micro" "always")
10490    (set_attr "length" "8")])
10491
10492 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
10493 ;; problems with TImode.
10494 ;; rD/rS = r5 is preferred, efficient form.
10495 (define_expand "movmemsi_4reg"
10496   [(parallel [(set (match_operand 0 "" "")
10497                    (match_operand 1 "" ""))
10498               (use (match_operand 2 "" ""))
10499               (use (match_operand 3 "" ""))
10500               (clobber (reg:SI 5))
10501               (clobber (reg:SI 6))
10502               (clobber (reg:SI 7))
10503               (clobber (reg:SI 8))
10504               (clobber (match_scratch:SI 4 ""))])]
10505   "TARGET_STRING"
10506   "")
10507
10508 (define_insn ""
10509   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10510         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10511    (use (match_operand:SI 2 "immediate_operand" "i"))
10512    (use (match_operand:SI 3 "immediate_operand" "i"))
10513    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10514    (clobber (reg:SI 6))
10515    (clobber (reg:SI 7))
10516    (clobber (reg:SI 8))
10517    (clobber (match_scratch:SI 5 "=q"))]
10518   "TARGET_STRING && TARGET_POWER
10519    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
10520    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
10521    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
10522    && REGNO (operands[4]) == 5"
10523   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10524   [(set_attr "type" "store_ux")
10525    (set_attr "cell_micro" "always")
10526    (set_attr "length" "8")])
10527
10528 (define_insn ""
10529   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10530         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10531    (use (match_operand:SI 2 "immediate_operand" "i"))
10532    (use (match_operand:SI 3 "immediate_operand" "i"))
10533    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10534    (clobber (reg:SI 6))
10535    (clobber (reg:SI 7))
10536    (clobber (reg:SI 8))
10537    (clobber (match_scratch:SI 5 "=X"))]
10538   "TARGET_STRING && ! TARGET_POWER
10539    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
10540    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
10541    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
10542    && REGNO (operands[4]) == 5"
10543   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10544   [(set_attr "type" "store_ux")
10545    (set_attr "cell_micro" "always")
10546    (set_attr "length" "8")])
10547
10548 ;; Move up to 8 bytes at a time.
10549 (define_expand "movmemsi_2reg"
10550   [(parallel [(set (match_operand 0 "" "")
10551                    (match_operand 1 "" ""))
10552               (use (match_operand 2 "" ""))
10553               (use (match_operand 3 "" ""))
10554               (clobber (match_scratch:DI 4 ""))
10555               (clobber (match_scratch:SI 5 ""))])]
10556   "TARGET_STRING && ! TARGET_POWERPC64"
10557   "")
10558
10559 (define_insn ""
10560   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10561         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10562    (use (match_operand:SI 2 "immediate_operand" "i"))
10563    (use (match_operand:SI 3 "immediate_operand" "i"))
10564    (clobber (match_scratch:DI 4 "=&r"))
10565    (clobber (match_scratch:SI 5 "=q"))]
10566   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
10567    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
10568   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10569   [(set_attr "type" "store_ux")
10570    (set_attr "cell_micro" "always")
10571    (set_attr "length" "8")])
10572
10573 (define_insn ""
10574   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10575         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10576    (use (match_operand:SI 2 "immediate_operand" "i"))
10577    (use (match_operand:SI 3 "immediate_operand" "i"))
10578    (clobber (match_scratch:DI 4 "=&r"))
10579    (clobber (match_scratch:SI 5 "=X"))]
10580   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
10581    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
10582   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10583   [(set_attr "type" "store_ux")
10584    (set_attr "cell_micro" "always")
10585    (set_attr "length" "8")])
10586
10587 ;; Move up to 4 bytes at a time.
10588 (define_expand "movmemsi_1reg"
10589   [(parallel [(set (match_operand 0 "" "")
10590                    (match_operand 1 "" ""))
10591               (use (match_operand 2 "" ""))
10592               (use (match_operand 3 "" ""))
10593               (clobber (match_scratch:SI 4 ""))
10594               (clobber (match_scratch:SI 5 ""))])]
10595   "TARGET_STRING"
10596   "")
10597
10598 (define_insn ""
10599   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10600         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10601    (use (match_operand:SI 2 "immediate_operand" "i"))
10602    (use (match_operand:SI 3 "immediate_operand" "i"))
10603    (clobber (match_scratch:SI 4 "=&r"))
10604    (clobber (match_scratch:SI 5 "=q"))]
10605   "TARGET_STRING && TARGET_POWER
10606    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
10607   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10608   [(set_attr "type" "store_ux")
10609    (set_attr "cell_micro" "always")
10610    (set_attr "length" "8")])
10611
10612 (define_insn ""
10613   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10614         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10615    (use (match_operand:SI 2 "immediate_operand" "i"))
10616    (use (match_operand:SI 3 "immediate_operand" "i"))
10617    (clobber (match_scratch:SI 4 "=&r"))
10618    (clobber (match_scratch:SI 5 "=X"))]
10619   "TARGET_STRING && ! TARGET_POWER
10620    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
10621   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10622   [(set_attr "type" "store_ux")
10623    (set_attr "cell_micro" "always")
10624    (set_attr "length" "8")])
10625 \f
10626 ;; Define insns that do load or store with update.  Some of these we can
10627 ;; get by using pre-decrement or pre-increment, but the hardware can also
10628 ;; do cases where the increment is not the size of the object.
10629 ;;
10630 ;; In all these cases, we use operands 0 and 1 for the register being
10631 ;; incremented because those are the operands that local-alloc will
10632 ;; tie and these are the pair most likely to be tieable (and the ones
10633 ;; that will benefit the most).
10634
10635 (define_insn "*movdi_update1"
10636   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
10637         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
10638                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
10639    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
10640         (plus:DI (match_dup 1) (match_dup 2)))]
10641   "TARGET_POWERPC64 && TARGET_UPDATE
10642    && (!avoiding_indexed_address_p (DImode)
10643        || !gpc_reg_operand (operands[2], DImode))"
10644   "@
10645    ldux %3,%0,%2
10646    ldu %3,%2(%0)"
10647   [(set_attr "type" "load_ux,load_u")])
10648
10649 (define_insn "movdi_<mode>_update"
10650   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10651                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10652         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10653    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10654         (plus:P (match_dup 1) (match_dup 2)))]
10655   "TARGET_POWERPC64 && TARGET_UPDATE
10656    && (!avoiding_indexed_address_p (Pmode)
10657        || !gpc_reg_operand (operands[2], Pmode)
10658        || (REG_P (operands[0])
10659            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10660   "@
10661    stdux %3,%0,%2
10662    stdu %3,%2(%0)"
10663   [(set_attr "type" "store_ux,store_u")])
10664
10665 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
10666 ;; needed for stack allocation, even if the user passes -mno-update.
10667 (define_insn "movdi_<mode>_update_stack"
10668   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10669                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10670         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10671    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10672         (plus:P (match_dup 1) (match_dup 2)))]
10673   "TARGET_POWERPC64"
10674   "@
10675    stdux %3,%0,%2
10676    stdu %3,%2(%0)"
10677   [(set_attr "type" "store_ux,store_u")])
10678
10679 (define_insn "*movsi_update1"
10680   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10681         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10682                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10683    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10684         (plus:SI (match_dup 1) (match_dup 2)))]
10685   "TARGET_UPDATE
10686    && (!avoiding_indexed_address_p (SImode)
10687        || !gpc_reg_operand (operands[2], SImode))"
10688   "@
10689    {lux|lwzux} %3,%0,%2
10690    {lu|lwzu} %3,%2(%0)"
10691   [(set_attr "type" "load_ux,load_u")])
10692
10693 (define_insn "*movsi_update2"
10694   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
10695         (sign_extend:DI
10696          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
10697                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
10698    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
10699         (plus:DI (match_dup 1) (match_dup 2)))]
10700   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
10701    && !avoiding_indexed_address_p (DImode)"
10702   "lwaux %3,%0,%2"
10703   [(set_attr "type" "load_ext_ux")])
10704
10705 (define_insn "movsi_update"
10706   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10707                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10708         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10709    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10710         (plus:SI (match_dup 1) (match_dup 2)))]
10711   "TARGET_UPDATE
10712    && (!avoiding_indexed_address_p (SImode)
10713        || !gpc_reg_operand (operands[2], SImode)
10714        || (REG_P (operands[0])
10715            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10716   "@
10717    {stux|stwux} %3,%0,%2
10718    {stu|stwu} %3,%2(%0)"
10719   [(set_attr "type" "store_ux,store_u")])
10720
10721 ;; This is an unconditional pattern; needed for stack allocation, even
10722 ;; if the user passes -mno-update.
10723 (define_insn "movsi_update_stack"
10724   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10725                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10726         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10727    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10728         (plus:SI (match_dup 1) (match_dup 2)))]
10729   ""
10730   "@
10731    {stux|stwux} %3,%0,%2
10732    {stu|stwu} %3,%2(%0)"
10733   [(set_attr "type" "store_ux,store_u")])
10734
10735 (define_insn "*movhi_update1"
10736   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
10737         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10738                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10739    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10740         (plus:SI (match_dup 1) (match_dup 2)))]
10741   "TARGET_UPDATE
10742    && (!avoiding_indexed_address_p (SImode)
10743        || !gpc_reg_operand (operands[2], SImode))"
10744   "@
10745    lhzux %3,%0,%2
10746    lhzu %3,%2(%0)"
10747   [(set_attr "type" "load_ux,load_u")])
10748
10749 (define_insn "*movhi_update2"
10750   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10751         (zero_extend:SI
10752          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10753                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10754    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10755         (plus:SI (match_dup 1) (match_dup 2)))]
10756   "TARGET_UPDATE
10757    && (!avoiding_indexed_address_p (SImode)
10758        || !gpc_reg_operand (operands[2], SImode))"
10759   "@
10760    lhzux %3,%0,%2
10761    lhzu %3,%2(%0)"
10762   [(set_attr "type" "load_ux,load_u")])
10763
10764 (define_insn "*movhi_update3"
10765   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10766         (sign_extend:SI
10767          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10768                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10769    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10770         (plus:SI (match_dup 1) (match_dup 2)))]
10771   "TARGET_UPDATE && rs6000_gen_cell_microcode
10772    && (!avoiding_indexed_address_p (SImode)
10773        || !gpc_reg_operand (operands[2], SImode))"
10774   "@
10775    lhaux %3,%0,%2
10776    lhau %3,%2(%0)"
10777   [(set_attr "type" "load_ext_ux,load_ext_u")])
10778
10779 (define_insn "*movhi_update4"
10780   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10781                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10782         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
10783    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10784         (plus:SI (match_dup 1) (match_dup 2)))]
10785   "TARGET_UPDATE
10786    && (!avoiding_indexed_address_p (SImode)
10787        || !gpc_reg_operand (operands[2], SImode))"
10788   "@
10789    sthux %3,%0,%2
10790    sthu %3,%2(%0)"
10791   [(set_attr "type" "store_ux,store_u")])
10792
10793 (define_insn "*movqi_update1"
10794   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
10795         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10796                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10797    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10798         (plus:SI (match_dup 1) (match_dup 2)))]
10799   "TARGET_UPDATE
10800    && (!avoiding_indexed_address_p (SImode)
10801        || !gpc_reg_operand (operands[2], SImode))"
10802   "@
10803    lbzux %3,%0,%2
10804    lbzu %3,%2(%0)"
10805   [(set_attr "type" "load_ux,load_u")])
10806
10807 (define_insn "*movqi_update2"
10808   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10809         (zero_extend:SI
10810          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10811                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10812    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10813         (plus:SI (match_dup 1) (match_dup 2)))]
10814   "TARGET_UPDATE
10815    && (!avoiding_indexed_address_p (SImode)
10816        || !gpc_reg_operand (operands[2], SImode))"
10817   "@
10818    lbzux %3,%0,%2
10819    lbzu %3,%2(%0)"
10820   [(set_attr "type" "load_ux,load_u")])
10821
10822 (define_insn "*movqi_update3"
10823   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10824                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10825         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
10826    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10827         (plus:SI (match_dup 1) (match_dup 2)))]
10828   "TARGET_UPDATE
10829    && (!avoiding_indexed_address_p (SImode)
10830        || !gpc_reg_operand (operands[2], SImode))"
10831   "@
10832    stbux %3,%0,%2
10833    stbu %3,%2(%0)"
10834   [(set_attr "type" "store_ux,store_u")])
10835
10836 (define_insn "*movsf_update1"
10837   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
10838         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10839                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10840    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10841         (plus:SI (match_dup 1) (match_dup 2)))]
10842   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10843    && (!avoiding_indexed_address_p (SImode)
10844        || !gpc_reg_operand (operands[2], SImode))"
10845   "@
10846    lfsux %3,%0,%2
10847    lfsu %3,%2(%0)"
10848   [(set_attr "type" "fpload_ux,fpload_u")])
10849
10850 (define_insn "*movsf_update2"
10851   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10852                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10853         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
10854    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10855         (plus:SI (match_dup 1) (match_dup 2)))]
10856   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10857    && (!avoiding_indexed_address_p (SImode)
10858        || !gpc_reg_operand (operands[2], SImode))"
10859   "@
10860    stfsux %3,%0,%2
10861    stfsu %3,%2(%0)"
10862   [(set_attr "type" "fpstore_ux,fpstore_u")])
10863
10864 (define_insn "*movsf_update3"
10865   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
10866         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10867                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10868    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10869         (plus:SI (match_dup 1) (match_dup 2)))]
10870   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
10871    && (!avoiding_indexed_address_p (SImode)
10872        || !gpc_reg_operand (operands[2], SImode))"
10873   "@
10874    {lux|lwzux} %3,%0,%2
10875    {lu|lwzu} %3,%2(%0)"
10876   [(set_attr "type" "load_ux,load_u")])
10877
10878 (define_insn "*movsf_update4"
10879   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10880                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10881         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
10882    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10883         (plus:SI (match_dup 1) (match_dup 2)))]
10884   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
10885    && (!avoiding_indexed_address_p (SImode)
10886        || !gpc_reg_operand (operands[2], SImode))"
10887   "@
10888    {stux|stwux} %3,%0,%2
10889    {stu|stwu} %3,%2(%0)"
10890   [(set_attr "type" "store_ux,store_u")])
10891
10892 (define_insn "*movdf_update1"
10893   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
10894         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10895                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10896    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10897         (plus:SI (match_dup 1) (match_dup 2)))]
10898   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
10899    && (!avoiding_indexed_address_p (SImode)
10900        || !gpc_reg_operand (operands[2], SImode))"
10901   "@
10902    lfdux %3,%0,%2
10903    lfdu %3,%2(%0)"
10904   [(set_attr "type" "fpload_ux,fpload_u")])
10905
10906 (define_insn "*movdf_update2"
10907   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10908                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10909         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
10910    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10911         (plus:SI (match_dup 1) (match_dup 2)))]
10912   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
10913    && (!avoiding_indexed_address_p (SImode)
10914        || !gpc_reg_operand (operands[2], SImode))"
10915   "@
10916    stfdux %3,%0,%2
10917    stfdu %3,%2(%0)"
10918   [(set_attr "type" "fpstore_ux,fpstore_u")])
10919
10920 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
10921
10922 (define_insn "*lfq_power2"
10923   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
10924         (match_operand:V2DF 1 "memory_operand" ""))]
10925   "TARGET_POWER2
10926    && TARGET_HARD_FLOAT && TARGET_FPRS"
10927   "lfq%U1%X1 %0,%1")
10928
10929 (define_peephole2
10930   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10931         (match_operand:DF 1 "memory_operand" ""))
10932    (set (match_operand:DF 2 "gpc_reg_operand" "")
10933         (match_operand:DF 3 "memory_operand" ""))]
10934   "TARGET_POWER2
10935    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
10936    && registers_ok_for_quad_peep (operands[0], operands[2])
10937    && mems_ok_for_quad_peep (operands[1], operands[3])"
10938   [(set (match_dup 0)
10939         (match_dup 1))]
10940   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
10941    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
10942
10943 (define_insn "*stfq_power2"
10944   [(set (match_operand:V2DF 0 "memory_operand" "")
10945         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
10946   "TARGET_POWER2
10947    && TARGET_HARD_FLOAT && TARGET_FPRS"
10948   "stfq%U0%X0 %1,%0")
10949
10950
10951 (define_peephole2
10952   [(set (match_operand:DF 0 "memory_operand" "")
10953         (match_operand:DF 1 "gpc_reg_operand" ""))
10954    (set (match_operand:DF 2 "memory_operand" "")
10955         (match_operand:DF 3 "gpc_reg_operand" ""))]
10956   "TARGET_POWER2
10957    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
10958    && registers_ok_for_quad_peep (operands[1], operands[3])
10959    && mems_ok_for_quad_peep (operands[0], operands[2])"
10960   [(set (match_dup 0)
10961         (match_dup 1))]
10962   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
10963    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
10964
10965 ;; After inserting conditional returns we can sometimes have
10966 ;; unnecessary register moves.  Unfortunately we cannot have a
10967 ;; modeless peephole here, because some single SImode sets have early
10968 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
10969 ;; sequences, using get_attr_length here will smash the operands
10970 ;; array.  Neither is there an early_cobbler_p predicate.
10971 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
10972 (define_peephole2
10973   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10974         (match_operand:DF 1 "any_operand" ""))
10975    (set (match_operand:DF 2 "gpc_reg_operand" "")
10976         (match_dup 0))]
10977   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
10978    && peep2_reg_dead_p (2, operands[0])"
10979   [(set (match_dup 2) (match_dup 1))])
10980
10981 (define_peephole2
10982   [(set (match_operand:SF 0 "gpc_reg_operand" "")
10983         (match_operand:SF 1 "any_operand" ""))
10984    (set (match_operand:SF 2 "gpc_reg_operand" "")
10985         (match_dup 0))]
10986   "peep2_reg_dead_p (2, operands[0])"
10987   [(set (match_dup 2) (match_dup 1))])
10988
10989 \f
10990 ;; TLS support.
10991
10992 ;; Mode attributes for different ABIs.
10993 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
10994 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
10995 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
10996 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
10997
10998 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
10999   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11000         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11001               (match_operand 4 "" "g")))
11002    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11003                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11004                    UNSPEC_TLSGD)
11005    (clobber (reg:SI LR_REGNO))]
11006   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11007   "addi %0,%1,%2@got@tlsgd\;bl %z3\;%."
11008   "&& TARGET_TLS_MARKERS"
11009   [(set (match_dup 0)
11010         (unspec:TLSmode [(match_dup 1)
11011                          (match_dup 2)]
11012                         UNSPEC_TLSGD))
11013    (parallel [(set (match_dup 0)
11014                    (call (mem:TLSmode (match_dup 3))
11015                          (match_dup 4)))
11016               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11017               (clobber (reg:SI LR_REGNO))])]
11018   ""
11019   [(set_attr "type" "two")
11020    (set_attr "length" "12")])
11021
11022 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
11023   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11024         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11025               (match_operand 4 "" "g")))
11026    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11027                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11028                    UNSPEC_TLSGD)
11029    (clobber (reg:SI LR_REGNO))]
11030   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11031 {
11032   if (flag_pic)
11033     {
11034       if (TARGET_SECURE_PLT && flag_pic == 2)
11035         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
11036       else
11037         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
11038     }
11039   else
11040     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
11041 }
11042   "&& TARGET_TLS_MARKERS"
11043   [(set (match_dup 0)
11044         (unspec:TLSmode [(match_dup 1)
11045                          (match_dup 2)]
11046                         UNSPEC_TLSGD))
11047    (parallel [(set (match_dup 0)
11048                    (call (mem:TLSmode (match_dup 3))
11049                          (match_dup 4)))
11050               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11051               (clobber (reg:SI LR_REGNO))])]
11052   ""
11053   [(set_attr "type" "two")
11054    (set_attr "length" "8")])
11055
11056 (define_insn "*tls_gd<TLSmode:tls_abi_suffix>"
11057   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11058         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11059                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11060                         UNSPEC_TLSGD))]
11061   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11062   "addi %0,%1,%2@got@tlsgd"
11063   [(set_attr "length" "4")])
11064
11065 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
11066   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11067         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11068               (match_operand 2 "" "g")))
11069    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11070                    UNSPEC_TLSGD)
11071    (clobber (reg:SI LR_REGNO))]
11072   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11073   "bl %z1(%3@tlsgd)\;%."
11074   [(set_attr "type" "branch")
11075    (set_attr "length" "8")])
11076
11077 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
11078   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11079         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11080               (match_operand 2 "" "g")))
11081    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11082                    UNSPEC_TLSGD)
11083    (clobber (reg:SI LR_REGNO))]
11084   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11085 {
11086   if (flag_pic)
11087     {
11088       if (TARGET_SECURE_PLT && flag_pic == 2)
11089         return "bl %z1+32768(%3@tlsgd)@plt";
11090       return "bl %z1(%3@tlsgd)@plt";
11091     }
11092   return "bl %z1(%3@tlsgd)";
11093 }
11094   [(set_attr "type" "branch")
11095    (set_attr "length" "4")])
11096
11097 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
11098   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11099         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11100               (match_operand 3 "" "g")))
11101    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11102                    UNSPEC_TLSLD)
11103    (clobber (reg:SI LR_REGNO))]
11104   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11105   "addi %0,%1,%&@got@tlsld\;bl %z2\;%."
11106   "&& TARGET_TLS_MARKERS"
11107   [(set (match_dup 0)
11108         (unspec:TLSmode [(match_dup 1)]
11109                         UNSPEC_TLSLD))
11110    (parallel [(set (match_dup 0)
11111                    (call (mem:TLSmode (match_dup 2))
11112                          (match_dup 3)))
11113               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11114               (clobber (reg:SI LR_REGNO))])]
11115   ""
11116   [(set_attr "length" "12")])
11117
11118 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
11119   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11120         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11121               (match_operand 3 "" "g")))
11122    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11123                    UNSPEC_TLSLD)
11124    (clobber (reg:SI LR_REGNO))]
11125   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11126 {
11127   if (flag_pic)
11128     {
11129       if (TARGET_SECURE_PLT && flag_pic == 2)
11130         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11131       else
11132         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11133     }
11134   else
11135     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11136 }
11137   "&& TARGET_TLS_MARKERS"
11138   [(set (match_dup 0)
11139         (unspec:TLSmode [(match_dup 1)]
11140                         UNSPEC_TLSLD))
11141    (parallel [(set (match_dup 0)
11142                    (call (mem:TLSmode (match_dup 2))
11143                          (match_dup 3)))
11144               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11145               (clobber (reg:SI LR_REGNO))])]
11146   ""
11147   [(set_attr "length" "8")])
11148
11149 (define_insn "*tls_ld<TLSmode:tls_abi_suffix>"
11150   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11151         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11152                         UNSPEC_TLSLD))]
11153   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11154   "addi %0,%1,%&@got@tlsld"
11155   [(set_attr "length" "4")])
11156
11157 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11158   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11159         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11160               (match_operand 2 "" "g")))
11161    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11162    (clobber (reg:SI LR_REGNO))]
11163   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11164   "bl %z1(%&@tlsld)\;%."
11165   [(set_attr "type" "branch")
11166    (set_attr "length" "8")])
11167
11168 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11169   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11170         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11171               (match_operand 2 "" "g")))
11172    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11173    (clobber (reg:SI LR_REGNO))]
11174   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11175 {
11176   if (flag_pic)
11177     {
11178       if (TARGET_SECURE_PLT && flag_pic == 2)
11179         return "bl %z1+32768(%&@tlsld)@plt";
11180       return "bl %z1(%&@tlsld)@plt";
11181     }
11182   return "bl %z1(%&@tlsld)";
11183 }
11184   [(set_attr "type" "branch")
11185    (set_attr "length" "4")])
11186
11187 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11188   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11189         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11190                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11191                         UNSPEC_TLSDTPREL))]
11192   "HAVE_AS_TLS"
11193   "addi %0,%1,%2@dtprel")
11194
11195 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11196   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11197         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11198                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11199                         UNSPEC_TLSDTPRELHA))]
11200   "HAVE_AS_TLS"
11201   "addis %0,%1,%2@dtprel@ha")
11202
11203 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11204   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11205         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11206                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11207                         UNSPEC_TLSDTPRELLO))]
11208   "HAVE_AS_TLS"
11209   "addi %0,%1,%2@dtprel@l")
11210
11211 (define_insn "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11212   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11213         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11214                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11215                         UNSPEC_TLSGOTDTPREL))]
11216   "HAVE_AS_TLS"
11217   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)")
11218
11219 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11220   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11221         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11222                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11223                         UNSPEC_TLSTPREL))]
11224   "HAVE_AS_TLS"
11225   "addi %0,%1,%2@tprel")
11226
11227 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11228   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11229         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11230                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11231                         UNSPEC_TLSTPRELHA))]
11232   "HAVE_AS_TLS"
11233   "addis %0,%1,%2@tprel@ha")
11234
11235 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11236   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11237         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11238                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11239                         UNSPEC_TLSTPRELLO))]
11240   "HAVE_AS_TLS"
11241   "addi %0,%1,%2@tprel@l")
11242
11243 ;; "b" output constraint here and on tls_tls input to support linker tls
11244 ;; optimization.  The linker may edit the instructions emitted by a
11245 ;; tls_got_tprel/tls_tls pair to addis,addi.
11246 (define_insn "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11247   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11248         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11249                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11250                         UNSPEC_TLSGOTTPREL))]
11251   "HAVE_AS_TLS"
11252   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)")
11253
11254 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11255   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11256         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11257                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11258                         UNSPEC_TLSTLS))]
11259   "HAVE_AS_TLS"
11260   "add %0,%1,%2@tls")
11261
11262 \f
11263 ;; Next come insns related to the calling sequence.
11264 ;;
11265 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11266 ;; We move the back-chain and decrement the stack pointer.
11267
11268 (define_expand "allocate_stack"
11269   [(set (match_operand 0 "gpc_reg_operand" "")
11270         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11271    (set (reg 1)
11272         (minus (reg 1) (match_dup 1)))]
11273   ""
11274   "
11275 { rtx chain = gen_reg_rtx (Pmode);
11276   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11277   rtx neg_op0;
11278   rtx insn, par, set, mem;
11279
11280   emit_move_insn (chain, stack_bot);
11281
11282   /* Check stack bounds if necessary.  */
11283   if (crtl->limit_stack)
11284     {
11285       rtx available;
11286       available = expand_binop (Pmode, sub_optab,
11287                                 stack_pointer_rtx, stack_limit_rtx,
11288                                 NULL_RTX, 1, OPTAB_WIDEN);
11289       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11290     }
11291
11292   if (GET_CODE (operands[1]) != CONST_INT
11293       || INTVAL (operands[1]) < -32767
11294       || INTVAL (operands[1]) > 32768)
11295     {
11296       neg_op0 = gen_reg_rtx (Pmode);
11297       if (TARGET_32BIT)
11298         emit_insn (gen_negsi2 (neg_op0, operands[1]));
11299       else
11300         emit_insn (gen_negdi2 (neg_op0, operands[1]));
11301     }
11302   else
11303     neg_op0 = GEN_INT (- INTVAL (operands[1]));
11304
11305   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
11306                                        : gen_movdi_di_update_stack))
11307                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
11308                          chain));
11309   /* Since we didn't use gen_frame_mem to generate the MEM, grab
11310      it now and set the alias set/attributes. The above gen_*_update
11311      calls will generate a PARALLEL with the MEM set being the first
11312      operation. */
11313   par = PATTERN (insn);
11314   gcc_assert (GET_CODE (par) == PARALLEL);
11315   set = XVECEXP (par, 0, 0);
11316   gcc_assert (GET_CODE (set) == SET);
11317   mem = SET_DEST (set);
11318   gcc_assert (MEM_P (mem));
11319   MEM_NOTRAP_P (mem) = 1;
11320   set_mem_alias_set (mem, get_frame_alias_set ());
11321
11322   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
11323   DONE;
11324 }")
11325
11326 ;; These patterns say how to save and restore the stack pointer.  We need not
11327 ;; save the stack pointer at function level since we are careful to
11328 ;; preserve the backchain.  At block level, we have to restore the backchain
11329 ;; when we restore the stack pointer.
11330 ;;
11331 ;; For nonlocal gotos, we must save both the stack pointer and its
11332 ;; backchain and restore both.  Note that in the nonlocal case, the
11333 ;; save area is a memory location.
11334
11335 (define_expand "save_stack_function"
11336   [(match_operand 0 "any_operand" "")
11337    (match_operand 1 "any_operand" "")]
11338   ""
11339   "DONE;")
11340
11341 (define_expand "restore_stack_function"
11342   [(match_operand 0 "any_operand" "")
11343    (match_operand 1 "any_operand" "")]
11344   ""
11345   "DONE;")
11346
11347 ;; Adjust stack pointer (op0) to a new value (op1).
11348 ;; First copy old stack backchain to new location, and ensure that the
11349 ;; scheduler won't reorder the sp assignment before the backchain write.
11350 (define_expand "restore_stack_block"
11351   [(set (match_dup 2) (match_dup 3))
11352    (set (match_dup 4) (match_dup 2))
11353    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
11354    (set (match_operand 0 "register_operand" "")
11355         (match_operand 1 "register_operand" ""))]
11356   ""
11357   "
11358 {
11359   operands[1] = force_reg (Pmode, operands[1]);
11360   operands[2] = gen_reg_rtx (Pmode);
11361   operands[3] = gen_frame_mem (Pmode, operands[0]);
11362   operands[4] = gen_frame_mem (Pmode, operands[1]);
11363   operands[5] = gen_frame_mem (BLKmode, operands[0]);
11364 }")
11365
11366 (define_expand "save_stack_nonlocal"
11367   [(set (match_dup 3) (match_dup 4))
11368    (set (match_operand 0 "memory_operand" "") (match_dup 3))
11369    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
11370   ""
11371   "
11372 {
11373   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11374
11375   /* Copy the backchain to the first word, sp to the second.  */
11376   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
11377   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
11378   operands[3] = gen_reg_rtx (Pmode);
11379   operands[4] = gen_frame_mem (Pmode, operands[1]);
11380 }")
11381
11382 (define_expand "restore_stack_nonlocal"
11383   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
11384    (set (match_dup 3) (match_dup 4))
11385    (set (match_dup 5) (match_dup 2))
11386    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
11387    (set (match_operand 0 "register_operand" "") (match_dup 3))]
11388   ""
11389   "
11390 {
11391   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11392
11393   /* Restore the backchain from the first word, sp from the second.  */
11394   operands[2] = gen_reg_rtx (Pmode);
11395   operands[3] = gen_reg_rtx (Pmode);
11396   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
11397   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
11398   operands[5] = gen_frame_mem (Pmode, operands[3]);
11399   operands[6] = gen_frame_mem (BLKmode, operands[0]);
11400 }")
11401 \f
11402 ;; TOC register handling.
11403
11404 ;; Code to initialize the TOC register...
11405
11406 (define_insn "load_toc_aix_si"
11407   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11408                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
11409               (use (reg:SI 2))])]
11410   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
11411   "*
11412 {
11413   char buf[30];
11414   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11415   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11416   operands[2] = gen_rtx_REG (Pmode, 2);
11417   return \"{l|lwz} %0,%1(%2)\";
11418 }"
11419   [(set_attr "type" "load")])
11420
11421 (define_insn "load_toc_aix_di"
11422   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11423                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
11424               (use (reg:DI 2))])]
11425   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
11426   "*
11427 {
11428   char buf[30];
11429 #ifdef TARGET_RELOCATABLE
11430   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
11431                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
11432 #else
11433   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11434 #endif
11435   if (TARGET_ELF)
11436     strcat (buf, \"@toc\");
11437   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11438   operands[2] = gen_rtx_REG (Pmode, 2);
11439   return \"ld %0,%1(%2)\";
11440 }"
11441   [(set_attr "type" "load")])
11442
11443 (define_insn "load_toc_v4_pic_si"
11444   [(set (reg:SI LR_REGNO)
11445         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
11446   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
11447   "bl _GLOBAL_OFFSET_TABLE_@local-4"
11448   [(set_attr "type" "branch")
11449    (set_attr "length" "4")])
11450
11451 (define_insn "load_toc_v4_PIC_1"
11452   [(set (reg:SI LR_REGNO)
11453         (match_operand:SI 0 "immediate_operand" "s"))
11454    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11455   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
11456    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11457   "bcl 20,31,%0\\n%0:"
11458   [(set_attr "type" "branch")
11459    (set_attr "length" "4")])
11460
11461 (define_insn "load_toc_v4_PIC_1b"
11462   [(set (reg:SI LR_REGNO)
11463         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11464                     (label_ref (match_operand 1 "" ""))]
11465                 UNSPEC_TOCPTR))
11466    (match_dup 1)]
11467   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11468   "bcl 20,31,$+8\;.long %0-$"
11469   [(set_attr "type" "branch")
11470    (set_attr "length" "8")])
11471
11472 (define_insn "load_toc_v4_PIC_2"
11473   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11474         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11475                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
11476                              (match_operand:SI 3 "immediate_operand" "s")))))]
11477   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11478   "{l|lwz} %0,%2-%3(%1)"
11479   [(set_attr "type" "load")])
11480
11481 (define_insn "load_toc_v4_PIC_3b"
11482   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
11483         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
11484                  (high:SI
11485                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11486                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
11487   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
11488   "{cau|addis} %0,%1,%2-%3@ha")
11489
11490 (define_insn "load_toc_v4_PIC_3c"
11491   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11492         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11493                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11494                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
11495   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
11496   "{cal %0,%2-%3@l(%1)|addi %0,%1,%2-%3@l}")
11497
11498 ;; If the TOC is shared over a translation unit, as happens with all
11499 ;; the kinds of PIC that we support, we need to restore the TOC
11500 ;; pointer only when jumping over units of translation.
11501 ;; On Darwin, we need to reload the picbase.
11502
11503 (define_expand "builtin_setjmp_receiver"
11504   [(use (label_ref (match_operand 0 "" "")))]
11505   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11506    || (TARGET_TOC && TARGET_MINIMAL_TOC)
11507    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
11508   "
11509 {
11510 #if TARGET_MACHO
11511   if (DEFAULT_ABI == ABI_DARWIN)
11512     {
11513       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
11514       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
11515       rtx tmplabrtx;
11516       char tmplab[20];
11517
11518       crtl->uses_pic_offset_table = 1;
11519       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
11520                                   CODE_LABEL_NUMBER (operands[0]));
11521       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
11522
11523       emit_insn (gen_load_macho_picbase (tmplabrtx));
11524       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
11525       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
11526     }
11527   else
11528 #endif
11529     rs6000_emit_load_toc_table (FALSE);
11530   DONE;
11531 }")
11532
11533 ;; Elf specific ways of loading addresses for non-PIC code.
11534 ;; The output of this could be r0, but we make a very strong
11535 ;; preference for a base register because it will usually
11536 ;; be needed there.
11537 (define_insn "elf_high"
11538   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
11539         (high:SI (match_operand 1 "" "")))]
11540   "TARGET_ELF && ! TARGET_64BIT"
11541   "{liu|lis} %0,%1@ha")
11542
11543 (define_insn "elf_low"
11544   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11545         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
11546                    (match_operand 2 "" "")))]
11547    "TARGET_ELF && ! TARGET_64BIT"
11548    "@
11549     {cal|la} %0,%2@l(%1)
11550     {ai|addic} %0,%1,%K2")
11551 \f
11552 ;; A function pointer under AIX is a pointer to a data area whose first word
11553 ;; contains the actual address of the function, whose second word contains a
11554 ;; pointer to its TOC, and whose third word contains a value to place in the
11555 ;; static chain register (r11).  Note that if we load the static chain, our
11556 ;; "trampoline" need not have any executable code.
11557
11558 (define_expand "call_indirect_aix32"
11559   [(set (match_dup 2)
11560         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
11561    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
11562         (reg:SI 2))
11563    (set (reg:SI 11)
11564         (mem:SI (plus:SI (match_dup 0)
11565                          (const_int 8))))
11566    (parallel [(call (mem:SI (match_dup 2))
11567                     (match_operand 1 "" ""))
11568               (use (mem:SI (plus:SI (match_dup 0) (const_int 4))))
11569               (use (reg:SI 11))
11570               (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11571               (clobber (reg:SI LR_REGNO))])]
11572   "TARGET_32BIT"
11573   "
11574 { operands[2] = gen_reg_rtx (SImode); }")
11575
11576 (define_expand "call_indirect_aix64"
11577   [(set (match_dup 2)
11578         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
11579    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
11580         (reg:DI 2))
11581    (set (reg:DI 11)
11582         (mem:DI (plus:DI (match_dup 0)
11583                          (const_int 16))))
11584    (parallel [(call (mem:SI (match_dup 2))
11585                     (match_operand 1 "" ""))
11586               (use (mem:DI (plus:DI (match_dup 0) (const_int 8))))
11587               (use (reg:DI 11))
11588               (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11589               (clobber (reg:SI LR_REGNO))])]
11590   "TARGET_64BIT"
11591   "
11592 { operands[2] = gen_reg_rtx (DImode); }")
11593
11594 (define_expand "call_value_indirect_aix32"
11595   [(set (match_dup 3)
11596         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11597    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
11598         (reg:SI 2))
11599    (set (reg:SI 11)
11600         (mem:SI (plus:SI (match_dup 1)
11601                          (const_int 8))))
11602    (parallel [(set (match_operand 0 "" "")
11603                    (call (mem:SI (match_dup 3))
11604                          (match_operand 2 "" "")))
11605               (use (mem:SI (plus:SI (match_dup 1) (const_int 4))))
11606               (use (reg:SI 11))
11607               (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11608               (clobber (reg:SI LR_REGNO))])]
11609   "TARGET_32BIT"
11610   "
11611 { operands[3] = gen_reg_rtx (SImode); }")
11612
11613 (define_expand "call_value_indirect_aix64"
11614   [(set (match_dup 3)
11615         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11616    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
11617         (reg:DI 2))
11618    (set (reg:DI 11)
11619         (mem:DI (plus:DI (match_dup 1)
11620                          (const_int 16))))
11621    (parallel [(set (match_operand 0 "" "")
11622                    (call (mem:SI (match_dup 3))
11623                          (match_operand 2 "" "")))
11624               (use (mem:DI (plus:DI (match_dup 1) (const_int 8))))
11625               (use (reg:DI 11))
11626               (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11627               (clobber (reg:SI LR_REGNO))])]
11628   "TARGET_64BIT"
11629   "
11630 { operands[3] = gen_reg_rtx (DImode); }")
11631
11632 ;; Now the definitions for the call and call_value insns
11633 (define_expand "call"
11634   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11635                     (match_operand 1 "" ""))
11636               (use (match_operand 2 "" ""))
11637               (clobber (reg:SI LR_REGNO))])]
11638   ""
11639   "
11640 {
11641 #if TARGET_MACHO
11642   if (MACHOPIC_INDIRECT)
11643     operands[0] = machopic_indirect_call_target (operands[0]);
11644 #endif
11645
11646   gcc_assert (GET_CODE (operands[0]) == MEM);
11647   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11648
11649   operands[0] = XEXP (operands[0], 0);
11650
11651   if (GET_CODE (operands[0]) != SYMBOL_REF
11652       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
11653       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
11654     {
11655       if (INTVAL (operands[2]) & CALL_LONG)
11656         operands[0] = rs6000_longcall_ref (operands[0]);
11657
11658       switch (DEFAULT_ABI)
11659         {
11660         case ABI_V4:
11661         case ABI_DARWIN:
11662           operands[0] = force_reg (Pmode, operands[0]);
11663           break;
11664
11665         case ABI_AIX:
11666           /* AIX function pointers are really pointers to a three word
11667              area.  */
11668           emit_call_insn (TARGET_32BIT
11669                           ? gen_call_indirect_aix32 (force_reg (SImode,
11670                                                                 operands[0]),
11671                                                      operands[1])
11672                           : gen_call_indirect_aix64 (force_reg (DImode,
11673                                                                 operands[0]),
11674                                                      operands[1]));
11675           DONE;
11676
11677         default:
11678           gcc_unreachable ();
11679         }
11680     }
11681 }")
11682
11683 (define_expand "call_value"
11684   [(parallel [(set (match_operand 0 "" "")
11685                    (call (mem:SI (match_operand 1 "address_operand" ""))
11686                          (match_operand 2 "" "")))
11687               (use (match_operand 3 "" ""))
11688               (clobber (reg:SI LR_REGNO))])]
11689   ""
11690   "
11691 {
11692 #if TARGET_MACHO
11693   if (MACHOPIC_INDIRECT)
11694     operands[1] = machopic_indirect_call_target (operands[1]);
11695 #endif
11696
11697   gcc_assert (GET_CODE (operands[1]) == MEM);
11698   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11699
11700   operands[1] = XEXP (operands[1], 0);
11701
11702   if (GET_CODE (operands[1]) != SYMBOL_REF
11703       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
11704       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
11705     {
11706       if (INTVAL (operands[3]) & CALL_LONG)
11707         operands[1] = rs6000_longcall_ref (operands[1]);
11708
11709       switch (DEFAULT_ABI)
11710         {
11711         case ABI_V4:
11712         case ABI_DARWIN:
11713           operands[1] = force_reg (Pmode, operands[1]);
11714           break;
11715
11716         case ABI_AIX:
11717           /* AIX function pointers are really pointers to a three word
11718              area.  */
11719           emit_call_insn (TARGET_32BIT
11720                           ? gen_call_value_indirect_aix32 (operands[0],
11721                                                            force_reg (SImode,
11722                                                                       operands[1]),
11723                                                            operands[2])
11724                           : gen_call_value_indirect_aix64 (operands[0],
11725                                                            force_reg (DImode,
11726                                                                       operands[1]),
11727                                                            operands[2]));
11728           DONE;
11729
11730         default:
11731           gcc_unreachable ();
11732         }
11733     }
11734 }")
11735
11736 ;; Call to function in current module.  No TOC pointer reload needed.
11737 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11738 ;; either the function was not prototyped, or it was prototyped as a
11739 ;; variable argument function.  It is > 0 if FP registers were passed
11740 ;; and < 0 if they were not.
11741
11742 (define_insn "*call_local32"
11743   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11744          (match_operand 1 "" "g,g"))
11745    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11746    (clobber (reg:SI LR_REGNO))]
11747   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11748   "*
11749 {
11750   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11751     output_asm_insn (\"crxor 6,6,6\", operands);
11752
11753   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11754     output_asm_insn (\"creqv 6,6,6\", operands);
11755
11756   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11757 }"
11758   [(set_attr "type" "branch")
11759    (set_attr "length" "4,8")])
11760
11761 (define_insn "*call_local64"
11762   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11763          (match_operand 1 "" "g,g"))
11764    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11765    (clobber (reg:SI LR_REGNO))]
11766   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11767   "*
11768 {
11769   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11770     output_asm_insn (\"crxor 6,6,6\", operands);
11771
11772   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11773     output_asm_insn (\"creqv 6,6,6\", operands);
11774
11775   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11776 }"
11777   [(set_attr "type" "branch")
11778    (set_attr "length" "4,8")])
11779
11780 (define_insn "*call_value_local32"
11781   [(set (match_operand 0 "" "")
11782         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11783               (match_operand 2 "" "g,g")))
11784    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11785    (clobber (reg:SI LR_REGNO))]
11786   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11787   "*
11788 {
11789   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11790     output_asm_insn (\"crxor 6,6,6\", operands);
11791
11792   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11793     output_asm_insn (\"creqv 6,6,6\", operands);
11794
11795   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11796 }"
11797   [(set_attr "type" "branch")
11798    (set_attr "length" "4,8")])
11799
11800
11801 (define_insn "*call_value_local64"
11802   [(set (match_operand 0 "" "")
11803         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11804               (match_operand 2 "" "g,g")))
11805    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11806    (clobber (reg:SI LR_REGNO))]
11807   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11808   "*
11809 {
11810   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11811     output_asm_insn (\"crxor 6,6,6\", operands);
11812
11813   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11814     output_asm_insn (\"creqv 6,6,6\", operands);
11815
11816   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11817 }"
11818   [(set_attr "type" "branch")
11819    (set_attr "length" "4,8")])
11820
11821 ;; Call to function which may be in another module.  Restore the TOC
11822 ;; pointer (r2) after the call unless this is System V.
11823 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11824 ;; either the function was not prototyped, or it was prototyped as a
11825 ;; variable argument function.  It is > 0 if FP registers were passed
11826 ;; and < 0 if they were not.
11827
11828 (define_insn_and_split "*call_indirect_nonlocal_aix32_internal"
11829   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
11830                  (match_operand 1 "" "g,g"))
11831    (use (mem:SI (plus:SI (match_operand:SI 2 "register_operand" "b,b") (const_int 4))))
11832    (use (reg:SI 11))
11833    (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11834    (clobber (reg:SI LR_REGNO))]
11835   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
11836   "#"
11837   "&& reload_completed"
11838   [(set (reg:SI 2)
11839         (mem:SI (plus:SI (match_dup 2) (const_int 4))))
11840    (parallel [(call (mem:SI (match_dup 0))
11841                     (match_dup 1))
11842               (use (reg:SI 2))
11843               (use (reg:SI 11))
11844               (set (reg:SI 2)
11845                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11846               (clobber (reg:SI LR_REGNO))])]
11847   ""
11848   [(set_attr "type" "jmpreg")
11849    (set_attr "length" "12")])
11850
11851 (define_insn "*call_indirect_nonlocal_aix32"
11852   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
11853          (match_operand 1 "" "g,g"))
11854    (use (reg:SI 2))
11855    (use (reg:SI 11))
11856    (set (reg:SI 2)
11857         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11858    (clobber (reg:SI LR_REGNO))]
11859   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
11860   "b%T0l\;{l|lwz} 2,20(1)"
11861   [(set_attr "type" "jmpreg")
11862    (set_attr "length" "8")])
11863
11864 (define_insn "*call_nonlocal_aix32"
11865   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
11866          (match_operand 1 "" "g"))
11867    (use (match_operand:SI 2 "immediate_operand" "O"))
11868    (clobber (reg:SI LR_REGNO))]
11869   "TARGET_32BIT
11870    && DEFAULT_ABI == ABI_AIX
11871    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11872   "bl %z0\;%."
11873   [(set_attr "type" "branch")
11874    (set_attr "length" "8")])
11875    
11876 (define_insn_and_split "*call_indirect_nonlocal_aix64_internal"
11877   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
11878                  (match_operand 1 "" "g,g"))
11879    (use (mem:DI (plus:DI (match_operand:DI 2 "register_operand" "b,b")
11880                          (const_int 8))))
11881    (use (reg:DI 11))
11882    (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11883    (clobber (reg:SI LR_REGNO))]
11884   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
11885   "#"
11886   "&& reload_completed"
11887   [(set (reg:DI 2)
11888         (mem:DI (plus:DI (match_dup 2) (const_int 8))))
11889    (parallel [(call (mem:SI (match_dup 0))
11890                     (match_dup 1))
11891               (use (reg:DI 2))
11892               (use (reg:DI 11))
11893               (set (reg:DI 2)
11894                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11895               (clobber (reg:SI LR_REGNO))])]
11896   ""
11897   [(set_attr "type" "jmpreg")
11898    (set_attr "length" "12")])
11899
11900 (define_insn "*call_indirect_nonlocal_aix64"
11901   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
11902          (match_operand 1 "" "g,g"))
11903    (use (reg:DI 2))
11904    (use (reg:DI 11))
11905    (set (reg:DI 2)
11906         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11907    (clobber (reg:SI LR_REGNO))]
11908   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
11909   "b%T0l\;ld 2,40(1)"
11910   [(set_attr "type" "jmpreg")
11911    (set_attr "length" "8")])
11912
11913 (define_insn "*call_nonlocal_aix64"
11914   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
11915          (match_operand 1 "" "g"))
11916    (use (match_operand:SI 2 "immediate_operand" "O"))
11917    (clobber (reg:SI LR_REGNO))]
11918   "TARGET_64BIT
11919    && DEFAULT_ABI == ABI_AIX
11920    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11921   "bl %z0\;%."
11922   [(set_attr "type" "branch")
11923    (set_attr "length" "8")])
11924
11925 (define_insn_and_split "*call_value_indirect_nonlocal_aix32_internal"
11926   [(set (match_operand 0 "" "")
11927         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
11928                       (match_operand 2 "" "g,g")))
11929         (use (mem:SI (plus:SI (match_operand:SI 3 "register_operand" "b,b")
11930                               (const_int 4))))
11931         (use (reg:SI 11))
11932         (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11933         (clobber (reg:SI LR_REGNO))]
11934   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
11935   "#"
11936   "&& reload_completed"
11937   [(set (reg:SI 2)
11938         (mem:SI (plus:SI (match_dup 3) (const_int 4))))
11939    (parallel [(set (match_dup 0) (call (mem:SI (match_dup 1))
11940                                        (match_dup 2)))
11941               (use (reg:SI 2))
11942               (use (reg:SI 11))
11943               (set (reg:SI 2)
11944                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11945               (clobber (reg:SI LR_REGNO))])]
11946   ""
11947   [(set_attr "type" "jmpreg")
11948    (set_attr "length" "12")])
11949
11950 (define_insn "*call_value_indirect_nonlocal_aix32"
11951   [(set (match_operand 0 "" "")
11952         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
11953               (match_operand 2 "" "g,g")))
11954    (use (reg:SI 2))
11955    (use (reg:SI 11))
11956    (set (reg:SI 2)
11957         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11958    (clobber (reg:SI LR_REGNO))]
11959   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
11960   "b%T1l\;{l|lwz} 2,20(1)"
11961   [(set_attr "type" "jmpreg")
11962    (set_attr "length" "8")])
11963
11964 (define_insn "*call_value_nonlocal_aix32"
11965   [(set (match_operand 0 "" "")
11966         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
11967               (match_operand 2 "" "g")))
11968    (use (match_operand:SI 3 "immediate_operand" "O"))
11969    (clobber (reg:SI LR_REGNO))]
11970   "TARGET_32BIT
11971    && DEFAULT_ABI == ABI_AIX
11972    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11973   "bl %z1\;%."
11974   [(set_attr "type" "branch")
11975    (set_attr "length" "8")])
11976
11977 (define_insn_and_split "*call_value_indirect_nonlocal_aix64_internal"
11978   [(set (match_operand 0 "" "")
11979         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
11980                       (match_operand 2 "" "g,g")))
11981         (use (mem:DI (plus:DI (match_operand:DI 3 "register_operand" "b,b")
11982                               (const_int 8))))
11983         (use (reg:DI 11))
11984         (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11985         (clobber (reg:SI LR_REGNO))]
11986   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
11987   "#"
11988   "&& reload_completed"
11989   [(set (reg:DI 2)
11990         (mem:DI (plus:DI (match_dup 3) (const_int 8))))
11991    (parallel [(set (match_dup 0) (call (mem:SI (match_dup 1))
11992                                        (match_dup 2)))
11993               (use (reg:DI 2))
11994               (use (reg:DI 11))
11995               (set (reg:DI 2)
11996                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11997               (clobber (reg:SI LR_REGNO))])]
11998   ""
11999   [(set_attr "type" "jmpreg")
12000    (set_attr "length" "12")])
12001
12002 (define_insn "*call_value_indirect_nonlocal_aix64"
12003   [(set (match_operand 0 "" "")
12004         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
12005               (match_operand 2 "" "g,g")))
12006    (use (reg:DI 2))
12007    (use (reg:DI 11))
12008    (set (reg:DI 2)
12009         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12010    (clobber (reg:SI LR_REGNO))]
12011   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12012   "b%T1l\;ld 2,40(1)"
12013   [(set_attr "type" "jmpreg")
12014    (set_attr "length" "8")])
12015
12016 (define_insn "*call_value_nonlocal_aix64"
12017   [(set (match_operand 0 "" "")
12018         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12019               (match_operand 2 "" "g")))
12020    (use (match_operand:SI 3 "immediate_operand" "O"))
12021    (clobber (reg:SI LR_REGNO))]
12022   "TARGET_64BIT
12023    && DEFAULT_ABI == ABI_AIX
12024    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12025   "bl %z1\;%."
12026   [(set_attr "type" "branch")
12027    (set_attr "length" "8")])
12028
12029 ;; A function pointer under System V is just a normal pointer
12030 ;; operands[0] is the function pointer
12031 ;; operands[1] is the stack size to clean up
12032 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12033 ;; which indicates how to set cr1
12034
12035 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12036   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12037          (match_operand 1 "" "g,g,g,g"))
12038    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12039    (clobber (reg:SI LR_REGNO))]
12040   "DEFAULT_ABI == ABI_V4
12041    || DEFAULT_ABI == ABI_DARWIN"
12042 {
12043   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12044     output_asm_insn ("crxor 6,6,6", operands);
12045
12046   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12047     output_asm_insn ("creqv 6,6,6", operands);
12048
12049   return "b%T0l";
12050 }
12051   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12052    (set_attr "length" "4,4,8,8")])
12053
12054 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12055   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12056          (match_operand 1 "" "g,g"))
12057    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12058    (clobber (reg:SI LR_REGNO))]
12059   "(DEFAULT_ABI == ABI_DARWIN
12060    || (DEFAULT_ABI == ABI_V4
12061        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12062 {
12063   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12064     output_asm_insn ("crxor 6,6,6", operands);
12065
12066   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12067     output_asm_insn ("creqv 6,6,6", operands);
12068
12069 #if TARGET_MACHO
12070   return output_call(insn, operands, 0, 2);
12071 #else
12072   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12073     {
12074       gcc_assert (!TARGET_SECURE_PLT);
12075       return "bl %z0@plt";
12076     }
12077   else
12078     return "bl %z0";
12079 #endif
12080 }
12081   "DEFAULT_ABI == ABI_V4
12082    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12083    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12084   [(parallel [(call (mem:SI (match_dup 0))
12085                     (match_dup 1))
12086               (use (match_dup 2))
12087               (use (match_dup 3))
12088               (clobber (reg:SI LR_REGNO))])]
12089 {
12090   operands[3] = pic_offset_table_rtx;
12091 }
12092   [(set_attr "type" "branch,branch")
12093    (set_attr "length" "4,8")])
12094
12095 (define_insn "*call_nonlocal_sysv_secure<mode>"
12096   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12097          (match_operand 1 "" "g,g"))
12098    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12099    (use (match_operand:SI 3 "register_operand" "r,r"))
12100    (clobber (reg:SI LR_REGNO))]
12101   "(DEFAULT_ABI == ABI_V4
12102     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12103     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
12104 {
12105   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12106     output_asm_insn ("crxor 6,6,6", operands);
12107
12108   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12109     output_asm_insn ("creqv 6,6,6", operands);
12110
12111   if (flag_pic == 2)
12112     /* The magic 32768 offset here and in the other sysv call insns
12113        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12114        See sysv4.h:toc_section.  */
12115     return "bl %z0+32768@plt";
12116   else
12117     return "bl %z0@plt";
12118 }
12119   [(set_attr "type" "branch,branch")
12120    (set_attr "length" "4,8")])
12121
12122 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12123   [(set (match_operand 0 "" "")
12124         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12125               (match_operand 2 "" "g,g,g,g")))
12126    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12127    (clobber (reg:SI LR_REGNO))]
12128   "DEFAULT_ABI == ABI_V4
12129    || DEFAULT_ABI == ABI_DARWIN"
12130 {
12131   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12132     output_asm_insn ("crxor 6,6,6", operands);
12133
12134   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12135     output_asm_insn ("creqv 6,6,6", operands);
12136
12137   return "b%T1l";
12138 }
12139   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12140    (set_attr "length" "4,4,8,8")])
12141
12142 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12143   [(set (match_operand 0 "" "")
12144         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12145               (match_operand 2 "" "g,g")))
12146    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12147    (clobber (reg:SI LR_REGNO))]
12148   "(DEFAULT_ABI == ABI_DARWIN
12149    || (DEFAULT_ABI == ABI_V4
12150        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12151 {
12152   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12153     output_asm_insn ("crxor 6,6,6", operands);
12154
12155   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12156     output_asm_insn ("creqv 6,6,6", operands);
12157
12158 #if TARGET_MACHO
12159   return output_call(insn, operands, 1, 3);
12160 #else
12161   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12162     {
12163       gcc_assert (!TARGET_SECURE_PLT);
12164       return "bl %z1@plt";
12165     }
12166   else
12167     return "bl %z1";
12168 #endif
12169 }
12170   "DEFAULT_ABI == ABI_V4
12171    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12172    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12173   [(parallel [(set (match_dup 0)
12174                    (call (mem:SI (match_dup 1))
12175                          (match_dup 2)))
12176               (use (match_dup 3))
12177               (use (match_dup 4))
12178               (clobber (reg:SI LR_REGNO))])]
12179 {
12180   operands[4] = pic_offset_table_rtx;
12181 }
12182   [(set_attr "type" "branch,branch")
12183    (set_attr "length" "4,8")])
12184
12185 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12186   [(set (match_operand 0 "" "")
12187         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12188               (match_operand 2 "" "g,g")))
12189    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12190    (use (match_operand:SI 4 "register_operand" "r,r"))
12191    (clobber (reg:SI LR_REGNO))]
12192   "(DEFAULT_ABI == ABI_V4
12193     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12194     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12195 {
12196   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12197     output_asm_insn ("crxor 6,6,6", operands);
12198
12199   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12200     output_asm_insn ("creqv 6,6,6", operands);
12201
12202   if (flag_pic == 2)
12203     return "bl %z1+32768@plt";
12204   else
12205     return "bl %z1@plt";
12206 }
12207   [(set_attr "type" "branch,branch")
12208    (set_attr "length" "4,8")])
12209
12210 ;; Call subroutine returning any type.
12211 (define_expand "untyped_call"
12212   [(parallel [(call (match_operand 0 "" "")
12213                     (const_int 0))
12214               (match_operand 1 "" "")
12215               (match_operand 2 "" "")])]
12216   ""
12217   "
12218 {
12219   int i;
12220
12221   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12222
12223   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12224     {
12225       rtx set = XVECEXP (operands[2], 0, i);
12226       emit_move_insn (SET_DEST (set), SET_SRC (set));
12227     }
12228
12229   /* The optimizer does not know that the call sets the function value
12230      registers we stored in the result block.  We avoid problems by
12231      claiming that all hard registers are used and clobbered at this
12232      point.  */
12233   emit_insn (gen_blockage ());
12234
12235   DONE;
12236 }")
12237
12238 ;; sibling call patterns
12239 (define_expand "sibcall"
12240   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12241                     (match_operand 1 "" ""))
12242               (use (match_operand 2 "" ""))
12243               (use (reg:SI LR_REGNO))
12244               (return)])]
12245   ""
12246   "
12247 {
12248 #if TARGET_MACHO
12249   if (MACHOPIC_INDIRECT)
12250     operands[0] = machopic_indirect_call_target (operands[0]);
12251 #endif
12252
12253   gcc_assert (GET_CODE (operands[0]) == MEM);
12254   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12255
12256   operands[0] = XEXP (operands[0], 0);
12257 }")
12258
12259 ;; this and similar patterns must be marked as using LR, otherwise
12260 ;; dataflow will try to delete the store into it.  This is true
12261 ;; even when the actual reg to jump to is in CTR, when LR was
12262 ;; saved and restored around the PIC-setting BCL.
12263 (define_insn "*sibcall_local32"
12264   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12265          (match_operand 1 "" "g,g"))
12266    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12267    (use (reg:SI LR_REGNO))
12268    (return)]
12269   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12270   "*
12271 {
12272   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12273     output_asm_insn (\"crxor 6,6,6\", operands);
12274
12275   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12276     output_asm_insn (\"creqv 6,6,6\", operands);
12277
12278   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12279 }"
12280   [(set_attr "type" "branch")
12281    (set_attr "length" "4,8")])
12282
12283 (define_insn "*sibcall_local64"
12284   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12285          (match_operand 1 "" "g,g"))
12286    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12287    (use (reg:SI LR_REGNO))
12288    (return)]
12289   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12290   "*
12291 {
12292   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12293     output_asm_insn (\"crxor 6,6,6\", operands);
12294
12295   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12296     output_asm_insn (\"creqv 6,6,6\", operands);
12297
12298   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12299 }"
12300   [(set_attr "type" "branch")
12301    (set_attr "length" "4,8")])
12302
12303 (define_insn "*sibcall_value_local32"
12304   [(set (match_operand 0 "" "")
12305         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12306               (match_operand 2 "" "g,g")))
12307    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12308    (use (reg:SI LR_REGNO))
12309    (return)]
12310   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12311   "*
12312 {
12313   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12314     output_asm_insn (\"crxor 6,6,6\", operands);
12315
12316   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12317     output_asm_insn (\"creqv 6,6,6\", operands);
12318
12319   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12320 }"
12321   [(set_attr "type" "branch")
12322    (set_attr "length" "4,8")])
12323
12324
12325 (define_insn "*sibcall_value_local64"
12326   [(set (match_operand 0 "" "")
12327         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12328               (match_operand 2 "" "g,g")))
12329    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12330    (use (reg:SI LR_REGNO))
12331    (return)]
12332   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12333   "*
12334 {
12335   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12336     output_asm_insn (\"crxor 6,6,6\", operands);
12337
12338   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12339     output_asm_insn (\"creqv 6,6,6\", operands);
12340
12341   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12342 }"
12343   [(set_attr "type" "branch")
12344    (set_attr "length" "4,8")])
12345
12346 (define_insn "*sibcall_nonlocal_aix32"
12347   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
12348          (match_operand 1 "" "g"))
12349    (use (match_operand:SI 2 "immediate_operand" "O"))
12350    (use (reg:SI LR_REGNO))
12351    (return)]
12352   "TARGET_32BIT
12353    && DEFAULT_ABI == ABI_AIX
12354    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12355   "b %z0"
12356   [(set_attr "type" "branch")
12357    (set_attr "length" "4")])
12358
12359 (define_insn "*sibcall_nonlocal_aix64"
12360   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
12361          (match_operand 1 "" "g"))
12362    (use (match_operand:SI 2 "immediate_operand" "O"))
12363    (use (reg:SI LR_REGNO))
12364    (return)]
12365   "TARGET_64BIT
12366    && DEFAULT_ABI == ABI_AIX
12367    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12368   "b %z0"
12369   [(set_attr "type" "branch")
12370    (set_attr "length" "4")])
12371
12372 (define_insn "*sibcall_value_nonlocal_aix32"
12373   [(set (match_operand 0 "" "")
12374         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12375               (match_operand 2 "" "g")))
12376    (use (match_operand:SI 3 "immediate_operand" "O"))
12377    (use (reg:SI LR_REGNO))
12378    (return)]
12379   "TARGET_32BIT
12380    && DEFAULT_ABI == ABI_AIX
12381    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12382   "b %z1"
12383   [(set_attr "type" "branch")
12384    (set_attr "length" "4")])
12385
12386 (define_insn "*sibcall_value_nonlocal_aix64"
12387   [(set (match_operand 0 "" "")
12388         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12389               (match_operand 2 "" "g")))
12390    (use (match_operand:SI 3 "immediate_operand" "O"))
12391    (use (reg:SI LR_REGNO))
12392    (return)]
12393   "TARGET_64BIT
12394    && DEFAULT_ABI == ABI_AIX
12395    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12396   "b %z1"
12397   [(set_attr "type" "branch")
12398    (set_attr "length" "4")])
12399
12400 (define_insn "*sibcall_nonlocal_sysv<mode>"
12401   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12402          (match_operand 1 "" ""))
12403    (use (match_operand 2 "immediate_operand" "O,n"))
12404    (use (reg:SI LR_REGNO))
12405    (return)]
12406   "(DEFAULT_ABI == ABI_DARWIN
12407      || DEFAULT_ABI == ABI_V4)
12408    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12409   "*
12410 {
12411   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12412     output_asm_insn (\"crxor 6,6,6\", operands);
12413
12414   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12415     output_asm_insn (\"creqv 6,6,6\", operands);
12416
12417   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12418     {
12419       gcc_assert (!TARGET_SECURE_PLT);
12420       return \"b %z0@plt\";
12421     }
12422   else
12423     return \"b %z0\";
12424 }"
12425   [(set_attr "type" "branch,branch")
12426    (set_attr "length" "4,8")])
12427
12428 (define_expand "sibcall_value"
12429   [(parallel [(set (match_operand 0 "register_operand" "")
12430                 (call (mem:SI (match_operand 1 "address_operand" ""))
12431                       (match_operand 2 "" "")))
12432               (use (match_operand 3 "" ""))
12433               (use (reg:SI LR_REGNO))
12434               (return)])]
12435   ""
12436   "
12437 {
12438 #if TARGET_MACHO
12439   if (MACHOPIC_INDIRECT)
12440     operands[1] = machopic_indirect_call_target (operands[1]);
12441 #endif
12442
12443   gcc_assert (GET_CODE (operands[1]) == MEM);
12444   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12445
12446   operands[1] = XEXP (operands[1], 0);
12447 }")
12448
12449 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
12450   [(set (match_operand 0 "" "")
12451         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12452               (match_operand 2 "" "")))
12453    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12454    (use (reg:SI LR_REGNO))
12455    (return)]
12456   "(DEFAULT_ABI == ABI_DARWIN
12457        || DEFAULT_ABI == ABI_V4)
12458    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12459   "*
12460 {
12461   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12462     output_asm_insn (\"crxor 6,6,6\", operands);
12463
12464   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12465     output_asm_insn (\"creqv 6,6,6\", operands);
12466
12467   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12468     {
12469       gcc_assert (!TARGET_SECURE_PLT);
12470       return \"b %z1@plt\";
12471     }
12472   else
12473     return \"b %z1\";
12474 }"
12475   [(set_attr "type" "branch,branch")
12476    (set_attr "length" "4,8")])
12477
12478 (define_expand "sibcall_epilogue"
12479   [(use (const_int 0))]
12480   "TARGET_SCHED_PROLOG"
12481   "
12482 {
12483       rs6000_emit_epilogue (TRUE);
12484       DONE;
12485 }")
12486
12487 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12488 ;; all of memory.  This blocks insns from being moved across this point.
12489
12490 (define_insn "blockage"
12491   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
12492   ""
12493   "")
12494
12495 (define_insn "probe_stack"
12496   [(set (match_operand 0 "memory_operand" "=m")
12497         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
12498   ""
12499   "{st%U0%X0|stw%U0%X0} 0,%0"
12500   [(set_attr "type" "store")
12501    (set_attr "length" "4")])
12502 \f
12503 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
12504 ;; signed & unsigned, and one type of branch.
12505 ;;
12506 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
12507 ;; insns, and branches.
12508
12509 (define_expand "cbranch<mode>4"
12510   [(use (match_operator 0 "rs6000_cbranch_operator"
12511          [(match_operand:GPR 1 "gpc_reg_operand" "")
12512           (match_operand:GPR 2 "reg_or_short_operand" "")]))
12513    (use (match_operand 3 ""))]
12514   ""
12515   "
12516 {
12517   /* Take care of the possibility that operands[2] might be negative but
12518      this might be a logical operation.  That insn doesn't exist.  */
12519   if (GET_CODE (operands[2]) == CONST_INT
12520       && INTVAL (operands[2]) < 0)
12521     {
12522       operands[2] = force_reg (<MODE>mode, operands[2]);
12523       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
12524                                     GET_MODE (operands[0]),
12525                                     operands[1], operands[2]);
12526    }
12527
12528   rs6000_emit_cbranch (<MODE>mode, operands);
12529   DONE;
12530 }")
12531
12532 (define_expand "cbranch<mode>4"
12533   [(use (match_operator 0 "rs6000_cbranch_operator"
12534          [(match_operand:FP 1 "gpc_reg_operand" "")
12535           (match_operand:FP 2 "gpc_reg_operand" "")]))
12536    (use (match_operand 3 ""))]
12537   ""
12538   "
12539 {
12540   rs6000_emit_cbranch (<MODE>mode, operands);
12541   DONE;
12542 }")
12543
12544 (define_expand "cstore<mode>4"
12545   [(use (match_operator 1 "rs6000_cbranch_operator"
12546          [(match_operand:GPR 2 "gpc_reg_operand" "")
12547           (match_operand:GPR 3 "reg_or_short_operand" "")]))
12548    (clobber (match_operand:SI 0 "register_operand"))]
12549   ""
12550   "
12551 {
12552   /* Take care of the possibility that operands[3] might be negative but
12553      this might be a logical operation.  That insn doesn't exist.  */
12554   if (GET_CODE (operands[3]) == CONST_INT
12555       && INTVAL (operands[3]) < 0)
12556     {
12557       operands[3] = force_reg (<MODE>mode, operands[3]);
12558       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
12559                                     GET_MODE (operands[1]),
12560                                     operands[2], operands[3]);
12561     }
12562
12563   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
12564      For SEQ, likewise, except that comparisons with zero should be done
12565      with an scc insns.  However, due to the order that combine see the
12566      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
12567      the cases we don't want to handle or are best handled by portable
12568      code.  */
12569   if (GET_CODE (operands[1]) == NE)
12570     FAIL;
12571   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
12572        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
12573       && operands[3] == const0_rtx)
12574     FAIL;
12575   rs6000_emit_sCOND (<MODE>mode, operands);
12576   DONE;
12577 }")
12578
12579 (define_expand "cstore<mode>4"
12580   [(use (match_operator 1 "rs6000_cbranch_operator"
12581          [(match_operand:FP 2 "gpc_reg_operand" "")
12582           (match_operand:FP 3 "gpc_reg_operand" "")]))
12583    (clobber (match_operand:SI 0 "register_operand"))]
12584   ""
12585   "
12586 {
12587   rs6000_emit_sCOND (<MODE>mode, operands);
12588   DONE;
12589 }")
12590
12591
12592 (define_expand "stack_protect_set"
12593   [(match_operand 0 "memory_operand" "")
12594    (match_operand 1 "memory_operand" "")]
12595   ""
12596 {
12597 #ifdef TARGET_THREAD_SSP_OFFSET
12598   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12599   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12600   operands[1] = gen_rtx_MEM (Pmode, addr);
12601 #endif
12602   if (TARGET_64BIT)
12603     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
12604   else
12605     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
12606   DONE;
12607 })
12608
12609 (define_insn "stack_protect_setsi"
12610   [(set (match_operand:SI 0 "memory_operand" "=m")
12611         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12612    (set (match_scratch:SI 2 "=&r") (const_int 0))]
12613   "TARGET_32BIT"
12614   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
12615   [(set_attr "type" "three")
12616    (set_attr "length" "12")])
12617
12618 (define_insn "stack_protect_setdi"
12619   [(set (match_operand:DI 0 "memory_operand" "=m")
12620         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12621    (set (match_scratch:DI 2 "=&r") (const_int 0))]
12622   "TARGET_64BIT"
12623   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
12624   [(set_attr "type" "three")
12625    (set_attr "length" "12")])
12626
12627 (define_expand "stack_protect_test"
12628   [(match_operand 0 "memory_operand" "")
12629    (match_operand 1 "memory_operand" "")
12630    (match_operand 2 "" "")]
12631   ""
12632 {
12633   rtx test, op0, op1;
12634 #ifdef TARGET_THREAD_SSP_OFFSET
12635   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12636   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12637   operands[1] = gen_rtx_MEM (Pmode, addr);
12638 #endif
12639   op0 = operands[0];
12640   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
12641   test = gen_rtx_EQ (VOIDmode, op0, op1);
12642   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
12643   DONE;
12644 })
12645
12646 (define_insn "stack_protect_testsi"
12647   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12648         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
12649                       (match_operand:SI 2 "memory_operand" "m,m")]
12650                      UNSPEC_SP_TEST))
12651    (set (match_scratch:SI 4 "=r,r") (const_int 0))
12652    (clobber (match_scratch:SI 3 "=&r,&r"))]
12653   "TARGET_32BIT"
12654   "@
12655    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
12656    {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"
12657   [(set_attr "length" "16,20")])
12658
12659 (define_insn "stack_protect_testdi"
12660   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12661         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
12662                       (match_operand:DI 2 "memory_operand" "m,m")]
12663                      UNSPEC_SP_TEST))
12664    (set (match_scratch:DI 4 "=r,r") (const_int 0))
12665    (clobber (match_scratch:DI 3 "=&r,&r"))]
12666   "TARGET_64BIT"
12667   "@
12668    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
12669    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
12670   [(set_attr "length" "16,20")])
12671
12672 \f
12673 ;; Here are the actual compare insns.
12674 (define_insn "*cmp<mode>_internal1"
12675   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
12676         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
12677                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
12678   ""
12679   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
12680   [(set_attr "type" "cmp")])
12681
12682 ;; If we are comparing a register for equality with a large constant,
12683 ;; we can do this with an XOR followed by a compare.  But this is profitable
12684 ;; only if the large constant is only used for the comparison (and in this
12685 ;; case we already have a register to reuse as scratch).
12686 ;;
12687 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
12688 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
12689
12690 (define_peephole2
12691   [(set (match_operand:SI 0 "register_operand")
12692         (match_operand:SI 1 "logical_const_operand" ""))
12693    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
12694                        [(match_dup 0)
12695                         (match_operand:SI 2 "logical_const_operand" "")]))
12696    (set (match_operand:CC 4 "cc_reg_operand" "")
12697         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
12698                     (match_dup 0)))
12699    (set (pc)
12700         (if_then_else (match_operator 6 "equality_operator"
12701                        [(match_dup 4) (const_int 0)])
12702                       (match_operand 7 "" "")
12703                       (match_operand 8 "" "")))]
12704   "peep2_reg_dead_p (3, operands[0])
12705    && peep2_reg_dead_p (4, operands[4])"
12706  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
12707   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
12708   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
12709  
12710 {
12711   /* Get the constant we are comparing against, and see what it looks like
12712      when sign-extended from 16 to 32 bits.  Then see what constant we could
12713      XOR with SEXTC to get the sign-extended value.  */
12714   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
12715                                               SImode,
12716                                               operands[1], operands[2]);
12717   HOST_WIDE_INT c = INTVAL (cnst);
12718   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
12719   HOST_WIDE_INT xorv = c ^ sextc;
12720
12721   operands[9] = GEN_INT (xorv);
12722   operands[10] = GEN_INT (sextc);
12723 })
12724
12725 (define_insn "*cmpsi_internal2"
12726   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12727         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12728                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
12729   ""
12730   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
12731   [(set_attr "type" "cmp")])
12732
12733 (define_insn "*cmpdi_internal2"
12734   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12735         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
12736                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
12737   ""
12738   "cmpld%I2 %0,%1,%b2"
12739   [(set_attr "type" "cmp")])
12740
12741 ;; The following two insns don't exist as single insns, but if we provide
12742 ;; them, we can swap an add and compare, which will enable us to overlap more
12743 ;; of the required delay between a compare and branch.  We generate code for
12744 ;; them by splitting.
12745
12746 (define_insn ""
12747   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
12748         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
12749                     (match_operand:SI 2 "short_cint_operand" "i")))
12750    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12751         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12752   ""
12753   "#"
12754   [(set_attr "length" "8")])
12755
12756 (define_insn ""
12757   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
12758         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12759                        (match_operand:SI 2 "u_short_cint_operand" "i")))
12760    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12761         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12762   ""
12763   "#"
12764   [(set_attr "length" "8")])
12765
12766 (define_split
12767   [(set (match_operand:CC 3 "cc_reg_operand" "")
12768         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
12769                     (match_operand:SI 2 "short_cint_operand" "")))
12770    (set (match_operand:SI 0 "gpc_reg_operand" "")
12771         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12772   ""
12773   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
12774    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12775
12776 (define_split
12777   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
12778         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
12779                        (match_operand:SI 2 "u_short_cint_operand" "")))
12780    (set (match_operand:SI 0 "gpc_reg_operand" "")
12781         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12782   ""
12783   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
12784    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12785
12786 (define_insn "*cmpsf_internal1"
12787   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12788         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
12789                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
12790   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
12791   "fcmpu %0,%1,%2"
12792   [(set_attr "type" "fpcompare")])
12793
12794 (define_insn "*cmpdf_internal1"
12795   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12796         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
12797                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
12798   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
12799    && !VECTOR_UNIT_VSX_P (DFmode)"
12800   "fcmpu %0,%1,%2"
12801   [(set_attr "type" "fpcompare")])
12802
12803 ;; Only need to compare second words if first words equal
12804 (define_insn "*cmptf_internal1"
12805   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12806         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12807                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
12808   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
12809    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12810   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
12811   [(set_attr "type" "fpcompare")
12812    (set_attr "length" "12")])
12813
12814 (define_insn_and_split "*cmptf_internal2"
12815   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12816         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12817                       (match_operand:TF 2 "gpc_reg_operand" "d")))
12818     (clobber (match_scratch:DF 3 "=d"))
12819     (clobber (match_scratch:DF 4 "=d"))
12820     (clobber (match_scratch:DF 5 "=d"))
12821     (clobber (match_scratch:DF 6 "=d"))
12822     (clobber (match_scratch:DF 7 "=d"))
12823     (clobber (match_scratch:DF 8 "=d"))
12824     (clobber (match_scratch:DF 9 "=d"))
12825     (clobber (match_scratch:DF 10 "=d"))]
12826   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
12827    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12828   "#"
12829   "&& reload_completed"
12830   [(set (match_dup 3) (match_dup 13))
12831    (set (match_dup 4) (match_dup 14))
12832    (set (match_dup 9) (abs:DF (match_dup 5)))
12833    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
12834    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
12835                            (label_ref (match_dup 11))
12836                            (pc)))
12837    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
12838    (set (pc) (label_ref (match_dup 12)))
12839    (match_dup 11)
12840    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
12841    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
12842    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
12843    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
12844    (match_dup 12)]
12845 {
12846   REAL_VALUE_TYPE rv;
12847   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
12848   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
12849
12850   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
12851   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
12852   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
12853   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
12854   operands[11] = gen_label_rtx ();
12855   operands[12] = gen_label_rtx ();
12856   real_inf (&rv);
12857   operands[13] = force_const_mem (DFmode,
12858                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
12859   operands[14] = force_const_mem (DFmode,
12860                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
12861                                                                 DFmode));
12862   if (TARGET_TOC)
12863     {
12864       operands[13] = gen_const_mem (DFmode,
12865                                     create_TOC_reference (XEXP (operands[13], 0)));
12866       operands[14] = gen_const_mem (DFmode,
12867                                     create_TOC_reference (XEXP (operands[14], 0)));
12868       set_mem_alias_set (operands[13], get_TOC_alias_set ());
12869       set_mem_alias_set (operands[14], get_TOC_alias_set ());
12870     }
12871 })
12872 \f
12873 ;; Now we have the scc insns.  We can do some combinations because of the
12874 ;; way the machine works.
12875 ;;
12876 ;; Note that this is probably faster if we can put an insn between the
12877 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
12878 ;; cases the insns below which don't use an intermediate CR field will
12879 ;; be used instead.
12880 (define_insn ""
12881   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12882         (match_operator:SI 1 "scc_comparison_operator"
12883                            [(match_operand 2 "cc_reg_operand" "y")
12884                             (const_int 0)]))]
12885   ""
12886   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
12887   [(set (attr "type")
12888      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12889                 (const_string "mfcrf")
12890            ]
12891         (const_string "mfcr")))
12892    (set_attr "length" "8")])
12893
12894 ;; Same as above, but get the GT bit.
12895 (define_insn "move_from_CR_gt_bit"
12896   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12897         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
12898   "TARGET_HARD_FLOAT && !TARGET_FPRS"
12899   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
12900   [(set_attr "type" "mfcr")
12901    (set_attr "length" "8")])
12902
12903 ;; Same as above, but get the OV/ORDERED bit.
12904 (define_insn "move_from_CR_ov_bit"
12905   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12906         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
12907   "TARGET_ISEL"
12908   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
12909   [(set_attr "type" "mfcr")
12910    (set_attr "length" "8")])
12911
12912 (define_insn ""
12913   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12914         (match_operator:DI 1 "scc_comparison_operator"
12915                            [(match_operand 2 "cc_reg_operand" "y")
12916                             (const_int 0)]))]
12917   "TARGET_POWERPC64"
12918   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
12919   [(set (attr "type")
12920      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12921                 (const_string "mfcrf")
12922            ]
12923         (const_string "mfcr")))
12924    (set_attr "length" "8")])
12925
12926 (define_insn ""
12927   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12928         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12929                                        [(match_operand 2 "cc_reg_operand" "y,y")
12930                                         (const_int 0)])
12931                     (const_int 0)))
12932    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
12933         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12934   "TARGET_32BIT"
12935   "@
12936    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
12937    #"
12938   [(set_attr "type" "delayed_compare")
12939    (set_attr "length" "8,16")])
12940
12941 (define_split
12942   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12943         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12944                                        [(match_operand 2 "cc_reg_operand" "")
12945                                         (const_int 0)])
12946                     (const_int 0)))
12947    (set (match_operand:SI 3 "gpc_reg_operand" "")
12948         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12949   "TARGET_32BIT && reload_completed"
12950   [(set (match_dup 3)
12951         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
12952    (set (match_dup 0)
12953         (compare:CC (match_dup 3)
12954                     (const_int 0)))]
12955   "")
12956
12957 (define_insn ""
12958   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12959         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12960                                       [(match_operand 2 "cc_reg_operand" "y")
12961                                        (const_int 0)])
12962                    (match_operand:SI 3 "const_int_operand" "n")))]
12963   ""
12964   "*
12965 {
12966   int is_bit = ccr_bit (operands[1], 1);
12967   int put_bit = 31 - (INTVAL (operands[3]) & 31);
12968   int count;
12969
12970   if (is_bit >= put_bit)
12971     count = is_bit - put_bit;
12972   else
12973     count = 32 - (put_bit - is_bit);
12974
12975   operands[4] = GEN_INT (count);
12976   operands[5] = GEN_INT (put_bit);
12977
12978   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
12979 }"
12980   [(set (attr "type")
12981      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12982                 (const_string "mfcrf")
12983            ]
12984         (const_string "mfcr")))
12985    (set_attr "length" "8")])
12986
12987 (define_insn ""
12988   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12989         (compare:CC
12990          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12991                                        [(match_operand 2 "cc_reg_operand" "y,y")
12992                                         (const_int 0)])
12993                     (match_operand:SI 3 "const_int_operand" "n,n"))
12994          (const_int 0)))
12995    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
12996         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12997                    (match_dup 3)))]
12998   ""
12999   "*
13000 {
13001   int is_bit = ccr_bit (operands[1], 1);
13002   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13003   int count;
13004
13005   /* Force split for non-cc0 compare.  */
13006   if (which_alternative == 1)
13007      return \"#\";
13008
13009   if (is_bit >= put_bit)
13010     count = is_bit - put_bit;
13011   else
13012     count = 32 - (put_bit - is_bit);
13013
13014   operands[5] = GEN_INT (count);
13015   operands[6] = GEN_INT (put_bit);
13016
13017   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
13018 }"
13019   [(set_attr "type" "delayed_compare")
13020    (set_attr "length" "8,16")])
13021
13022 (define_split
13023   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13024         (compare:CC
13025          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13026                                        [(match_operand 2 "cc_reg_operand" "")
13027                                         (const_int 0)])
13028                     (match_operand:SI 3 "const_int_operand" ""))
13029          (const_int 0)))
13030    (set (match_operand:SI 4 "gpc_reg_operand" "")
13031         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13032                    (match_dup 3)))]
13033   "reload_completed"
13034   [(set (match_dup 4)
13035         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13036                    (match_dup 3)))
13037    (set (match_dup 0)
13038         (compare:CC (match_dup 4)
13039                     (const_int 0)))]
13040   "")
13041
13042 ;; There is a 3 cycle delay between consecutive mfcr instructions
13043 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13044
13045 (define_peephole
13046   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13047         (match_operator:SI 1 "scc_comparison_operator"
13048                            [(match_operand 2 "cc_reg_operand" "y")
13049                             (const_int 0)]))
13050    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13051         (match_operator:SI 4 "scc_comparison_operator"
13052                            [(match_operand 5 "cc_reg_operand" "y")
13053                             (const_int 0)]))]
13054   "REGNO (operands[2]) != REGNO (operands[5])"
13055   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13056   [(set_attr "type" "mfcr")
13057    (set_attr "length" "12")])
13058
13059 (define_peephole
13060   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13061         (match_operator:DI 1 "scc_comparison_operator"
13062                            [(match_operand 2 "cc_reg_operand" "y")
13063                             (const_int 0)]))
13064    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13065         (match_operator:DI 4 "scc_comparison_operator"
13066                            [(match_operand 5 "cc_reg_operand" "y")
13067                             (const_int 0)]))]
13068   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13069   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13070   [(set_attr "type" "mfcr")
13071    (set_attr "length" "12")])
13072
13073 ;; There are some scc insns that can be done directly, without a compare.
13074 ;; These are faster because they don't involve the communications between
13075 ;; the FXU and branch units.   In fact, we will be replacing all of the
13076 ;; integer scc insns here or in the portable methods in emit_store_flag.
13077 ;;
13078 ;; Also support (neg (scc ..)) since that construct is used to replace
13079 ;; branches, (plus (scc ..) ..) since that construct is common and
13080 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13081 ;; cases where it is no more expensive than (neg (scc ..)).
13082
13083 ;; Have reload force a constant into a register for the simple insns that
13084 ;; otherwise won't accept constants.  We do this because it is faster than
13085 ;; the cmp/mfcr sequence we would otherwise generate.
13086
13087 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13088                               (DI "rKJI")])
13089
13090 (define_insn_and_split "*eq<mode>"
13091   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13092         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13093                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13094   "!TARGET_POWER"
13095   "#"
13096   "!TARGET_POWER"
13097   [(set (match_dup 0)
13098         (clz:GPR (match_dup 3)))
13099    (set (match_dup 0)
13100         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13101   {
13102     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13103       {
13104         /* Use output operand as intermediate.  */
13105         operands[3] = operands[0];
13106
13107         if (logical_operand (operands[2], <MODE>mode))
13108           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13109                                   gen_rtx_XOR (<MODE>mode,
13110                                                operands[1], operands[2])));
13111         else
13112           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13113                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13114                                                 negate_rtx (<MODE>mode,
13115                                                             operands[2]))));
13116       }
13117     else
13118       operands[3] = operands[1];
13119
13120     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13121   })
13122
13123 (define_insn_and_split "*eq<mode>_compare"
13124   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13125         (compare:CC
13126          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13127                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13128          (const_int 0)))
13129    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13130         (eq:P (match_dup 1) (match_dup 2)))]
13131   "!TARGET_POWER && optimize_size"
13132   "#"
13133   "!TARGET_POWER && optimize_size"
13134   [(set (match_dup 0)
13135         (clz:P (match_dup 4)))
13136    (parallel [(set (match_dup 3)
13137                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13138                                (const_int 0)))
13139               (set (match_dup 0)
13140                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13141   {
13142     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13143       {
13144         /* Use output operand as intermediate.  */
13145         operands[4] = operands[0];
13146
13147         if (logical_operand (operands[2], <MODE>mode))
13148           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13149                                   gen_rtx_XOR (<MODE>mode,
13150                                                operands[1], operands[2])));
13151         else
13152           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13153                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13154                                                 negate_rtx (<MODE>mode,
13155                                                             operands[2]))));
13156       }
13157     else
13158       operands[4] = operands[1];
13159
13160     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13161   })
13162
13163 (define_insn "*eqsi_power"
13164   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
13165         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13166                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
13167    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
13168   "TARGET_POWER"
13169   "@
13170    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13171    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
13172    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13173    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13174    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
13175   [(set_attr "type" "three,two,three,three,three")
13176    (set_attr "length" "12,8,12,12,12")])
13177
13178 ;; We have insns of the form shown by the first define_insn below.  If
13179 ;; there is something inside the comparison operation, we must split it.
13180 (define_split
13181   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13182         (plus:SI (match_operator 1 "comparison_operator"
13183                                  [(match_operand:SI 2 "" "")
13184                                   (match_operand:SI 3
13185                                                     "reg_or_cint_operand" "")])
13186                  (match_operand:SI 4 "gpc_reg_operand" "")))
13187    (clobber (match_operand:SI 5 "register_operand" ""))]
13188   "! gpc_reg_operand (operands[2], SImode)"
13189   [(set (match_dup 5) (match_dup 2))
13190    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
13191                                (match_dup 4)))])
13192
13193 (define_insn "*plus_eqsi"
13194   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13195         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13196                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13197                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13198   "TARGET_32BIT"
13199   "@
13200    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13201    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
13202    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13203    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13204    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
13205   [(set_attr "type" "three,two,three,three,three")
13206    (set_attr "length" "12,8,12,12,12")])
13207
13208 (define_insn "*compare_plus_eqsi"
13209   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13210         (compare:CC
13211          (plus:SI
13212           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13213                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13214           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13215          (const_int 0)))
13216    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13217   "TARGET_32BIT && optimize_size"
13218   "@
13219    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13220    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
13221    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13222    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13223    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13224    #
13225    #
13226    #
13227    #
13228    #"
13229   [(set_attr "type" "compare")
13230    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13231
13232 (define_split
13233   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13234         (compare:CC
13235          (plus:SI
13236           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13237                  (match_operand:SI 2 "scc_eq_operand" ""))
13238           (match_operand:SI 3 "gpc_reg_operand" ""))
13239          (const_int 0)))
13240    (clobber (match_scratch:SI 4 ""))]
13241   "TARGET_32BIT && optimize_size && reload_completed"
13242   [(set (match_dup 4)
13243         (plus:SI (eq:SI (match_dup 1)
13244                  (match_dup 2))
13245           (match_dup 3)))
13246    (set (match_dup 0)
13247         (compare:CC (match_dup 4)
13248                     (const_int 0)))]
13249   "")
13250
13251 (define_insn "*plus_eqsi_compare"
13252   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13253         (compare:CC
13254          (plus:SI
13255           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13256                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13257           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13258          (const_int 0)))
13259    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13260         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13261   "TARGET_32BIT && optimize_size"
13262   "@
13263    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13264    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
13265    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13266    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13267    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13268    #
13269    #
13270    #
13271    #
13272    #"
13273   [(set_attr "type" "compare")
13274    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13275
13276 (define_split
13277   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13278         (compare:CC
13279          (plus:SI
13280           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13281                  (match_operand:SI 2 "scc_eq_operand" ""))
13282           (match_operand:SI 3 "gpc_reg_operand" ""))
13283          (const_int 0)))
13284    (set (match_operand:SI 0 "gpc_reg_operand" "")
13285         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13286   "TARGET_32BIT && optimize_size && reload_completed"
13287   [(set (match_dup 0)
13288         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13289    (set (match_dup 4)
13290         (compare:CC (match_dup 0)
13291                     (const_int 0)))]
13292   "")
13293
13294 (define_insn "*neg_eq0<mode>"
13295   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13296         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13297                      (const_int 0))))]
13298   ""
13299   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
13300   [(set_attr "type" "two")
13301    (set_attr "length" "8")])
13302
13303 (define_insn_and_split "*neg_eq<mode>"
13304   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13305         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
13306                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
13307   ""
13308   "#"
13309   ""
13310   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
13311   {
13312     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13313       {
13314         /* Use output operand as intermediate.  */
13315         operands[3] = operands[0];
13316
13317         if (logical_operand (operands[2], <MODE>mode))
13318           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13319                                   gen_rtx_XOR (<MODE>mode,
13320                                                operands[1], operands[2])));
13321         else
13322           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13323                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13324                                                 negate_rtx (<MODE>mode,
13325                                                             operands[2]))));
13326       }
13327     else
13328       operands[3] = operands[1];
13329   })
13330
13331 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
13332 ;; since it nabs/sr is just as fast.
13333 (define_insn "*ne0si"
13334   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13335         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
13336                      (const_int 31)))
13337    (clobber (match_scratch:SI 2 "=&r"))]
13338   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
13339   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
13340   [(set_attr "type" "two")
13341    (set_attr "length" "8")])
13342
13343 (define_insn "*ne0di"
13344   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13345         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
13346                      (const_int 63)))
13347    (clobber (match_scratch:DI 2 "=&r"))]
13348   "TARGET_64BIT"
13349   "addic %2,%1,-1\;subfe %0,%2,%1"
13350   [(set_attr "type" "two")
13351    (set_attr "length" "8")])
13352
13353 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
13354 (define_insn "*plus_ne0si"
13355   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13356         (plus:SI (lshiftrt:SI
13357                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
13358                   (const_int 31))
13359                  (match_operand:SI 2 "gpc_reg_operand" "r")))
13360    (clobber (match_scratch:SI 3 "=&r"))]
13361   "TARGET_32BIT"
13362   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
13363   [(set_attr "type" "two")
13364    (set_attr "length" "8")])
13365
13366 (define_insn "*plus_ne0di"
13367   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13368         (plus:DI (lshiftrt:DI
13369                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
13370                   (const_int 63))
13371                  (match_operand:DI 2 "gpc_reg_operand" "r")))
13372    (clobber (match_scratch:DI 3 "=&r"))]
13373   "TARGET_64BIT"
13374   "addic %3,%1,-1\;addze %0,%2"
13375   [(set_attr "type" "two")
13376    (set_attr "length" "8")])
13377
13378 (define_insn "*compare_plus_ne0si"
13379   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13380         (compare:CC
13381          (plus:SI (lshiftrt:SI
13382                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
13383                    (const_int 31))
13384                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13385          (const_int 0)))
13386    (clobber (match_scratch:SI 3 "=&r,&r"))
13387    (clobber (match_scratch:SI 4 "=X,&r"))]
13388   "TARGET_32BIT"
13389   "@
13390    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
13391    #"
13392   [(set_attr "type" "compare")
13393    (set_attr "length" "8,12")])
13394
13395 (define_split
13396   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13397         (compare:CC
13398          (plus:SI (lshiftrt:SI
13399                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
13400                    (const_int 31))
13401                   (match_operand:SI 2 "gpc_reg_operand" ""))
13402          (const_int 0)))
13403    (clobber (match_scratch:SI 3 ""))
13404    (clobber (match_scratch:SI 4 ""))]
13405   "TARGET_32BIT && reload_completed"
13406   [(parallel [(set (match_dup 3)
13407                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
13408                                          (const_int 31))
13409                             (match_dup 2)))
13410               (clobber (match_dup 4))])
13411    (set (match_dup 0)
13412         (compare:CC (match_dup 3)
13413                     (const_int 0)))]
13414   "")
13415
13416 (define_insn "*compare_plus_ne0di"
13417   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13418         (compare:CC
13419          (plus:DI (lshiftrt:DI
13420                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
13421                    (const_int 63))
13422                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13423          (const_int 0)))
13424    (clobber (match_scratch:DI 3 "=&r,&r"))]
13425   "TARGET_64BIT"
13426   "@
13427    addic %3,%1,-1\;addze. %3,%2
13428    #"
13429   [(set_attr "type" "compare")
13430    (set_attr "length" "8,12")])
13431
13432 (define_split
13433   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13434         (compare:CC
13435          (plus:DI (lshiftrt:DI
13436                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
13437                    (const_int 63))
13438                   (match_operand:DI 2 "gpc_reg_operand" ""))
13439          (const_int 0)))
13440    (clobber (match_scratch:DI 3 ""))]
13441   "TARGET_64BIT && reload_completed"
13442   [(set (match_dup 3)
13443         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
13444                    (const_int 63))
13445                   (match_dup 2)))
13446    (set (match_dup 0)
13447         (compare:CC (match_dup 3)
13448                     (const_int 0)))]
13449   "")
13450
13451 (define_insn "*plus_ne0si_compare"
13452   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13453         (compare:CC
13454          (plus:SI (lshiftrt:SI
13455                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
13456                    (const_int 31))
13457                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13458          (const_int 0)))
13459    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13460         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13461                  (match_dup 2)))
13462    (clobber (match_scratch:SI 3 "=&r,&r"))]
13463   "TARGET_32BIT"
13464   "@
13465    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
13466    #"
13467   [(set_attr "type" "compare")
13468    (set_attr "length" "8,12")])
13469
13470 (define_split
13471   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13472         (compare:CC
13473          (plus:SI (lshiftrt:SI
13474                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
13475                    (const_int 31))
13476                   (match_operand:SI 2 "gpc_reg_operand" ""))
13477          (const_int 0)))
13478    (set (match_operand:SI 0 "gpc_reg_operand" "")
13479         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13480                  (match_dup 2)))
13481    (clobber (match_scratch:SI 3 ""))]
13482   "TARGET_32BIT && reload_completed"
13483   [(parallel [(set (match_dup 0)
13484         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13485                  (match_dup 2)))
13486    (clobber (match_dup 3))])
13487    (set (match_dup 4)
13488         (compare:CC (match_dup 0)
13489                     (const_int 0)))]
13490   "")
13491
13492 (define_insn "*plus_ne0di_compare"
13493   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13494         (compare:CC
13495          (plus:DI (lshiftrt:DI
13496                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
13497                    (const_int 63))
13498                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13499          (const_int 0)))
13500    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13501         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13502                  (match_dup 2)))
13503    (clobber (match_scratch:DI 3 "=&r,&r"))]
13504   "TARGET_64BIT"
13505   "@
13506    addic %3,%1,-1\;addze. %0,%2
13507    #"
13508   [(set_attr "type" "compare")
13509    (set_attr "length" "8,12")])
13510
13511 (define_split
13512   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
13513         (compare:CC
13514          (plus:DI (lshiftrt:DI
13515                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
13516                    (const_int 63))
13517                   (match_operand:DI 2 "gpc_reg_operand" ""))
13518          (const_int 0)))
13519    (set (match_operand:DI 0 "gpc_reg_operand" "")
13520         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13521                  (match_dup 2)))
13522    (clobber (match_scratch:DI 3 ""))]
13523   "TARGET_64BIT && reload_completed"
13524   [(parallel [(set (match_dup 0)
13525         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13526                  (match_dup 2)))
13527    (clobber (match_dup 3))])
13528    (set (match_dup 4)
13529         (compare:CC (match_dup 0)
13530                     (const_int 0)))]
13531   "")
13532
13533 (define_insn ""
13534   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13535         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13536                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
13537    (clobber (match_scratch:SI 3 "=r,X"))]
13538   "TARGET_POWER"
13539   "@
13540    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
13541    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
13542   [(set_attr "length" "12")])
13543
13544 (define_insn ""
13545   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13546         (compare:CC
13547          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13548                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13549          (const_int 0)))
13550    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
13551         (le:SI (match_dup 1) (match_dup 2)))
13552    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
13553   "TARGET_POWER"
13554   "@
13555    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
13556    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
13557    #
13558    #"
13559   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
13560    (set_attr "length" "12,12,16,16")])
13561
13562 (define_split
13563   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13564         (compare:CC
13565          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13566                 (match_operand:SI 2 "reg_or_short_operand" ""))
13567          (const_int 0)))
13568    (set (match_operand:SI 0 "gpc_reg_operand" "")
13569         (le:SI (match_dup 1) (match_dup 2)))
13570    (clobber (match_scratch:SI 3 ""))]
13571   "TARGET_POWER && reload_completed"
13572   [(parallel [(set (match_dup 0)
13573         (le:SI (match_dup 1) (match_dup 2)))
13574    (clobber (match_dup 3))])
13575    (set (match_dup 4)
13576         (compare:CC (match_dup 0)
13577                     (const_int 0)))]
13578   "")
13579
13580 (define_insn ""
13581   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13582         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13583                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
13584                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
13585   "TARGET_POWER"
13586   "@
13587    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13588    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
13589   [(set_attr "length" "12")])
13590
13591 (define_insn ""
13592   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13593         (compare:CC
13594          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13595                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13596                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13597          (const_int 0)))
13598    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13599   "TARGET_POWER"
13600   "@
13601    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13602    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
13603    #
13604    #"
13605   [(set_attr "type" "compare")
13606    (set_attr "length" "12,12,16,16")])
13607
13608 (define_split
13609   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13610         (compare:CC
13611          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13612                          (match_operand:SI 2 "reg_or_short_operand" ""))
13613                   (match_operand:SI 3 "gpc_reg_operand" ""))
13614          (const_int 0)))
13615    (clobber (match_scratch:SI 4 ""))]
13616   "TARGET_POWER && reload_completed"
13617   [(set (match_dup 4)
13618         (plus:SI (le:SI (match_dup 1) (match_dup 2))
13619                  (match_dup 3)))
13620    (set (match_dup 0)
13621         (compare:CC (match_dup 4)
13622                     (const_int 0)))]
13623   "")
13624
13625 (define_insn ""
13626   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13627         (compare:CC
13628          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13629                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13630                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13631          (const_int 0)))
13632    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13633         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13634   "TARGET_POWER"
13635   "@
13636    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13637    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
13638    #
13639    #"
13640   [(set_attr "type" "compare")
13641    (set_attr "length" "12,12,16,16")])
13642
13643 (define_split
13644   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13645         (compare:CC
13646          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13647                          (match_operand:SI 2 "reg_or_short_operand" ""))
13648                   (match_operand:SI 3 "gpc_reg_operand" ""))
13649          (const_int 0)))
13650    (set (match_operand:SI 0 "gpc_reg_operand" "")
13651         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13652   "TARGET_POWER && reload_completed"
13653   [(set (match_dup 0)
13654         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13655    (set (match_dup 4)
13656         (compare:CC (match_dup 0)
13657                     (const_int 0)))]
13658   "")
13659
13660 (define_insn ""
13661   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13662         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13663                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
13664   "TARGET_POWER"
13665   "@
13666    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
13667    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
13668   [(set_attr "length" "12")])
13669
13670 (define_insn "*leu<mode>"
13671   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13672         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13673                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13674   ""
13675   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
13676   [(set_attr "type" "three")
13677    (set_attr "length" "12")])
13678
13679 (define_insn "*leu<mode>_compare"
13680   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13681         (compare:CC
13682          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13683                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13684          (const_int 0)))
13685    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13686         (leu:P (match_dup 1) (match_dup 2)))]
13687   ""
13688   "@
13689    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
13690    #"
13691   [(set_attr "type" "compare")
13692    (set_attr "length" "12,16")])
13693
13694 (define_split
13695   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13696         (compare:CC
13697          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
13698                 (match_operand:P 2 "reg_or_short_operand" ""))
13699          (const_int 0)))
13700    (set (match_operand:P 0 "gpc_reg_operand" "")
13701         (leu:P (match_dup 1) (match_dup 2)))]
13702   "reload_completed"
13703   [(set (match_dup 0)
13704         (leu:P (match_dup 1) (match_dup 2)))
13705    (set (match_dup 3)
13706         (compare:CC (match_dup 0)
13707                     (const_int 0)))]
13708   "")
13709
13710 (define_insn "*plus_leu<mode>"
13711   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13712         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13713                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13714                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13715   ""
13716   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
13717   [(set_attr "type" "two")
13718    (set_attr "length" "8")])
13719
13720 (define_insn ""
13721   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13722         (compare:CC
13723          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13724                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13725                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13726          (const_int 0)))
13727    (clobber (match_scratch:SI 4 "=&r,&r"))]
13728   "TARGET_32BIT"
13729   "@
13730    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
13731    #"
13732   [(set_attr "type" "compare")
13733    (set_attr "length" "8,12")])
13734
13735 (define_split
13736   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13737         (compare:CC
13738          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13739                           (match_operand:SI 2 "reg_or_short_operand" ""))
13740                   (match_operand:SI 3 "gpc_reg_operand" ""))
13741          (const_int 0)))
13742    (clobber (match_scratch:SI 4 ""))]
13743   "TARGET_32BIT && reload_completed"
13744   [(set (match_dup 4)
13745         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
13746                   (match_dup 3)))
13747    (set (match_dup 0)
13748         (compare:CC (match_dup 4)
13749                     (const_int 0)))]
13750   "")
13751
13752 (define_insn ""
13753   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13754         (compare:CC
13755          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13756                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13757                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13758          (const_int 0)))
13759    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13760         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13761   "TARGET_32BIT"
13762   "@
13763    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
13764    #"
13765   [(set_attr "type" "compare")
13766    (set_attr "length" "8,12")])
13767
13768 (define_split
13769   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13770         (compare:CC
13771          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13772                           (match_operand:SI 2 "reg_or_short_operand" ""))
13773                   (match_operand:SI 3 "gpc_reg_operand" ""))
13774          (const_int 0)))
13775    (set (match_operand:SI 0 "gpc_reg_operand" "")
13776         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13777   "TARGET_32BIT && reload_completed"
13778   [(set (match_dup 0)
13779         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13780    (set (match_dup 4)
13781         (compare:CC (match_dup 0)
13782                     (const_int 0)))]
13783   "")
13784
13785 (define_insn "*neg_leu<mode>"
13786   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13787         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13788                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13789   ""
13790   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
13791    [(set_attr "type" "three")
13792     (set_attr "length" "12")])
13793
13794 (define_insn "*and_neg_leu<mode>"
13795   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13796         (and:P (neg:P
13797                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13798                         (match_operand:P 2 "reg_or_short_operand" "rI")))
13799                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13800   ""
13801   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
13802   [(set_attr "type" "three")
13803    (set_attr "length" "12")])
13804
13805 (define_insn ""
13806   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13807         (compare:CC
13808          (and:SI (neg:SI
13809                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13810                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13811                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13812          (const_int 0)))
13813    (clobber (match_scratch:SI 4 "=&r,&r"))]
13814   "TARGET_32BIT"
13815   "@
13816    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13817    #"
13818   [(set_attr "type" "compare")
13819    (set_attr "length" "12,16")])
13820
13821 (define_split
13822   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13823         (compare:CC
13824          (and:SI (neg:SI
13825                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13826                           (match_operand:SI 2 "reg_or_short_operand" "")))
13827                  (match_operand:SI 3 "gpc_reg_operand" ""))
13828          (const_int 0)))
13829    (clobber (match_scratch:SI 4 ""))]
13830   "TARGET_32BIT && reload_completed"
13831   [(set (match_dup 4)
13832         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13833                 (match_dup 3)))
13834    (set (match_dup 0)
13835         (compare:CC (match_dup 4)
13836                     (const_int 0)))]
13837   "")
13838
13839 (define_insn ""
13840   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13841         (compare:CC
13842          (and:SI (neg:SI
13843                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13844                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13845                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13846          (const_int 0)))
13847    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13848         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13849   "TARGET_32BIT"
13850   "@
13851    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13852    #"
13853   [(set_attr "type" "compare")
13854    (set_attr "length" "12,16")])
13855
13856 (define_split
13857   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13858         (compare:CC
13859          (and:SI (neg:SI
13860                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13861                           (match_operand:SI 2 "reg_or_short_operand" "")))
13862                  (match_operand:SI 3 "gpc_reg_operand" ""))
13863          (const_int 0)))
13864    (set (match_operand:SI 0 "gpc_reg_operand" "")
13865         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13866   "TARGET_32BIT && reload_completed"
13867   [(set (match_dup 0)
13868         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13869                 (match_dup 3)))
13870    (set (match_dup 4)
13871         (compare:CC (match_dup 0)
13872                     (const_int 0)))]
13873   "")
13874
13875 (define_insn ""
13876   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13877         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13878                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13879   "TARGET_POWER"
13880   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13881    [(set_attr "length" "12")])
13882
13883 (define_insn ""
13884   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13885         (compare:CC
13886          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13887                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13888          (const_int 0)))
13889    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13890         (lt:SI (match_dup 1) (match_dup 2)))]
13891   "TARGET_POWER"
13892   "@
13893    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13894    #"
13895   [(set_attr "type" "delayed_compare")
13896    (set_attr "length" "12,16")])
13897
13898 (define_split
13899   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13900         (compare:CC
13901          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13902                 (match_operand:SI 2 "reg_or_short_operand" ""))
13903          (const_int 0)))
13904    (set (match_operand:SI 0 "gpc_reg_operand" "")
13905         (lt:SI (match_dup 1) (match_dup 2)))]
13906   "TARGET_POWER && reload_completed"
13907   [(set (match_dup 0)
13908         (lt:SI (match_dup 1) (match_dup 2)))
13909    (set (match_dup 3)
13910         (compare:CC (match_dup 0)
13911                     (const_int 0)))]
13912   "")
13913
13914 (define_insn ""
13915   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13916         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13917                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
13918                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13919   "TARGET_POWER"
13920   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13921   [(set_attr "length" "12")])
13922
13923 (define_insn ""
13924   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13925         (compare:CC
13926          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13927                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13928                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13929          (const_int 0)))
13930    (clobber (match_scratch:SI 4 "=&r,&r"))]
13931   "TARGET_POWER"
13932   "@
13933    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13934    #"
13935   [(set_attr "type" "compare")
13936    (set_attr "length" "12,16")])
13937
13938 (define_split
13939   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13940         (compare:CC
13941          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13942                          (match_operand:SI 2 "reg_or_short_operand" ""))
13943                   (match_operand:SI 3 "gpc_reg_operand" ""))
13944          (const_int 0)))
13945    (clobber (match_scratch:SI 4 ""))]
13946   "TARGET_POWER && reload_completed"
13947   [(set (match_dup 4)
13948         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
13949                  (match_dup 3)))
13950    (set (match_dup 0)
13951         (compare:CC (match_dup 4)
13952                     (const_int 0)))]
13953   "")
13954
13955 (define_insn ""
13956   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13957         (compare:CC
13958          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13959                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13960                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13961          (const_int 0)))
13962    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13963         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13964   "TARGET_POWER"
13965   "@
13966    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13967    #"
13968   [(set_attr "type" "compare")
13969    (set_attr "length" "12,16")])
13970
13971 (define_split
13972   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13973         (compare:CC
13974          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13975                          (match_operand:SI 2 "reg_or_short_operand" ""))
13976                   (match_operand:SI 3 "gpc_reg_operand" ""))
13977          (const_int 0)))
13978    (set (match_operand:SI 0 "gpc_reg_operand" "")
13979         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13980   "TARGET_POWER && reload_completed"
13981   [(set (match_dup 0)
13982         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13983    (set (match_dup 4)
13984         (compare:CC (match_dup 0)
13985                     (const_int 0)))]
13986   "")
13987
13988 (define_insn ""
13989   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13990         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13991                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13992   "TARGET_POWER"
13993   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13994   [(set_attr "length" "12")])
13995
13996 (define_insn_and_split "*ltu<mode>"
13997   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13998         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13999                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14000   ""
14001   "#"
14002   ""
14003   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14004    (set (match_dup 0) (neg:P (match_dup 0)))]
14005   "")
14006
14007 (define_insn_and_split "*ltu<mode>_compare"
14008   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14009         (compare:CC
14010          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14011                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14012          (const_int 0)))
14013    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14014         (ltu:P (match_dup 1) (match_dup 2)))]
14015   ""
14016   "#"
14017   ""
14018   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14019    (parallel [(set (match_dup 3)
14020                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14021               (set (match_dup 0) (neg:P (match_dup 0)))])]
14022   "")
14023
14024 (define_insn_and_split "*plus_ltu<mode>"
14025   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
14026         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14027                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14028                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
14029   ""
14030   "#"
14031   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14032   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14033    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14034   "")
14035
14036 (define_insn_and_split "*plus_ltu<mode>_compare"
14037   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14038         (compare:CC
14039          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14040                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14041                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14042          (const_int 0)))
14043    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14044         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14045   ""
14046   "#"
14047   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14048   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14049    (parallel [(set (match_dup 4)
14050                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14051                                (const_int 0)))
14052               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14053   "")
14054
14055 (define_insn "*neg_ltu<mode>"
14056   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14057         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14058                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
14059   ""
14060   "@
14061    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
14062    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
14063   [(set_attr "type" "two")
14064    (set_attr "length" "8")])
14065
14066 (define_insn ""
14067   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14068         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14069                (match_operand:SI 2 "reg_or_short_operand" "rI")))
14070    (clobber (match_scratch:SI 3 "=r"))]
14071   "TARGET_POWER"
14072   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
14073    [(set_attr "length" "12")])
14074
14075 (define_insn ""
14076   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14077         (compare:CC
14078          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14079                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14080          (const_int 0)))
14081    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14082         (ge:SI (match_dup 1) (match_dup 2)))
14083    (clobber (match_scratch:SI 3 "=r,r"))]
14084   "TARGET_POWER"
14085   "@
14086    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14087    #"
14088   [(set_attr "type" "compare")
14089    (set_attr "length" "12,16")])
14090
14091 (define_split
14092   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14093         (compare:CC
14094          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14095                 (match_operand:SI 2 "reg_or_short_operand" ""))
14096          (const_int 0)))
14097    (set (match_operand:SI 0 "gpc_reg_operand" "")
14098         (ge:SI (match_dup 1) (match_dup 2)))
14099    (clobber (match_scratch:SI 3 ""))]
14100   "TARGET_POWER && reload_completed"
14101   [(parallel [(set (match_dup 0)
14102                    (ge:SI (match_dup 1) (match_dup 2)))
14103               (clobber (match_dup 3))])
14104    (set (match_dup 4)
14105         (compare:CC (match_dup 0)
14106                     (const_int 0)))]
14107   "")
14108
14109 (define_insn ""
14110   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14111         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14112                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14113                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14114   "TARGET_POWER"
14115   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
14116   [(set_attr "length" "12")])
14117
14118 (define_insn ""
14119   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14120         (compare:CC
14121          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14122                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14123                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14124          (const_int 0)))
14125    (clobber (match_scratch:SI 4 "=&r,&r"))]
14126   "TARGET_POWER"
14127   "@
14128    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14129    #"
14130   [(set_attr "type" "compare")
14131    (set_attr "length" "12,16")])
14132
14133 (define_split
14134   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14135         (compare:CC
14136          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14137                          (match_operand:SI 2 "reg_or_short_operand" ""))
14138                   (match_operand:SI 3 "gpc_reg_operand" ""))
14139          (const_int 0)))
14140    (clobber (match_scratch:SI 4 ""))]
14141   "TARGET_POWER && reload_completed"
14142   [(set (match_dup 4)
14143         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
14144                  (match_dup 3)))
14145    (set (match_dup 0)
14146         (compare:CC (match_dup 4)
14147                     (const_int 0)))]
14148   "")
14149
14150 (define_insn ""
14151   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14152         (compare:CC
14153          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14154                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14155                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14156          (const_int 0)))
14157    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14158         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14159   "TARGET_POWER"
14160   "@
14161    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14162    #"
14163   [(set_attr "type" "compare")
14164    (set_attr "length" "12,16")])
14165
14166 (define_split
14167   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14168         (compare:CC
14169          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14170                          (match_operand:SI 2 "reg_or_short_operand" ""))
14171                   (match_operand:SI 3 "gpc_reg_operand" ""))
14172          (const_int 0)))
14173    (set (match_operand:SI 0 "gpc_reg_operand" "")
14174         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14175   "TARGET_POWER && reload_completed"
14176   [(set (match_dup 0)
14177         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14178    (set (match_dup 4)
14179         (compare:CC (match_dup 0)
14180                     (const_int 0)))]
14181   "")
14182
14183 (define_insn ""
14184   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14185         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14186                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14187   "TARGET_POWER"
14188   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
14189   [(set_attr "length" "12")])
14190
14191 (define_insn "*geu<mode>"
14192   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14193         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14194                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14195   ""
14196   "@
14197    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
14198    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14199   [(set_attr "type" "three")
14200    (set_attr "length" "12")])
14201
14202 (define_insn "*geu<mode>_compare"
14203   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14204         (compare:CC
14205          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14206                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14207          (const_int 0)))
14208    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14209         (geu:P (match_dup 1) (match_dup 2)))]
14210   ""
14211   "@
14212    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14213    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14214    #
14215    #"
14216   [(set_attr "type" "compare")
14217    (set_attr "length" "12,12,16,16")])
14218
14219 (define_split
14220   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14221         (compare:CC
14222          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
14223                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
14224          (const_int 0)))
14225    (set (match_operand:P 0 "gpc_reg_operand" "")
14226         (geu:P (match_dup 1) (match_dup 2)))]
14227   "reload_completed"
14228   [(set (match_dup 0)
14229         (geu:P (match_dup 1) (match_dup 2)))
14230    (set (match_dup 3)
14231         (compare:CC (match_dup 0)
14232                     (const_int 0)))]
14233   "")
14234
14235 (define_insn "*plus_geu<mode>"
14236   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14237         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14238                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14239                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14240   ""
14241   "@
14242    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
14243    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
14244   [(set_attr "type" "two")
14245    (set_attr "length" "8")])
14246
14247 (define_insn ""
14248   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14249         (compare:CC
14250          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14251                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14252                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14253          (const_int 0)))
14254    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14255   "TARGET_32BIT"
14256   "@
14257    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
14258    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
14259    #
14260    #"
14261   [(set_attr "type" "compare")
14262    (set_attr "length" "8,8,12,12")])
14263
14264 (define_split
14265   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14266         (compare:CC
14267          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14268                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14269                   (match_operand:SI 3 "gpc_reg_operand" ""))
14270          (const_int 0)))
14271    (clobber (match_scratch:SI 4 ""))]
14272   "TARGET_32BIT && reload_completed"
14273   [(set (match_dup 4)
14274         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
14275                   (match_dup 3)))
14276    (set (match_dup 0)
14277         (compare:CC (match_dup 4)
14278                     (const_int 0)))]
14279   "")
14280
14281 (define_insn ""
14282   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14283         (compare:CC
14284          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14285                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14286                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14287          (const_int 0)))
14288    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14289         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14290   "TARGET_32BIT"
14291   "@
14292    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
14293    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
14294    #
14295    #"
14296   [(set_attr "type" "compare")
14297    (set_attr "length" "8,8,12,12")])
14298
14299 (define_split
14300   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14301         (compare:CC
14302          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14303                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14304                   (match_operand:SI 3 "gpc_reg_operand" ""))
14305          (const_int 0)))
14306    (set (match_operand:SI 0 "gpc_reg_operand" "")
14307         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14308   "TARGET_32BIT && reload_completed"
14309   [(set (match_dup 0)
14310         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14311    (set (match_dup 4)
14312         (compare:CC (match_dup 0)
14313                     (const_int 0)))]
14314   "")
14315
14316 (define_insn "*neg_geu<mode>"
14317   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14318         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14319                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
14320   ""
14321   "@
14322    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
14323    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
14324   [(set_attr "type" "three")
14325    (set_attr "length" "12")])
14326
14327 (define_insn "*and_neg_geu<mode>"
14328   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14329         (and:P (neg:P
14330                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14331                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
14332                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14333   ""
14334   "@
14335    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
14336    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
14337   [(set_attr "type" "three")
14338    (set_attr "length" "12")])
14339
14340 (define_insn ""
14341   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14342         (compare:CC
14343          (and:SI (neg:SI
14344                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14345                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14346                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14347          (const_int 0)))
14348    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14349   "TARGET_32BIT"
14350   "@
14351    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14352    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14353    #
14354    #"
14355   [(set_attr "type" "compare")
14356    (set_attr "length" "12,12,16,16")])
14357
14358 (define_split
14359   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14360         (compare:CC
14361          (and:SI (neg:SI
14362                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14363                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14364                  (match_operand:SI 3 "gpc_reg_operand" ""))
14365          (const_int 0)))
14366    (clobber (match_scratch:SI 4 ""))]
14367   "TARGET_32BIT && reload_completed"
14368   [(set (match_dup 4)
14369         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
14370                 (match_dup 3)))
14371    (set (match_dup 0)
14372         (compare:CC (match_dup 4)
14373                     (const_int 0)))]
14374   "")
14375
14376 (define_insn ""
14377   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14378         (compare:CC
14379          (and:SI (neg:SI
14380                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14381                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14382                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14383          (const_int 0)))
14384    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14385         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14386   "TARGET_32BIT"
14387   "@
14388    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14389    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14390    #
14391    #"
14392   [(set_attr "type" "compare")
14393    (set_attr "length" "12,12,16,16")])
14394
14395 (define_split
14396   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14397         (compare:CC
14398          (and:SI (neg:SI
14399                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14400                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14401                  (match_operand:SI 3 "gpc_reg_operand" ""))
14402          (const_int 0)))
14403    (set (match_operand:SI 0 "gpc_reg_operand" "")
14404         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14405   "TARGET_32BIT && reload_completed"
14406   [(set (match_dup 0)
14407         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
14408    (set (match_dup 4)
14409         (compare:CC (match_dup 0)
14410                     (const_int 0)))]
14411   "")
14412
14413 (define_insn ""
14414   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14415         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14416                (match_operand:SI 2 "reg_or_short_operand" "r")))]
14417   "TARGET_POWER"
14418   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
14419   [(set_attr "length" "12")])
14420
14421 (define_insn ""
14422   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14423         (compare:CC
14424          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14425                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14426          (const_int 0)))
14427    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14428         (gt:SI (match_dup 1) (match_dup 2)))]
14429   "TARGET_POWER"
14430   "@
14431    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
14432    #"
14433   [(set_attr "type" "delayed_compare")
14434    (set_attr "length" "12,16")])
14435
14436 (define_split
14437   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14438         (compare:CC
14439          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14440                 (match_operand:SI 2 "reg_or_short_operand" ""))
14441          (const_int 0)))
14442    (set (match_operand:SI 0 "gpc_reg_operand" "")
14443         (gt:SI (match_dup 1) (match_dup 2)))]
14444   "TARGET_POWER && reload_completed"
14445   [(set (match_dup 0)
14446         (gt:SI (match_dup 1) (match_dup 2)))
14447    (set (match_dup 3)
14448         (compare:CC (match_dup 0)
14449                     (const_int 0)))]
14450   "")
14451
14452 (define_insn "*plus_gt0<mode>"
14453   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14454         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
14455                       (const_int 0))
14456                  (match_operand:P 2 "gpc_reg_operand" "r")))]
14457   ""
14458   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
14459   [(set_attr "type" "three")
14460    (set_attr "length" "12")])
14461
14462 (define_insn ""
14463   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14464         (compare:CC
14465          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14466                          (const_int 0))
14467                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14468          (const_int 0)))
14469    (clobber (match_scratch:SI 3 "=&r,&r"))]
14470   "TARGET_32BIT"
14471   "@
14472    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
14473    #"
14474   [(set_attr "type" "compare")
14475    (set_attr "length" "12,16")])
14476
14477 (define_split
14478   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14479         (compare:CC
14480          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14481                          (const_int 0))
14482                   (match_operand:SI 2 "gpc_reg_operand" ""))
14483          (const_int 0)))
14484    (clobber (match_scratch:SI 3 ""))]
14485   "TARGET_32BIT && reload_completed"
14486   [(set (match_dup 3)
14487         (plus:SI (gt:SI (match_dup 1) (const_int 0))
14488                   (match_dup 2)))
14489    (set (match_dup 0)
14490         (compare:CC (match_dup 3)
14491                     (const_int 0)))]
14492   "")
14493
14494 (define_insn ""
14495   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14496         (compare:CC
14497          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14498                          (const_int 0))
14499                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14500          (const_int 0)))
14501    (clobber (match_scratch:DI 3 "=&r,&r"))]
14502   "TARGET_64BIT"
14503   "@
14504    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14505    #"
14506   [(set_attr "type" "compare")
14507    (set_attr "length" "12,16")])
14508
14509 (define_split
14510   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14511         (compare:CC
14512          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14513                          (const_int 0))
14514                   (match_operand:DI 2 "gpc_reg_operand" ""))
14515          (const_int 0)))
14516    (clobber (match_scratch:DI 3 ""))]
14517   "TARGET_64BIT && reload_completed"
14518   [(set (match_dup 3)
14519         (plus:DI (gt:DI (match_dup 1) (const_int 0))
14520                  (match_dup 2)))
14521    (set (match_dup 0)
14522         (compare:CC (match_dup 3)
14523                     (const_int 0)))]
14524   "")
14525
14526 (define_insn ""
14527   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14528         (compare:CC
14529          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14530                          (const_int 0))
14531                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14532          (const_int 0)))
14533    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14534         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14535   "TARGET_32BIT"
14536   "@
14537    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
14538    #"
14539   [(set_attr "type" "compare")
14540    (set_attr "length" "12,16")])
14541
14542 (define_split
14543   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14544         (compare:CC
14545          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14546                          (const_int 0))
14547                   (match_operand:SI 2 "gpc_reg_operand" ""))
14548          (const_int 0)))
14549    (set (match_operand:SI 0 "gpc_reg_operand" "")
14550         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14551   "TARGET_32BIT && reload_completed"
14552   [(set (match_dup 0)
14553         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
14554    (set (match_dup 3)
14555         (compare:CC (match_dup 0)
14556                     (const_int 0)))]
14557   "")
14558
14559 (define_insn ""
14560   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14561         (compare:CC
14562          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14563                          (const_int 0))
14564                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14565          (const_int 0)))
14566    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
14567         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14568   "TARGET_64BIT"
14569   "@
14570    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14571    #"
14572   [(set_attr "type" "compare")
14573    (set_attr "length" "12,16")])
14574
14575 (define_split
14576   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14577         (compare:CC
14578          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14579                          (const_int 0))
14580                   (match_operand:DI 2 "gpc_reg_operand" ""))
14581          (const_int 0)))
14582    (set (match_operand:DI 0 "gpc_reg_operand" "")
14583         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14584   "TARGET_64BIT && reload_completed"
14585   [(set (match_dup 0)
14586         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
14587    (set (match_dup 3)
14588         (compare:CC (match_dup 0)
14589                     (const_int 0)))]
14590   "")
14591
14592 (define_insn ""
14593   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14594         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14595                         (match_operand:SI 2 "reg_or_short_operand" "r"))
14596                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14597   "TARGET_POWER"
14598   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
14599   [(set_attr "length" "12")])
14600
14601 (define_insn ""
14602   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14603         (compare:CC
14604          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14605                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14606                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14607          (const_int 0)))
14608    (clobber (match_scratch:SI 4 "=&r,&r"))]
14609   "TARGET_POWER"
14610   "@
14611    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
14612    #"
14613   [(set_attr "type" "compare")
14614    (set_attr "length" "12,16")])
14615
14616 (define_split
14617   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14618         (compare:CC
14619          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14620                          (match_operand:SI 2 "reg_or_short_operand" ""))
14621                   (match_operand:SI 3 "gpc_reg_operand" ""))
14622          (const_int 0)))
14623    (clobber (match_scratch:SI 4 ""))]
14624   "TARGET_POWER && reload_completed"
14625   [(set (match_dup 4)
14626         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14627    (set (match_dup 0)
14628         (compare:CC (match_dup 4)
14629                     (const_int 0)))]
14630   "")
14631
14632 (define_insn ""
14633   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14634         (compare:CC
14635          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14636                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14637                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14638          (const_int 0)))
14639    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14640         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14641   "TARGET_POWER"
14642   "@
14643    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
14644    #"
14645   [(set_attr "type" "compare")
14646    (set_attr "length" "12,16")])
14647
14648 (define_split
14649   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14650         (compare:CC
14651          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14652                          (match_operand:SI 2 "reg_or_short_operand" ""))
14653                   (match_operand:SI 3 "gpc_reg_operand" ""))
14654          (const_int 0)))
14655    (set (match_operand:SI 0 "gpc_reg_operand" "")
14656         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14657   "TARGET_POWER && reload_completed"
14658   [(set (match_dup 0)
14659         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14660    (set (match_dup 4)
14661         (compare:CC (match_dup 0)
14662                     (const_int 0)))]
14663   "")
14664
14665 (define_insn ""
14666   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14667         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14668                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
14669   "TARGET_POWER"
14670   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
14671   [(set_attr "length" "12")])
14672
14673 (define_insn_and_split "*gtu<mode>"
14674   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14675         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14676                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14677   ""
14678   "#"
14679   ""
14680   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14681    (set (match_dup 0) (neg:P (match_dup 0)))]
14682   "")
14683
14684 (define_insn_and_split "*gtu<mode>_compare"
14685   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14686         (compare:CC
14687          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14688                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14689          (const_int 0)))
14690    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14691         (gtu:P (match_dup 1) (match_dup 2)))]
14692   ""
14693   "#"
14694   ""
14695   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14696    (parallel [(set (match_dup 3)
14697                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14698               (set (match_dup 0) (neg:P (match_dup 0)))])]
14699   "")
14700
14701 (define_insn_and_split "*plus_gtu<mode>"
14702   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14703         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14704                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14705                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
14706   ""
14707   "#"
14708   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14709   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14710    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14711   "")
14712
14713 (define_insn_and_split "*plus_gtu<mode>_compare"
14714   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14715         (compare:CC
14716          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14717                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
14718                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14719          (const_int 0)))
14720    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14721         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14722   ""
14723   "#"
14724   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14725   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14726    (parallel [(set (match_dup 4)
14727                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14728                                (const_int 0)))
14729               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14730   "")
14731
14732 (define_insn "*neg_gtu<mode>"
14733   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14734         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14735                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14736   ""
14737   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
14738   [(set_attr "type" "two")
14739    (set_attr "length" "8")])
14740
14741 \f
14742 ;; Define both directions of branch and return.  If we need a reload
14743 ;; register, we'd rather use CR0 since it is much easier to copy a
14744 ;; register CC value to there.
14745
14746 (define_insn ""
14747   [(set (pc)
14748         (if_then_else (match_operator 1 "branch_comparison_operator"
14749                                       [(match_operand 2
14750                                                       "cc_reg_operand" "y")
14751                                        (const_int 0)])
14752                       (label_ref (match_operand 0 "" ""))
14753                       (pc)))]
14754   ""
14755   "*
14756 {
14757   return output_cbranch (operands[1], \"%l0\", 0, insn);
14758 }"
14759   [(set_attr "type" "branch")])
14760
14761 (define_insn ""
14762   [(set (pc)
14763         (if_then_else (match_operator 0 "branch_comparison_operator"
14764                                       [(match_operand 1
14765                                                       "cc_reg_operand" "y")
14766                                        (const_int 0)])
14767                       (return)
14768                       (pc)))]
14769   "direct_return ()"
14770   "*
14771 {
14772   return output_cbranch (operands[0], NULL, 0, insn);
14773 }"
14774   [(set_attr "type" "jmpreg")
14775    (set_attr "length" "4")])
14776
14777 (define_insn ""
14778   [(set (pc)
14779         (if_then_else (match_operator 1 "branch_comparison_operator"
14780                                       [(match_operand 2
14781                                                       "cc_reg_operand" "y")
14782                                        (const_int 0)])
14783                       (pc)
14784                       (label_ref (match_operand 0 "" ""))))]
14785   ""
14786   "*
14787 {
14788   return output_cbranch (operands[1], \"%l0\", 1, insn);
14789 }"
14790   [(set_attr "type" "branch")])
14791
14792 (define_insn ""
14793   [(set (pc)
14794         (if_then_else (match_operator 0 "branch_comparison_operator"
14795                                       [(match_operand 1
14796                                                       "cc_reg_operand" "y")
14797                                        (const_int 0)])
14798                       (pc)
14799                       (return)))]
14800   "direct_return ()"
14801   "*
14802 {
14803   return output_cbranch (operands[0], NULL, 1, insn);
14804 }"
14805   [(set_attr "type" "jmpreg")
14806    (set_attr "length" "4")])
14807
14808 ;; Logic on condition register values.
14809
14810 ; This pattern matches things like
14811 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
14812 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
14813 ;                                  (const_int 1)))
14814 ; which are generated by the branch logic.
14815 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
14816
14817 (define_insn "*cceq_ior_compare"
14818   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14819         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
14820                         [(match_operator:SI 2
14821                                       "branch_positive_comparison_operator"
14822                                       [(match_operand 3
14823                                                       "cc_reg_operand" "y,y")
14824                                        (const_int 0)])
14825                          (match_operator:SI 4
14826                                       "branch_positive_comparison_operator"
14827                                       [(match_operand 5
14828                                                       "cc_reg_operand" "0,y")
14829                                        (const_int 0)])])
14830                       (const_int 1)))]
14831   ""
14832   "cr%q1 %E0,%j2,%j4"
14833   [(set_attr "type" "cr_logical,delayed_cr")])
14834
14835 ; Why is the constant -1 here, but 1 in the previous pattern?
14836 ; Because ~1 has all but the low bit set.
14837 (define_insn ""
14838   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14839         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
14840                         [(not:SI (match_operator:SI 2
14841                                       "branch_positive_comparison_operator"
14842                                       [(match_operand 3
14843                                                       "cc_reg_operand" "y,y")
14844                                        (const_int 0)]))
14845                          (match_operator:SI 4
14846                                 "branch_positive_comparison_operator"
14847                                 [(match_operand 5
14848                                                 "cc_reg_operand" "0,y")
14849                                  (const_int 0)])])
14850                       (const_int -1)))]
14851   ""
14852   "cr%q1 %E0,%j2,%j4"
14853   [(set_attr "type" "cr_logical,delayed_cr")])
14854
14855 (define_insn "*cceq_rev_compare"
14856   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14857         (compare:CCEQ (match_operator:SI 1
14858                                       "branch_positive_comparison_operator"
14859                                       [(match_operand 2
14860                                                       "cc_reg_operand" "0,y")
14861                                        (const_int 0)])
14862                       (const_int 0)))]
14863   ""
14864   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
14865   [(set_attr "type" "cr_logical,delayed_cr")])
14866
14867 ;; If we are comparing the result of two comparisons, this can be done
14868 ;; using creqv or crxor.
14869
14870 (define_insn_and_split ""
14871   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
14872         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
14873                               [(match_operand 2 "cc_reg_operand" "y")
14874                                (const_int 0)])
14875                       (match_operator 3 "branch_comparison_operator"
14876                               [(match_operand 4 "cc_reg_operand" "y")
14877                                (const_int 0)])))]
14878   ""
14879   "#"
14880   ""
14881   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
14882                                     (match_dup 5)))]
14883   "
14884 {
14885   int positive_1, positive_2;
14886
14887   positive_1 = branch_positive_comparison_operator (operands[1],
14888                                                     GET_MODE (operands[1]));
14889   positive_2 = branch_positive_comparison_operator (operands[3],
14890                                                     GET_MODE (operands[3]));
14891
14892   if (! positive_1)
14893     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
14894                                                             GET_CODE (operands[1])),
14895                                   SImode,
14896                                   operands[2], const0_rtx);
14897   else if (GET_MODE (operands[1]) != SImode)
14898     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
14899                                   operands[2], const0_rtx);
14900
14901   if (! positive_2)
14902     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
14903                                                             GET_CODE (operands[3])),
14904                                   SImode,
14905                                   operands[4], const0_rtx);
14906   else if (GET_MODE (operands[3]) != SImode)
14907     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
14908                                   operands[4], const0_rtx);
14909
14910   if (positive_1 == positive_2)
14911     {
14912       operands[1] = gen_rtx_NOT (SImode, operands[1]);
14913       operands[5] = constm1_rtx;
14914     }
14915   else
14916     {
14917       operands[5] = const1_rtx;
14918     }
14919 }")
14920
14921 ;; Unconditional branch and return.
14922
14923 (define_insn "jump"
14924   [(set (pc)
14925         (label_ref (match_operand 0 "" "")))]
14926   ""
14927   "b %l0"
14928   [(set_attr "type" "branch")])
14929
14930 (define_insn "return"
14931   [(return)]
14932   "direct_return ()"
14933   "{br|blr}"
14934   [(set_attr "type" "jmpreg")])
14935
14936 (define_expand "indirect_jump"
14937   [(set (pc) (match_operand 0 "register_operand" ""))])
14938
14939 (define_insn "*indirect_jump<mode>"
14940   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
14941   ""
14942   "@
14943    bctr
14944    {br|blr}"
14945   [(set_attr "type" "jmpreg")])
14946
14947 ;; Table jump for switch statements:
14948 (define_expand "tablejump"
14949   [(use (match_operand 0 "" ""))
14950    (use (label_ref (match_operand 1 "" "")))]
14951   ""
14952   "
14953 {
14954   if (TARGET_32BIT)
14955     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
14956   else
14957     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
14958   DONE;
14959 }")
14960
14961 (define_expand "tablejumpsi"
14962   [(set (match_dup 3)
14963         (plus:SI (match_operand:SI 0 "" "")
14964                  (match_dup 2)))
14965    (parallel [(set (pc) (match_dup 3))
14966               (use (label_ref (match_operand 1 "" "")))])]
14967   "TARGET_32BIT"
14968   "
14969 { operands[0] = force_reg (SImode, operands[0]);
14970   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
14971   operands[3] = gen_reg_rtx (SImode);
14972 }")
14973
14974 (define_expand "tablejumpdi"
14975   [(set (match_dup 4)
14976         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
14977    (set (match_dup 3)
14978         (plus:DI (match_dup 4)
14979                  (match_dup 2)))
14980    (parallel [(set (pc) (match_dup 3))
14981               (use (label_ref (match_operand 1 "" "")))])]
14982   "TARGET_64BIT"
14983   "
14984 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
14985   operands[3] = gen_reg_rtx (DImode);
14986   operands[4] = gen_reg_rtx (DImode);
14987 }")
14988
14989 (define_insn "*tablejump<mode>_internal1"
14990   [(set (pc)
14991         (match_operand:P 0 "register_operand" "c,*l"))
14992    (use (label_ref (match_operand 1 "" "")))]
14993   ""
14994   "@
14995    bctr
14996    {br|blr}"
14997   [(set_attr "type" "jmpreg")])
14998
14999 (define_insn "nop"
15000   [(const_int 0)]
15001   ""
15002   "{cror 0,0,0|nop}")
15003 \f
15004 ;; Define the subtract-one-and-jump insns, starting with the template
15005 ;; so loop.c knows what to generate.
15006
15007 (define_expand "doloop_end"
15008   [(use (match_operand 0 "" ""))        ; loop pseudo
15009    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
15010    (use (match_operand 2 "" ""))        ; max iterations
15011    (use (match_operand 3 "" ""))        ; loop level
15012    (use (match_operand 4 "" ""))]       ; label
15013   ""
15014   "
15015 {
15016   /* Only use this on innermost loops.  */
15017   if (INTVAL (operands[3]) > 1)
15018     FAIL;
15019   if (TARGET_64BIT)
15020     {
15021       if (GET_MODE (operands[0]) != DImode)
15022         FAIL;
15023       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
15024     }
15025   else
15026     {
15027       if (GET_MODE (operands[0]) != SImode)
15028         FAIL;
15029       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
15030     }
15031   DONE;
15032 }")
15033
15034 (define_expand "ctr<mode>"
15035   [(parallel [(set (pc)
15036                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
15037                                      (const_int 1))
15038                                  (label_ref (match_operand 1 "" ""))
15039                                  (pc)))
15040               (set (match_dup 0)
15041                    (plus:P (match_dup 0)
15042                             (const_int -1)))
15043               (clobber (match_scratch:CC 2 ""))
15044               (clobber (match_scratch:P 3 ""))])]
15045   ""
15046   "")
15047
15048 ;; We need to be able to do this for any operand, including MEM, or we
15049 ;; will cause reload to blow up since we don't allow output reloads on
15050 ;; JUMP_INSNs.
15051 ;; For the length attribute to be calculated correctly, the
15052 ;; label MUST be operand 0.
15053
15054 (define_insn "*ctr<mode>_internal1"
15055   [(set (pc)
15056         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15057                           (const_int 1))
15058                       (label_ref (match_operand 0 "" ""))
15059                       (pc)))
15060    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15061         (plus:P (match_dup 1)
15062                  (const_int -1)))
15063    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15064    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15065   ""
15066   "*
15067 {
15068   if (which_alternative != 0)
15069     return \"#\";
15070   else if (get_attr_length (insn) == 4)
15071     return \"{bdn|bdnz} %l0\";
15072   else
15073     return \"bdz $+8\;b %l0\";
15074 }"
15075   [(set_attr "type" "branch")
15076    (set_attr "length" "*,12,16,16")])
15077
15078 (define_insn "*ctr<mode>_internal2"
15079   [(set (pc)
15080         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15081                           (const_int 1))
15082                       (pc)
15083                       (label_ref (match_operand 0 "" ""))))
15084    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15085         (plus:P (match_dup 1)
15086                  (const_int -1)))
15087    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15088    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15089   ""
15090   "*
15091 {
15092   if (which_alternative != 0)
15093     return \"#\";
15094   else if (get_attr_length (insn) == 4)
15095     return \"bdz %l0\";
15096   else
15097     return \"{bdn|bdnz} $+8\;b %l0\";
15098 }"
15099   [(set_attr "type" "branch")
15100    (set_attr "length" "*,12,16,16")])
15101
15102 ;; Similar but use EQ
15103
15104 (define_insn "*ctr<mode>_internal5"
15105   [(set (pc)
15106         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15107                           (const_int 1))
15108                       (label_ref (match_operand 0 "" ""))
15109                       (pc)))
15110    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15111         (plus:P (match_dup 1)
15112                  (const_int -1)))
15113    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15114    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15115   ""
15116   "*
15117 {
15118   if (which_alternative != 0)
15119     return \"#\";
15120   else if (get_attr_length (insn) == 4)
15121     return \"bdz %l0\";
15122   else
15123     return \"{bdn|bdnz} $+8\;b %l0\";
15124 }"
15125   [(set_attr "type" "branch")
15126    (set_attr "length" "*,12,16,16")])
15127
15128 (define_insn "*ctr<mode>_internal6"
15129   [(set (pc)
15130         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15131                           (const_int 1))
15132                       (pc)
15133                       (label_ref (match_operand 0 "" ""))))
15134    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15135         (plus:P (match_dup 1)
15136                  (const_int -1)))
15137    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15138    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15139   ""
15140   "*
15141 {
15142   if (which_alternative != 0)
15143     return \"#\";
15144   else if (get_attr_length (insn) == 4)
15145     return \"{bdn|bdnz} %l0\";
15146   else
15147     return \"bdz $+8\;b %l0\";
15148 }"
15149   [(set_attr "type" "branch")
15150    (set_attr "length" "*,12,16,16")])
15151
15152 ;; Now the splitters if we could not allocate the CTR register
15153
15154 (define_split
15155   [(set (pc)
15156         (if_then_else (match_operator 2 "comparison_operator"
15157                                       [(match_operand:P 1 "gpc_reg_operand" "")
15158                                        (const_int 1)])
15159                       (match_operand 5 "" "")
15160                       (match_operand 6 "" "")))
15161    (set (match_operand:P 0 "gpc_reg_operand" "")
15162         (plus:P (match_dup 1) (const_int -1)))
15163    (clobber (match_scratch:CC 3 ""))
15164    (clobber (match_scratch:P 4 ""))]
15165   "reload_completed"
15166   [(parallel [(set (match_dup 3)
15167                    (compare:CC (plus:P (match_dup 1)
15168                                         (const_int -1))
15169                                (const_int 0)))
15170               (set (match_dup 0)
15171                    (plus:P (match_dup 1)
15172                             (const_int -1)))])
15173    (set (pc) (if_then_else (match_dup 7)
15174                            (match_dup 5)
15175                            (match_dup 6)))]
15176   "
15177 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15178                                 operands[3], const0_rtx); }")
15179
15180 (define_split
15181   [(set (pc)
15182         (if_then_else (match_operator 2 "comparison_operator"
15183                                       [(match_operand:P 1 "gpc_reg_operand" "")
15184                                        (const_int 1)])
15185                       (match_operand 5 "" "")
15186                       (match_operand 6 "" "")))
15187    (set (match_operand:P 0 "nonimmediate_operand" "")
15188         (plus:P (match_dup 1) (const_int -1)))
15189    (clobber (match_scratch:CC 3 ""))
15190    (clobber (match_scratch:P 4 ""))]
15191   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
15192   [(parallel [(set (match_dup 3)
15193                    (compare:CC (plus:P (match_dup 1)
15194                                         (const_int -1))
15195                                (const_int 0)))
15196               (set (match_dup 4)
15197                    (plus:P (match_dup 1)
15198                             (const_int -1)))])
15199    (set (match_dup 0)
15200         (match_dup 4))
15201    (set (pc) (if_then_else (match_dup 7)
15202                            (match_dup 5)
15203                            (match_dup 6)))]
15204   "
15205 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15206                                 operands[3], const0_rtx); }")
15207 \f
15208 (define_insn "trap"
15209   [(trap_if (const_int 1) (const_int 0))]
15210   ""
15211   "{t 31,0,0|trap}"
15212   [(set_attr "type" "trap")])
15213
15214 (define_expand "ctrap<mode>4"
15215   [(trap_if (match_operator 0 "ordered_comparison_operator"
15216                             [(match_operand:GPR 1 "register_operand")
15217                              (match_operand:GPR 2 "reg_or_short_operand")])
15218             (match_operand 3 "zero_constant" ""))]
15219   ""
15220   "")
15221
15222 (define_insn ""
15223   [(trap_if (match_operator 0 "ordered_comparison_operator"
15224                             [(match_operand:GPR 1 "register_operand" "r")
15225                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
15226             (const_int 0))]
15227   ""
15228   "{t|t<wd>}%V0%I2 %1,%2"
15229   [(set_attr "type" "trap")])
15230 \f
15231 ;; Insns related to generating the function prologue and epilogue.
15232
15233 (define_expand "prologue"
15234   [(use (const_int 0))]
15235   "TARGET_SCHED_PROLOG"
15236   "
15237 {
15238       rs6000_emit_prologue ();
15239       DONE;
15240 }")
15241
15242 (define_insn "*movesi_from_cr_one"
15243   [(match_parallel 0 "mfcr_operation"
15244                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15245                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
15246                                      (match_operand 3 "immediate_operand" "n")]
15247                           UNSPEC_MOVESI_FROM_CR))])]
15248   "TARGET_MFCRF"
15249   "*
15250 {
15251   int mask = 0;
15252   int i;
15253   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15254   {
15255     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15256     operands[4] = GEN_INT (mask);
15257     output_asm_insn (\"mfcr %1,%4\", operands);
15258   }
15259   return \"\";
15260 }"
15261   [(set_attr "type" "mfcrf")])
15262
15263 (define_insn "movesi_from_cr"
15264   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15265         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
15266                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
15267                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
15268                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
15269                    UNSPEC_MOVESI_FROM_CR))]
15270   ""
15271   "mfcr %0"
15272   [(set_attr "type" "mfcr")])
15273
15274 (define_insn "*stmw"
15275   [(match_parallel 0 "stmw_operation"
15276                    [(set (match_operand:SI 1 "memory_operand" "=m")
15277                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
15278   "TARGET_MULTIPLE"
15279   "{stm|stmw} %2,%1"
15280   [(set_attr "type" "store_ux")])
15281
15282 (define_insn "*save_gpregs_<mode>"
15283   [(match_parallel 0 "any_parallel_operand"
15284                    [(clobber (reg:P 65))
15285                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15286                     (use (match_operand:P 2 "gpc_reg_operand" "r"))
15287                     (set (match_operand:P 3 "memory_operand" "=m")
15288                          (match_operand:P 4 "gpc_reg_operand" "r"))])]
15289   ""
15290   "bl %1"
15291   [(set_attr "type" "branch")
15292    (set_attr "length" "4")])
15293
15294 (define_insn "*save_fpregs_<mode>"
15295   [(match_parallel 0 "any_parallel_operand"
15296                    [(clobber (reg:P 65))
15297                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15298                     (use (match_operand:P 2 "gpc_reg_operand" "r"))
15299                     (set (match_operand:DF 3 "memory_operand" "=m")
15300                          (match_operand:DF 4 "gpc_reg_operand" "d"))])]
15301   ""
15302   "bl %1"
15303   [(set_attr "type" "branch")
15304    (set_attr "length" "4")])
15305
15306 ; These are to explain that changes to the stack pointer should
15307 ; not be moved over stores to stack memory.
15308 (define_insn "stack_tie"
15309   [(set (match_operand:BLK 0 "memory_operand" "+m")
15310         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
15311   ""
15312   ""
15313   [(set_attr "length" "0")])
15314
15315 ; Like stack_tie, but depend on both fp and sp based memory.
15316 (define_insn "frame_tie"
15317   [(set (match_operand:BLK 0 "memory_operand" "+m")
15318         (unspec:BLK [(match_dup 0)
15319                      (match_operand:BLK 1 "memory_operand" "m")] UNSPEC_TIE))]
15320   ""
15321   ""
15322   [(set_attr "length" "0")])
15323
15324
15325 (define_expand "epilogue"
15326   [(use (const_int 0))]
15327   "TARGET_SCHED_PROLOG"
15328   "
15329 {
15330       rs6000_emit_epilogue (FALSE);
15331       DONE;
15332 }")
15333
15334 ; On some processors, doing the mtcrf one CC register at a time is
15335 ; faster (like on the 604e).  On others, doing them all at once is
15336 ; faster; for instance, on the 601 and 750.
15337
15338 (define_expand "movsi_to_cr_one"
15339   [(set (match_operand:CC 0 "cc_reg_operand" "")
15340         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
15341                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
15342   ""
15343   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
15344
15345 (define_insn "*movsi_to_cr"
15346   [(match_parallel 0 "mtcrf_operation"
15347                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
15348                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
15349                                      (match_operand 3 "immediate_operand" "n")]
15350                                     UNSPEC_MOVESI_TO_CR))])]
15351  ""
15352  "*
15353 {
15354   int mask = 0;
15355   int i;
15356   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15357     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15358   operands[4] = GEN_INT (mask);
15359   return \"mtcrf %4,%2\";
15360 }"
15361   [(set_attr "type" "mtcr")])
15362
15363 (define_insn "*mtcrfsi"
15364   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
15365         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15366                     (match_operand 2 "immediate_operand" "n")]
15367                    UNSPEC_MOVESI_TO_CR))]
15368   "GET_CODE (operands[0]) == REG
15369    && CR_REGNO_P (REGNO (operands[0]))
15370    && GET_CODE (operands[2]) == CONST_INT
15371    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
15372   "mtcrf %R0,%1"
15373   [(set_attr "type" "mtcr")])
15374
15375 ; The load-multiple instructions have similar properties.
15376 ; Note that "load_multiple" is a name known to the machine-independent
15377 ; code that actually corresponds to the PowerPC load-string.
15378
15379 (define_insn "*lmw"
15380   [(match_parallel 0 "lmw_operation"
15381                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15382                          (match_operand:SI 2 "memory_operand" "m"))])]
15383   "TARGET_MULTIPLE"
15384   "{lm|lmw} %1,%2"
15385   [(set_attr "type" "load_ux")
15386    (set_attr "cell_micro" "always")])
15387
15388 (define_insn "*return_internal_<mode>"
15389   [(return)
15390    (use (match_operand:P 0 "register_operand" "lc"))]
15391   ""
15392   "b%T0"
15393   [(set_attr "type" "jmpreg")])
15394
15395 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
15396 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
15397
15398 (define_insn "*restore_gpregs_<mode>"
15399  [(match_parallel 0 "any_parallel_operand"
15400                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15401                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15402                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15403                    (set (match_operand:P 4 "gpc_reg_operand" "=r")
15404                         (match_operand:P 5 "memory_operand" "m"))])]
15405  ""
15406  "bl %2"
15407  [(set_attr "type" "branch")
15408   (set_attr "length" "4")])
15409
15410 (define_insn "*return_and_restore_gpregs_<mode>"
15411  [(match_parallel 0 "any_parallel_operand"
15412                   [(return)
15413                    (clobber (match_operand:P 1 "register_operand" "=l"))
15414                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15415                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15416                    (set (match_operand:P 4 "gpc_reg_operand" "=r")
15417                         (match_operand:P 5 "memory_operand" "m"))])]
15418  ""
15419  "b %2"
15420  [(set_attr "type" "branch")
15421   (set_attr "length" "4")])
15422
15423 (define_insn "*return_and_restore_fpregs_<mode>"
15424  [(match_parallel 0 "any_parallel_operand"
15425                   [(return)
15426                    (clobber (match_operand:P 1 "register_operand" "=l"))
15427                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15428                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15429                    (set (match_operand:DF 4 "gpc_reg_operand" "=d")
15430                         (match_operand:DF 5 "memory_operand" "m"))])]
15431  ""
15432  "b %2"
15433  [(set_attr "type" "branch")
15434   (set_attr "length" "4")])
15435
15436 (define_insn "*return_and_restore_fpregs_aix_<mode>"
15437  [(match_parallel 0 "any_parallel_operand"
15438                   [(return)
15439                    (use (match_operand:P 1 "register_operand" "l"))
15440                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15441                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15442                    (set (match_operand:DF 4 "gpc_reg_operand" "=d")
15443                         (match_operand:DF 5 "memory_operand" "m"))])]
15444  ""
15445  "b %2"
15446  [(set_attr "type" "branch")
15447   (set_attr "length" "4")])
15448
15449 ; This is used in compiling the unwind routines.
15450 (define_expand "eh_return"
15451   [(use (match_operand 0 "general_operand" ""))]
15452   ""
15453   "
15454 {
15455   if (TARGET_32BIT)
15456     emit_insn (gen_eh_set_lr_si (operands[0]));
15457   else
15458     emit_insn (gen_eh_set_lr_di (operands[0]));
15459   DONE;
15460 }")
15461
15462 ; We can't expand this before we know where the link register is stored.
15463 (define_insn "eh_set_lr_<mode>"
15464   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
15465                     UNSPECV_EH_RR)
15466    (clobber (match_scratch:P 1 "=&b"))]
15467   ""
15468   "#")
15469
15470 (define_split
15471   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
15472    (clobber (match_scratch 1 ""))]
15473   "reload_completed"
15474   [(const_int 0)]
15475   "
15476 {
15477   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
15478   DONE;
15479 }")
15480
15481 (define_insn "prefetch"
15482   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
15483              (match_operand:SI 1 "const_int_operand" "n")
15484              (match_operand:SI 2 "const_int_operand" "n"))]
15485   "TARGET_POWERPC"
15486   "*
15487 {
15488   if (GET_CODE (operands[0]) == REG)
15489     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
15490   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
15491 }"
15492   [(set_attr "type" "load")])
15493 \f
15494 (define_insn "bpermd_<mode>"
15495   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15496         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
15497                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
15498   "TARGET_POPCNTD"
15499   "bpermd %0,%1,%2"
15500   [(set_attr "type" "integer")])
15501
15502 \f
15503
15504 (include "sync.md")
15505 (include "vector.md")
15506 (include "vsx.md")
15507 (include "altivec.md")
15508 (include "spe.md")
15509 (include "dfp.md")
15510 (include "paired.md")