OSDN Git Service

b3faab8375d2e6e794a7cdb5d5d44ccd5f339d52
[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 {
11008   if (TARGET_CMODEL != CMODEL_SMALL)
11009     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;bl %z3\;%.";
11010   else
11011     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;%.";
11012 }
11013   "&& TARGET_TLS_MARKERS"
11014   [(set (match_dup 0)
11015         (unspec:TLSmode [(match_dup 1)
11016                          (match_dup 2)]
11017                         UNSPEC_TLSGD))
11018    (parallel [(set (match_dup 0)
11019                    (call (mem:TLSmode (match_dup 3))
11020                          (match_dup 4)))
11021               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11022               (clobber (reg:SI LR_REGNO))])]
11023   ""
11024   [(set_attr "type" "two")
11025    (set (attr "length")
11026      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11027                    (const_int 16)
11028                    (const_int 12)))])
11029
11030 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
11031   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11032         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11033               (match_operand 4 "" "g")))
11034    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11035                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11036                    UNSPEC_TLSGD)
11037    (clobber (reg:SI LR_REGNO))]
11038   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11039 {
11040   if (flag_pic)
11041     {
11042       if (TARGET_SECURE_PLT && flag_pic == 2)
11043         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
11044       else
11045         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
11046     }
11047   else
11048     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
11049 }
11050   "&& TARGET_TLS_MARKERS"
11051   [(set (match_dup 0)
11052         (unspec:TLSmode [(match_dup 1)
11053                          (match_dup 2)]
11054                         UNSPEC_TLSGD))
11055    (parallel [(set (match_dup 0)
11056                    (call (mem:TLSmode (match_dup 3))
11057                          (match_dup 4)))
11058               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11059               (clobber (reg:SI LR_REGNO))])]
11060   ""
11061   [(set_attr "type" "two")
11062    (set_attr "length" "8")])
11063
11064 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
11065   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11066         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11067                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11068                         UNSPEC_TLSGD))]
11069   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11070   "addi %0,%1,%2@got@tlsgd"
11071   "&& TARGET_CMODEL != CMODEL_SMALL"
11072   [(set (match_dup 3)
11073         (plus:TLSmode (match_dup 1)
11074           (high:TLSmode
11075             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD))))
11076    (set (match_dup 0)
11077         (lo_sum:TLSmode (match_dup 3)
11078             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)))]
11079   "
11080 {
11081   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11082 }"
11083   [(set (attr "length")
11084      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11085                    (const_int 8)
11086                    (const_int 4)))])
11087
11088 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
11089   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11090      (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11091        (high:TLSmode
11092           (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11093                           UNSPEC_TLSGD))))]
11094   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11095   "addis %0,%1,%2@got@tlsgd@ha"
11096   [(set_attr "length" "4")])
11097
11098 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
11099   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11100      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11101        (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11102                        UNSPEC_TLSGD)))]
11103   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11104   "addi %0,%1,%2@got@tlsgd@l"
11105   [(set_attr "length" "4")])
11106
11107 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
11108   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11109         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11110               (match_operand 2 "" "g")))
11111    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11112                    UNSPEC_TLSGD)
11113    (clobber (reg:SI LR_REGNO))]
11114   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11115   "bl %z1(%3@tlsgd)\;%."
11116   [(set_attr "type" "branch")
11117    (set_attr "length" "8")])
11118
11119 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
11120   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11121         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11122               (match_operand 2 "" "g")))
11123    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11124                    UNSPEC_TLSGD)
11125    (clobber (reg:SI LR_REGNO))]
11126   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11127 {
11128   if (flag_pic)
11129     {
11130       if (TARGET_SECURE_PLT && flag_pic == 2)
11131         return "bl %z1+32768(%3@tlsgd)@plt";
11132       return "bl %z1(%3@tlsgd)@plt";
11133     }
11134   return "bl %z1(%3@tlsgd)";
11135 }
11136   [(set_attr "type" "branch")
11137    (set_attr "length" "4")])
11138
11139 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
11140   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11141         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11142               (match_operand 3 "" "g")))
11143    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11144                    UNSPEC_TLSLD)
11145    (clobber (reg:SI LR_REGNO))]
11146   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11147 {
11148   if (TARGET_CMODEL != CMODEL_SMALL)
11149     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;bl %z2\;%.";
11150   else
11151     return "addi %0,%1,%&@got@tlsld\;bl %z2\;%.";
11152 }
11153   "&& TARGET_TLS_MARKERS"
11154   [(set (match_dup 0)
11155         (unspec:TLSmode [(match_dup 1)]
11156                         UNSPEC_TLSLD))
11157    (parallel [(set (match_dup 0)
11158                    (call (mem:TLSmode (match_dup 2))
11159                          (match_dup 3)))
11160               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11161               (clobber (reg:SI LR_REGNO))])]
11162   ""
11163   [(set_attr "type" "two")
11164    (set (attr "length")
11165      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11166                    (const_int 16)
11167                    (const_int 12)))])
11168
11169 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
11170   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11171         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11172               (match_operand 3 "" "g")))
11173    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11174                    UNSPEC_TLSLD)
11175    (clobber (reg:SI LR_REGNO))]
11176   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11177 {
11178   if (flag_pic)
11179     {
11180       if (TARGET_SECURE_PLT && flag_pic == 2)
11181         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11182       else
11183         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11184     }
11185   else
11186     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11187 }
11188   "&& TARGET_TLS_MARKERS"
11189   [(set (match_dup 0)
11190         (unspec:TLSmode [(match_dup 1)]
11191                         UNSPEC_TLSLD))
11192    (parallel [(set (match_dup 0)
11193                    (call (mem:TLSmode (match_dup 2))
11194                          (match_dup 3)))
11195               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11196               (clobber (reg:SI LR_REGNO))])]
11197   ""
11198   [(set_attr "length" "8")])
11199
11200 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
11201   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11202         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11203                         UNSPEC_TLSLD))]
11204   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11205   "addi %0,%1,%&@got@tlsld"
11206   "&& TARGET_CMODEL != CMODEL_SMALL"
11207   [(set (match_dup 2)
11208         (plus:TLSmode (match_dup 1)
11209           (high:TLSmode
11210             (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD))))
11211    (set (match_dup 0)
11212         (lo_sum:TLSmode (match_dup 2)
11213             (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
11214   "
11215 {
11216   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11217 }"
11218   [(set (attr "length")
11219      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11220                    (const_int 8)
11221                    (const_int 4)))])
11222
11223 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
11224   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11225      (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11226        (high:TLSmode
11227           (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD))))]
11228   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11229   "addis %0,%1,%&@got@tlsld@ha"
11230   [(set_attr "length" "4")])
11231
11232 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
11233   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11234      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11235        (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
11236   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11237   "addi %0,%1,%&@got@tlsld@l"
11238   [(set_attr "length" "4")])
11239
11240 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11241   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11242         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11243               (match_operand 2 "" "g")))
11244    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11245    (clobber (reg:SI LR_REGNO))]
11246   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11247   "bl %z1(%&@tlsld)\;%."
11248   [(set_attr "type" "branch")
11249    (set_attr "length" "8")])
11250
11251 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11252   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11253         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11254               (match_operand 2 "" "g")))
11255    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11256    (clobber (reg:SI LR_REGNO))]
11257   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11258 {
11259   if (flag_pic)
11260     {
11261       if (TARGET_SECURE_PLT && flag_pic == 2)
11262         return "bl %z1+32768(%&@tlsld)@plt";
11263       return "bl %z1(%&@tlsld)@plt";
11264     }
11265   return "bl %z1(%&@tlsld)";
11266 }
11267   [(set_attr "type" "branch")
11268    (set_attr "length" "4")])
11269
11270 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11271   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11272         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11273                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11274                         UNSPEC_TLSDTPREL))]
11275   "HAVE_AS_TLS"
11276   "addi %0,%1,%2@dtprel")
11277
11278 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11279   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11280         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11281                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11282                         UNSPEC_TLSDTPRELHA))]
11283   "HAVE_AS_TLS"
11284   "addis %0,%1,%2@dtprel@ha")
11285
11286 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11287   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11288         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11289                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11290                         UNSPEC_TLSDTPRELLO))]
11291   "HAVE_AS_TLS"
11292   "addi %0,%1,%2@dtprel@l")
11293
11294 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11295   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11296         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11297                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11298                         UNSPEC_TLSGOTDTPREL))]
11299   "HAVE_AS_TLS"
11300   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
11301   "&& TARGET_CMODEL != CMODEL_SMALL"
11302   [(set (match_dup 3)
11303         (plus:TLSmode (match_dup 1)
11304           (high:TLSmode
11305             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL))))
11306    (set (match_dup 0)
11307         (lo_sum:TLSmode (match_dup 3)
11308             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
11309   "
11310 {
11311   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11312 }"
11313   [(set (attr "length")
11314      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11315                    (const_int 8)
11316                    (const_int 4)))])
11317
11318 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
11319   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11320      (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11321        (high:TLSmode
11322          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11323                          UNSPEC_TLSGOTDTPREL))))]
11324   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11325   "addis %0,%1,%2@got@dtprel@ha"
11326   [(set_attr "length" "4")])
11327
11328 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
11329   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11330      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11331          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11332                          UNSPEC_TLSGOTDTPREL)))]
11333   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11334   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
11335   [(set_attr "length" "4")])
11336
11337 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11338   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11339         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11340                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11341                         UNSPEC_TLSTPREL))]
11342   "HAVE_AS_TLS"
11343   "addi %0,%1,%2@tprel")
11344
11345 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11346   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11347         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11348                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11349                         UNSPEC_TLSTPRELHA))]
11350   "HAVE_AS_TLS"
11351   "addis %0,%1,%2@tprel@ha")
11352
11353 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11354   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11355         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11356                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11357                         UNSPEC_TLSTPRELLO))]
11358   "HAVE_AS_TLS"
11359   "addi %0,%1,%2@tprel@l")
11360
11361 ;; "b" output constraint here and on tls_tls input to support linker tls
11362 ;; optimization.  The linker may edit the instructions emitted by a
11363 ;; tls_got_tprel/tls_tls pair to addis,addi.
11364 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11365   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11366         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11367                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11368                         UNSPEC_TLSGOTTPREL))]
11369   "HAVE_AS_TLS"
11370   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
11371   "&& TARGET_CMODEL != CMODEL_SMALL"
11372   [(set (match_dup 3)
11373         (plus:TLSmode (match_dup 1)
11374           (high:TLSmode
11375             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL))))
11376    (set (match_dup 0)
11377         (lo_sum:TLSmode (match_dup 3)
11378             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL)))]
11379   "
11380 {
11381   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11382 }"
11383   [(set (attr "length")
11384      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11385                    (const_int 8)
11386                    (const_int 4)))])
11387
11388 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
11389   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11390      (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11391        (high:TLSmode
11392          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11393                          UNSPEC_TLSGOTTPREL))))]
11394   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11395   "addis %0,%1,%2@got@tprel@ha"
11396   [(set_attr "length" "4")])
11397
11398 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
11399   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11400      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11401          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11402                          UNSPEC_TLSGOTTPREL)))]
11403   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11404   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
11405   [(set_attr "length" "4")])
11406
11407 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11408   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11409         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11410                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11411                         UNSPEC_TLSTLS))]
11412   "HAVE_AS_TLS"
11413   "add %0,%1,%2@tls")
11414 \f
11415 ;; Next come insns related to the calling sequence.
11416 ;;
11417 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11418 ;; We move the back-chain and decrement the stack pointer.
11419
11420 (define_expand "allocate_stack"
11421   [(set (match_operand 0 "gpc_reg_operand" "")
11422         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11423    (set (reg 1)
11424         (minus (reg 1) (match_dup 1)))]
11425   ""
11426   "
11427 { rtx chain = gen_reg_rtx (Pmode);
11428   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11429   rtx neg_op0;
11430   rtx insn, par, set, mem;
11431
11432   emit_move_insn (chain, stack_bot);
11433
11434   /* Check stack bounds if necessary.  */
11435   if (crtl->limit_stack)
11436     {
11437       rtx available;
11438       available = expand_binop (Pmode, sub_optab,
11439                                 stack_pointer_rtx, stack_limit_rtx,
11440                                 NULL_RTX, 1, OPTAB_WIDEN);
11441       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11442     }
11443
11444   if (GET_CODE (operands[1]) != CONST_INT
11445       || INTVAL (operands[1]) < -32767
11446       || INTVAL (operands[1]) > 32768)
11447     {
11448       neg_op0 = gen_reg_rtx (Pmode);
11449       if (TARGET_32BIT)
11450         emit_insn (gen_negsi2 (neg_op0, operands[1]));
11451       else
11452         emit_insn (gen_negdi2 (neg_op0, operands[1]));
11453     }
11454   else
11455     neg_op0 = GEN_INT (- INTVAL (operands[1]));
11456
11457   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
11458                                        : gen_movdi_di_update_stack))
11459                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
11460                          chain));
11461   /* Since we didn't use gen_frame_mem to generate the MEM, grab
11462      it now and set the alias set/attributes. The above gen_*_update
11463      calls will generate a PARALLEL with the MEM set being the first
11464      operation. */
11465   par = PATTERN (insn);
11466   gcc_assert (GET_CODE (par) == PARALLEL);
11467   set = XVECEXP (par, 0, 0);
11468   gcc_assert (GET_CODE (set) == SET);
11469   mem = SET_DEST (set);
11470   gcc_assert (MEM_P (mem));
11471   MEM_NOTRAP_P (mem) = 1;
11472   set_mem_alias_set (mem, get_frame_alias_set ());
11473
11474   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
11475   DONE;
11476 }")
11477
11478 ;; These patterns say how to save and restore the stack pointer.  We need not
11479 ;; save the stack pointer at function level since we are careful to
11480 ;; preserve the backchain.  At block level, we have to restore the backchain
11481 ;; when we restore the stack pointer.
11482 ;;
11483 ;; For nonlocal gotos, we must save both the stack pointer and its
11484 ;; backchain and restore both.  Note that in the nonlocal case, the
11485 ;; save area is a memory location.
11486
11487 (define_expand "save_stack_function"
11488   [(match_operand 0 "any_operand" "")
11489    (match_operand 1 "any_operand" "")]
11490   ""
11491   "DONE;")
11492
11493 (define_expand "restore_stack_function"
11494   [(match_operand 0 "any_operand" "")
11495    (match_operand 1 "any_operand" "")]
11496   ""
11497   "DONE;")
11498
11499 ;; Adjust stack pointer (op0) to a new value (op1).
11500 ;; First copy old stack backchain to new location, and ensure that the
11501 ;; scheduler won't reorder the sp assignment before the backchain write.
11502 (define_expand "restore_stack_block"
11503   [(set (match_dup 2) (match_dup 3))
11504    (set (match_dup 4) (match_dup 2))
11505    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
11506    (set (match_operand 0 "register_operand" "")
11507         (match_operand 1 "register_operand" ""))]
11508   ""
11509   "
11510 {
11511   operands[1] = force_reg (Pmode, operands[1]);
11512   operands[2] = gen_reg_rtx (Pmode);
11513   operands[3] = gen_frame_mem (Pmode, operands[0]);
11514   operands[4] = gen_frame_mem (Pmode, operands[1]);
11515   operands[5] = gen_frame_mem (BLKmode, operands[0]);
11516 }")
11517
11518 (define_expand "save_stack_nonlocal"
11519   [(set (match_dup 3) (match_dup 4))
11520    (set (match_operand 0 "memory_operand" "") (match_dup 3))
11521    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
11522   ""
11523   "
11524 {
11525   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11526
11527   /* Copy the backchain to the first word, sp to the second.  */
11528   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
11529   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
11530   operands[3] = gen_reg_rtx (Pmode);
11531   operands[4] = gen_frame_mem (Pmode, operands[1]);
11532 }")
11533
11534 (define_expand "restore_stack_nonlocal"
11535   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
11536    (set (match_dup 3) (match_dup 4))
11537    (set (match_dup 5) (match_dup 2))
11538    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
11539    (set (match_operand 0 "register_operand" "") (match_dup 3))]
11540   ""
11541   "
11542 {
11543   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11544
11545   /* Restore the backchain from the first word, sp from the second.  */
11546   operands[2] = gen_reg_rtx (Pmode);
11547   operands[3] = gen_reg_rtx (Pmode);
11548   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
11549   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
11550   operands[5] = gen_frame_mem (Pmode, operands[3]);
11551   operands[6] = gen_frame_mem (BLKmode, operands[0]);
11552 }")
11553 \f
11554 ;; TOC register handling.
11555
11556 ;; Code to initialize the TOC register...
11557
11558 (define_insn "load_toc_aix_si"
11559   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11560                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
11561               (use (reg:SI 2))])]
11562   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
11563   "*
11564 {
11565   char buf[30];
11566   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11567   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11568   operands[2] = gen_rtx_REG (Pmode, 2);
11569   return \"{l|lwz} %0,%1(%2)\";
11570 }"
11571   [(set_attr "type" "load")])
11572
11573 (define_insn "load_toc_aix_di"
11574   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11575                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
11576               (use (reg:DI 2))])]
11577   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
11578   "*
11579 {
11580   char buf[30];
11581 #ifdef TARGET_RELOCATABLE
11582   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
11583                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
11584 #else
11585   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11586 #endif
11587   if (TARGET_ELF)
11588     strcat (buf, \"@toc\");
11589   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11590   operands[2] = gen_rtx_REG (Pmode, 2);
11591   return \"ld %0,%1(%2)\";
11592 }"
11593   [(set_attr "type" "load")])
11594
11595 (define_insn "load_toc_v4_pic_si"
11596   [(set (reg:SI LR_REGNO)
11597         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
11598   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
11599   "bl _GLOBAL_OFFSET_TABLE_@local-4"
11600   [(set_attr "type" "branch")
11601    (set_attr "length" "4")])
11602
11603 (define_insn "load_toc_v4_PIC_1"
11604   [(set (reg:SI LR_REGNO)
11605         (match_operand:SI 0 "immediate_operand" "s"))
11606    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11607   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
11608    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11609   "bcl 20,31,%0\\n%0:"
11610   [(set_attr "type" "branch")
11611    (set_attr "length" "4")])
11612
11613 (define_insn "load_toc_v4_PIC_1b"
11614   [(set (reg:SI LR_REGNO)
11615         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11616                     (label_ref (match_operand 1 "" ""))]
11617                 UNSPEC_TOCPTR))
11618    (match_dup 1)]
11619   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11620   "bcl 20,31,$+8\;.long %0-$"
11621   [(set_attr "type" "branch")
11622    (set_attr "length" "8")])
11623
11624 (define_insn "load_toc_v4_PIC_2"
11625   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11626         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11627                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
11628                              (match_operand:SI 3 "immediate_operand" "s")))))]
11629   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11630   "{l|lwz} %0,%2-%3(%1)"
11631   [(set_attr "type" "load")])
11632
11633 (define_insn "load_toc_v4_PIC_3b"
11634   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
11635         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
11636                  (high:SI
11637                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11638                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
11639   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
11640   "{cau|addis} %0,%1,%2-%3@ha")
11641
11642 (define_insn "load_toc_v4_PIC_3c"
11643   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11644         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11645                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11646                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
11647   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
11648   "{cal %0,%2-%3@l(%1)|addi %0,%1,%2-%3@l}")
11649
11650 ;; If the TOC is shared over a translation unit, as happens with all
11651 ;; the kinds of PIC that we support, we need to restore the TOC
11652 ;; pointer only when jumping over units of translation.
11653 ;; On Darwin, we need to reload the picbase.
11654
11655 (define_expand "builtin_setjmp_receiver"
11656   [(use (label_ref (match_operand 0 "" "")))]
11657   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11658    || (TARGET_TOC && TARGET_MINIMAL_TOC)
11659    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
11660   "
11661 {
11662 #if TARGET_MACHO
11663   if (DEFAULT_ABI == ABI_DARWIN)
11664     {
11665       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
11666       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
11667       rtx tmplabrtx;
11668       char tmplab[20];
11669
11670       crtl->uses_pic_offset_table = 1;
11671       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
11672                                   CODE_LABEL_NUMBER (operands[0]));
11673       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
11674
11675       emit_insn (gen_load_macho_picbase (tmplabrtx));
11676       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
11677       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
11678     }
11679   else
11680 #endif
11681     rs6000_emit_load_toc_table (FALSE);
11682   DONE;
11683 }")
11684
11685 ;; Elf specific ways of loading addresses for non-PIC code.
11686 ;; The output of this could be r0, but we make a very strong
11687 ;; preference for a base register because it will usually
11688 ;; be needed there.
11689 (define_insn "elf_high"
11690   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
11691         (high:SI (match_operand 1 "" "")))]
11692   "TARGET_ELF && ! TARGET_64BIT"
11693   "{liu|lis} %0,%1@ha")
11694
11695 (define_insn "elf_low"
11696   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11697         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
11698                    (match_operand 2 "" "")))]
11699    "TARGET_ELF && ! TARGET_64BIT"
11700    "@
11701     {cal|la} %0,%2@l(%1)
11702     {ai|addic} %0,%1,%K2")
11703
11704 ;; Largetoc support
11705 (define_insn "largetoc_high"
11706   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
11707         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "b")
11708                  (high:DI (match_operand:DI 2 "" ""))))]
11709    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11710    "{cau|addis} %0,%1,%2@ha")
11711
11712 (define_insn "largetoc_low"
11713   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11714         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b")
11715                    (match_operand:DI 2 "" "")))]
11716    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11717    "{cal %0,%2@l(%1)|addi %0,%1,%2@l}")
11718 \f
11719 ;; A function pointer under AIX is a pointer to a data area whose first word
11720 ;; contains the actual address of the function, whose second word contains a
11721 ;; pointer to its TOC, and whose third word contains a value to place in the
11722 ;; static chain register (r11).  Note that if we load the static chain, our
11723 ;; "trampoline" need not have any executable code.
11724
11725 (define_expand "call_indirect_aix32"
11726   [(set (match_dup 2)
11727         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
11728    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
11729         (reg:SI 2))
11730    (set (reg:SI 11)
11731         (mem:SI (plus:SI (match_dup 0)
11732                          (const_int 8))))
11733    (parallel [(call (mem:SI (match_dup 2))
11734                     (match_operand 1 "" ""))
11735               (use (mem:SI (plus:SI (match_dup 0) (const_int 4))))
11736               (use (reg:SI 11))
11737               (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11738               (clobber (reg:SI LR_REGNO))])]
11739   "TARGET_32BIT"
11740   "
11741 { operands[2] = gen_reg_rtx (SImode); }")
11742
11743 (define_expand "call_indirect_aix64"
11744   [(set (match_dup 2)
11745         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
11746    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
11747         (reg:DI 2))
11748    (set (reg:DI 11)
11749         (mem:DI (plus:DI (match_dup 0)
11750                          (const_int 16))))
11751    (parallel [(call (mem:SI (match_dup 2))
11752                     (match_operand 1 "" ""))
11753               (use (mem:DI (plus:DI (match_dup 0) (const_int 8))))
11754               (use (reg:DI 11))
11755               (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11756               (clobber (reg:SI LR_REGNO))])]
11757   "TARGET_64BIT"
11758   "
11759 { operands[2] = gen_reg_rtx (DImode); }")
11760
11761 (define_expand "call_value_indirect_aix32"
11762   [(set (match_dup 3)
11763         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11764    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
11765         (reg:SI 2))
11766    (set (reg:SI 11)
11767         (mem:SI (plus:SI (match_dup 1)
11768                          (const_int 8))))
11769    (parallel [(set (match_operand 0 "" "")
11770                    (call (mem:SI (match_dup 3))
11771                          (match_operand 2 "" "")))
11772               (use (mem:SI (plus:SI (match_dup 1) (const_int 4))))
11773               (use (reg:SI 11))
11774               (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11775               (clobber (reg:SI LR_REGNO))])]
11776   "TARGET_32BIT"
11777   "
11778 { operands[3] = gen_reg_rtx (SImode); }")
11779
11780 (define_expand "call_value_indirect_aix64"
11781   [(set (match_dup 3)
11782         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11783    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
11784         (reg:DI 2))
11785    (set (reg:DI 11)
11786         (mem:DI (plus:DI (match_dup 1)
11787                          (const_int 16))))
11788    (parallel [(set (match_operand 0 "" "")
11789                    (call (mem:SI (match_dup 3))
11790                          (match_operand 2 "" "")))
11791               (use (mem:DI (plus:DI (match_dup 1) (const_int 8))))
11792               (use (reg:DI 11))
11793               (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11794               (clobber (reg:SI LR_REGNO))])]
11795   "TARGET_64BIT"
11796   "
11797 { operands[3] = gen_reg_rtx (DImode); }")
11798
11799 ;; Now the definitions for the call and call_value insns
11800 (define_expand "call"
11801   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11802                     (match_operand 1 "" ""))
11803               (use (match_operand 2 "" ""))
11804               (clobber (reg:SI LR_REGNO))])]
11805   ""
11806   "
11807 {
11808 #if TARGET_MACHO
11809   if (MACHOPIC_INDIRECT)
11810     operands[0] = machopic_indirect_call_target (operands[0]);
11811 #endif
11812
11813   gcc_assert (GET_CODE (operands[0]) == MEM);
11814   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11815
11816   operands[0] = XEXP (operands[0], 0);
11817
11818   if (GET_CODE (operands[0]) != SYMBOL_REF
11819       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
11820       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
11821     {
11822       if (INTVAL (operands[2]) & CALL_LONG)
11823         operands[0] = rs6000_longcall_ref (operands[0]);
11824
11825       switch (DEFAULT_ABI)
11826         {
11827         case ABI_V4:
11828         case ABI_DARWIN:
11829           operands[0] = force_reg (Pmode, operands[0]);
11830           break;
11831
11832         case ABI_AIX:
11833           /* AIX function pointers are really pointers to a three word
11834              area.  */
11835           emit_call_insn (TARGET_32BIT
11836                           ? gen_call_indirect_aix32 (force_reg (SImode,
11837                                                                 operands[0]),
11838                                                      operands[1])
11839                           : gen_call_indirect_aix64 (force_reg (DImode,
11840                                                                 operands[0]),
11841                                                      operands[1]));
11842           DONE;
11843
11844         default:
11845           gcc_unreachable ();
11846         }
11847     }
11848 }")
11849
11850 (define_expand "call_value"
11851   [(parallel [(set (match_operand 0 "" "")
11852                    (call (mem:SI (match_operand 1 "address_operand" ""))
11853                          (match_operand 2 "" "")))
11854               (use (match_operand 3 "" ""))
11855               (clobber (reg:SI LR_REGNO))])]
11856   ""
11857   "
11858 {
11859 #if TARGET_MACHO
11860   if (MACHOPIC_INDIRECT)
11861     operands[1] = machopic_indirect_call_target (operands[1]);
11862 #endif
11863
11864   gcc_assert (GET_CODE (operands[1]) == MEM);
11865   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11866
11867   operands[1] = XEXP (operands[1], 0);
11868
11869   if (GET_CODE (operands[1]) != SYMBOL_REF
11870       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
11871       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
11872     {
11873       if (INTVAL (operands[3]) & CALL_LONG)
11874         operands[1] = rs6000_longcall_ref (operands[1]);
11875
11876       switch (DEFAULT_ABI)
11877         {
11878         case ABI_V4:
11879         case ABI_DARWIN:
11880           operands[1] = force_reg (Pmode, operands[1]);
11881           break;
11882
11883         case ABI_AIX:
11884           /* AIX function pointers are really pointers to a three word
11885              area.  */
11886           emit_call_insn (TARGET_32BIT
11887                           ? gen_call_value_indirect_aix32 (operands[0],
11888                                                            force_reg (SImode,
11889                                                                       operands[1]),
11890                                                            operands[2])
11891                           : gen_call_value_indirect_aix64 (operands[0],
11892                                                            force_reg (DImode,
11893                                                                       operands[1]),
11894                                                            operands[2]));
11895           DONE;
11896
11897         default:
11898           gcc_unreachable ();
11899         }
11900     }
11901 }")
11902
11903 ;; Call to function in current module.  No TOC pointer reload needed.
11904 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11905 ;; either the function was not prototyped, or it was prototyped as a
11906 ;; variable argument function.  It is > 0 if FP registers were passed
11907 ;; and < 0 if they were not.
11908
11909 (define_insn "*call_local32"
11910   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11911          (match_operand 1 "" "g,g"))
11912    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11913    (clobber (reg:SI LR_REGNO))]
11914   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11915   "*
11916 {
11917   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11918     output_asm_insn (\"crxor 6,6,6\", operands);
11919
11920   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11921     output_asm_insn (\"creqv 6,6,6\", operands);
11922
11923   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11924 }"
11925   [(set_attr "type" "branch")
11926    (set_attr "length" "4,8")])
11927
11928 (define_insn "*call_local64"
11929   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11930          (match_operand 1 "" "g,g"))
11931    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11932    (clobber (reg:SI LR_REGNO))]
11933   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11934   "*
11935 {
11936   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11937     output_asm_insn (\"crxor 6,6,6\", operands);
11938
11939   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11940     output_asm_insn (\"creqv 6,6,6\", operands);
11941
11942   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11943 }"
11944   [(set_attr "type" "branch")
11945    (set_attr "length" "4,8")])
11946
11947 (define_insn "*call_value_local32"
11948   [(set (match_operand 0 "" "")
11949         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11950               (match_operand 2 "" "g,g")))
11951    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11952    (clobber (reg:SI LR_REGNO))]
11953   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11954   "*
11955 {
11956   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11957     output_asm_insn (\"crxor 6,6,6\", operands);
11958
11959   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11960     output_asm_insn (\"creqv 6,6,6\", operands);
11961
11962   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11963 }"
11964   [(set_attr "type" "branch")
11965    (set_attr "length" "4,8")])
11966
11967
11968 (define_insn "*call_value_local64"
11969   [(set (match_operand 0 "" "")
11970         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11971               (match_operand 2 "" "g,g")))
11972    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11973    (clobber (reg:SI LR_REGNO))]
11974   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11975   "*
11976 {
11977   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11978     output_asm_insn (\"crxor 6,6,6\", operands);
11979
11980   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11981     output_asm_insn (\"creqv 6,6,6\", operands);
11982
11983   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11984 }"
11985   [(set_attr "type" "branch")
11986    (set_attr "length" "4,8")])
11987
11988 ;; Call to function which may be in another module.  Restore the TOC
11989 ;; pointer (r2) after the call unless this is System V.
11990 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11991 ;; either the function was not prototyped, or it was prototyped as a
11992 ;; variable argument function.  It is > 0 if FP registers were passed
11993 ;; and < 0 if they were not.
11994
11995 (define_insn_and_split "*call_indirect_nonlocal_aix32_internal"
11996   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
11997                  (match_operand 1 "" "g,g"))
11998    (use (mem:SI (plus:SI (match_operand:SI 2 "register_operand" "b,b") (const_int 4))))
11999    (use (reg:SI 11))
12000    (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12001    (clobber (reg:SI LR_REGNO))]
12002   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
12003   "#"
12004   "&& reload_completed"
12005   [(set (reg:SI 2)
12006         (mem:SI (plus:SI (match_dup 2) (const_int 4))))
12007    (parallel [(call (mem:SI (match_dup 0))
12008                     (match_dup 1))
12009               (use (reg:SI 2))
12010               (use (reg:SI 11))
12011               (set (reg:SI 2)
12012                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12013               (clobber (reg:SI LR_REGNO))])]
12014   ""
12015   [(set_attr "type" "jmpreg")
12016    (set_attr "length" "12")])
12017
12018 (define_insn "*call_indirect_nonlocal_aix32"
12019   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
12020          (match_operand 1 "" "g,g"))
12021    (use (reg:SI 2))
12022    (use (reg:SI 11))
12023    (set (reg:SI 2)
12024         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12025    (clobber (reg:SI LR_REGNO))]
12026   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12027   "b%T0l\;{l|lwz} 2,20(1)"
12028   [(set_attr "type" "jmpreg")
12029    (set_attr "length" "8")])
12030
12031 (define_insn "*call_nonlocal_aix32"
12032   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
12033          (match_operand 1 "" "g"))
12034    (use (match_operand:SI 2 "immediate_operand" "O"))
12035    (clobber (reg:SI LR_REGNO))]
12036   "TARGET_32BIT
12037    && DEFAULT_ABI == ABI_AIX
12038    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12039   "bl %z0\;%."
12040   [(set_attr "type" "branch")
12041    (set_attr "length" "8")])
12042    
12043 (define_insn_and_split "*call_indirect_nonlocal_aix64_internal"
12044   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
12045                  (match_operand 1 "" "g,g"))
12046    (use (mem:DI (plus:DI (match_operand:DI 2 "register_operand" "b,b")
12047                          (const_int 8))))
12048    (use (reg:DI 11))
12049    (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12050    (clobber (reg:SI LR_REGNO))]
12051   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
12052   "#"
12053   "&& reload_completed"
12054   [(set (reg:DI 2)
12055         (mem:DI (plus:DI (match_dup 2) (const_int 8))))
12056    (parallel [(call (mem:SI (match_dup 0))
12057                     (match_dup 1))
12058               (use (reg:DI 2))
12059               (use (reg:DI 11))
12060               (set (reg:DI 2)
12061                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12062               (clobber (reg:SI LR_REGNO))])]
12063   ""
12064   [(set_attr "type" "jmpreg")
12065    (set_attr "length" "12")])
12066
12067 (define_insn "*call_indirect_nonlocal_aix64"
12068   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
12069          (match_operand 1 "" "g,g"))
12070    (use (reg:DI 2))
12071    (use (reg:DI 11))
12072    (set (reg:DI 2)
12073         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12074    (clobber (reg:SI LR_REGNO))]
12075   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12076   "b%T0l\;ld 2,40(1)"
12077   [(set_attr "type" "jmpreg")
12078    (set_attr "length" "8")])
12079
12080 (define_insn "*call_nonlocal_aix64"
12081   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
12082          (match_operand 1 "" "g"))
12083    (use (match_operand:SI 2 "immediate_operand" "O"))
12084    (clobber (reg:SI LR_REGNO))]
12085   "TARGET_64BIT
12086    && DEFAULT_ABI == ABI_AIX
12087    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12088   "bl %z0\;%."
12089   [(set_attr "type" "branch")
12090    (set_attr "length" "8")])
12091
12092 (define_insn_and_split "*call_value_indirect_nonlocal_aix32_internal"
12093   [(set (match_operand 0 "" "")
12094         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
12095                       (match_operand 2 "" "g,g")))
12096         (use (mem:SI (plus:SI (match_operand:SI 3 "register_operand" "b,b")
12097                               (const_int 4))))
12098         (use (reg:SI 11))
12099         (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12100         (clobber (reg:SI LR_REGNO))]
12101   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
12102   "#"
12103   "&& reload_completed"
12104   [(set (reg:SI 2)
12105         (mem:SI (plus:SI (match_dup 3) (const_int 4))))
12106    (parallel [(set (match_dup 0) (call (mem:SI (match_dup 1))
12107                                        (match_dup 2)))
12108               (use (reg:SI 2))
12109               (use (reg:SI 11))
12110               (set (reg:SI 2)
12111                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12112               (clobber (reg:SI LR_REGNO))])]
12113   ""
12114   [(set_attr "type" "jmpreg")
12115    (set_attr "length" "12")])
12116
12117 (define_insn "*call_value_indirect_nonlocal_aix32"
12118   [(set (match_operand 0 "" "")
12119         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
12120               (match_operand 2 "" "g,g")))
12121    (use (reg:SI 2))
12122    (use (reg:SI 11))
12123    (set (reg:SI 2)
12124         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12125    (clobber (reg:SI LR_REGNO))]
12126   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12127   "b%T1l\;{l|lwz} 2,20(1)"
12128   [(set_attr "type" "jmpreg")
12129    (set_attr "length" "8")])
12130
12131 (define_insn "*call_value_nonlocal_aix32"
12132   [(set (match_operand 0 "" "")
12133         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12134               (match_operand 2 "" "g")))
12135    (use (match_operand:SI 3 "immediate_operand" "O"))
12136    (clobber (reg:SI LR_REGNO))]
12137   "TARGET_32BIT
12138    && DEFAULT_ABI == ABI_AIX
12139    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12140   "bl %z1\;%."
12141   [(set_attr "type" "branch")
12142    (set_attr "length" "8")])
12143
12144 (define_insn_and_split "*call_value_indirect_nonlocal_aix64_internal"
12145   [(set (match_operand 0 "" "")
12146         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
12147                       (match_operand 2 "" "g,g")))
12148         (use (mem:DI (plus:DI (match_operand:DI 3 "register_operand" "b,b")
12149                               (const_int 8))))
12150         (use (reg:DI 11))
12151         (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12152         (clobber (reg:SI LR_REGNO))]
12153   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
12154   "#"
12155   "&& reload_completed"
12156   [(set (reg:DI 2)
12157         (mem:DI (plus:DI (match_dup 3) (const_int 8))))
12158    (parallel [(set (match_dup 0) (call (mem:SI (match_dup 1))
12159                                        (match_dup 2)))
12160               (use (reg:DI 2))
12161               (use (reg:DI 11))
12162               (set (reg:DI 2)
12163                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12164               (clobber (reg:SI LR_REGNO))])]
12165   ""
12166   [(set_attr "type" "jmpreg")
12167    (set_attr "length" "12")])
12168
12169 (define_insn "*call_value_indirect_nonlocal_aix64"
12170   [(set (match_operand 0 "" "")
12171         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
12172               (match_operand 2 "" "g,g")))
12173    (use (reg:DI 2))
12174    (use (reg:DI 11))
12175    (set (reg:DI 2)
12176         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12177    (clobber (reg:SI LR_REGNO))]
12178   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12179   "b%T1l\;ld 2,40(1)"
12180   [(set_attr "type" "jmpreg")
12181    (set_attr "length" "8")])
12182
12183 (define_insn "*call_value_nonlocal_aix64"
12184   [(set (match_operand 0 "" "")
12185         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12186               (match_operand 2 "" "g")))
12187    (use (match_operand:SI 3 "immediate_operand" "O"))
12188    (clobber (reg:SI LR_REGNO))]
12189   "TARGET_64BIT
12190    && DEFAULT_ABI == ABI_AIX
12191    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12192   "bl %z1\;%."
12193   [(set_attr "type" "branch")
12194    (set_attr "length" "8")])
12195
12196 ;; A function pointer under System V is just a normal pointer
12197 ;; operands[0] is the function pointer
12198 ;; operands[1] is the stack size to clean up
12199 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12200 ;; which indicates how to set cr1
12201
12202 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12203   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12204          (match_operand 1 "" "g,g,g,g"))
12205    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12206    (clobber (reg:SI LR_REGNO))]
12207   "DEFAULT_ABI == ABI_V4
12208    || DEFAULT_ABI == ABI_DARWIN"
12209 {
12210   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12211     output_asm_insn ("crxor 6,6,6", operands);
12212
12213   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12214     output_asm_insn ("creqv 6,6,6", operands);
12215
12216   return "b%T0l";
12217 }
12218   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12219    (set_attr "length" "4,4,8,8")])
12220
12221 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12222   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12223          (match_operand 1 "" "g,g"))
12224    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12225    (clobber (reg:SI LR_REGNO))]
12226   "(DEFAULT_ABI == ABI_DARWIN
12227    || (DEFAULT_ABI == ABI_V4
12228        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12229 {
12230   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12231     output_asm_insn ("crxor 6,6,6", operands);
12232
12233   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12234     output_asm_insn ("creqv 6,6,6", operands);
12235
12236 #if TARGET_MACHO
12237   return output_call(insn, operands, 0, 2);
12238 #else
12239   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12240     {
12241       gcc_assert (!TARGET_SECURE_PLT);
12242       return "bl %z0@plt";
12243     }
12244   else
12245     return "bl %z0";
12246 #endif
12247 }
12248   "DEFAULT_ABI == ABI_V4
12249    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12250    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12251   [(parallel [(call (mem:SI (match_dup 0))
12252                     (match_dup 1))
12253               (use (match_dup 2))
12254               (use (match_dup 3))
12255               (clobber (reg:SI LR_REGNO))])]
12256 {
12257   operands[3] = pic_offset_table_rtx;
12258 }
12259   [(set_attr "type" "branch,branch")
12260    (set_attr "length" "4,8")])
12261
12262 (define_insn "*call_nonlocal_sysv_secure<mode>"
12263   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12264          (match_operand 1 "" "g,g"))
12265    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12266    (use (match_operand:SI 3 "register_operand" "r,r"))
12267    (clobber (reg:SI LR_REGNO))]
12268   "(DEFAULT_ABI == ABI_V4
12269     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12270     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
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   if (flag_pic == 2)
12279     /* The magic 32768 offset here and in the other sysv call insns
12280        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12281        See sysv4.h:toc_section.  */
12282     return "bl %z0+32768@plt";
12283   else
12284     return "bl %z0@plt";
12285 }
12286   [(set_attr "type" "branch,branch")
12287    (set_attr "length" "4,8")])
12288
12289 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12290   [(set (match_operand 0 "" "")
12291         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12292               (match_operand 2 "" "g,g,g,g")))
12293    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12294    (clobber (reg:SI LR_REGNO))]
12295   "DEFAULT_ABI == ABI_V4
12296    || DEFAULT_ABI == ABI_DARWIN"
12297 {
12298   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12299     output_asm_insn ("crxor 6,6,6", operands);
12300
12301   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12302     output_asm_insn ("creqv 6,6,6", operands);
12303
12304   return "b%T1l";
12305 }
12306   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12307    (set_attr "length" "4,4,8,8")])
12308
12309 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12310   [(set (match_operand 0 "" "")
12311         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12312               (match_operand 2 "" "g,g")))
12313    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12314    (clobber (reg:SI LR_REGNO))]
12315   "(DEFAULT_ABI == ABI_DARWIN
12316    || (DEFAULT_ABI == ABI_V4
12317        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12318 {
12319   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12320     output_asm_insn ("crxor 6,6,6", operands);
12321
12322   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12323     output_asm_insn ("creqv 6,6,6", operands);
12324
12325 #if TARGET_MACHO
12326   return output_call(insn, operands, 1, 3);
12327 #else
12328   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12329     {
12330       gcc_assert (!TARGET_SECURE_PLT);
12331       return "bl %z1@plt";
12332     }
12333   else
12334     return "bl %z1";
12335 #endif
12336 }
12337   "DEFAULT_ABI == ABI_V4
12338    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12339    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12340   [(parallel [(set (match_dup 0)
12341                    (call (mem:SI (match_dup 1))
12342                          (match_dup 2)))
12343               (use (match_dup 3))
12344               (use (match_dup 4))
12345               (clobber (reg:SI LR_REGNO))])]
12346 {
12347   operands[4] = pic_offset_table_rtx;
12348 }
12349   [(set_attr "type" "branch,branch")
12350    (set_attr "length" "4,8")])
12351
12352 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12353   [(set (match_operand 0 "" "")
12354         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12355               (match_operand 2 "" "g,g")))
12356    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12357    (use (match_operand:SI 4 "register_operand" "r,r"))
12358    (clobber (reg:SI LR_REGNO))]
12359   "(DEFAULT_ABI == ABI_V4
12360     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12361     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12362 {
12363   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12364     output_asm_insn ("crxor 6,6,6", operands);
12365
12366   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12367     output_asm_insn ("creqv 6,6,6", operands);
12368
12369   if (flag_pic == 2)
12370     return "bl %z1+32768@plt";
12371   else
12372     return "bl %z1@plt";
12373 }
12374   [(set_attr "type" "branch,branch")
12375    (set_attr "length" "4,8")])
12376
12377 ;; Call subroutine returning any type.
12378 (define_expand "untyped_call"
12379   [(parallel [(call (match_operand 0 "" "")
12380                     (const_int 0))
12381               (match_operand 1 "" "")
12382               (match_operand 2 "" "")])]
12383   ""
12384   "
12385 {
12386   int i;
12387
12388   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12389
12390   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12391     {
12392       rtx set = XVECEXP (operands[2], 0, i);
12393       emit_move_insn (SET_DEST (set), SET_SRC (set));
12394     }
12395
12396   /* The optimizer does not know that the call sets the function value
12397      registers we stored in the result block.  We avoid problems by
12398      claiming that all hard registers are used and clobbered at this
12399      point.  */
12400   emit_insn (gen_blockage ());
12401
12402   DONE;
12403 }")
12404
12405 ;; sibling call patterns
12406 (define_expand "sibcall"
12407   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12408                     (match_operand 1 "" ""))
12409               (use (match_operand 2 "" ""))
12410               (use (reg:SI LR_REGNO))
12411               (return)])]
12412   ""
12413   "
12414 {
12415 #if TARGET_MACHO
12416   if (MACHOPIC_INDIRECT)
12417     operands[0] = machopic_indirect_call_target (operands[0]);
12418 #endif
12419
12420   gcc_assert (GET_CODE (operands[0]) == MEM);
12421   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12422
12423   operands[0] = XEXP (operands[0], 0);
12424 }")
12425
12426 ;; this and similar patterns must be marked as using LR, otherwise
12427 ;; dataflow will try to delete the store into it.  This is true
12428 ;; even when the actual reg to jump to is in CTR, when LR was
12429 ;; saved and restored around the PIC-setting BCL.
12430 (define_insn "*sibcall_local32"
12431   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12432          (match_operand 1 "" "g,g"))
12433    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12434    (use (reg:SI LR_REGNO))
12435    (return)]
12436   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12437   "*
12438 {
12439   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12440     output_asm_insn (\"crxor 6,6,6\", operands);
12441
12442   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12443     output_asm_insn (\"creqv 6,6,6\", operands);
12444
12445   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12446 }"
12447   [(set_attr "type" "branch")
12448    (set_attr "length" "4,8")])
12449
12450 (define_insn "*sibcall_local64"
12451   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12452          (match_operand 1 "" "g,g"))
12453    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12454    (use (reg:SI LR_REGNO))
12455    (return)]
12456   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12457   "*
12458 {
12459   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12460     output_asm_insn (\"crxor 6,6,6\", operands);
12461
12462   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12463     output_asm_insn (\"creqv 6,6,6\", operands);
12464
12465   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12466 }"
12467   [(set_attr "type" "branch")
12468    (set_attr "length" "4,8")])
12469
12470 (define_insn "*sibcall_value_local32"
12471   [(set (match_operand 0 "" "")
12472         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12473               (match_operand 2 "" "g,g")))
12474    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12475    (use (reg:SI LR_REGNO))
12476    (return)]
12477   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12478   "*
12479 {
12480   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12481     output_asm_insn (\"crxor 6,6,6\", operands);
12482
12483   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12484     output_asm_insn (\"creqv 6,6,6\", operands);
12485
12486   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12487 }"
12488   [(set_attr "type" "branch")
12489    (set_attr "length" "4,8")])
12490
12491
12492 (define_insn "*sibcall_value_local64"
12493   [(set (match_operand 0 "" "")
12494         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12495               (match_operand 2 "" "g,g")))
12496    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12497    (use (reg:SI LR_REGNO))
12498    (return)]
12499   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12500   "*
12501 {
12502   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12503     output_asm_insn (\"crxor 6,6,6\", operands);
12504
12505   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12506     output_asm_insn (\"creqv 6,6,6\", operands);
12507
12508   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12509 }"
12510   [(set_attr "type" "branch")
12511    (set_attr "length" "4,8")])
12512
12513 (define_insn "*sibcall_nonlocal_aix32"
12514   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
12515          (match_operand 1 "" "g"))
12516    (use (match_operand:SI 2 "immediate_operand" "O"))
12517    (use (reg:SI LR_REGNO))
12518    (return)]
12519   "TARGET_32BIT
12520    && DEFAULT_ABI == ABI_AIX
12521    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12522   "b %z0"
12523   [(set_attr "type" "branch")
12524    (set_attr "length" "4")])
12525
12526 (define_insn "*sibcall_nonlocal_aix64"
12527   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
12528          (match_operand 1 "" "g"))
12529    (use (match_operand:SI 2 "immediate_operand" "O"))
12530    (use (reg:SI LR_REGNO))
12531    (return)]
12532   "TARGET_64BIT
12533    && DEFAULT_ABI == ABI_AIX
12534    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12535   "b %z0"
12536   [(set_attr "type" "branch")
12537    (set_attr "length" "4")])
12538
12539 (define_insn "*sibcall_value_nonlocal_aix32"
12540   [(set (match_operand 0 "" "")
12541         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12542               (match_operand 2 "" "g")))
12543    (use (match_operand:SI 3 "immediate_operand" "O"))
12544    (use (reg:SI LR_REGNO))
12545    (return)]
12546   "TARGET_32BIT
12547    && DEFAULT_ABI == ABI_AIX
12548    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12549   "b %z1"
12550   [(set_attr "type" "branch")
12551    (set_attr "length" "4")])
12552
12553 (define_insn "*sibcall_value_nonlocal_aix64"
12554   [(set (match_operand 0 "" "")
12555         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12556               (match_operand 2 "" "g")))
12557    (use (match_operand:SI 3 "immediate_operand" "O"))
12558    (use (reg:SI LR_REGNO))
12559    (return)]
12560   "TARGET_64BIT
12561    && DEFAULT_ABI == ABI_AIX
12562    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12563   "b %z1"
12564   [(set_attr "type" "branch")
12565    (set_attr "length" "4")])
12566
12567 (define_insn "*sibcall_nonlocal_sysv<mode>"
12568   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12569          (match_operand 1 "" ""))
12570    (use (match_operand 2 "immediate_operand" "O,n"))
12571    (use (reg:SI LR_REGNO))
12572    (return)]
12573   "(DEFAULT_ABI == ABI_DARWIN
12574      || DEFAULT_ABI == ABI_V4)
12575    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12576   "*
12577 {
12578   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12579     output_asm_insn (\"crxor 6,6,6\", operands);
12580
12581   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12582     output_asm_insn (\"creqv 6,6,6\", operands);
12583
12584   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12585     {
12586       gcc_assert (!TARGET_SECURE_PLT);
12587       return \"b %z0@plt\";
12588     }
12589   else
12590     return \"b %z0\";
12591 }"
12592   [(set_attr "type" "branch,branch")
12593    (set_attr "length" "4,8")])
12594
12595 (define_expand "sibcall_value"
12596   [(parallel [(set (match_operand 0 "register_operand" "")
12597                 (call (mem:SI (match_operand 1 "address_operand" ""))
12598                       (match_operand 2 "" "")))
12599               (use (match_operand 3 "" ""))
12600               (use (reg:SI LR_REGNO))
12601               (return)])]
12602   ""
12603   "
12604 {
12605 #if TARGET_MACHO
12606   if (MACHOPIC_INDIRECT)
12607     operands[1] = machopic_indirect_call_target (operands[1]);
12608 #endif
12609
12610   gcc_assert (GET_CODE (operands[1]) == MEM);
12611   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12612
12613   operands[1] = XEXP (operands[1], 0);
12614 }")
12615
12616 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
12617   [(set (match_operand 0 "" "")
12618         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12619               (match_operand 2 "" "")))
12620    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12621    (use (reg:SI LR_REGNO))
12622    (return)]
12623   "(DEFAULT_ABI == ABI_DARWIN
12624        || DEFAULT_ABI == ABI_V4)
12625    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12626   "*
12627 {
12628   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12629     output_asm_insn (\"crxor 6,6,6\", operands);
12630
12631   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12632     output_asm_insn (\"creqv 6,6,6\", operands);
12633
12634   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12635     {
12636       gcc_assert (!TARGET_SECURE_PLT);
12637       return \"b %z1@plt\";
12638     }
12639   else
12640     return \"b %z1\";
12641 }"
12642   [(set_attr "type" "branch,branch")
12643    (set_attr "length" "4,8")])
12644
12645 (define_expand "sibcall_epilogue"
12646   [(use (const_int 0))]
12647   "TARGET_SCHED_PROLOG"
12648   "
12649 {
12650       rs6000_emit_epilogue (TRUE);
12651       DONE;
12652 }")
12653
12654 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12655 ;; all of memory.  This blocks insns from being moved across this point.
12656
12657 (define_insn "blockage"
12658   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
12659   ""
12660   "")
12661
12662 (define_insn "probe_stack"
12663   [(set (match_operand 0 "memory_operand" "=m")
12664         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
12665   ""
12666   "{st%U0%X0|stw%U0%X0} 0,%0"
12667   [(set_attr "type" "store")
12668    (set_attr "length" "4")])
12669 \f
12670 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
12671 ;; signed & unsigned, and one type of branch.
12672 ;;
12673 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
12674 ;; insns, and branches.
12675
12676 (define_expand "cbranch<mode>4"
12677   [(use (match_operator 0 "rs6000_cbranch_operator"
12678          [(match_operand:GPR 1 "gpc_reg_operand" "")
12679           (match_operand:GPR 2 "reg_or_short_operand" "")]))
12680    (use (match_operand 3 ""))]
12681   ""
12682   "
12683 {
12684   /* Take care of the possibility that operands[2] might be negative but
12685      this might be a logical operation.  That insn doesn't exist.  */
12686   if (GET_CODE (operands[2]) == CONST_INT
12687       && INTVAL (operands[2]) < 0)
12688     {
12689       operands[2] = force_reg (<MODE>mode, operands[2]);
12690       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
12691                                     GET_MODE (operands[0]),
12692                                     operands[1], operands[2]);
12693    }
12694
12695   rs6000_emit_cbranch (<MODE>mode, operands);
12696   DONE;
12697 }")
12698
12699 (define_expand "cbranch<mode>4"
12700   [(use (match_operator 0 "rs6000_cbranch_operator"
12701          [(match_operand:FP 1 "gpc_reg_operand" "")
12702           (match_operand:FP 2 "gpc_reg_operand" "")]))
12703    (use (match_operand 3 ""))]
12704   ""
12705   "
12706 {
12707   rs6000_emit_cbranch (<MODE>mode, operands);
12708   DONE;
12709 }")
12710
12711 (define_expand "cstore<mode>4"
12712   [(use (match_operator 1 "rs6000_cbranch_operator"
12713          [(match_operand:GPR 2 "gpc_reg_operand" "")
12714           (match_operand:GPR 3 "reg_or_short_operand" "")]))
12715    (clobber (match_operand:SI 0 "register_operand"))]
12716   ""
12717   "
12718 {
12719   /* Take care of the possibility that operands[3] might be negative but
12720      this might be a logical operation.  That insn doesn't exist.  */
12721   if (GET_CODE (operands[3]) == CONST_INT
12722       && INTVAL (operands[3]) < 0)
12723     {
12724       operands[3] = force_reg (<MODE>mode, operands[3]);
12725       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
12726                                     GET_MODE (operands[1]),
12727                                     operands[2], operands[3]);
12728     }
12729
12730   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
12731      For SEQ, likewise, except that comparisons with zero should be done
12732      with an scc insns.  However, due to the order that combine see the
12733      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
12734      the cases we don't want to handle or are best handled by portable
12735      code.  */
12736   if (GET_CODE (operands[1]) == NE)
12737     FAIL;
12738   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
12739        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
12740       && operands[3] == const0_rtx)
12741     FAIL;
12742   rs6000_emit_sCOND (<MODE>mode, operands);
12743   DONE;
12744 }")
12745
12746 (define_expand "cstore<mode>4"
12747   [(use (match_operator 1 "rs6000_cbranch_operator"
12748          [(match_operand:FP 2 "gpc_reg_operand" "")
12749           (match_operand:FP 3 "gpc_reg_operand" "")]))
12750    (clobber (match_operand:SI 0 "register_operand"))]
12751   ""
12752   "
12753 {
12754   rs6000_emit_sCOND (<MODE>mode, operands);
12755   DONE;
12756 }")
12757
12758
12759 (define_expand "stack_protect_set"
12760   [(match_operand 0 "memory_operand" "")
12761    (match_operand 1 "memory_operand" "")]
12762   ""
12763 {
12764 #ifdef TARGET_THREAD_SSP_OFFSET
12765   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12766   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12767   operands[1] = gen_rtx_MEM (Pmode, addr);
12768 #endif
12769   if (TARGET_64BIT)
12770     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
12771   else
12772     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
12773   DONE;
12774 })
12775
12776 (define_insn "stack_protect_setsi"
12777   [(set (match_operand:SI 0 "memory_operand" "=m")
12778         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12779    (set (match_scratch:SI 2 "=&r") (const_int 0))]
12780   "TARGET_32BIT"
12781   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
12782   [(set_attr "type" "three")
12783    (set_attr "length" "12")])
12784
12785 (define_insn "stack_protect_setdi"
12786   [(set (match_operand:DI 0 "memory_operand" "=m")
12787         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12788    (set (match_scratch:DI 2 "=&r") (const_int 0))]
12789   "TARGET_64BIT"
12790   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
12791   [(set_attr "type" "three")
12792    (set_attr "length" "12")])
12793
12794 (define_expand "stack_protect_test"
12795   [(match_operand 0 "memory_operand" "")
12796    (match_operand 1 "memory_operand" "")
12797    (match_operand 2 "" "")]
12798   ""
12799 {
12800   rtx test, op0, op1;
12801 #ifdef TARGET_THREAD_SSP_OFFSET
12802   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12803   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12804   operands[1] = gen_rtx_MEM (Pmode, addr);
12805 #endif
12806   op0 = operands[0];
12807   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
12808   test = gen_rtx_EQ (VOIDmode, op0, op1);
12809   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
12810   DONE;
12811 })
12812
12813 (define_insn "stack_protect_testsi"
12814   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12815         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
12816                       (match_operand:SI 2 "memory_operand" "m,m")]
12817                      UNSPEC_SP_TEST))
12818    (set (match_scratch:SI 4 "=r,r") (const_int 0))
12819    (clobber (match_scratch:SI 3 "=&r,&r"))]
12820   "TARGET_32BIT"
12821   "@
12822    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
12823    {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"
12824   [(set_attr "length" "16,20")])
12825
12826 (define_insn "stack_protect_testdi"
12827   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12828         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
12829                       (match_operand:DI 2 "memory_operand" "m,m")]
12830                      UNSPEC_SP_TEST))
12831    (set (match_scratch:DI 4 "=r,r") (const_int 0))
12832    (clobber (match_scratch:DI 3 "=&r,&r"))]
12833   "TARGET_64BIT"
12834   "@
12835    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
12836    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
12837   [(set_attr "length" "16,20")])
12838
12839 \f
12840 ;; Here are the actual compare insns.
12841 (define_insn "*cmp<mode>_internal1"
12842   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
12843         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
12844                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
12845   ""
12846   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
12847   [(set_attr "type" "cmp")])
12848
12849 ;; If we are comparing a register for equality with a large constant,
12850 ;; we can do this with an XOR followed by a compare.  But this is profitable
12851 ;; only if the large constant is only used for the comparison (and in this
12852 ;; case we already have a register to reuse as scratch).
12853 ;;
12854 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
12855 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
12856
12857 (define_peephole2
12858   [(set (match_operand:SI 0 "register_operand")
12859         (match_operand:SI 1 "logical_const_operand" ""))
12860    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
12861                        [(match_dup 0)
12862                         (match_operand:SI 2 "logical_const_operand" "")]))
12863    (set (match_operand:CC 4 "cc_reg_operand" "")
12864         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
12865                     (match_dup 0)))
12866    (set (pc)
12867         (if_then_else (match_operator 6 "equality_operator"
12868                        [(match_dup 4) (const_int 0)])
12869                       (match_operand 7 "" "")
12870                       (match_operand 8 "" "")))]
12871   "peep2_reg_dead_p (3, operands[0])
12872    && peep2_reg_dead_p (4, operands[4])"
12873  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
12874   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
12875   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
12876  
12877 {
12878   /* Get the constant we are comparing against, and see what it looks like
12879      when sign-extended from 16 to 32 bits.  Then see what constant we could
12880      XOR with SEXTC to get the sign-extended value.  */
12881   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
12882                                               SImode,
12883                                               operands[1], operands[2]);
12884   HOST_WIDE_INT c = INTVAL (cnst);
12885   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
12886   HOST_WIDE_INT xorv = c ^ sextc;
12887
12888   operands[9] = GEN_INT (xorv);
12889   operands[10] = GEN_INT (sextc);
12890 })
12891
12892 (define_insn "*cmpsi_internal2"
12893   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12894         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12895                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
12896   ""
12897   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
12898   [(set_attr "type" "cmp")])
12899
12900 (define_insn "*cmpdi_internal2"
12901   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12902         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
12903                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
12904   ""
12905   "cmpld%I2 %0,%1,%b2"
12906   [(set_attr "type" "cmp")])
12907
12908 ;; The following two insns don't exist as single insns, but if we provide
12909 ;; them, we can swap an add and compare, which will enable us to overlap more
12910 ;; of the required delay between a compare and branch.  We generate code for
12911 ;; them by splitting.
12912
12913 (define_insn ""
12914   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
12915         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
12916                     (match_operand:SI 2 "short_cint_operand" "i")))
12917    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12918         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12919   ""
12920   "#"
12921   [(set_attr "length" "8")])
12922
12923 (define_insn ""
12924   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
12925         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12926                        (match_operand:SI 2 "u_short_cint_operand" "i")))
12927    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12928         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12929   ""
12930   "#"
12931   [(set_attr "length" "8")])
12932
12933 (define_split
12934   [(set (match_operand:CC 3 "cc_reg_operand" "")
12935         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
12936                     (match_operand:SI 2 "short_cint_operand" "")))
12937    (set (match_operand:SI 0 "gpc_reg_operand" "")
12938         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12939   ""
12940   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
12941    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12942
12943 (define_split
12944   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
12945         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
12946                        (match_operand:SI 2 "u_short_cint_operand" "")))
12947    (set (match_operand:SI 0 "gpc_reg_operand" "")
12948         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12949   ""
12950   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
12951    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12952
12953 (define_insn "*cmpsf_internal1"
12954   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12955         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
12956                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
12957   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
12958   "fcmpu %0,%1,%2"
12959   [(set_attr "type" "fpcompare")])
12960
12961 (define_insn "*cmpdf_internal1"
12962   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12963         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
12964                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
12965   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
12966    && !VECTOR_UNIT_VSX_P (DFmode)"
12967   "fcmpu %0,%1,%2"
12968   [(set_attr "type" "fpcompare")])
12969
12970 ;; Only need to compare second words if first words equal
12971 (define_insn "*cmptf_internal1"
12972   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12973         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12974                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
12975   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
12976    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12977   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
12978   [(set_attr "type" "fpcompare")
12979    (set_attr "length" "12")])
12980
12981 (define_insn_and_split "*cmptf_internal2"
12982   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12983         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12984                       (match_operand:TF 2 "gpc_reg_operand" "d")))
12985     (clobber (match_scratch:DF 3 "=d"))
12986     (clobber (match_scratch:DF 4 "=d"))
12987     (clobber (match_scratch:DF 5 "=d"))
12988     (clobber (match_scratch:DF 6 "=d"))
12989     (clobber (match_scratch:DF 7 "=d"))
12990     (clobber (match_scratch:DF 8 "=d"))
12991     (clobber (match_scratch:DF 9 "=d"))
12992     (clobber (match_scratch:DF 10 "=d"))
12993     (clobber (match_scratch:GPR 11 "=b"))]
12994   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
12995    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12996   "#"
12997   "&& reload_completed"
12998   [(set (match_dup 3) (match_dup 14))
12999    (set (match_dup 4) (match_dup 15))
13000    (set (match_dup 9) (abs:DF (match_dup 5)))
13001    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
13002    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
13003                            (label_ref (match_dup 12))
13004                            (pc)))
13005    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
13006    (set (pc) (label_ref (match_dup 13)))
13007    (match_dup 12)
13008    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
13009    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
13010    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
13011    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
13012    (match_dup 13)]
13013 {
13014   REAL_VALUE_TYPE rv;
13015   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
13016   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
13017
13018   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
13019   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
13020   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
13021   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
13022   operands[12] = gen_label_rtx ();
13023   operands[13] = gen_label_rtx ();
13024   real_inf (&rv);
13025   operands[14] = force_const_mem (DFmode,
13026                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
13027   operands[15] = force_const_mem (DFmode,
13028                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
13029                                                                 DFmode));
13030   if (TARGET_TOC)
13031     {
13032       rtx tocref;
13033       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
13034       operands[14] = gen_const_mem (DFmode, tocref);
13035       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
13036       operands[15] = gen_const_mem (DFmode, tocref);
13037       set_mem_alias_set (operands[14], get_TOC_alias_set ());
13038       set_mem_alias_set (operands[15], get_TOC_alias_set ());
13039     }
13040 })
13041 \f
13042 ;; Now we have the scc insns.  We can do some combinations because of the
13043 ;; way the machine works.
13044 ;;
13045 ;; Note that this is probably faster if we can put an insn between the
13046 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
13047 ;; cases the insns below which don't use an intermediate CR field will
13048 ;; be used instead.
13049 (define_insn ""
13050   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13051         (match_operator:SI 1 "scc_comparison_operator"
13052                            [(match_operand 2 "cc_reg_operand" "y")
13053                             (const_int 0)]))]
13054   ""
13055   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
13056   [(set (attr "type")
13057      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
13058                 (const_string "mfcrf")
13059            ]
13060         (const_string "mfcr")))
13061    (set_attr "length" "8")])
13062
13063 ;; Same as above, but get the GT bit.
13064 (define_insn "move_from_CR_gt_bit"
13065   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13066         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
13067   "TARGET_HARD_FLOAT && !TARGET_FPRS"
13068   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
13069   [(set_attr "type" "mfcr")
13070    (set_attr "length" "8")])
13071
13072 ;; Same as above, but get the OV/ORDERED bit.
13073 (define_insn "move_from_CR_ov_bit"
13074   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13075         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
13076   "TARGET_ISEL"
13077   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
13078   [(set_attr "type" "mfcr")
13079    (set_attr "length" "8")])
13080
13081 (define_insn ""
13082   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13083         (match_operator:DI 1 "scc_comparison_operator"
13084                            [(match_operand 2 "cc_reg_operand" "y")
13085                             (const_int 0)]))]
13086   "TARGET_POWERPC64"
13087   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
13088   [(set (attr "type")
13089      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
13090                 (const_string "mfcrf")
13091            ]
13092         (const_string "mfcr")))
13093    (set_attr "length" "8")])
13094
13095 (define_insn ""
13096   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13097         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13098                                        [(match_operand 2 "cc_reg_operand" "y,y")
13099                                         (const_int 0)])
13100                     (const_int 0)))
13101    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
13102         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13103   "TARGET_32BIT"
13104   "@
13105    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
13106    #"
13107   [(set_attr "type" "delayed_compare")
13108    (set_attr "length" "8,16")])
13109
13110 (define_split
13111   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13112         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13113                                        [(match_operand 2 "cc_reg_operand" "")
13114                                         (const_int 0)])
13115                     (const_int 0)))
13116    (set (match_operand:SI 3 "gpc_reg_operand" "")
13117         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13118   "TARGET_32BIT && reload_completed"
13119   [(set (match_dup 3)
13120         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
13121    (set (match_dup 0)
13122         (compare:CC (match_dup 3)
13123                     (const_int 0)))]
13124   "")
13125
13126 (define_insn ""
13127   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13128         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13129                                       [(match_operand 2 "cc_reg_operand" "y")
13130                                        (const_int 0)])
13131                    (match_operand:SI 3 "const_int_operand" "n")))]
13132   ""
13133   "*
13134 {
13135   int is_bit = ccr_bit (operands[1], 1);
13136   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13137   int count;
13138
13139   if (is_bit >= put_bit)
13140     count = is_bit - put_bit;
13141   else
13142     count = 32 - (put_bit - is_bit);
13143
13144   operands[4] = GEN_INT (count);
13145   operands[5] = GEN_INT (put_bit);
13146
13147   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
13148 }"
13149   [(set (attr "type")
13150      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
13151                 (const_string "mfcrf")
13152            ]
13153         (const_string "mfcr")))
13154    (set_attr "length" "8")])
13155
13156 (define_insn ""
13157   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13158         (compare:CC
13159          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13160                                        [(match_operand 2 "cc_reg_operand" "y,y")
13161                                         (const_int 0)])
13162                     (match_operand:SI 3 "const_int_operand" "n,n"))
13163          (const_int 0)))
13164    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
13165         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13166                    (match_dup 3)))]
13167   ""
13168   "*
13169 {
13170   int is_bit = ccr_bit (operands[1], 1);
13171   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13172   int count;
13173
13174   /* Force split for non-cc0 compare.  */
13175   if (which_alternative == 1)
13176      return \"#\";
13177
13178   if (is_bit >= put_bit)
13179     count = is_bit - put_bit;
13180   else
13181     count = 32 - (put_bit - is_bit);
13182
13183   operands[5] = GEN_INT (count);
13184   operands[6] = GEN_INT (put_bit);
13185
13186   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
13187 }"
13188   [(set_attr "type" "delayed_compare")
13189    (set_attr "length" "8,16")])
13190
13191 (define_split
13192   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13193         (compare:CC
13194          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13195                                        [(match_operand 2 "cc_reg_operand" "")
13196                                         (const_int 0)])
13197                     (match_operand:SI 3 "const_int_operand" ""))
13198          (const_int 0)))
13199    (set (match_operand:SI 4 "gpc_reg_operand" "")
13200         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13201                    (match_dup 3)))]
13202   "reload_completed"
13203   [(set (match_dup 4)
13204         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13205                    (match_dup 3)))
13206    (set (match_dup 0)
13207         (compare:CC (match_dup 4)
13208                     (const_int 0)))]
13209   "")
13210
13211 ;; There is a 3 cycle delay between consecutive mfcr instructions
13212 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13213
13214 (define_peephole
13215   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13216         (match_operator:SI 1 "scc_comparison_operator"
13217                            [(match_operand 2 "cc_reg_operand" "y")
13218                             (const_int 0)]))
13219    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13220         (match_operator:SI 4 "scc_comparison_operator"
13221                            [(match_operand 5 "cc_reg_operand" "y")
13222                             (const_int 0)]))]
13223   "REGNO (operands[2]) != REGNO (operands[5])"
13224   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13225   [(set_attr "type" "mfcr")
13226    (set_attr "length" "12")])
13227
13228 (define_peephole
13229   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13230         (match_operator:DI 1 "scc_comparison_operator"
13231                            [(match_operand 2 "cc_reg_operand" "y")
13232                             (const_int 0)]))
13233    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13234         (match_operator:DI 4 "scc_comparison_operator"
13235                            [(match_operand 5 "cc_reg_operand" "y")
13236                             (const_int 0)]))]
13237   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13238   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13239   [(set_attr "type" "mfcr")
13240    (set_attr "length" "12")])
13241
13242 ;; There are some scc insns that can be done directly, without a compare.
13243 ;; These are faster because they don't involve the communications between
13244 ;; the FXU and branch units.   In fact, we will be replacing all of the
13245 ;; integer scc insns here or in the portable methods in emit_store_flag.
13246 ;;
13247 ;; Also support (neg (scc ..)) since that construct is used to replace
13248 ;; branches, (plus (scc ..) ..) since that construct is common and
13249 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13250 ;; cases where it is no more expensive than (neg (scc ..)).
13251
13252 ;; Have reload force a constant into a register for the simple insns that
13253 ;; otherwise won't accept constants.  We do this because it is faster than
13254 ;; the cmp/mfcr sequence we would otherwise generate.
13255
13256 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13257                               (DI "rKJI")])
13258
13259 (define_insn_and_split "*eq<mode>"
13260   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13261         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13262                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13263   "!TARGET_POWER"
13264   "#"
13265   "!TARGET_POWER"
13266   [(set (match_dup 0)
13267         (clz:GPR (match_dup 3)))
13268    (set (match_dup 0)
13269         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13270   {
13271     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13272       {
13273         /* Use output operand as intermediate.  */
13274         operands[3] = operands[0];
13275
13276         if (logical_operand (operands[2], <MODE>mode))
13277           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13278                                   gen_rtx_XOR (<MODE>mode,
13279                                                operands[1], operands[2])));
13280         else
13281           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13282                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13283                                                 negate_rtx (<MODE>mode,
13284                                                             operands[2]))));
13285       }
13286     else
13287       operands[3] = operands[1];
13288
13289     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13290   })
13291
13292 (define_insn_and_split "*eq<mode>_compare"
13293   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13294         (compare:CC
13295          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13296                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13297          (const_int 0)))
13298    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13299         (eq:P (match_dup 1) (match_dup 2)))]
13300   "!TARGET_POWER && optimize_size"
13301   "#"
13302   "!TARGET_POWER && optimize_size"
13303   [(set (match_dup 0)
13304         (clz:P (match_dup 4)))
13305    (parallel [(set (match_dup 3)
13306                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13307                                (const_int 0)))
13308               (set (match_dup 0)
13309                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13310   {
13311     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13312       {
13313         /* Use output operand as intermediate.  */
13314         operands[4] = operands[0];
13315
13316         if (logical_operand (operands[2], <MODE>mode))
13317           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13318                                   gen_rtx_XOR (<MODE>mode,
13319                                                operands[1], operands[2])));
13320         else
13321           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13322                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13323                                                 negate_rtx (<MODE>mode,
13324                                                             operands[2]))));
13325       }
13326     else
13327       operands[4] = operands[1];
13328
13329     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13330   })
13331
13332 (define_insn "*eqsi_power"
13333   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
13334         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13335                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
13336    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
13337   "TARGET_POWER"
13338   "@
13339    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13340    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
13341    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13342    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13343    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
13344   [(set_attr "type" "three,two,three,three,three")
13345    (set_attr "length" "12,8,12,12,12")])
13346
13347 ;; We have insns of the form shown by the first define_insn below.  If
13348 ;; there is something inside the comparison operation, we must split it.
13349 (define_split
13350   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13351         (plus:SI (match_operator 1 "comparison_operator"
13352                                  [(match_operand:SI 2 "" "")
13353                                   (match_operand:SI 3
13354                                                     "reg_or_cint_operand" "")])
13355                  (match_operand:SI 4 "gpc_reg_operand" "")))
13356    (clobber (match_operand:SI 5 "register_operand" ""))]
13357   "! gpc_reg_operand (operands[2], SImode)"
13358   [(set (match_dup 5) (match_dup 2))
13359    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
13360                                (match_dup 4)))])
13361
13362 (define_insn "*plus_eqsi"
13363   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13364         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13365                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13366                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13367   "TARGET_32BIT"
13368   "@
13369    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13370    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
13371    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13372    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13373    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
13374   [(set_attr "type" "three,two,three,three,three")
13375    (set_attr "length" "12,8,12,12,12")])
13376
13377 (define_insn "*compare_plus_eqsi"
13378   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13379         (compare:CC
13380          (plus:SI
13381           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13382                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13383           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13384          (const_int 0)))
13385    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13386   "TARGET_32BIT && optimize_size"
13387   "@
13388    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13389    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
13390    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13391    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13392    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13393    #
13394    #
13395    #
13396    #
13397    #"
13398   [(set_attr "type" "compare")
13399    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13400
13401 (define_split
13402   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13403         (compare:CC
13404          (plus:SI
13405           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13406                  (match_operand:SI 2 "scc_eq_operand" ""))
13407           (match_operand:SI 3 "gpc_reg_operand" ""))
13408          (const_int 0)))
13409    (clobber (match_scratch:SI 4 ""))]
13410   "TARGET_32BIT && optimize_size && reload_completed"
13411   [(set (match_dup 4)
13412         (plus:SI (eq:SI (match_dup 1)
13413                  (match_dup 2))
13414           (match_dup 3)))
13415    (set (match_dup 0)
13416         (compare:CC (match_dup 4)
13417                     (const_int 0)))]
13418   "")
13419
13420 (define_insn "*plus_eqsi_compare"
13421   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13422         (compare:CC
13423          (plus:SI
13424           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13425                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13426           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13427          (const_int 0)))
13428    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13429         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13430   "TARGET_32BIT && optimize_size"
13431   "@
13432    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13433    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
13434    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13435    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13436    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13437    #
13438    #
13439    #
13440    #
13441    #"
13442   [(set_attr "type" "compare")
13443    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13444
13445 (define_split
13446   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13447         (compare:CC
13448          (plus:SI
13449           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13450                  (match_operand:SI 2 "scc_eq_operand" ""))
13451           (match_operand:SI 3 "gpc_reg_operand" ""))
13452          (const_int 0)))
13453    (set (match_operand:SI 0 "gpc_reg_operand" "")
13454         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13455   "TARGET_32BIT && optimize_size && reload_completed"
13456   [(set (match_dup 0)
13457         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13458    (set (match_dup 4)
13459         (compare:CC (match_dup 0)
13460                     (const_int 0)))]
13461   "")
13462
13463 (define_insn "*neg_eq0<mode>"
13464   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13465         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13466                      (const_int 0))))]
13467   ""
13468   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
13469   [(set_attr "type" "two")
13470    (set_attr "length" "8")])
13471
13472 (define_insn_and_split "*neg_eq<mode>"
13473   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13474         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
13475                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
13476   ""
13477   "#"
13478   ""
13479   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
13480   {
13481     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13482       {
13483         /* Use output operand as intermediate.  */
13484         operands[3] = operands[0];
13485
13486         if (logical_operand (operands[2], <MODE>mode))
13487           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13488                                   gen_rtx_XOR (<MODE>mode,
13489                                                operands[1], operands[2])));
13490         else
13491           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13492                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13493                                                 negate_rtx (<MODE>mode,
13494                                                             operands[2]))));
13495       }
13496     else
13497       operands[3] = operands[1];
13498   })
13499
13500 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
13501 ;; since it nabs/sr is just as fast.
13502 (define_insn "*ne0si"
13503   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13504         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
13505                      (const_int 31)))
13506    (clobber (match_scratch:SI 2 "=&r"))]
13507   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
13508   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
13509   [(set_attr "type" "two")
13510    (set_attr "length" "8")])
13511
13512 (define_insn "*ne0di"
13513   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13514         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
13515                      (const_int 63)))
13516    (clobber (match_scratch:DI 2 "=&r"))]
13517   "TARGET_64BIT"
13518   "addic %2,%1,-1\;subfe %0,%2,%1"
13519   [(set_attr "type" "two")
13520    (set_attr "length" "8")])
13521
13522 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
13523 (define_insn "*plus_ne0si"
13524   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13525         (plus:SI (lshiftrt:SI
13526                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
13527                   (const_int 31))
13528                  (match_operand:SI 2 "gpc_reg_operand" "r")))
13529    (clobber (match_scratch:SI 3 "=&r"))]
13530   "TARGET_32BIT"
13531   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
13532   [(set_attr "type" "two")
13533    (set_attr "length" "8")])
13534
13535 (define_insn "*plus_ne0di"
13536   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13537         (plus:DI (lshiftrt:DI
13538                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
13539                   (const_int 63))
13540                  (match_operand:DI 2 "gpc_reg_operand" "r")))
13541    (clobber (match_scratch:DI 3 "=&r"))]
13542   "TARGET_64BIT"
13543   "addic %3,%1,-1\;addze %0,%2"
13544   [(set_attr "type" "two")
13545    (set_attr "length" "8")])
13546
13547 (define_insn "*compare_plus_ne0si"
13548   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13549         (compare:CC
13550          (plus:SI (lshiftrt:SI
13551                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
13552                    (const_int 31))
13553                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13554          (const_int 0)))
13555    (clobber (match_scratch:SI 3 "=&r,&r"))
13556    (clobber (match_scratch:SI 4 "=X,&r"))]
13557   "TARGET_32BIT"
13558   "@
13559    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
13560    #"
13561   [(set_attr "type" "compare")
13562    (set_attr "length" "8,12")])
13563
13564 (define_split
13565   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13566         (compare:CC
13567          (plus:SI (lshiftrt:SI
13568                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
13569                    (const_int 31))
13570                   (match_operand:SI 2 "gpc_reg_operand" ""))
13571          (const_int 0)))
13572    (clobber (match_scratch:SI 3 ""))
13573    (clobber (match_scratch:SI 4 ""))]
13574   "TARGET_32BIT && reload_completed"
13575   [(parallel [(set (match_dup 3)
13576                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
13577                                          (const_int 31))
13578                             (match_dup 2)))
13579               (clobber (match_dup 4))])
13580    (set (match_dup 0)
13581         (compare:CC (match_dup 3)
13582                     (const_int 0)))]
13583   "")
13584
13585 (define_insn "*compare_plus_ne0di"
13586   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13587         (compare:CC
13588          (plus:DI (lshiftrt:DI
13589                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
13590                    (const_int 63))
13591                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13592          (const_int 0)))
13593    (clobber (match_scratch:DI 3 "=&r,&r"))]
13594   "TARGET_64BIT"
13595   "@
13596    addic %3,%1,-1\;addze. %3,%2
13597    #"
13598   [(set_attr "type" "compare")
13599    (set_attr "length" "8,12")])
13600
13601 (define_split
13602   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13603         (compare:CC
13604          (plus:DI (lshiftrt:DI
13605                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
13606                    (const_int 63))
13607                   (match_operand:DI 2 "gpc_reg_operand" ""))
13608          (const_int 0)))
13609    (clobber (match_scratch:DI 3 ""))]
13610   "TARGET_64BIT && reload_completed"
13611   [(set (match_dup 3)
13612         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
13613                    (const_int 63))
13614                   (match_dup 2)))
13615    (set (match_dup 0)
13616         (compare:CC (match_dup 3)
13617                     (const_int 0)))]
13618   "")
13619
13620 (define_insn "*plus_ne0si_compare"
13621   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13622         (compare:CC
13623          (plus:SI (lshiftrt:SI
13624                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
13625                    (const_int 31))
13626                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13627          (const_int 0)))
13628    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13629         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13630                  (match_dup 2)))
13631    (clobber (match_scratch:SI 3 "=&r,&r"))]
13632   "TARGET_32BIT"
13633   "@
13634    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
13635    #"
13636   [(set_attr "type" "compare")
13637    (set_attr "length" "8,12")])
13638
13639 (define_split
13640   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13641         (compare:CC
13642          (plus:SI (lshiftrt:SI
13643                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
13644                    (const_int 31))
13645                   (match_operand:SI 2 "gpc_reg_operand" ""))
13646          (const_int 0)))
13647    (set (match_operand:SI 0 "gpc_reg_operand" "")
13648         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13649                  (match_dup 2)))
13650    (clobber (match_scratch:SI 3 ""))]
13651   "TARGET_32BIT && reload_completed"
13652   [(parallel [(set (match_dup 0)
13653         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
13654                  (match_dup 2)))
13655    (clobber (match_dup 3))])
13656    (set (match_dup 4)
13657         (compare:CC (match_dup 0)
13658                     (const_int 0)))]
13659   "")
13660
13661 (define_insn "*plus_ne0di_compare"
13662   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13663         (compare:CC
13664          (plus:DI (lshiftrt:DI
13665                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
13666                    (const_int 63))
13667                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13668          (const_int 0)))
13669    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13670         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13671                  (match_dup 2)))
13672    (clobber (match_scratch:DI 3 "=&r,&r"))]
13673   "TARGET_64BIT"
13674   "@
13675    addic %3,%1,-1\;addze. %0,%2
13676    #"
13677   [(set_attr "type" "compare")
13678    (set_attr "length" "8,12")])
13679
13680 (define_split
13681   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
13682         (compare:CC
13683          (plus:DI (lshiftrt:DI
13684                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
13685                    (const_int 63))
13686                   (match_operand:DI 2 "gpc_reg_operand" ""))
13687          (const_int 0)))
13688    (set (match_operand:DI 0 "gpc_reg_operand" "")
13689         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13690                  (match_dup 2)))
13691    (clobber (match_scratch:DI 3 ""))]
13692   "TARGET_64BIT && reload_completed"
13693   [(parallel [(set (match_dup 0)
13694         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
13695                  (match_dup 2)))
13696    (clobber (match_dup 3))])
13697    (set (match_dup 4)
13698         (compare:CC (match_dup 0)
13699                     (const_int 0)))]
13700   "")
13701
13702 (define_insn ""
13703   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13704         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13705                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
13706    (clobber (match_scratch:SI 3 "=r,X"))]
13707   "TARGET_POWER"
13708   "@
13709    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
13710    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
13711   [(set_attr "length" "12")])
13712
13713 (define_insn ""
13714   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13715         (compare:CC
13716          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13717                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13718          (const_int 0)))
13719    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
13720         (le:SI (match_dup 1) (match_dup 2)))
13721    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
13722   "TARGET_POWER"
13723   "@
13724    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
13725    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
13726    #
13727    #"
13728   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
13729    (set_attr "length" "12,12,16,16")])
13730
13731 (define_split
13732   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13733         (compare:CC
13734          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13735                 (match_operand:SI 2 "reg_or_short_operand" ""))
13736          (const_int 0)))
13737    (set (match_operand:SI 0 "gpc_reg_operand" "")
13738         (le:SI (match_dup 1) (match_dup 2)))
13739    (clobber (match_scratch:SI 3 ""))]
13740   "TARGET_POWER && reload_completed"
13741   [(parallel [(set (match_dup 0)
13742         (le:SI (match_dup 1) (match_dup 2)))
13743    (clobber (match_dup 3))])
13744    (set (match_dup 4)
13745         (compare:CC (match_dup 0)
13746                     (const_int 0)))]
13747   "")
13748
13749 (define_insn ""
13750   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13751         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13752                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
13753                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
13754   "TARGET_POWER"
13755   "@
13756    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13757    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
13758   [(set_attr "length" "12")])
13759
13760 (define_insn ""
13761   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13762         (compare:CC
13763          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13764                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13765                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13766          (const_int 0)))
13767    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13768   "TARGET_POWER"
13769   "@
13770    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13771    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
13772    #
13773    #"
13774   [(set_attr "type" "compare")
13775    (set_attr "length" "12,12,16,16")])
13776
13777 (define_split
13778   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13779         (compare:CC
13780          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13781                          (match_operand:SI 2 "reg_or_short_operand" ""))
13782                   (match_operand:SI 3 "gpc_reg_operand" ""))
13783          (const_int 0)))
13784    (clobber (match_scratch:SI 4 ""))]
13785   "TARGET_POWER && reload_completed"
13786   [(set (match_dup 4)
13787         (plus:SI (le:SI (match_dup 1) (match_dup 2))
13788                  (match_dup 3)))
13789    (set (match_dup 0)
13790         (compare:CC (match_dup 4)
13791                     (const_int 0)))]
13792   "")
13793
13794 (define_insn ""
13795   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13796         (compare:CC
13797          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13798                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
13799                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13800          (const_int 0)))
13801    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13802         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13803   "TARGET_POWER"
13804   "@
13805    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13806    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
13807    #
13808    #"
13809   [(set_attr "type" "compare")
13810    (set_attr "length" "12,12,16,16")])
13811
13812 (define_split
13813   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13814         (compare:CC
13815          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
13816                          (match_operand:SI 2 "reg_or_short_operand" ""))
13817                   (match_operand:SI 3 "gpc_reg_operand" ""))
13818          (const_int 0)))
13819    (set (match_operand:SI 0 "gpc_reg_operand" "")
13820         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13821   "TARGET_POWER && reload_completed"
13822   [(set (match_dup 0)
13823         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13824    (set (match_dup 4)
13825         (compare:CC (match_dup 0)
13826                     (const_int 0)))]
13827   "")
13828
13829 (define_insn ""
13830   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13831         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13832                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
13833   "TARGET_POWER"
13834   "@
13835    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
13836    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
13837   [(set_attr "length" "12")])
13838
13839 (define_insn "*leu<mode>"
13840   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13841         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13842                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13843   ""
13844   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
13845   [(set_attr "type" "three")
13846    (set_attr "length" "12")])
13847
13848 (define_insn "*leu<mode>_compare"
13849   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13850         (compare:CC
13851          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13852                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13853          (const_int 0)))
13854    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13855         (leu:P (match_dup 1) (match_dup 2)))]
13856   ""
13857   "@
13858    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
13859    #"
13860   [(set_attr "type" "compare")
13861    (set_attr "length" "12,16")])
13862
13863 (define_split
13864   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13865         (compare:CC
13866          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
13867                 (match_operand:P 2 "reg_or_short_operand" ""))
13868          (const_int 0)))
13869    (set (match_operand:P 0 "gpc_reg_operand" "")
13870         (leu:P (match_dup 1) (match_dup 2)))]
13871   "reload_completed"
13872   [(set (match_dup 0)
13873         (leu:P (match_dup 1) (match_dup 2)))
13874    (set (match_dup 3)
13875         (compare:CC (match_dup 0)
13876                     (const_int 0)))]
13877   "")
13878
13879 (define_insn "*plus_leu<mode>"
13880   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13881         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13882                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13883                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13884   ""
13885   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
13886   [(set_attr "type" "two")
13887    (set_attr "length" "8")])
13888
13889 (define_insn ""
13890   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13891         (compare:CC
13892          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13893                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13894                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13895          (const_int 0)))
13896    (clobber (match_scratch:SI 4 "=&r,&r"))]
13897   "TARGET_32BIT"
13898   "@
13899    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
13900    #"
13901   [(set_attr "type" "compare")
13902    (set_attr "length" "8,12")])
13903
13904 (define_split
13905   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13906         (compare:CC
13907          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13908                           (match_operand:SI 2 "reg_or_short_operand" ""))
13909                   (match_operand:SI 3 "gpc_reg_operand" ""))
13910          (const_int 0)))
13911    (clobber (match_scratch:SI 4 ""))]
13912   "TARGET_32BIT && reload_completed"
13913   [(set (match_dup 4)
13914         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
13915                   (match_dup 3)))
13916    (set (match_dup 0)
13917         (compare:CC (match_dup 4)
13918                     (const_int 0)))]
13919   "")
13920
13921 (define_insn ""
13922   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13923         (compare:CC
13924          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13925                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13926                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13927          (const_int 0)))
13928    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13929         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13930   "TARGET_32BIT"
13931   "@
13932    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
13933    #"
13934   [(set_attr "type" "compare")
13935    (set_attr "length" "8,12")])
13936
13937 (define_split
13938   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13939         (compare:CC
13940          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13941                           (match_operand:SI 2 "reg_or_short_operand" ""))
13942                   (match_operand:SI 3 "gpc_reg_operand" ""))
13943          (const_int 0)))
13944    (set (match_operand:SI 0 "gpc_reg_operand" "")
13945         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13946   "TARGET_32BIT && reload_completed"
13947   [(set (match_dup 0)
13948         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13949    (set (match_dup 4)
13950         (compare:CC (match_dup 0)
13951                     (const_int 0)))]
13952   "")
13953
13954 (define_insn "*neg_leu<mode>"
13955   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13956         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13957                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13958   ""
13959   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
13960    [(set_attr "type" "three")
13961     (set_attr "length" "12")])
13962
13963 (define_insn "*and_neg_leu<mode>"
13964   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13965         (and:P (neg:P
13966                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13967                         (match_operand:P 2 "reg_or_short_operand" "rI")))
13968                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13969   ""
13970   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
13971   [(set_attr "type" "three")
13972    (set_attr "length" "12")])
13973
13974 (define_insn ""
13975   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13976         (compare:CC
13977          (and:SI (neg:SI
13978                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13979                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13980                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13981          (const_int 0)))
13982    (clobber (match_scratch:SI 4 "=&r,&r"))]
13983   "TARGET_32BIT"
13984   "@
13985    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13986    #"
13987   [(set_attr "type" "compare")
13988    (set_attr "length" "12,16")])
13989
13990 (define_split
13991   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13992         (compare:CC
13993          (and:SI (neg:SI
13994                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13995                           (match_operand:SI 2 "reg_or_short_operand" "")))
13996                  (match_operand:SI 3 "gpc_reg_operand" ""))
13997          (const_int 0)))
13998    (clobber (match_scratch:SI 4 ""))]
13999   "TARGET_32BIT && reload_completed"
14000   [(set (match_dup 4)
14001         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
14002                 (match_dup 3)))
14003    (set (match_dup 0)
14004         (compare:CC (match_dup 4)
14005                     (const_int 0)))]
14006   "")
14007
14008 (define_insn ""
14009   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14010         (compare:CC
14011          (and:SI (neg:SI
14012                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14013                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
14014                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14015          (const_int 0)))
14016    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14017         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14018   "TARGET_32BIT"
14019   "@
14020    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14021    #"
14022   [(set_attr "type" "compare")
14023    (set_attr "length" "12,16")])
14024
14025 (define_split
14026   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14027         (compare:CC
14028          (and:SI (neg:SI
14029                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14030                           (match_operand:SI 2 "reg_or_short_operand" "")))
14031                  (match_operand:SI 3 "gpc_reg_operand" ""))
14032          (const_int 0)))
14033    (set (match_operand:SI 0 "gpc_reg_operand" "")
14034         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14035   "TARGET_32BIT && reload_completed"
14036   [(set (match_dup 0)
14037         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
14038                 (match_dup 3)))
14039    (set (match_dup 4)
14040         (compare:CC (match_dup 0)
14041                     (const_int 0)))]
14042   "")
14043
14044 (define_insn ""
14045   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14046         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14047                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
14048   "TARGET_POWER"
14049   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
14050    [(set_attr "length" "12")])
14051
14052 (define_insn ""
14053   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14054         (compare:CC
14055          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14056                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14057          (const_int 0)))
14058    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14059         (lt:SI (match_dup 1) (match_dup 2)))]
14060   "TARGET_POWER"
14061   "@
14062    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
14063    #"
14064   [(set_attr "type" "delayed_compare")
14065    (set_attr "length" "12,16")])
14066
14067 (define_split
14068   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14069         (compare:CC
14070          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14071                 (match_operand:SI 2 "reg_or_short_operand" ""))
14072          (const_int 0)))
14073    (set (match_operand:SI 0 "gpc_reg_operand" "")
14074         (lt:SI (match_dup 1) (match_dup 2)))]
14075   "TARGET_POWER && reload_completed"
14076   [(set (match_dup 0)
14077         (lt:SI (match_dup 1) (match_dup 2)))
14078    (set (match_dup 3)
14079         (compare:CC (match_dup 0)
14080                     (const_int 0)))]
14081   "")
14082
14083 (define_insn ""
14084   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14085         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14086                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14087                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14088   "TARGET_POWER"
14089   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
14090   [(set_attr "length" "12")])
14091
14092 (define_insn ""
14093   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14094         (compare:CC
14095          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14096                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14097                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14098          (const_int 0)))
14099    (clobber (match_scratch:SI 4 "=&r,&r"))]
14100   "TARGET_POWER"
14101   "@
14102    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
14103    #"
14104   [(set_attr "type" "compare")
14105    (set_attr "length" "12,16")])
14106
14107 (define_split
14108   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14109         (compare:CC
14110          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14111                          (match_operand:SI 2 "reg_or_short_operand" ""))
14112                   (match_operand:SI 3 "gpc_reg_operand" ""))
14113          (const_int 0)))
14114    (clobber (match_scratch:SI 4 ""))]
14115   "TARGET_POWER && reload_completed"
14116   [(set (match_dup 4)
14117         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
14118                  (match_dup 3)))
14119    (set (match_dup 0)
14120         (compare:CC (match_dup 4)
14121                     (const_int 0)))]
14122   "")
14123
14124 (define_insn ""
14125   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14126         (compare:CC
14127          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14128                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14129                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14130          (const_int 0)))
14131    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14132         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14133   "TARGET_POWER"
14134   "@
14135    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
14136    #"
14137   [(set_attr "type" "compare")
14138    (set_attr "length" "12,16")])
14139
14140 (define_split
14141   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14142         (compare:CC
14143          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14144                          (match_operand:SI 2 "reg_or_short_operand" ""))
14145                   (match_operand:SI 3 "gpc_reg_operand" ""))
14146          (const_int 0)))
14147    (set (match_operand:SI 0 "gpc_reg_operand" "")
14148         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14149   "TARGET_POWER && reload_completed"
14150   [(set (match_dup 0)
14151         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14152    (set (match_dup 4)
14153         (compare:CC (match_dup 0)
14154                     (const_int 0)))]
14155   "")
14156
14157 (define_insn ""
14158   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14159         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14160                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14161   "TARGET_POWER"
14162   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
14163   [(set_attr "length" "12")])
14164
14165 (define_insn_and_split "*ltu<mode>"
14166   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14167         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14168                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14169   ""
14170   "#"
14171   ""
14172   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14173    (set (match_dup 0) (neg:P (match_dup 0)))]
14174   "")
14175
14176 (define_insn_and_split "*ltu<mode>_compare"
14177   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14178         (compare:CC
14179          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14180                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14181          (const_int 0)))
14182    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14183         (ltu:P (match_dup 1) (match_dup 2)))]
14184   ""
14185   "#"
14186   ""
14187   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14188    (parallel [(set (match_dup 3)
14189                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14190               (set (match_dup 0) (neg:P (match_dup 0)))])]
14191   "")
14192
14193 (define_insn_and_split "*plus_ltu<mode>"
14194   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
14195         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14196                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14197                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
14198   ""
14199   "#"
14200   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14201   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14202    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14203   "")
14204
14205 (define_insn_and_split "*plus_ltu<mode>_compare"
14206   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14207         (compare:CC
14208          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14209                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14210                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14211          (const_int 0)))
14212    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14213         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14214   ""
14215   "#"
14216   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14217   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14218    (parallel [(set (match_dup 4)
14219                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14220                                (const_int 0)))
14221               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14222   "")
14223
14224 (define_insn "*neg_ltu<mode>"
14225   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14226         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14227                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
14228   ""
14229   "@
14230    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
14231    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
14232   [(set_attr "type" "two")
14233    (set_attr "length" "8")])
14234
14235 (define_insn ""
14236   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14237         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14238                (match_operand:SI 2 "reg_or_short_operand" "rI")))
14239    (clobber (match_scratch:SI 3 "=r"))]
14240   "TARGET_POWER"
14241   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
14242    [(set_attr "length" "12")])
14243
14244 (define_insn ""
14245   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14246         (compare:CC
14247          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14248                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14249          (const_int 0)))
14250    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14251         (ge:SI (match_dup 1) (match_dup 2)))
14252    (clobber (match_scratch:SI 3 "=r,r"))]
14253   "TARGET_POWER"
14254   "@
14255    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14256    #"
14257   [(set_attr "type" "compare")
14258    (set_attr "length" "12,16")])
14259
14260 (define_split
14261   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14262         (compare:CC
14263          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14264                 (match_operand:SI 2 "reg_or_short_operand" ""))
14265          (const_int 0)))
14266    (set (match_operand:SI 0 "gpc_reg_operand" "")
14267         (ge:SI (match_dup 1) (match_dup 2)))
14268    (clobber (match_scratch:SI 3 ""))]
14269   "TARGET_POWER && reload_completed"
14270   [(parallel [(set (match_dup 0)
14271                    (ge:SI (match_dup 1) (match_dup 2)))
14272               (clobber (match_dup 3))])
14273    (set (match_dup 4)
14274         (compare:CC (match_dup 0)
14275                     (const_int 0)))]
14276   "")
14277
14278 (define_insn ""
14279   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14280         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14281                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14282                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14283   "TARGET_POWER"
14284   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
14285   [(set_attr "length" "12")])
14286
14287 (define_insn ""
14288   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14289         (compare:CC
14290          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14291                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14292                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14293          (const_int 0)))
14294    (clobber (match_scratch:SI 4 "=&r,&r"))]
14295   "TARGET_POWER"
14296   "@
14297    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14298    #"
14299   [(set_attr "type" "compare")
14300    (set_attr "length" "12,16")])
14301
14302 (define_split
14303   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14304         (compare:CC
14305          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14306                          (match_operand:SI 2 "reg_or_short_operand" ""))
14307                   (match_operand:SI 3 "gpc_reg_operand" ""))
14308          (const_int 0)))
14309    (clobber (match_scratch:SI 4 ""))]
14310   "TARGET_POWER && reload_completed"
14311   [(set (match_dup 4)
14312         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
14313                  (match_dup 3)))
14314    (set (match_dup 0)
14315         (compare:CC (match_dup 4)
14316                     (const_int 0)))]
14317   "")
14318
14319 (define_insn ""
14320   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14321         (compare:CC
14322          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14323                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14324                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14325          (const_int 0)))
14326    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14327         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14328   "TARGET_POWER"
14329   "@
14330    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14331    #"
14332   [(set_attr "type" "compare")
14333    (set_attr "length" "12,16")])
14334
14335 (define_split
14336   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14337         (compare:CC
14338          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14339                          (match_operand:SI 2 "reg_or_short_operand" ""))
14340                   (match_operand:SI 3 "gpc_reg_operand" ""))
14341          (const_int 0)))
14342    (set (match_operand:SI 0 "gpc_reg_operand" "")
14343         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14344   "TARGET_POWER && reload_completed"
14345   [(set (match_dup 0)
14346         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14347    (set (match_dup 4)
14348         (compare:CC (match_dup 0)
14349                     (const_int 0)))]
14350   "")
14351
14352 (define_insn ""
14353   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14354         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14355                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14356   "TARGET_POWER"
14357   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
14358   [(set_attr "length" "12")])
14359
14360 (define_insn "*geu<mode>"
14361   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14362         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14363                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14364   ""
14365   "@
14366    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
14367    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14368   [(set_attr "type" "three")
14369    (set_attr "length" "12")])
14370
14371 (define_insn "*geu<mode>_compare"
14372   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14373         (compare:CC
14374          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14375                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14376          (const_int 0)))
14377    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14378         (geu:P (match_dup 1) (match_dup 2)))]
14379   ""
14380   "@
14381    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14382    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14383    #
14384    #"
14385   [(set_attr "type" "compare")
14386    (set_attr "length" "12,12,16,16")])
14387
14388 (define_split
14389   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14390         (compare:CC
14391          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
14392                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
14393          (const_int 0)))
14394    (set (match_operand:P 0 "gpc_reg_operand" "")
14395         (geu:P (match_dup 1) (match_dup 2)))]
14396   "reload_completed"
14397   [(set (match_dup 0)
14398         (geu:P (match_dup 1) (match_dup 2)))
14399    (set (match_dup 3)
14400         (compare:CC (match_dup 0)
14401                     (const_int 0)))]
14402   "")
14403
14404 (define_insn "*plus_geu<mode>"
14405   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14406         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14407                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14408                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14409   ""
14410   "@
14411    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
14412    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
14413   [(set_attr "type" "two")
14414    (set_attr "length" "8")])
14415
14416 (define_insn ""
14417   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14418         (compare:CC
14419          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14420                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14421                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14422          (const_int 0)))
14423    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14424   "TARGET_32BIT"
14425   "@
14426    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
14427    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
14428    #
14429    #"
14430   [(set_attr "type" "compare")
14431    (set_attr "length" "8,8,12,12")])
14432
14433 (define_split
14434   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14435         (compare:CC
14436          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14437                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14438                   (match_operand:SI 3 "gpc_reg_operand" ""))
14439          (const_int 0)))
14440    (clobber (match_scratch:SI 4 ""))]
14441   "TARGET_32BIT && reload_completed"
14442   [(set (match_dup 4)
14443         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
14444                   (match_dup 3)))
14445    (set (match_dup 0)
14446         (compare:CC (match_dup 4)
14447                     (const_int 0)))]
14448   "")
14449
14450 (define_insn ""
14451   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14452         (compare:CC
14453          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14454                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14455                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14456          (const_int 0)))
14457    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14458         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14459   "TARGET_32BIT"
14460   "@
14461    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
14462    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
14463    #
14464    #"
14465   [(set_attr "type" "compare")
14466    (set_attr "length" "8,8,12,12")])
14467
14468 (define_split
14469   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14470         (compare:CC
14471          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14472                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14473                   (match_operand:SI 3 "gpc_reg_operand" ""))
14474          (const_int 0)))
14475    (set (match_operand:SI 0 "gpc_reg_operand" "")
14476         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14477   "TARGET_32BIT && reload_completed"
14478   [(set (match_dup 0)
14479         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14480    (set (match_dup 4)
14481         (compare:CC (match_dup 0)
14482                     (const_int 0)))]
14483   "")
14484
14485 (define_insn "*neg_geu<mode>"
14486   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14487         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14488                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
14489   ""
14490   "@
14491    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
14492    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
14493   [(set_attr "type" "three")
14494    (set_attr "length" "12")])
14495
14496 (define_insn "*and_neg_geu<mode>"
14497   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14498         (and:P (neg:P
14499                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14500                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
14501                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14502   ""
14503   "@
14504    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
14505    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
14506   [(set_attr "type" "three")
14507    (set_attr "length" "12")])
14508
14509 (define_insn ""
14510   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14511         (compare:CC
14512          (and:SI (neg:SI
14513                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14514                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14515                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14516          (const_int 0)))
14517    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14518   "TARGET_32BIT"
14519   "@
14520    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14521    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14522    #
14523    #"
14524   [(set_attr "type" "compare")
14525    (set_attr "length" "12,12,16,16")])
14526
14527 (define_split
14528   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14529         (compare:CC
14530          (and:SI (neg:SI
14531                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14532                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14533                  (match_operand:SI 3 "gpc_reg_operand" ""))
14534          (const_int 0)))
14535    (clobber (match_scratch:SI 4 ""))]
14536   "TARGET_32BIT && reload_completed"
14537   [(set (match_dup 4)
14538         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
14539                 (match_dup 3)))
14540    (set (match_dup 0)
14541         (compare:CC (match_dup 4)
14542                     (const_int 0)))]
14543   "")
14544
14545 (define_insn ""
14546   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14547         (compare:CC
14548          (and:SI (neg:SI
14549                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14550                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14551                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14552          (const_int 0)))
14553    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14554         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14555   "TARGET_32BIT"
14556   "@
14557    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14558    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14559    #
14560    #"
14561   [(set_attr "type" "compare")
14562    (set_attr "length" "12,12,16,16")])
14563
14564 (define_split
14565   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14566         (compare:CC
14567          (and:SI (neg:SI
14568                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14569                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14570                  (match_operand:SI 3 "gpc_reg_operand" ""))
14571          (const_int 0)))
14572    (set (match_operand:SI 0 "gpc_reg_operand" "")
14573         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14574   "TARGET_32BIT && reload_completed"
14575   [(set (match_dup 0)
14576         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
14577    (set (match_dup 4)
14578         (compare:CC (match_dup 0)
14579                     (const_int 0)))]
14580   "")
14581
14582 (define_insn ""
14583   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14584         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14585                (match_operand:SI 2 "reg_or_short_operand" "r")))]
14586   "TARGET_POWER"
14587   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
14588   [(set_attr "length" "12")])
14589
14590 (define_insn ""
14591   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14592         (compare:CC
14593          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14594                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14595          (const_int 0)))
14596    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14597         (gt:SI (match_dup 1) (match_dup 2)))]
14598   "TARGET_POWER"
14599   "@
14600    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
14601    #"
14602   [(set_attr "type" "delayed_compare")
14603    (set_attr "length" "12,16")])
14604
14605 (define_split
14606   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14607         (compare:CC
14608          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14609                 (match_operand:SI 2 "reg_or_short_operand" ""))
14610          (const_int 0)))
14611    (set (match_operand:SI 0 "gpc_reg_operand" "")
14612         (gt:SI (match_dup 1) (match_dup 2)))]
14613   "TARGET_POWER && reload_completed"
14614   [(set (match_dup 0)
14615         (gt:SI (match_dup 1) (match_dup 2)))
14616    (set (match_dup 3)
14617         (compare:CC (match_dup 0)
14618                     (const_int 0)))]
14619   "")
14620
14621 (define_insn "*plus_gt0<mode>"
14622   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14623         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
14624                       (const_int 0))
14625                  (match_operand:P 2 "gpc_reg_operand" "r")))]
14626   ""
14627   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
14628   [(set_attr "type" "three")
14629    (set_attr "length" "12")])
14630
14631 (define_insn ""
14632   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14633         (compare:CC
14634          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14635                          (const_int 0))
14636                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14637          (const_int 0)))
14638    (clobber (match_scratch:SI 3 "=&r,&r"))]
14639   "TARGET_32BIT"
14640   "@
14641    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
14642    #"
14643   [(set_attr "type" "compare")
14644    (set_attr "length" "12,16")])
14645
14646 (define_split
14647   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14648         (compare:CC
14649          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14650                          (const_int 0))
14651                   (match_operand:SI 2 "gpc_reg_operand" ""))
14652          (const_int 0)))
14653    (clobber (match_scratch:SI 3 ""))]
14654   "TARGET_32BIT && reload_completed"
14655   [(set (match_dup 3)
14656         (plus:SI (gt:SI (match_dup 1) (const_int 0))
14657                   (match_dup 2)))
14658    (set (match_dup 0)
14659         (compare:CC (match_dup 3)
14660                     (const_int 0)))]
14661   "")
14662
14663 (define_insn ""
14664   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14665         (compare:CC
14666          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14667                          (const_int 0))
14668                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14669          (const_int 0)))
14670    (clobber (match_scratch:DI 3 "=&r,&r"))]
14671   "TARGET_64BIT"
14672   "@
14673    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14674    #"
14675   [(set_attr "type" "compare")
14676    (set_attr "length" "12,16")])
14677
14678 (define_split
14679   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14680         (compare:CC
14681          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14682                          (const_int 0))
14683                   (match_operand:DI 2 "gpc_reg_operand" ""))
14684          (const_int 0)))
14685    (clobber (match_scratch:DI 3 ""))]
14686   "TARGET_64BIT && reload_completed"
14687   [(set (match_dup 3)
14688         (plus:DI (gt:DI (match_dup 1) (const_int 0))
14689                  (match_dup 2)))
14690    (set (match_dup 0)
14691         (compare:CC (match_dup 3)
14692                     (const_int 0)))]
14693   "")
14694
14695 (define_insn ""
14696   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14697         (compare:CC
14698          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14699                          (const_int 0))
14700                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14701          (const_int 0)))
14702    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14703         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14704   "TARGET_32BIT"
14705   "@
14706    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
14707    #"
14708   [(set_attr "type" "compare")
14709    (set_attr "length" "12,16")])
14710
14711 (define_split
14712   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14713         (compare:CC
14714          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14715                          (const_int 0))
14716                   (match_operand:SI 2 "gpc_reg_operand" ""))
14717          (const_int 0)))
14718    (set (match_operand:SI 0 "gpc_reg_operand" "")
14719         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14720   "TARGET_32BIT && reload_completed"
14721   [(set (match_dup 0)
14722         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
14723    (set (match_dup 3)
14724         (compare:CC (match_dup 0)
14725                     (const_int 0)))]
14726   "")
14727
14728 (define_insn ""
14729   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14730         (compare:CC
14731          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14732                          (const_int 0))
14733                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14734          (const_int 0)))
14735    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
14736         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14737   "TARGET_64BIT"
14738   "@
14739    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14740    #"
14741   [(set_attr "type" "compare")
14742    (set_attr "length" "12,16")])
14743
14744 (define_split
14745   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14746         (compare:CC
14747          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14748                          (const_int 0))
14749                   (match_operand:DI 2 "gpc_reg_operand" ""))
14750          (const_int 0)))
14751    (set (match_operand:DI 0 "gpc_reg_operand" "")
14752         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14753   "TARGET_64BIT && reload_completed"
14754   [(set (match_dup 0)
14755         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
14756    (set (match_dup 3)
14757         (compare:CC (match_dup 0)
14758                     (const_int 0)))]
14759   "")
14760
14761 (define_insn ""
14762   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14763         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14764                         (match_operand:SI 2 "reg_or_short_operand" "r"))
14765                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14766   "TARGET_POWER"
14767   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
14768   [(set_attr "length" "12")])
14769
14770 (define_insn ""
14771   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14772         (compare:CC
14773          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14774                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14775                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14776          (const_int 0)))
14777    (clobber (match_scratch:SI 4 "=&r,&r"))]
14778   "TARGET_POWER"
14779   "@
14780    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
14781    #"
14782   [(set_attr "type" "compare")
14783    (set_attr "length" "12,16")])
14784
14785 (define_split
14786   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14787         (compare:CC
14788          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14789                          (match_operand:SI 2 "reg_or_short_operand" ""))
14790                   (match_operand:SI 3 "gpc_reg_operand" ""))
14791          (const_int 0)))
14792    (clobber (match_scratch:SI 4 ""))]
14793   "TARGET_POWER && reload_completed"
14794   [(set (match_dup 4)
14795         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14796    (set (match_dup 0)
14797         (compare:CC (match_dup 4)
14798                     (const_int 0)))]
14799   "")
14800
14801 (define_insn ""
14802   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14803         (compare:CC
14804          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14805                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
14806                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14807          (const_int 0)))
14808    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14809         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14810   "TARGET_POWER"
14811   "@
14812    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
14813    #"
14814   [(set_attr "type" "compare")
14815    (set_attr "length" "12,16")])
14816
14817 (define_split
14818   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14819         (compare:CC
14820          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14821                          (match_operand:SI 2 "reg_or_short_operand" ""))
14822                   (match_operand:SI 3 "gpc_reg_operand" ""))
14823          (const_int 0)))
14824    (set (match_operand:SI 0 "gpc_reg_operand" "")
14825         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14826   "TARGET_POWER && reload_completed"
14827   [(set (match_dup 0)
14828         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14829    (set (match_dup 4)
14830         (compare:CC (match_dup 0)
14831                     (const_int 0)))]
14832   "")
14833
14834 (define_insn ""
14835   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14836         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14837                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
14838   "TARGET_POWER"
14839   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
14840   [(set_attr "length" "12")])
14841
14842 (define_insn_and_split "*gtu<mode>"
14843   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14844         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14845                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14846   ""
14847   "#"
14848   ""
14849   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14850    (set (match_dup 0) (neg:P (match_dup 0)))]
14851   "")
14852
14853 (define_insn_and_split "*gtu<mode>_compare"
14854   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14855         (compare:CC
14856          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14857                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14858          (const_int 0)))
14859    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14860         (gtu:P (match_dup 1) (match_dup 2)))]
14861   ""
14862   "#"
14863   ""
14864   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14865    (parallel [(set (match_dup 3)
14866                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14867               (set (match_dup 0) (neg:P (match_dup 0)))])]
14868   "")
14869
14870 (define_insn_and_split "*plus_gtu<mode>"
14871   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14872         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14873                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14874                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
14875   ""
14876   "#"
14877   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14878   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14879    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14880   "")
14881
14882 (define_insn_and_split "*plus_gtu<mode>_compare"
14883   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14884         (compare:CC
14885          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14886                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
14887                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14888          (const_int 0)))
14889    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14890         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14891   ""
14892   "#"
14893   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14894   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14895    (parallel [(set (match_dup 4)
14896                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14897                                (const_int 0)))
14898               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14899   "")
14900
14901 (define_insn "*neg_gtu<mode>"
14902   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14903         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14904                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14905   ""
14906   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
14907   [(set_attr "type" "two")
14908    (set_attr "length" "8")])
14909
14910 \f
14911 ;; Define both directions of branch and return.  If we need a reload
14912 ;; register, we'd rather use CR0 since it is much easier to copy a
14913 ;; register CC value to there.
14914
14915 (define_insn ""
14916   [(set (pc)
14917         (if_then_else (match_operator 1 "branch_comparison_operator"
14918                                       [(match_operand 2
14919                                                       "cc_reg_operand" "y")
14920                                        (const_int 0)])
14921                       (label_ref (match_operand 0 "" ""))
14922                       (pc)))]
14923   ""
14924   "*
14925 {
14926   return output_cbranch (operands[1], \"%l0\", 0, insn);
14927 }"
14928   [(set_attr "type" "branch")])
14929
14930 (define_insn ""
14931   [(set (pc)
14932         (if_then_else (match_operator 0 "branch_comparison_operator"
14933                                       [(match_operand 1
14934                                                       "cc_reg_operand" "y")
14935                                        (const_int 0)])
14936                       (return)
14937                       (pc)))]
14938   "direct_return ()"
14939   "*
14940 {
14941   return output_cbranch (operands[0], NULL, 0, insn);
14942 }"
14943   [(set_attr "type" "jmpreg")
14944    (set_attr "length" "4")])
14945
14946 (define_insn ""
14947   [(set (pc)
14948         (if_then_else (match_operator 1 "branch_comparison_operator"
14949                                       [(match_operand 2
14950                                                       "cc_reg_operand" "y")
14951                                        (const_int 0)])
14952                       (pc)
14953                       (label_ref (match_operand 0 "" ""))))]
14954   ""
14955   "*
14956 {
14957   return output_cbranch (operands[1], \"%l0\", 1, insn);
14958 }"
14959   [(set_attr "type" "branch")])
14960
14961 (define_insn ""
14962   [(set (pc)
14963         (if_then_else (match_operator 0 "branch_comparison_operator"
14964                                       [(match_operand 1
14965                                                       "cc_reg_operand" "y")
14966                                        (const_int 0)])
14967                       (pc)
14968                       (return)))]
14969   "direct_return ()"
14970   "*
14971 {
14972   return output_cbranch (operands[0], NULL, 1, insn);
14973 }"
14974   [(set_attr "type" "jmpreg")
14975    (set_attr "length" "4")])
14976
14977 ;; Logic on condition register values.
14978
14979 ; This pattern matches things like
14980 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
14981 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
14982 ;                                  (const_int 1)))
14983 ; which are generated by the branch logic.
14984 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
14985
14986 (define_insn "*cceq_ior_compare"
14987   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14988         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
14989                         [(match_operator:SI 2
14990                                       "branch_positive_comparison_operator"
14991                                       [(match_operand 3
14992                                                       "cc_reg_operand" "y,y")
14993                                        (const_int 0)])
14994                          (match_operator:SI 4
14995                                       "branch_positive_comparison_operator"
14996                                       [(match_operand 5
14997                                                       "cc_reg_operand" "0,y")
14998                                        (const_int 0)])])
14999                       (const_int 1)))]
15000   ""
15001   "cr%q1 %E0,%j2,%j4"
15002   [(set_attr "type" "cr_logical,delayed_cr")])
15003
15004 ; Why is the constant -1 here, but 1 in the previous pattern?
15005 ; Because ~1 has all but the low bit set.
15006 (define_insn ""
15007   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15008         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
15009                         [(not:SI (match_operator:SI 2
15010                                       "branch_positive_comparison_operator"
15011                                       [(match_operand 3
15012                                                       "cc_reg_operand" "y,y")
15013                                        (const_int 0)]))
15014                          (match_operator:SI 4
15015                                 "branch_positive_comparison_operator"
15016                                 [(match_operand 5
15017                                                 "cc_reg_operand" "0,y")
15018                                  (const_int 0)])])
15019                       (const_int -1)))]
15020   ""
15021   "cr%q1 %E0,%j2,%j4"
15022   [(set_attr "type" "cr_logical,delayed_cr")])
15023
15024 (define_insn "*cceq_rev_compare"
15025   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15026         (compare:CCEQ (match_operator:SI 1
15027                                       "branch_positive_comparison_operator"
15028                                       [(match_operand 2
15029                                                       "cc_reg_operand" "0,y")
15030                                        (const_int 0)])
15031                       (const_int 0)))]
15032   ""
15033   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
15034   [(set_attr "type" "cr_logical,delayed_cr")])
15035
15036 ;; If we are comparing the result of two comparisons, this can be done
15037 ;; using creqv or crxor.
15038
15039 (define_insn_and_split ""
15040   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
15041         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
15042                               [(match_operand 2 "cc_reg_operand" "y")
15043                                (const_int 0)])
15044                       (match_operator 3 "branch_comparison_operator"
15045                               [(match_operand 4 "cc_reg_operand" "y")
15046                                (const_int 0)])))]
15047   ""
15048   "#"
15049   ""
15050   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
15051                                     (match_dup 5)))]
15052   "
15053 {
15054   int positive_1, positive_2;
15055
15056   positive_1 = branch_positive_comparison_operator (operands[1],
15057                                                     GET_MODE (operands[1]));
15058   positive_2 = branch_positive_comparison_operator (operands[3],
15059                                                     GET_MODE (operands[3]));
15060
15061   if (! positive_1)
15062     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
15063                                                             GET_CODE (operands[1])),
15064                                   SImode,
15065                                   operands[2], const0_rtx);
15066   else if (GET_MODE (operands[1]) != SImode)
15067     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
15068                                   operands[2], const0_rtx);
15069
15070   if (! positive_2)
15071     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
15072                                                             GET_CODE (operands[3])),
15073                                   SImode,
15074                                   operands[4], const0_rtx);
15075   else if (GET_MODE (operands[3]) != SImode)
15076     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
15077                                   operands[4], const0_rtx);
15078
15079   if (positive_1 == positive_2)
15080     {
15081       operands[1] = gen_rtx_NOT (SImode, operands[1]);
15082       operands[5] = constm1_rtx;
15083     }
15084   else
15085     {
15086       operands[5] = const1_rtx;
15087     }
15088 }")
15089
15090 ;; Unconditional branch and return.
15091
15092 (define_insn "jump"
15093   [(set (pc)
15094         (label_ref (match_operand 0 "" "")))]
15095   ""
15096   "b %l0"
15097   [(set_attr "type" "branch")])
15098
15099 (define_insn "return"
15100   [(return)]
15101   "direct_return ()"
15102   "{br|blr}"
15103   [(set_attr "type" "jmpreg")])
15104
15105 (define_expand "indirect_jump"
15106   [(set (pc) (match_operand 0 "register_operand" ""))])
15107
15108 (define_insn "*indirect_jump<mode>"
15109   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
15110   ""
15111   "@
15112    bctr
15113    {br|blr}"
15114   [(set_attr "type" "jmpreg")])
15115
15116 ;; Table jump for switch statements:
15117 (define_expand "tablejump"
15118   [(use (match_operand 0 "" ""))
15119    (use (label_ref (match_operand 1 "" "")))]
15120   ""
15121   "
15122 {
15123   if (TARGET_32BIT)
15124     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
15125   else
15126     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
15127   DONE;
15128 }")
15129
15130 (define_expand "tablejumpsi"
15131   [(set (match_dup 3)
15132         (plus:SI (match_operand:SI 0 "" "")
15133                  (match_dup 2)))
15134    (parallel [(set (pc) (match_dup 3))
15135               (use (label_ref (match_operand 1 "" "")))])]
15136   "TARGET_32BIT"
15137   "
15138 { operands[0] = force_reg (SImode, operands[0]);
15139   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
15140   operands[3] = gen_reg_rtx (SImode);
15141 }")
15142
15143 (define_expand "tablejumpdi"
15144   [(set (match_dup 4)
15145         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
15146    (set (match_dup 3)
15147         (plus:DI (match_dup 4)
15148                  (match_dup 2)))
15149    (parallel [(set (pc) (match_dup 3))
15150               (use (label_ref (match_operand 1 "" "")))])]
15151   "TARGET_64BIT"
15152   "
15153 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
15154   operands[3] = gen_reg_rtx (DImode);
15155   operands[4] = gen_reg_rtx (DImode);
15156 }")
15157
15158 (define_insn "*tablejump<mode>_internal1"
15159   [(set (pc)
15160         (match_operand:P 0 "register_operand" "c,*l"))
15161    (use (label_ref (match_operand 1 "" "")))]
15162   ""
15163   "@
15164    bctr
15165    {br|blr}"
15166   [(set_attr "type" "jmpreg")])
15167
15168 (define_insn "nop"
15169   [(const_int 0)]
15170   ""
15171   "{cror 0,0,0|nop}")
15172 \f
15173 ;; Define the subtract-one-and-jump insns, starting with the template
15174 ;; so loop.c knows what to generate.
15175
15176 (define_expand "doloop_end"
15177   [(use (match_operand 0 "" ""))        ; loop pseudo
15178    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
15179    (use (match_operand 2 "" ""))        ; max iterations
15180    (use (match_operand 3 "" ""))        ; loop level
15181    (use (match_operand 4 "" ""))]       ; label
15182   ""
15183   "
15184 {
15185   /* Only use this on innermost loops.  */
15186   if (INTVAL (operands[3]) > 1)
15187     FAIL;
15188   if (TARGET_64BIT)
15189     {
15190       if (GET_MODE (operands[0]) != DImode)
15191         FAIL;
15192       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
15193     }
15194   else
15195     {
15196       if (GET_MODE (operands[0]) != SImode)
15197         FAIL;
15198       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
15199     }
15200   DONE;
15201 }")
15202
15203 (define_expand "ctr<mode>"
15204   [(parallel [(set (pc)
15205                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
15206                                      (const_int 1))
15207                                  (label_ref (match_operand 1 "" ""))
15208                                  (pc)))
15209               (set (match_dup 0)
15210                    (plus:P (match_dup 0)
15211                             (const_int -1)))
15212               (clobber (match_scratch:CC 2 ""))
15213               (clobber (match_scratch:P 3 ""))])]
15214   ""
15215   "")
15216
15217 ;; We need to be able to do this for any operand, including MEM, or we
15218 ;; will cause reload to blow up since we don't allow output reloads on
15219 ;; JUMP_INSNs.
15220 ;; For the length attribute to be calculated correctly, the
15221 ;; label MUST be operand 0.
15222
15223 (define_insn "*ctr<mode>_internal1"
15224   [(set (pc)
15225         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15226                           (const_int 1))
15227                       (label_ref (match_operand 0 "" ""))
15228                       (pc)))
15229    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15230         (plus:P (match_dup 1)
15231                  (const_int -1)))
15232    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15233    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15234   ""
15235   "*
15236 {
15237   if (which_alternative != 0)
15238     return \"#\";
15239   else if (get_attr_length (insn) == 4)
15240     return \"{bdn|bdnz} %l0\";
15241   else
15242     return \"bdz $+8\;b %l0\";
15243 }"
15244   [(set_attr "type" "branch")
15245    (set_attr "length" "*,12,16,16")])
15246
15247 (define_insn "*ctr<mode>_internal2"
15248   [(set (pc)
15249         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15250                           (const_int 1))
15251                       (pc)
15252                       (label_ref (match_operand 0 "" ""))))
15253    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15254         (plus:P (match_dup 1)
15255                  (const_int -1)))
15256    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15257    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15258   ""
15259   "*
15260 {
15261   if (which_alternative != 0)
15262     return \"#\";
15263   else if (get_attr_length (insn) == 4)
15264     return \"bdz %l0\";
15265   else
15266     return \"{bdn|bdnz} $+8\;b %l0\";
15267 }"
15268   [(set_attr "type" "branch")
15269    (set_attr "length" "*,12,16,16")])
15270
15271 ;; Similar but use EQ
15272
15273 (define_insn "*ctr<mode>_internal5"
15274   [(set (pc)
15275         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15276                           (const_int 1))
15277                       (label_ref (match_operand 0 "" ""))
15278                       (pc)))
15279    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15280         (plus:P (match_dup 1)
15281                  (const_int -1)))
15282    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15283    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15284   ""
15285   "*
15286 {
15287   if (which_alternative != 0)
15288     return \"#\";
15289   else if (get_attr_length (insn) == 4)
15290     return \"bdz %l0\";
15291   else
15292     return \"{bdn|bdnz} $+8\;b %l0\";
15293 }"
15294   [(set_attr "type" "branch")
15295    (set_attr "length" "*,12,16,16")])
15296
15297 (define_insn "*ctr<mode>_internal6"
15298   [(set (pc)
15299         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15300                           (const_int 1))
15301                       (pc)
15302                       (label_ref (match_operand 0 "" ""))))
15303    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15304         (plus:P (match_dup 1)
15305                  (const_int -1)))
15306    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15307    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15308   ""
15309   "*
15310 {
15311   if (which_alternative != 0)
15312     return \"#\";
15313   else if (get_attr_length (insn) == 4)
15314     return \"{bdn|bdnz} %l0\";
15315   else
15316     return \"bdz $+8\;b %l0\";
15317 }"
15318   [(set_attr "type" "branch")
15319    (set_attr "length" "*,12,16,16")])
15320
15321 ;; Now the splitters if we could not allocate the CTR register
15322
15323 (define_split
15324   [(set (pc)
15325         (if_then_else (match_operator 2 "comparison_operator"
15326                                       [(match_operand:P 1 "gpc_reg_operand" "")
15327                                        (const_int 1)])
15328                       (match_operand 5 "" "")
15329                       (match_operand 6 "" "")))
15330    (set (match_operand:P 0 "gpc_reg_operand" "")
15331         (plus:P (match_dup 1) (const_int -1)))
15332    (clobber (match_scratch:CC 3 ""))
15333    (clobber (match_scratch:P 4 ""))]
15334   "reload_completed"
15335   [(parallel [(set (match_dup 3)
15336                    (compare:CC (plus:P (match_dup 1)
15337                                         (const_int -1))
15338                                (const_int 0)))
15339               (set (match_dup 0)
15340                    (plus:P (match_dup 1)
15341                             (const_int -1)))])
15342    (set (pc) (if_then_else (match_dup 7)
15343                            (match_dup 5)
15344                            (match_dup 6)))]
15345   "
15346 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15347                                 operands[3], const0_rtx); }")
15348
15349 (define_split
15350   [(set (pc)
15351         (if_then_else (match_operator 2 "comparison_operator"
15352                                       [(match_operand:P 1 "gpc_reg_operand" "")
15353                                        (const_int 1)])
15354                       (match_operand 5 "" "")
15355                       (match_operand 6 "" "")))
15356    (set (match_operand:P 0 "nonimmediate_operand" "")
15357         (plus:P (match_dup 1) (const_int -1)))
15358    (clobber (match_scratch:CC 3 ""))
15359    (clobber (match_scratch:P 4 ""))]
15360   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
15361   [(parallel [(set (match_dup 3)
15362                    (compare:CC (plus:P (match_dup 1)
15363                                         (const_int -1))
15364                                (const_int 0)))
15365               (set (match_dup 4)
15366                    (plus:P (match_dup 1)
15367                             (const_int -1)))])
15368    (set (match_dup 0)
15369         (match_dup 4))
15370    (set (pc) (if_then_else (match_dup 7)
15371                            (match_dup 5)
15372                            (match_dup 6)))]
15373   "
15374 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15375                                 operands[3], const0_rtx); }")
15376 \f
15377 (define_insn "trap"
15378   [(trap_if (const_int 1) (const_int 0))]
15379   ""
15380   "{t 31,0,0|trap}"
15381   [(set_attr "type" "trap")])
15382
15383 (define_expand "ctrap<mode>4"
15384   [(trap_if (match_operator 0 "ordered_comparison_operator"
15385                             [(match_operand:GPR 1 "register_operand")
15386                              (match_operand:GPR 2 "reg_or_short_operand")])
15387             (match_operand 3 "zero_constant" ""))]
15388   ""
15389   "")
15390
15391 (define_insn ""
15392   [(trap_if (match_operator 0 "ordered_comparison_operator"
15393                             [(match_operand:GPR 1 "register_operand" "r")
15394                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
15395             (const_int 0))]
15396   ""
15397   "{t|t<wd>}%V0%I2 %1,%2"
15398   [(set_attr "type" "trap")])
15399 \f
15400 ;; Insns related to generating the function prologue and epilogue.
15401
15402 (define_expand "prologue"
15403   [(use (const_int 0))]
15404   "TARGET_SCHED_PROLOG"
15405   "
15406 {
15407       rs6000_emit_prologue ();
15408       DONE;
15409 }")
15410
15411 (define_insn "*movesi_from_cr_one"
15412   [(match_parallel 0 "mfcr_operation"
15413                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15414                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
15415                                      (match_operand 3 "immediate_operand" "n")]
15416                           UNSPEC_MOVESI_FROM_CR))])]
15417   "TARGET_MFCRF"
15418   "*
15419 {
15420   int mask = 0;
15421   int i;
15422   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15423   {
15424     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15425     operands[4] = GEN_INT (mask);
15426     output_asm_insn (\"mfcr %1,%4\", operands);
15427   }
15428   return \"\";
15429 }"
15430   [(set_attr "type" "mfcrf")])
15431
15432 (define_insn "movesi_from_cr"
15433   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15434         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
15435                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
15436                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
15437                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
15438                    UNSPEC_MOVESI_FROM_CR))]
15439   ""
15440   "mfcr %0"
15441   [(set_attr "type" "mfcr")])
15442
15443 (define_insn "*stmw"
15444   [(match_parallel 0 "stmw_operation"
15445                    [(set (match_operand:SI 1 "memory_operand" "=m")
15446                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
15447   "TARGET_MULTIPLE"
15448   "{stm|stmw} %2,%1"
15449   [(set_attr "type" "store_ux")])
15450
15451 (define_insn "*save_gpregs_<mode>"
15452   [(match_parallel 0 "any_parallel_operand"
15453                    [(clobber (reg:P 65))
15454                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15455                     (use (match_operand:P 2 "gpc_reg_operand" "r"))
15456                     (set (match_operand:P 3 "memory_operand" "=m")
15457                          (match_operand:P 4 "gpc_reg_operand" "r"))])]
15458   ""
15459   "bl %1"
15460   [(set_attr "type" "branch")
15461    (set_attr "length" "4")])
15462
15463 (define_insn "*save_fpregs_<mode>"
15464   [(match_parallel 0 "any_parallel_operand"
15465                    [(clobber (reg:P 65))
15466                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15467                     (use (match_operand:P 2 "gpc_reg_operand" "r"))
15468                     (set (match_operand:DF 3 "memory_operand" "=m")
15469                          (match_operand:DF 4 "gpc_reg_operand" "d"))])]
15470   ""
15471   "bl %1"
15472   [(set_attr "type" "branch")
15473    (set_attr "length" "4")])
15474
15475 ; These are to explain that changes to the stack pointer should
15476 ; not be moved over stores to stack memory.
15477 (define_insn "stack_tie"
15478   [(set (match_operand:BLK 0 "memory_operand" "+m")
15479         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
15480   ""
15481   ""
15482   [(set_attr "length" "0")])
15483
15484 ; Like stack_tie, but depend on both fp and sp based memory.
15485 (define_insn "frame_tie"
15486   [(set (match_operand:BLK 0 "memory_operand" "+m")
15487         (unspec:BLK [(match_dup 0)
15488                      (match_operand:BLK 1 "memory_operand" "m")] UNSPEC_TIE))]
15489   ""
15490   ""
15491   [(set_attr "length" "0")])
15492
15493
15494 (define_expand "epilogue"
15495   [(use (const_int 0))]
15496   "TARGET_SCHED_PROLOG"
15497   "
15498 {
15499       rs6000_emit_epilogue (FALSE);
15500       DONE;
15501 }")
15502
15503 ; On some processors, doing the mtcrf one CC register at a time is
15504 ; faster (like on the 604e).  On others, doing them all at once is
15505 ; faster; for instance, on the 601 and 750.
15506
15507 (define_expand "movsi_to_cr_one"
15508   [(set (match_operand:CC 0 "cc_reg_operand" "")
15509         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
15510                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
15511   ""
15512   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
15513
15514 (define_insn "*movsi_to_cr"
15515   [(match_parallel 0 "mtcrf_operation"
15516                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
15517                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
15518                                      (match_operand 3 "immediate_operand" "n")]
15519                                     UNSPEC_MOVESI_TO_CR))])]
15520  ""
15521  "*
15522 {
15523   int mask = 0;
15524   int i;
15525   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15526     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15527   operands[4] = GEN_INT (mask);
15528   return \"mtcrf %4,%2\";
15529 }"
15530   [(set_attr "type" "mtcr")])
15531
15532 (define_insn "*mtcrfsi"
15533   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
15534         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15535                     (match_operand 2 "immediate_operand" "n")]
15536                    UNSPEC_MOVESI_TO_CR))]
15537   "GET_CODE (operands[0]) == REG
15538    && CR_REGNO_P (REGNO (operands[0]))
15539    && GET_CODE (operands[2]) == CONST_INT
15540    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
15541   "mtcrf %R0,%1"
15542   [(set_attr "type" "mtcr")])
15543
15544 ; The load-multiple instructions have similar properties.
15545 ; Note that "load_multiple" is a name known to the machine-independent
15546 ; code that actually corresponds to the PowerPC load-string.
15547
15548 (define_insn "*lmw"
15549   [(match_parallel 0 "lmw_operation"
15550                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15551                          (match_operand:SI 2 "memory_operand" "m"))])]
15552   "TARGET_MULTIPLE"
15553   "{lm|lmw} %1,%2"
15554   [(set_attr "type" "load_ux")
15555    (set_attr "cell_micro" "always")])
15556
15557 (define_insn "*return_internal_<mode>"
15558   [(return)
15559    (use (match_operand:P 0 "register_operand" "lc"))]
15560   ""
15561   "b%T0"
15562   [(set_attr "type" "jmpreg")])
15563
15564 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
15565 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
15566
15567 (define_insn "*restore_gpregs_<mode>"
15568  [(match_parallel 0 "any_parallel_operand"
15569                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15570                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15571                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15572                    (set (match_operand:P 4 "gpc_reg_operand" "=r")
15573                         (match_operand:P 5 "memory_operand" "m"))])]
15574  ""
15575  "bl %2"
15576  [(set_attr "type" "branch")
15577   (set_attr "length" "4")])
15578
15579 (define_insn "*return_and_restore_gpregs_<mode>"
15580  [(match_parallel 0 "any_parallel_operand"
15581                   [(return)
15582                    (clobber (match_operand:P 1 "register_operand" "=l"))
15583                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15584                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15585                    (set (match_operand:P 4 "gpc_reg_operand" "=r")
15586                         (match_operand:P 5 "memory_operand" "m"))])]
15587  ""
15588  "b %2"
15589  [(set_attr "type" "branch")
15590   (set_attr "length" "4")])
15591
15592 (define_insn "*return_and_restore_fpregs_<mode>"
15593  [(match_parallel 0 "any_parallel_operand"
15594                   [(return)
15595                    (clobber (match_operand:P 1 "register_operand" "=l"))
15596                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15597                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15598                    (set (match_operand:DF 4 "gpc_reg_operand" "=d")
15599                         (match_operand:DF 5 "memory_operand" "m"))])]
15600  ""
15601  "b %2"
15602  [(set_attr "type" "branch")
15603   (set_attr "length" "4")])
15604
15605 (define_insn "*return_and_restore_fpregs_aix_<mode>"
15606  [(match_parallel 0 "any_parallel_operand"
15607                   [(return)
15608                    (use (match_operand:P 1 "register_operand" "l"))
15609                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15610                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
15611                    (set (match_operand:DF 4 "gpc_reg_operand" "=d")
15612                         (match_operand:DF 5 "memory_operand" "m"))])]
15613  ""
15614  "b %2"
15615  [(set_attr "type" "branch")
15616   (set_attr "length" "4")])
15617
15618 ; This is used in compiling the unwind routines.
15619 (define_expand "eh_return"
15620   [(use (match_operand 0 "general_operand" ""))]
15621   ""
15622   "
15623 {
15624   if (TARGET_32BIT)
15625     emit_insn (gen_eh_set_lr_si (operands[0]));
15626   else
15627     emit_insn (gen_eh_set_lr_di (operands[0]));
15628   DONE;
15629 }")
15630
15631 ; We can't expand this before we know where the link register is stored.
15632 (define_insn "eh_set_lr_<mode>"
15633   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
15634                     UNSPECV_EH_RR)
15635    (clobber (match_scratch:P 1 "=&b"))]
15636   ""
15637   "#")
15638
15639 (define_split
15640   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
15641    (clobber (match_scratch 1 ""))]
15642   "reload_completed"
15643   [(const_int 0)]
15644   "
15645 {
15646   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
15647   DONE;
15648 }")
15649
15650 (define_insn "prefetch"
15651   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
15652              (match_operand:SI 1 "const_int_operand" "n")
15653              (match_operand:SI 2 "const_int_operand" "n"))]
15654   "TARGET_POWERPC"
15655   "*
15656 {
15657   if (GET_CODE (operands[0]) == REG)
15658     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
15659   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
15660 }"
15661   [(set_attr "type" "load")])
15662 \f
15663 (define_insn "bpermd_<mode>"
15664   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15665         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
15666                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
15667   "TARGET_POPCNTD"
15668   "bpermd %0,%1,%2"
15669   [(set_attr "type" "integer")])
15670
15671 \f
15672
15673 (include "sync.md")
15674 (include "vector.md")
15675 (include "vsx.md")
15676 (include "altivec.md")
15677 (include "spe.md")
15678 (include "dfp.md")
15679 (include "paired.md")