OSDN Git Service

Add fma support
[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    (UNSPEC_COPYSIGN             52)
107    (UNSPEC_PARITY               53)
108    (UNSPEC_FCTIW                54)
109    (UNSPEC_FCTID                55)
110    (UNSPEC_LFIWAX               56)
111    (UNSPEC_LFIWZX               57)
112    (UNSPEC_FCTIWUZ              58)
113   ])
114
115 ;;
116 ;; UNSPEC_VOLATILE usage
117 ;;
118
119 (define_constants
120   [(UNSPECV_BLOCK               0)
121    (UNSPECV_LL                  1)      ; load-locked
122    (UNSPECV_SC                  2)      ; store-conditional
123    (UNSPECV_PROBE_STACK_RANGE   3)      ; probe range of stack addresses
124    (UNSPECV_EH_RR               9)      ; eh_reg_restore
125   ])
126 \f
127 ;; Define an insn type attribute.  This is used in function unit delay
128 ;; computations.
129 (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"
130   (const_string "integer"))
131
132 ;; Define floating point instruction sub-types for use with Xfpu.md
133 (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"))
134
135 ;; Length (in bytes).
136 ; '(pc)' in the following doesn't include the instruction itself; it is
137 ; calculated as if the instruction had zero size.
138 (define_attr "length" ""
139   (if_then_else (eq_attr "type" "branch")
140                 (if_then_else (and (ge (minus (match_dup 0) (pc))
141                                        (const_int -32768))
142                                    (lt (minus (match_dup 0) (pc))
143                                        (const_int 32764)))
144                               (const_int 4)
145                               (const_int 8))
146                 (const_int 4)))
147
148 ;; Processor type -- this attribute must exactly match the processor_type
149 ;; enumeration in rs6000.h.
150
151 (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,titan"
152   (const (symbol_ref "rs6000_cpu_attr")))
153
154
155 ;; If this instruction is microcoded on the CELL processor
156 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
157 (define_attr "cell_micro" "not,conditional,always"
158   (if_then_else (eq_attr "type" "compare,delayed_compare,imul_compare,lmul_compare,load_ext,load_ext_ux,var_shift_rotate,var_delayed_compare")
159                 (const_string "always")
160                 (const_string "not")))
161
162 (automata_option "ndfa")
163
164 (include "rios1.md")
165 (include "rios2.md")
166 (include "rs64.md")
167 (include "mpc.md")
168 (include "40x.md")
169 (include "440.md")
170 (include "476.md")
171 (include "603.md")
172 (include "6xx.md")
173 (include "7xx.md")
174 (include "7450.md")
175 (include "8540.md")
176 (include "e300c2c3.md")
177 (include "e500mc.md")
178 (include "e500mc64.md")
179 (include "power4.md")
180 (include "power5.md")
181 (include "power6.md")
182 (include "power7.md")
183 (include "cell.md")
184 (include "xfpu.md")
185 (include "a2.md")
186 (include "titan.md")
187
188 (include "predicates.md")
189 (include "constraints.md")
190
191 (include "darwin.md")
192
193 \f
194 ;; Mode iterators
195
196 ; This mode iterator allows :GPR to be used to indicate the allowable size
197 ; of whole values in GPRs.
198 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
199
200 ; Any supported integer mode.
201 (define_mode_iterator INT [QI HI SI DI TI])
202
203 ; Any supported integer mode that fits in one register.
204 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
205
206 ; extend modes for DImode
207 (define_mode_iterator QHSI [QI HI SI])
208
209 ; SImode or DImode, even if DImode doesn't fit in GPRs.
210 (define_mode_iterator SDI [SI DI])
211
212 ; The size of a pointer.  Also, the size of the value that a record-condition
213 ; (one with a '.') will compare; and the size used for arithmetic carries.
214 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
215
216 ; Any hardware-supported floating-point mode
217 (define_mode_iterator FP [
218   (SF "TARGET_HARD_FLOAT 
219    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) || TARGET_E500_SINGLE)")
220   (DF "TARGET_HARD_FLOAT 
221    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)")
222   (TF "!TARGET_IEEEQUAD
223    && TARGET_HARD_FLOAT
224    && (TARGET_FPRS || TARGET_E500_DOUBLE)
225    && TARGET_LONG_DOUBLE_128")
226   (DD "TARGET_DFP")
227   (TD "TARGET_DFP")])
228
229 ; These modes do not fit in integer registers in 32-bit mode.
230 ; but on e500v2, the gpr are 64 bit registers
231 (define_mode_iterator DIFD [DI (DF "!TARGET_E500_DOUBLE") DD])
232
233 ; Iterator for reciprocal estimate instructions
234 (define_mode_iterator RECIPF [SF DF V4SF V2DF])
235
236 ; Iterator for just SF/DF
237 (define_mode_iterator SFDF [SF DF])
238
239 ; Various instructions that come in SI and DI forms.
240 ; A generic w/d attribute, for things like cmpw/cmpd.
241 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
242
243 ; DImode bits
244 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
245
246 ;; ISEL/ISEL64 target selection
247 (define_mode_attr sel [(SI "") (DI "64")])
248
249 ;; Suffix for reload patterns
250 (define_mode_attr ptrsize [(SI "32bit")
251                            (DI "64bit")])
252
253 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
254                             (DI "TARGET_64BIT")])
255
256 (define_mode_attr mptrsize [(SI "si")
257                             (DI "di")])
258
259 (define_mode_attr rreg [(SF   "f")
260                         (DF   "ws")
261                         (V4SF "wf")
262                         (V2DF "wd")])
263
264 (define_mode_attr rreg2 [(SF   "f")
265                          (DF   "d")])
266
267 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
268                                  (DF "TARGET_FCFID")])
269
270 (define_mode_attr E500_CONVERT [(SF "!TARGET_FPRS")
271                                 (DF "TARGET_E500_DOUBLE")])
272
273 (define_mode_attr TARGET_FLOAT [(SF "TARGET_SINGLE_FLOAT")
274                                 (DF "TARGET_DOUBLE_FLOAT")])
275 \f
276 ;; Start with fixed-point load and store insns.  Here we put only the more
277 ;; complex forms.  Basic data transfer is done later.
278
279 (define_expand "zero_extend<mode>di2"
280   [(set (match_operand:DI 0 "gpc_reg_operand" "")
281         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
282   "TARGET_POWERPC64"
283   "")
284
285 (define_insn "*zero_extend<mode>di2_internal1"
286   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
287         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
288   "TARGET_POWERPC64"
289   "@
290    l<wd>z%U1%X1 %0,%1
291    rldicl %0,%1,0,<dbits>"
292   [(set_attr "type" "load,*")])
293
294 (define_insn "*zero_extend<mode>di2_internal2"
295   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
296         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
297                     (const_int 0)))
298    (clobber (match_scratch:DI 2 "=r,r"))]
299   "TARGET_64BIT"
300   "@
301    rldicl. %2,%1,0,<dbits>
302    #"
303   [(set_attr "type" "compare")
304    (set_attr "length" "4,8")])
305
306 (define_split
307   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
308         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
309                     (const_int 0)))
310    (clobber (match_scratch:DI 2 ""))]
311   "TARGET_POWERPC64 && reload_completed"
312   [(set (match_dup 2)
313         (zero_extend:DI (match_dup 1)))
314    (set (match_dup 0)
315         (compare:CC (match_dup 2)
316                     (const_int 0)))]
317   "")
318
319 (define_insn "*zero_extend<mode>di2_internal3"
320   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
321         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
322                     (const_int 0)))
323    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
324         (zero_extend:DI (match_dup 1)))]
325   "TARGET_64BIT"
326   "@
327    rldicl. %0,%1,0,<dbits>
328    #"
329   [(set_attr "type" "compare")
330    (set_attr "length" "4,8")])
331
332 (define_split
333   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
334         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
335                     (const_int 0)))
336    (set (match_operand:DI 0 "gpc_reg_operand" "")
337         (zero_extend:DI (match_dup 1)))]
338   "TARGET_POWERPC64 && reload_completed"
339   [(set (match_dup 0)
340         (zero_extend:DI (match_dup 1)))
341    (set (match_dup 2)
342         (compare:CC (match_dup 0)
343                     (const_int 0)))]
344   "")
345
346 (define_insn "extendqidi2"
347   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
348         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
349   "TARGET_POWERPC64"
350   "extsb %0,%1"
351   [(set_attr "type" "exts")])
352
353 (define_insn ""
354   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
355         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
356                     (const_int 0)))
357    (clobber (match_scratch:DI 2 "=r,r"))]
358   "TARGET_64BIT"
359   "@
360    extsb. %2,%1
361    #"
362   [(set_attr "type" "compare")
363    (set_attr "length" "4,8")])
364
365 (define_split
366   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
367         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
368                     (const_int 0)))
369    (clobber (match_scratch:DI 2 ""))]
370   "TARGET_POWERPC64 && reload_completed"
371   [(set (match_dup 2)
372         (sign_extend:DI (match_dup 1)))
373    (set (match_dup 0)
374         (compare:CC (match_dup 2)
375                     (const_int 0)))]
376   "")
377
378 (define_insn ""
379   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
380         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
381                     (const_int 0)))
382    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
383         (sign_extend:DI (match_dup 1)))]
384   "TARGET_64BIT"
385   "@
386    extsb. %0,%1
387    #"
388   [(set_attr "type" "compare")
389    (set_attr "length" "4,8")])
390
391 (define_split
392   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
393         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
394                     (const_int 0)))
395    (set (match_operand:DI 0 "gpc_reg_operand" "")
396         (sign_extend:DI (match_dup 1)))]
397   "TARGET_POWERPC64 && reload_completed"
398   [(set (match_dup 0)
399         (sign_extend:DI (match_dup 1)))
400    (set (match_dup 2)
401         (compare:CC (match_dup 0)
402                     (const_int 0)))]
403   "")
404
405 (define_expand "extendhidi2"
406   [(set (match_operand:DI 0 "gpc_reg_operand" "")
407         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
408   "TARGET_POWERPC64"
409   "")
410
411 (define_insn ""
412   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
413         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
414   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
415   "@
416    lha%U1%X1 %0,%1
417    extsh %0,%1"
418   [(set_attr "type" "load_ext,exts")])
419
420 (define_insn ""
421   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
422         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
423   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
424   "extsh %0,%1"
425   [(set_attr "type" "exts")])
426
427 (define_insn ""
428   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
429         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
430                     (const_int 0)))
431    (clobber (match_scratch:DI 2 "=r,r"))]
432   "TARGET_64BIT"
433   "@
434    extsh. %2,%1
435    #"
436   [(set_attr "type" "compare")
437    (set_attr "length" "4,8")])
438
439 (define_split
440   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
441         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
442                     (const_int 0)))
443    (clobber (match_scratch:DI 2 ""))]
444   "TARGET_POWERPC64 && reload_completed"
445   [(set (match_dup 2)
446         (sign_extend:DI (match_dup 1)))
447    (set (match_dup 0)
448         (compare:CC (match_dup 2)
449                     (const_int 0)))]
450   "")
451
452 (define_insn ""
453   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
454         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
455                     (const_int 0)))
456    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
457         (sign_extend:DI (match_dup 1)))]
458   "TARGET_64BIT"
459   "@
460    extsh. %0,%1
461    #"
462   [(set_attr "type" "compare")
463    (set_attr "length" "4,8")])
464
465 (define_split
466   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
467         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
468                     (const_int 0)))
469    (set (match_operand:DI 0 "gpc_reg_operand" "")
470         (sign_extend:DI (match_dup 1)))]
471   "TARGET_POWERPC64 && reload_completed"
472   [(set (match_dup 0)
473         (sign_extend:DI (match_dup 1)))
474    (set (match_dup 2)
475         (compare:CC (match_dup 0)
476                     (const_int 0)))]
477   "")
478
479 (define_expand "extendsidi2"
480   [(set (match_operand:DI 0 "gpc_reg_operand" "")
481         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
482   "TARGET_POWERPC64"
483   "")
484
485 (define_insn ""
486   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
487         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
488   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
489   "@
490    lwa%U1%X1 %0,%1
491    extsw %0,%1"
492   [(set_attr "type" "load_ext,exts")])
493
494 (define_insn ""
495   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
496         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
497   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
498   "extsw %0,%1"
499   [(set_attr "type" "exts")])
500
501 (define_insn ""
502   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
503         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
504                     (const_int 0)))
505    (clobber (match_scratch:DI 2 "=r,r"))]
506   "TARGET_64BIT"
507   "@
508    extsw. %2,%1
509    #"
510   [(set_attr "type" "compare")
511    (set_attr "length" "4,8")])
512
513 (define_split
514   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
515         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
516                     (const_int 0)))
517    (clobber (match_scratch:DI 2 ""))]
518   "TARGET_POWERPC64 && reload_completed"
519   [(set (match_dup 2)
520         (sign_extend:DI (match_dup 1)))
521    (set (match_dup 0)
522         (compare:CC (match_dup 2)
523                     (const_int 0)))]
524   "")
525
526 (define_insn ""
527   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
528         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
529                     (const_int 0)))
530    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
531         (sign_extend:DI (match_dup 1)))]
532   "TARGET_64BIT"
533   "@
534    extsw. %0,%1
535    #"
536   [(set_attr "type" "compare")
537    (set_attr "length" "4,8")])
538
539 (define_split
540   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
541         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
542                     (const_int 0)))
543    (set (match_operand:DI 0 "gpc_reg_operand" "")
544         (sign_extend:DI (match_dup 1)))]
545   "TARGET_POWERPC64 && reload_completed"
546   [(set (match_dup 0)
547         (sign_extend:DI (match_dup 1)))
548    (set (match_dup 2)
549         (compare:CC (match_dup 0)
550                     (const_int 0)))]
551   "")
552
553 (define_expand "zero_extendqisi2"
554   [(set (match_operand:SI 0 "gpc_reg_operand" "")
555         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
556   ""
557   "")
558
559 (define_insn ""
560   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
561         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
562   ""
563   "@
564    lbz%U1%X1 %0,%1
565    {rlinm|rlwinm} %0,%1,0,0xff"
566   [(set_attr "type" "load,*")])
567
568 (define_insn ""
569   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
570         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
571                     (const_int 0)))
572    (clobber (match_scratch:SI 2 "=r,r"))]
573   ""
574   "@
575    {andil.|andi.} %2,%1,0xff
576    #"
577   [(set_attr "type" "fast_compare,compare")
578    (set_attr "length" "4,8")])
579
580 (define_split
581   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
582         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
583                     (const_int 0)))
584    (clobber (match_scratch:SI 2 ""))]
585   "reload_completed"
586   [(set (match_dup 2)
587         (zero_extend:SI (match_dup 1)))
588    (set (match_dup 0)
589         (compare:CC (match_dup 2)
590                     (const_int 0)))]
591   "")
592
593 (define_insn ""
594   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
595         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
596                     (const_int 0)))
597    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
598         (zero_extend:SI (match_dup 1)))]
599   ""
600   "@
601    {andil.|andi.} %0,%1,0xff
602    #"
603   [(set_attr "type" "fast_compare,compare")
604    (set_attr "length" "4,8")])
605
606 (define_split
607   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
608         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
609                     (const_int 0)))
610    (set (match_operand:SI 0 "gpc_reg_operand" "")
611         (zero_extend:SI (match_dup 1)))]
612   "reload_completed"
613   [(set (match_dup 0)
614         (zero_extend:SI (match_dup 1)))
615    (set (match_dup 2)
616         (compare:CC (match_dup 0)
617                     (const_int 0)))]
618   "")
619
620 (define_expand "extendqisi2"
621   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
622    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
623   ""
624   "
625 {
626   if (TARGET_POWERPC)
627     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
628   else if (TARGET_POWER)
629     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
630   else
631     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
632   DONE;
633 }")
634
635 (define_insn "extendqisi2_ppc"
636   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
637         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
638   "TARGET_POWERPC"
639   "extsb %0,%1"
640   [(set_attr "type" "exts")])
641
642 (define_insn ""
643   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
644         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
645                     (const_int 0)))
646    (clobber (match_scratch:SI 2 "=r,r"))]
647   "TARGET_POWERPC"
648   "@
649    extsb. %2,%1
650    #"
651   [(set_attr "type" "compare")
652    (set_attr "length" "4,8")])
653
654 (define_split
655   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
656         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
657                     (const_int 0)))
658    (clobber (match_scratch:SI 2 ""))]
659   "TARGET_POWERPC && reload_completed"
660   [(set (match_dup 2)
661         (sign_extend:SI (match_dup 1)))
662    (set (match_dup 0)
663         (compare:CC (match_dup 2)
664                     (const_int 0)))]
665   "")
666
667 (define_insn ""
668   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
669         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
670                     (const_int 0)))
671    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
672         (sign_extend:SI (match_dup 1)))]
673   "TARGET_POWERPC"
674   "@
675    extsb. %0,%1
676    #"
677   [(set_attr "type" "compare")
678    (set_attr "length" "4,8")])
679
680 (define_split
681   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
682         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
683                     (const_int 0)))
684    (set (match_operand:SI 0 "gpc_reg_operand" "")
685         (sign_extend:SI (match_dup 1)))]
686   "TARGET_POWERPC && reload_completed"
687   [(set (match_dup 0)
688         (sign_extend:SI (match_dup 1)))
689    (set (match_dup 2)
690         (compare:CC (match_dup 0)
691                     (const_int 0)))]
692   "")
693
694 (define_expand "extendqisi2_power"
695   [(parallel [(set (match_dup 2)
696                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
697                               (const_int 24)))
698               (clobber (scratch:SI))])
699    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
700                    (ashiftrt:SI (match_dup 2)
701                                 (const_int 24)))
702               (clobber (scratch:SI))])]
703   "TARGET_POWER"
704   "
705 { operands[1] = gen_lowpart (SImode, operands[1]);
706   operands[2] = gen_reg_rtx (SImode); }")
707
708 (define_expand "extendqisi2_no_power"
709   [(set (match_dup 2)
710         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
711                    (const_int 24)))
712    (set (match_operand:SI 0 "gpc_reg_operand" "")
713         (ashiftrt:SI (match_dup 2)
714                      (const_int 24)))]
715   "! TARGET_POWER && ! TARGET_POWERPC"
716   "
717 { operands[1] = gen_lowpart (SImode, operands[1]);
718   operands[2] = gen_reg_rtx (SImode); }")
719
720 (define_expand "zero_extendqihi2"
721   [(set (match_operand:HI 0 "gpc_reg_operand" "")
722         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
723   ""
724   "")
725
726 (define_insn ""
727   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
728         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
729   ""
730   "@
731    lbz%U1%X1 %0,%1
732    {rlinm|rlwinm} %0,%1,0,0xff"
733   [(set_attr "type" "load,*")])
734
735 (define_insn ""
736   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
737         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
738                     (const_int 0)))
739    (clobber (match_scratch:HI 2 "=r,r"))]
740   ""
741   "@
742    {andil.|andi.} %2,%1,0xff
743    #"
744   [(set_attr "type" "fast_compare,compare")
745    (set_attr "length" "4,8")])
746
747 (define_split
748   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
749         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
750                     (const_int 0)))
751    (clobber (match_scratch:HI 2 ""))]
752   "reload_completed"
753   [(set (match_dup 2)
754         (zero_extend:HI (match_dup 1)))
755    (set (match_dup 0)
756         (compare:CC (match_dup 2)
757                     (const_int 0)))]
758   "")
759
760 (define_insn ""
761   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
762         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
763                     (const_int 0)))
764    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
765         (zero_extend:HI (match_dup 1)))]
766   ""
767   "@
768    {andil.|andi.} %0,%1,0xff
769    #"
770   [(set_attr "type" "fast_compare,compare")
771    (set_attr "length" "4,8")])
772
773 (define_split
774   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
775         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
776                     (const_int 0)))
777    (set (match_operand:HI 0 "gpc_reg_operand" "")
778         (zero_extend:HI (match_dup 1)))]
779   "reload_completed"
780   [(set (match_dup 0)
781         (zero_extend:HI (match_dup 1)))
782    (set (match_dup 2)
783         (compare:CC (match_dup 0)
784                     (const_int 0)))]
785   "")
786
787 (define_expand "extendqihi2"
788   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
789    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
790   ""
791   "
792 {
793   if (TARGET_POWERPC)
794     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
795   else if (TARGET_POWER)
796     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
797   else
798     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
799   DONE;
800 }")
801
802 (define_insn "extendqihi2_ppc"
803   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
804         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
805   "TARGET_POWERPC"
806   "extsb %0,%1"
807   [(set_attr "type" "exts")])
808
809 (define_insn ""
810   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
811         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
812                     (const_int 0)))
813    (clobber (match_scratch:HI 2 "=r,r"))]
814   "TARGET_POWERPC"
815   "@
816    extsb. %2,%1
817    #"
818   [(set_attr "type" "compare")
819    (set_attr "length" "4,8")])
820
821 (define_split
822   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
823         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
824                     (const_int 0)))
825    (clobber (match_scratch:HI 2 ""))]
826   "TARGET_POWERPC && reload_completed"
827   [(set (match_dup 2)
828         (sign_extend:HI (match_dup 1)))
829    (set (match_dup 0)
830         (compare:CC (match_dup 2)
831                     (const_int 0)))]
832   "")
833
834 (define_insn ""
835   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
836         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
837                     (const_int 0)))
838    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
839         (sign_extend:HI (match_dup 1)))]
840   "TARGET_POWERPC"
841   "@
842    extsb. %0,%1
843    #"
844   [(set_attr "type" "compare")
845    (set_attr "length" "4,8")])
846
847 (define_split
848   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
849         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
850                     (const_int 0)))
851    (set (match_operand:HI 0 "gpc_reg_operand" "")
852         (sign_extend:HI (match_dup 1)))]
853   "TARGET_POWERPC && reload_completed"
854   [(set (match_dup 0)
855         (sign_extend:HI (match_dup 1)))
856    (set (match_dup 2)
857         (compare:CC (match_dup 0)
858                     (const_int 0)))]
859   "")
860
861 (define_expand "extendqihi2_power"
862   [(parallel [(set (match_dup 2)
863                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
864                               (const_int 24)))
865               (clobber (scratch:SI))])
866    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
867                    (ashiftrt:SI (match_dup 2)
868                                 (const_int 24)))
869               (clobber (scratch:SI))])]
870   "TARGET_POWER"
871   "
872 { operands[0] = gen_lowpart (SImode, operands[0]);
873   operands[1] = gen_lowpart (SImode, operands[1]);
874   operands[2] = gen_reg_rtx (SImode); }")
875
876 (define_expand "extendqihi2_no_power"
877   [(set (match_dup 2)
878         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
879                    (const_int 24)))
880    (set (match_operand:HI 0 "gpc_reg_operand" "")
881         (ashiftrt:SI (match_dup 2)
882                      (const_int 24)))]
883   "! TARGET_POWER && ! TARGET_POWERPC"
884   "
885 { operands[0] = gen_lowpart (SImode, operands[0]);
886   operands[1] = gen_lowpart (SImode, operands[1]);
887   operands[2] = gen_reg_rtx (SImode); }")
888
889 (define_expand "zero_extendhisi2"
890   [(set (match_operand:SI 0 "gpc_reg_operand" "")
891         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
892   ""
893   "")
894
895 (define_insn ""
896   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
897         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
898   ""
899   "@
900    lhz%U1%X1 %0,%1
901    {rlinm|rlwinm} %0,%1,0,0xffff"
902   [(set_attr "type" "load,*")])
903
904 (define_insn ""
905   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
906         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
907                     (const_int 0)))
908    (clobber (match_scratch:SI 2 "=r,r"))]
909   ""
910   "@
911    {andil.|andi.} %2,%1,0xffff
912    #"
913   [(set_attr "type" "fast_compare,compare")
914    (set_attr "length" "4,8")])
915
916 (define_split
917   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
918         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
919                     (const_int 0)))
920    (clobber (match_scratch:SI 2 ""))]
921   "reload_completed"
922   [(set (match_dup 2)
923         (zero_extend:SI (match_dup 1)))
924    (set (match_dup 0)
925         (compare:CC (match_dup 2)
926                     (const_int 0)))]
927   "")
928
929 (define_insn ""
930   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
931         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
932                     (const_int 0)))
933    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
934         (zero_extend:SI (match_dup 1)))]
935   ""
936   "@
937    {andil.|andi.} %0,%1,0xffff
938    #"
939   [(set_attr "type" "fast_compare,compare")
940    (set_attr "length" "4,8")])
941
942 (define_split
943   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
944         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
945                     (const_int 0)))
946    (set (match_operand:SI 0 "gpc_reg_operand" "")
947         (zero_extend:SI (match_dup 1)))]
948   "reload_completed"
949   [(set (match_dup 0)
950         (zero_extend:SI (match_dup 1)))
951    (set (match_dup 2)
952         (compare:CC (match_dup 0)
953                     (const_int 0)))]
954   "")
955
956 (define_expand "extendhisi2"
957   [(set (match_operand:SI 0 "gpc_reg_operand" "")
958         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
959   ""
960   "")
961
962 (define_insn ""
963   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
964         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
965   "rs6000_gen_cell_microcode"
966   "@
967    lha%U1%X1 %0,%1
968    {exts|extsh} %0,%1"
969   [(set_attr "type" "load_ext,exts")])
970
971 (define_insn ""
972   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
973         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
974   "!rs6000_gen_cell_microcode"
975   "{exts|extsh} %0,%1"
976   [(set_attr "type" "exts")])
977
978 (define_insn ""
979   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
980         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
981                     (const_int 0)))
982    (clobber (match_scratch:SI 2 "=r,r"))]
983   ""
984   "@
985    {exts.|extsh.} %2,%1
986    #"
987   [(set_attr "type" "compare")
988    (set_attr "length" "4,8")])
989
990 (define_split
991   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
992         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
993                     (const_int 0)))
994    (clobber (match_scratch:SI 2 ""))]
995   "reload_completed"
996   [(set (match_dup 2)
997         (sign_extend:SI (match_dup 1)))
998    (set (match_dup 0)
999         (compare:CC (match_dup 2)
1000                     (const_int 0)))]
1001   "")
1002
1003 (define_insn ""
1004   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1005         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1006                     (const_int 0)))
1007    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1008         (sign_extend:SI (match_dup 1)))]
1009   ""
1010   "@
1011    {exts.|extsh.} %0,%1
1012    #"
1013   [(set_attr "type" "compare")
1014    (set_attr "length" "4,8")])
1015 \f
1016 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
1017
1018 (define_insn "*macchwc"
1019   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1020         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1021                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1022                                        (const_int 16))
1023                                       (sign_extend:SI
1024                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1025                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1026                     (const_int 0)))
1027    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1028         (plus:SI (mult:SI (ashiftrt:SI
1029                            (match_dup 2)
1030                            (const_int 16))
1031                           (sign_extend:SI
1032                            (match_dup 1)))
1033                  (match_dup 4)))]
1034   "TARGET_MULHW"
1035   "macchw. %0, %1, %2"
1036   [(set_attr "type" "imul3")])
1037
1038 (define_insn "*macchw"
1039   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1040         (plus:SI (mult:SI (ashiftrt:SI
1041                            (match_operand:SI 2 "gpc_reg_operand" "r")
1042                            (const_int 16))
1043                           (sign_extend:SI
1044                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1045                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1046   "TARGET_MULHW"
1047   "macchw %0, %1, %2"
1048   [(set_attr "type" "imul3")])
1049
1050 (define_insn "*macchwuc"
1051   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1052         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1053                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1054                                        (const_int 16))
1055                                       (zero_extend:SI
1056                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1057                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1058                     (const_int 0)))
1059    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1060         (plus:SI (mult:SI (lshiftrt:SI
1061                            (match_dup 2)
1062                            (const_int 16))
1063                           (zero_extend:SI
1064                            (match_dup 1)))
1065                  (match_dup 4)))]
1066   "TARGET_MULHW"
1067   "macchwu. %0, %1, %2"
1068   [(set_attr "type" "imul3")])
1069
1070 (define_insn "*macchwu"
1071   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1072         (plus:SI (mult:SI (lshiftrt:SI
1073                            (match_operand:SI 2 "gpc_reg_operand" "r")
1074                            (const_int 16))
1075                           (zero_extend:SI
1076                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1077                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1078   "TARGET_MULHW"
1079   "macchwu %0, %1, %2"
1080   [(set_attr "type" "imul3")])
1081
1082 (define_insn "*machhwc"
1083   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1084         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1085                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1086                                        (const_int 16))
1087                                       (ashiftrt:SI
1088                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1089                                        (const_int 16)))
1090                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1091                     (const_int 0)))
1092    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1093         (plus:SI (mult:SI (ashiftrt:SI
1094                            (match_dup 1)
1095                            (const_int 16))
1096                           (ashiftrt:SI
1097                            (match_dup 2)
1098                            (const_int 16)))
1099                  (match_dup 4)))]
1100   "TARGET_MULHW"
1101   "machhw. %0, %1, %2"
1102   [(set_attr "type" "imul3")])
1103
1104 (define_insn "*machhw"
1105   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1106         (plus:SI (mult:SI (ashiftrt:SI
1107                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1108                            (const_int 16))
1109                           (ashiftrt:SI
1110                            (match_operand:SI 2 "gpc_reg_operand" "r")
1111                            (const_int 16)))
1112                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1113   "TARGET_MULHW"
1114   "machhw %0, %1, %2"
1115   [(set_attr "type" "imul3")])
1116
1117 (define_insn "*machhwuc"
1118   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1119         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1120                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1121                                        (const_int 16))
1122                                       (lshiftrt:SI
1123                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1124                                        (const_int 16)))
1125                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1126                     (const_int 0)))
1127    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1128         (plus:SI (mult:SI (lshiftrt:SI
1129                            (match_dup 1)
1130                            (const_int 16))
1131                           (lshiftrt:SI
1132                            (match_dup 2)
1133                            (const_int 16)))
1134                  (match_dup 4)))]
1135   "TARGET_MULHW"
1136   "machhwu. %0, %1, %2"
1137   [(set_attr "type" "imul3")])
1138
1139 (define_insn "*machhwu"
1140   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1141         (plus:SI (mult:SI (lshiftrt:SI
1142                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1143                            (const_int 16))
1144                           (lshiftrt:SI
1145                            (match_operand:SI 2 "gpc_reg_operand" "r")
1146                            (const_int 16)))
1147                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1148   "TARGET_MULHW"
1149   "machhwu %0, %1, %2"
1150   [(set_attr "type" "imul3")])
1151
1152 (define_insn "*maclhwc"
1153   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1154         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1155                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1156                                       (sign_extend:SI
1157                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1158                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1159                     (const_int 0)))
1160    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1161         (plus:SI (mult:SI (sign_extend:SI
1162                            (match_dup 1))
1163                           (sign_extend:SI
1164                            (match_dup 2)))
1165                  (match_dup 4)))]
1166   "TARGET_MULHW"
1167   "maclhw. %0, %1, %2"
1168   [(set_attr "type" "imul3")])
1169
1170 (define_insn "*maclhw"
1171   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1172         (plus:SI (mult:SI (sign_extend:SI
1173                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1174                           (sign_extend:SI
1175                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1176                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1177   "TARGET_MULHW"
1178   "maclhw %0, %1, %2"
1179   [(set_attr "type" "imul3")])
1180
1181 (define_insn "*maclhwuc"
1182   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1183         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1184                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1185                                       (zero_extend:SI
1186                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1187                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1188                     (const_int 0)))
1189    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1190         (plus:SI (mult:SI (zero_extend:SI
1191                            (match_dup 1))
1192                           (zero_extend:SI
1193                            (match_dup 2)))
1194                  (match_dup 4)))]
1195   "TARGET_MULHW"
1196   "maclhwu. %0, %1, %2"
1197   [(set_attr "type" "imul3")])
1198
1199 (define_insn "*maclhwu"
1200   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1201         (plus:SI (mult:SI (zero_extend:SI
1202                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1203                           (zero_extend:SI
1204                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1205                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1206   "TARGET_MULHW"
1207   "maclhwu %0, %1, %2"
1208   [(set_attr "type" "imul3")])
1209
1210 (define_insn "*nmacchwc"
1211   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1212         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1213                               (mult:SI (ashiftrt:SI
1214                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1215                                         (const_int 16))
1216                                        (sign_extend:SI
1217                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1218                     (const_int 0)))
1219    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1220         (minus:SI (match_dup 4)
1221                   (mult:SI (ashiftrt:SI
1222                             (match_dup 2)
1223                             (const_int 16))
1224                            (sign_extend:SI
1225                             (match_dup 1)))))]
1226   "TARGET_MULHW"
1227   "nmacchw. %0, %1, %2"
1228   [(set_attr "type" "imul3")])
1229
1230 (define_insn "*nmacchw"
1231   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1232         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1233                   (mult:SI (ashiftrt:SI
1234                             (match_operand:SI 2 "gpc_reg_operand" "r")
1235                             (const_int 16))
1236                            (sign_extend:SI
1237                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1238   "TARGET_MULHW"
1239   "nmacchw %0, %1, %2"
1240   [(set_attr "type" "imul3")])
1241
1242 (define_insn "*nmachhwc"
1243   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1244         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1245                               (mult:SI (ashiftrt:SI
1246                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1247                                         (const_int 16))
1248                                        (ashiftrt:SI
1249                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1250                                         (const_int 16))))
1251                     (const_int 0)))
1252    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1253         (minus:SI (match_dup 4)
1254                   (mult:SI (ashiftrt:SI
1255                             (match_dup 1)
1256                             (const_int 16))
1257                            (ashiftrt:SI
1258                             (match_dup 2)
1259                             (const_int 16)))))]
1260   "TARGET_MULHW"
1261   "nmachhw. %0, %1, %2"
1262   [(set_attr "type" "imul3")])
1263
1264 (define_insn "*nmachhw"
1265   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1266         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1267                   (mult:SI (ashiftrt:SI
1268                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1269                             (const_int 16))
1270                            (ashiftrt:SI
1271                             (match_operand:SI 2 "gpc_reg_operand" "r")
1272                             (const_int 16)))))]
1273   "TARGET_MULHW"
1274   "nmachhw %0, %1, %2"
1275   [(set_attr "type" "imul3")])
1276
1277 (define_insn "*nmaclhwc"
1278   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1279         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1280                               (mult:SI (sign_extend:SI
1281                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1282                                        (sign_extend:SI
1283                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1284                     (const_int 0)))
1285    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1286         (minus:SI (match_dup 4)
1287                   (mult:SI (sign_extend:SI
1288                             (match_dup 1))
1289                            (sign_extend:SI
1290                             (match_dup 2)))))]
1291   "TARGET_MULHW"
1292   "nmaclhw. %0, %1, %2"
1293   [(set_attr "type" "imul3")])
1294
1295 (define_insn "*nmaclhw"
1296   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1297         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1298                   (mult:SI (sign_extend:SI
1299                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1300                            (sign_extend:SI
1301                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1302   "TARGET_MULHW"
1303   "nmaclhw %0, %1, %2"
1304   [(set_attr "type" "imul3")])
1305
1306 (define_insn "*mulchwc"
1307   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1308         (compare:CC (mult:SI (ashiftrt:SI
1309                               (match_operand:SI 2 "gpc_reg_operand" "r")
1310                               (const_int 16))
1311                              (sign_extend:SI
1312                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1313                     (const_int 0)))
1314    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1315         (mult:SI (ashiftrt:SI
1316                   (match_dup 2)
1317                   (const_int 16))
1318                  (sign_extend:SI
1319                   (match_dup 1))))]
1320   "TARGET_MULHW"
1321   "mulchw. %0, %1, %2"
1322   [(set_attr "type" "imul3")])
1323
1324 (define_insn "*mulchw"
1325   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1326         (mult:SI (ashiftrt:SI
1327                   (match_operand:SI 2 "gpc_reg_operand" "r")
1328                   (const_int 16))
1329                  (sign_extend:SI
1330                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1331   "TARGET_MULHW"
1332   "mulchw %0, %1, %2"
1333   [(set_attr "type" "imul3")])
1334
1335 (define_insn "*mulchwuc"
1336   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1337         (compare:CC (mult:SI (lshiftrt:SI
1338                               (match_operand:SI 2 "gpc_reg_operand" "r")
1339                               (const_int 16))
1340                              (zero_extend:SI
1341                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1342                     (const_int 0)))
1343    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1344         (mult:SI (lshiftrt:SI
1345                   (match_dup 2)
1346                   (const_int 16))
1347                  (zero_extend:SI
1348                   (match_dup 1))))]
1349   "TARGET_MULHW"
1350   "mulchwu. %0, %1, %2"
1351   [(set_attr "type" "imul3")])
1352
1353 (define_insn "*mulchwu"
1354   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1355         (mult:SI (lshiftrt:SI
1356                   (match_operand:SI 2 "gpc_reg_operand" "r")
1357                   (const_int 16))
1358                  (zero_extend:SI
1359                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1360   "TARGET_MULHW"
1361   "mulchwu %0, %1, %2"
1362   [(set_attr "type" "imul3")])
1363
1364 (define_insn "*mulhhwc"
1365   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1366         (compare:CC (mult:SI (ashiftrt:SI
1367                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1368                               (const_int 16))
1369                              (ashiftrt:SI
1370                               (match_operand:SI 2 "gpc_reg_operand" "r")
1371                               (const_int 16)))
1372                     (const_int 0)))
1373    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1374         (mult:SI (ashiftrt:SI
1375                   (match_dup 1)
1376                   (const_int 16))
1377                  (ashiftrt:SI
1378                   (match_dup 2)
1379                   (const_int 16))))]
1380   "TARGET_MULHW"
1381   "mulhhw. %0, %1, %2"
1382   [(set_attr "type" "imul3")])
1383
1384 (define_insn "*mulhhw"
1385   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1386         (mult:SI (ashiftrt:SI
1387                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1388                   (const_int 16))
1389                  (ashiftrt:SI
1390                   (match_operand:SI 2 "gpc_reg_operand" "r")
1391                   (const_int 16))))]
1392   "TARGET_MULHW"
1393   "mulhhw %0, %1, %2"
1394   [(set_attr "type" "imul3")])
1395
1396 (define_insn "*mulhhwuc"
1397   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1398         (compare:CC (mult:SI (lshiftrt:SI
1399                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1400                               (const_int 16))
1401                              (lshiftrt:SI
1402                               (match_operand:SI 2 "gpc_reg_operand" "r")
1403                               (const_int 16)))
1404                     (const_int 0)))
1405    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1406         (mult:SI (lshiftrt:SI
1407                   (match_dup 1)
1408                   (const_int 16))
1409                  (lshiftrt:SI
1410                   (match_dup 2)
1411                   (const_int 16))))]
1412   "TARGET_MULHW"
1413   "mulhhwu. %0, %1, %2"
1414   [(set_attr "type" "imul3")])
1415
1416 (define_insn "*mulhhwu"
1417   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1418         (mult:SI (lshiftrt:SI
1419                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1420                   (const_int 16))
1421                  (lshiftrt:SI
1422                   (match_operand:SI 2 "gpc_reg_operand" "r")
1423                   (const_int 16))))]
1424   "TARGET_MULHW"
1425   "mulhhwu %0, %1, %2"
1426   [(set_attr "type" "imul3")])
1427
1428 (define_insn "*mullhwc"
1429   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1430         (compare:CC (mult:SI (sign_extend:SI
1431                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1432                              (sign_extend:SI
1433                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1434                     (const_int 0)))
1435    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1436         (mult:SI (sign_extend:SI
1437                   (match_dup 1))
1438                  (sign_extend:SI
1439                   (match_dup 2))))]
1440   "TARGET_MULHW"
1441   "mullhw. %0, %1, %2"
1442   [(set_attr "type" "imul3")])
1443
1444 (define_insn "*mullhw"
1445   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1446         (mult:SI (sign_extend:SI
1447                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1448                  (sign_extend:SI
1449                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1450   "TARGET_MULHW"
1451   "mullhw %0, %1, %2"
1452   [(set_attr "type" "imul3")])
1453
1454 (define_insn "*mullhwuc"
1455   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1456         (compare:CC (mult:SI (zero_extend:SI
1457                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1458                              (zero_extend:SI
1459                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1460                     (const_int 0)))
1461    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1462         (mult:SI (zero_extend:SI
1463                   (match_dup 1))
1464                  (zero_extend:SI
1465                   (match_dup 2))))]
1466   "TARGET_MULHW"
1467   "mullhwu. %0, %1, %2"
1468   [(set_attr "type" "imul3")])
1469
1470 (define_insn "*mullhwu"
1471   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1472         (mult:SI (zero_extend:SI
1473                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1474                  (zero_extend:SI
1475                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1476   "TARGET_MULHW"
1477   "mullhwu %0, %1, %2"
1478   [(set_attr "type" "imul3")])
1479 \f
1480 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1481 (define_insn "dlmzb"
1482   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1483         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1484                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1485                    UNSPEC_DLMZB_CR))
1486    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1487         (unspec:SI [(match_dup 1)
1488                     (match_dup 2)]
1489                    UNSPEC_DLMZB))]
1490   "TARGET_DLMZB"
1491   "dlmzb. %0, %1, %2")
1492
1493 (define_expand "strlensi"
1494   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1495         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1496                     (match_operand:QI 2 "const_int_operand" "")
1497                     (match_operand 3 "const_int_operand" "")]
1498                    UNSPEC_DLMZB_STRLEN))
1499    (clobber (match_scratch:CC 4 "=x"))]
1500   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1501 {
1502   rtx result = operands[0];
1503   rtx src = operands[1];
1504   rtx search_char = operands[2];
1505   rtx align = operands[3];
1506   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1507   rtx loop_label, end_label, mem, cr0, cond;
1508   if (search_char != const0_rtx
1509       || GET_CODE (align) != CONST_INT
1510       || INTVAL (align) < 8)
1511         FAIL;
1512   word1 = gen_reg_rtx (SImode);
1513   word2 = gen_reg_rtx (SImode);
1514   scratch_dlmzb = gen_reg_rtx (SImode);
1515   scratch_string = gen_reg_rtx (Pmode);
1516   loop_label = gen_label_rtx ();
1517   end_label = gen_label_rtx ();
1518   addr = force_reg (Pmode, XEXP (src, 0));
1519   emit_move_insn (scratch_string, addr);
1520   emit_label (loop_label);
1521   mem = change_address (src, SImode, scratch_string);
1522   emit_move_insn (word1, mem);
1523   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1524   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1525   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1526   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1527   emit_jump_insn (gen_rtx_SET (VOIDmode,
1528                                pc_rtx,
1529                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1530                                                      cond,
1531                                                      gen_rtx_LABEL_REF
1532                                                        (VOIDmode,
1533                                                         end_label),
1534                                                      pc_rtx)));
1535   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1536   emit_jump_insn (gen_rtx_SET (VOIDmode,
1537                                pc_rtx,
1538                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1539   emit_barrier ();
1540   emit_label (end_label);
1541   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1542   emit_insn (gen_subsi3 (result, scratch_string, addr));
1543   emit_insn (gen_subsi3 (result, result, const1_rtx));
1544   DONE;
1545 })
1546 \f
1547 (define_split
1548   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1549         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1550                     (const_int 0)))
1551    (set (match_operand:SI 0 "gpc_reg_operand" "")
1552         (sign_extend:SI (match_dup 1)))]
1553   "reload_completed"
1554   [(set (match_dup 0)
1555         (sign_extend:SI (match_dup 1)))
1556    (set (match_dup 2)
1557         (compare:CC (match_dup 0)
1558                     (const_int 0)))]
1559   "")
1560
1561 ;; Fixed-point arithmetic insns.
1562
1563 (define_expand "add<mode>3"
1564   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1565         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1566                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1567   ""
1568 {
1569   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1570     {
1571       if (non_short_cint_operand (operands[2], DImode))
1572         FAIL;
1573     }
1574   else if (GET_CODE (operands[2]) == CONST_INT
1575            && ! add_operand (operands[2], <MODE>mode))
1576     {
1577       rtx tmp = ((!can_create_pseudo_p ()
1578                   || rtx_equal_p (operands[0], operands[1]))
1579                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1580
1581       HOST_WIDE_INT val = INTVAL (operands[2]);
1582       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1583       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1584
1585       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1586         FAIL;
1587
1588       /* The ordering here is important for the prolog expander.
1589          When space is allocated from the stack, adding 'low' first may
1590          produce a temporary deallocation (which would be bad).  */
1591       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1592       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1593       DONE;
1594     }
1595 })
1596
1597 ;; Discourage ai/addic because of carry but provide it in an alternative
1598 ;; allowing register zero as source.
1599 (define_insn "*add<mode>3_internal1"
1600   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1601         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1602                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1603   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1604   "@
1605    {cax|add} %0,%1,%2
1606    {cal %0,%2(%1)|addi %0,%1,%2}
1607    {ai|addic} %0,%1,%2
1608    {cau|addis} %0,%1,%v2"
1609   [(set_attr "length" "4,4,4,4")])
1610
1611 (define_insn "addsi3_high"
1612   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1613         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1614                  (high:SI (match_operand 2 "" ""))))]
1615   "TARGET_MACHO && !TARGET_64BIT"
1616   "{cau|addis} %0,%1,ha16(%2)"
1617   [(set_attr "length" "4")])
1618
1619 (define_insn "*add<mode>3_internal2"
1620   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1621         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1622                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1623                     (const_int 0)))
1624    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1625   ""
1626   "@
1627    {cax.|add.} %3,%1,%2
1628    {ai.|addic.} %3,%1,%2
1629    #
1630    #"
1631   [(set_attr "type" "fast_compare,compare,compare,compare")
1632    (set_attr "length" "4,4,8,8")])
1633
1634 (define_split
1635   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1636         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1637                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1638                     (const_int 0)))
1639    (clobber (match_scratch:GPR 3 ""))]
1640   "reload_completed"
1641   [(set (match_dup 3)
1642         (plus:GPR (match_dup 1)
1643                  (match_dup 2)))
1644    (set (match_dup 0)
1645         (compare:CC (match_dup 3)
1646                     (const_int 0)))]
1647   "")
1648
1649 (define_insn "*add<mode>3_internal3"
1650   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1651         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1652                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1653                     (const_int 0)))
1654    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1655         (plus:P (match_dup 1)
1656                 (match_dup 2)))]
1657   ""
1658   "@
1659    {cax.|add.} %0,%1,%2
1660    {ai.|addic.} %0,%1,%2
1661    #
1662    #"
1663   [(set_attr "type" "fast_compare,compare,compare,compare")
1664    (set_attr "length" "4,4,8,8")])
1665
1666 (define_split
1667   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1668         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1669                             (match_operand:P 2 "reg_or_short_operand" ""))
1670                     (const_int 0)))
1671    (set (match_operand:P 0 "gpc_reg_operand" "")
1672         (plus:P (match_dup 1) (match_dup 2)))]
1673   "reload_completed"
1674   [(set (match_dup 0)
1675         (plus:P (match_dup 1)
1676                 (match_dup 2)))
1677    (set (match_dup 3)
1678         (compare:CC (match_dup 0)
1679                     (const_int 0)))]
1680   "")
1681
1682 ;; Split an add that we can't do in one insn into two insns, each of which
1683 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1684 ;; add should be last in case the result gets used in an address.
1685
1686 (define_split
1687   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1688         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1689                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1690   ""
1691   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1692    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1693 {
1694   HOST_WIDE_INT val = INTVAL (operands[2]);
1695   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1696   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1697
1698   operands[4] = GEN_INT (low);
1699   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1700     operands[3] = GEN_INT (rest);
1701   else if (can_create_pseudo_p ())
1702     {
1703       operands[3] = gen_reg_rtx (DImode);
1704       emit_move_insn (operands[3], operands[2]);
1705       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1706       DONE;
1707     }
1708   else
1709     FAIL;
1710 })
1711
1712 (define_insn "one_cmpl<mode>2"
1713   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1714         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1715   ""
1716   "nor %0,%1,%1")
1717
1718 (define_insn ""
1719   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1720         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1721                     (const_int 0)))
1722    (clobber (match_scratch:P 2 "=r,r"))]
1723   ""
1724   "@
1725    nor. %2,%1,%1
1726    #"
1727   [(set_attr "type" "fast_compare,compare")
1728    (set_attr "length" "4,8")])
1729
1730 (define_split
1731   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1732         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1733                     (const_int 0)))
1734    (clobber (match_scratch:P 2 ""))]
1735   "reload_completed"
1736   [(set (match_dup 2)
1737         (not:P (match_dup 1)))
1738    (set (match_dup 0)
1739         (compare:CC (match_dup 2)
1740                     (const_int 0)))]
1741   "")
1742
1743 (define_insn ""
1744   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1745         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1746                     (const_int 0)))
1747    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1748         (not:P (match_dup 1)))]
1749   ""
1750   "@
1751    nor. %0,%1,%1
1752    #"
1753   [(set_attr "type" "fast_compare,compare")
1754    (set_attr "length" "4,8")])
1755
1756 (define_split
1757   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1758         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1759                     (const_int 0)))
1760    (set (match_operand:P 0 "gpc_reg_operand" "")
1761         (not:P (match_dup 1)))]
1762   "reload_completed"
1763   [(set (match_dup 0)
1764         (not:P (match_dup 1)))
1765    (set (match_dup 2)
1766         (compare:CC (match_dup 0)
1767                     (const_int 0)))]
1768   "")
1769
1770 (define_insn ""
1771   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1772         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1773                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1774   "! TARGET_POWERPC"
1775   "{sf%I1|subf%I1c} %0,%2,%1")
1776
1777 (define_insn ""
1778   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1779         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1780                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1781   "TARGET_POWERPC"
1782   "@
1783    subf %0,%2,%1
1784    subfic %0,%2,%1")
1785
1786 (define_insn ""
1787   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1788         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1789                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1790                     (const_int 0)))
1791    (clobber (match_scratch:SI 3 "=r,r"))]
1792   "! TARGET_POWERPC"
1793   "@
1794    {sf.|subfc.} %3,%2,%1
1795    #"
1796   [(set_attr "type" "compare")
1797    (set_attr "length" "4,8")])
1798
1799 (define_insn ""
1800   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1801         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1802                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1803                     (const_int 0)))
1804    (clobber (match_scratch:P 3 "=r,r"))]
1805   "TARGET_POWERPC"
1806   "@
1807    subf. %3,%2,%1
1808    #"
1809   [(set_attr "type" "fast_compare")
1810    (set_attr "length" "4,8")])
1811
1812 (define_split
1813   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1814         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1815                              (match_operand:P 2 "gpc_reg_operand" ""))
1816                     (const_int 0)))
1817    (clobber (match_scratch:P 3 ""))]
1818   "reload_completed"
1819   [(set (match_dup 3)
1820         (minus:P (match_dup 1)
1821                   (match_dup 2)))
1822    (set (match_dup 0)
1823         (compare:CC (match_dup 3)
1824                     (const_int 0)))]
1825   "")
1826
1827 (define_insn ""
1828   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1829         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1830                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1831                     (const_int 0)))
1832    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1833         (minus:SI (match_dup 1) (match_dup 2)))]
1834   "! TARGET_POWERPC"
1835   "@
1836    {sf.|subfc.} %0,%2,%1
1837    #"
1838   [(set_attr "type" "compare")
1839    (set_attr "length" "4,8")])
1840
1841 (define_insn ""
1842   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1843         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1844                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1845                     (const_int 0)))
1846    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1847         (minus:P (match_dup 1)
1848                   (match_dup 2)))]
1849   "TARGET_POWERPC"
1850   "@
1851    subf. %0,%2,%1
1852    #"
1853   [(set_attr "type" "fast_compare")
1854    (set_attr "length" "4,8")])
1855
1856 (define_split
1857   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1858         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1859                              (match_operand:P 2 "gpc_reg_operand" ""))
1860                     (const_int 0)))
1861    (set (match_operand:P 0 "gpc_reg_operand" "")
1862         (minus:P (match_dup 1)
1863                   (match_dup 2)))]
1864   "reload_completed"
1865   [(set (match_dup 0)
1866         (minus:P (match_dup 1)
1867                   (match_dup 2)))
1868    (set (match_dup 3)
1869         (compare:CC (match_dup 0)
1870                     (const_int 0)))]
1871   "")
1872
1873 (define_expand "sub<mode>3"
1874   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1875         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1876                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1877   ""
1878   "
1879 {
1880   if (GET_CODE (operands[2]) == CONST_INT)
1881     {
1882       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1883                                  negate_rtx (<MODE>mode, operands[2])));
1884       DONE;
1885     }
1886 }")
1887
1888 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1889 ;; instruction and some auxiliary computations.  Then we just have a single
1890 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1891 ;; combine.
1892
1893 (define_expand "sminsi3"
1894   [(set (match_dup 3)
1895         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1896                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1897                          (const_int 0)
1898                          (minus:SI (match_dup 2) (match_dup 1))))
1899    (set (match_operand:SI 0 "gpc_reg_operand" "")
1900         (minus:SI (match_dup 2) (match_dup 3)))]
1901   "TARGET_POWER || TARGET_ISEL"
1902   "
1903 {
1904   if (TARGET_ISEL)
1905     {
1906       operands[2] = force_reg (SImode, operands[2]);
1907       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1908       DONE;
1909     }
1910
1911   operands[3] = gen_reg_rtx (SImode);
1912 }")
1913
1914 (define_split
1915   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1916         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1917                  (match_operand:SI 2 "reg_or_short_operand" "")))
1918    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1919   "TARGET_POWER"
1920   [(set (match_dup 3)
1921         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1922                          (const_int 0)
1923                          (minus:SI (match_dup 2) (match_dup 1))))
1924    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1925   "")
1926
1927 (define_expand "smaxsi3"
1928   [(set (match_dup 3)
1929         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1930                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1931                          (const_int 0)
1932                          (minus:SI (match_dup 2) (match_dup 1))))
1933    (set (match_operand:SI 0 "gpc_reg_operand" "")
1934         (plus:SI (match_dup 3) (match_dup 1)))]
1935   "TARGET_POWER || TARGET_ISEL"
1936   "
1937 {
1938   if (TARGET_ISEL)
1939     {
1940       operands[2] = force_reg (SImode, operands[2]);
1941       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1942       DONE;
1943     }
1944   operands[3] = gen_reg_rtx (SImode);
1945 }")
1946
1947 (define_split
1948   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1949         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1950                  (match_operand:SI 2 "reg_or_short_operand" "")))
1951    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1952   "TARGET_POWER"
1953   [(set (match_dup 3)
1954         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1955                          (const_int 0)
1956                          (minus:SI (match_dup 2) (match_dup 1))))
1957    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1958   "")
1959
1960 (define_expand "uminsi3"
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         (minus:SI (match_dup 2) (match_dup 3)))]
1970   "TARGET_POWER || TARGET_ISEL"
1971   "
1972 {
1973   if (TARGET_ISEL)
1974     {
1975       rs6000_emit_minmax (operands[0], UMIN, 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_expand "umaxsi3"
1984   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1985                               (match_dup 5)))
1986    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1987                               (match_dup 5)))
1988    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1989                                        (const_int 0)
1990                                        (minus:SI (match_dup 4) (match_dup 3))))
1991    (set (match_operand:SI 0 "gpc_reg_operand" "")
1992         (plus:SI (match_dup 3) (match_dup 1)))]
1993   "TARGET_POWER || TARGET_ISEL"
1994   "
1995 {
1996   if (TARGET_ISEL)
1997     {
1998       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1999       DONE;
2000     }
2001   operands[3] = gen_reg_rtx (SImode);
2002   operands[4] = gen_reg_rtx (SImode);
2003   operands[5] = GEN_INT (-2147483647 - 1);
2004 }")
2005
2006 (define_insn ""
2007   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2008         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
2009                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
2010                          (const_int 0)
2011                          (minus:SI (match_dup 2) (match_dup 1))))]
2012   "TARGET_POWER"
2013   "doz%I2 %0,%1,%2")
2014
2015 (define_insn ""
2016   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2017         (compare:CC
2018          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2019                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2020                           (const_int 0)
2021                           (minus:SI (match_dup 2) (match_dup 1)))
2022          (const_int 0)))
2023    (clobber (match_scratch:SI 3 "=r,r"))]
2024   "TARGET_POWER"
2025   "@
2026    doz%I2. %3,%1,%2
2027    #"
2028   [(set_attr "type" "delayed_compare")
2029    (set_attr "length" "4,8")])
2030
2031 (define_split
2032   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2033         (compare:CC
2034          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2035                               (match_operand:SI 2 "reg_or_short_operand" ""))
2036                           (const_int 0)
2037                           (minus:SI (match_dup 2) (match_dup 1)))
2038          (const_int 0)))
2039    (clobber (match_scratch:SI 3 ""))]
2040   "TARGET_POWER && reload_completed"
2041   [(set (match_dup 3)
2042         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2043                           (const_int 0)
2044                           (minus:SI (match_dup 2) (match_dup 1))))
2045    (set (match_dup 0)
2046         (compare:CC (match_dup 3)
2047                     (const_int 0)))]
2048   "")
2049
2050 (define_insn ""
2051   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2052         (compare:CC
2053          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2054                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2055                           (const_int 0)
2056                           (minus:SI (match_dup 2) (match_dup 1)))
2057          (const_int 0)))
2058    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2059         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2060                          (const_int 0)
2061                          (minus:SI (match_dup 2) (match_dup 1))))]
2062   "TARGET_POWER"
2063   "@
2064    doz%I2. %0,%1,%2
2065    #"
2066   [(set_attr "type" "delayed_compare")
2067    (set_attr "length" "4,8")])
2068
2069 (define_split
2070   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2071         (compare:CC
2072          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2073                               (match_operand:SI 2 "reg_or_short_operand" ""))
2074                           (const_int 0)
2075                           (minus:SI (match_dup 2) (match_dup 1)))
2076          (const_int 0)))
2077    (set (match_operand:SI 0 "gpc_reg_operand" "")
2078         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2079                          (const_int 0)
2080                          (minus:SI (match_dup 2) (match_dup 1))))]
2081   "TARGET_POWER && reload_completed"
2082   [(set (match_dup 0)
2083         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2084                          (const_int 0)
2085                          (minus:SI (match_dup 2) (match_dup 1))))
2086    (set (match_dup 3)
2087         (compare:CC (match_dup 0)
2088                     (const_int 0)))]
2089   "")
2090
2091 ;; We don't need abs with condition code because such comparisons should
2092 ;; never be done.
2093 (define_expand "abssi2"
2094   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2095         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2096   ""
2097   "
2098 {
2099   if (TARGET_ISEL)
2100     {
2101       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
2102       DONE;
2103     }
2104   else if (! TARGET_POWER)
2105     {
2106       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
2107       DONE;
2108     }
2109 }")
2110
2111 (define_insn "*abssi2_power"
2112   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2113         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2114   "TARGET_POWER"
2115   "abs %0,%1")
2116
2117 (define_insn_and_split "abs<mode>2_isel"
2118   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2119         (abs:GPR (match_operand:GPR 1 "gpc_reg_operand" "b")))
2120    (clobber (match_scratch:GPR 2 "=&b"))
2121    (clobber (match_scratch:CC 3 "=y"))]
2122   "TARGET_ISEL"
2123   "#"
2124   "&& reload_completed"
2125   [(set (match_dup 2) (neg:GPR (match_dup 1)))
2126    (set (match_dup 3)
2127         (compare:CC (match_dup 1)
2128                     (const_int 0)))
2129    (set (match_dup 0)
2130         (if_then_else:GPR (lt (match_dup 3)
2131                               (const_int 0))
2132                           (match_dup 2)
2133                           (match_dup 1)))]
2134   "")
2135
2136 (define_insn_and_split "nabs<mode>2_isel"
2137   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2138         (neg:GPR (abs:GPR (match_operand:GPR 1 "gpc_reg_operand" "b"))))
2139    (clobber (match_scratch:GPR 2 "=&b"))
2140    (clobber (match_scratch:CC 3 "=y"))]
2141   "TARGET_ISEL"
2142   "#"
2143   "&& reload_completed"
2144   [(set (match_dup 2) (neg:GPR (match_dup 1)))
2145    (set (match_dup 3)
2146         (compare:CC (match_dup 1)
2147                     (const_int 0)))
2148    (set (match_dup 0)
2149         (if_then_else:GPR (lt (match_dup 3)
2150                               (const_int 0))
2151                           (match_dup 1)
2152                           (match_dup 2)))]
2153   "")
2154
2155 (define_insn_and_split "abssi2_nopower"
2156   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2157         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2158    (clobber (match_scratch:SI 2 "=&r,&r"))]
2159   "! TARGET_POWER && ! TARGET_ISEL"
2160   "#"
2161   "&& reload_completed"
2162   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2163    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2164    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2165   "")
2166
2167 (define_insn "*nabs_power"
2168   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2169         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2170   "TARGET_POWER"
2171   "nabs %0,%1")
2172
2173 (define_insn_and_split "*nabs_nopower"
2174   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2175         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2176    (clobber (match_scratch:SI 2 "=&r,&r"))]
2177   "! TARGET_POWER"
2178   "#"
2179   "&& reload_completed"
2180   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2181    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2182    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2183   "")
2184
2185 (define_expand "neg<mode>2"
2186   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2187         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2188   ""
2189   "")
2190
2191 (define_insn "*neg<mode>2_internal"
2192   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2193         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2194   ""
2195   "neg %0,%1")
2196
2197 (define_insn ""
2198   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2199         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2200                     (const_int 0)))
2201    (clobber (match_scratch:P 2 "=r,r"))]
2202   ""
2203   "@
2204    neg. %2,%1
2205    #"
2206   [(set_attr "type" "fast_compare")
2207    (set_attr "length" "4,8")])
2208
2209 (define_split
2210   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2211         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2212                     (const_int 0)))
2213    (clobber (match_scratch:P 2 ""))]
2214   "reload_completed"
2215   [(set (match_dup 2)
2216         (neg:P (match_dup 1)))
2217    (set (match_dup 0)
2218         (compare:CC (match_dup 2)
2219                     (const_int 0)))]
2220   "")
2221
2222 (define_insn ""
2223   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2224         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2225                     (const_int 0)))
2226    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2227         (neg:P (match_dup 1)))]
2228   ""
2229   "@
2230    neg. %0,%1
2231    #"
2232   [(set_attr "type" "fast_compare")
2233    (set_attr "length" "4,8")])
2234
2235 (define_split
2236   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2237         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2238                     (const_int 0)))
2239    (set (match_operand:P 0 "gpc_reg_operand" "")
2240         (neg:P (match_dup 1)))]
2241   "reload_completed"
2242   [(set (match_dup 0)
2243         (neg:P (match_dup 1)))
2244    (set (match_dup 2)
2245         (compare:CC (match_dup 0)
2246                     (const_int 0)))]
2247   "")
2248
2249 (define_insn "clz<mode>2"
2250   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2251         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2252   ""
2253   "{cntlz|cntlz<wd>} %0,%1"
2254   [(set_attr "type" "cntlz")])
2255
2256 (define_expand "ctz<mode>2"
2257   [(set (match_dup 2)
2258         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2259    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2260                                           (match_dup 2)))
2261               (clobber (scratch:CC))])
2262    (set (match_dup 4) (clz:GPR (match_dup 3)))
2263    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2264         (minus:GPR (match_dup 5) (match_dup 4)))]
2265   ""
2266   {
2267      operands[2] = gen_reg_rtx (<MODE>mode);
2268      operands[3] = gen_reg_rtx (<MODE>mode);
2269      operands[4] = gen_reg_rtx (<MODE>mode);
2270      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2271   })
2272
2273 (define_expand "ffs<mode>2"
2274   [(set (match_dup 2)
2275         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2276    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2277                                           (match_dup 2)))
2278               (clobber (scratch:CC))])
2279    (set (match_dup 4) (clz:GPR (match_dup 3)))
2280    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2281         (minus:GPR (match_dup 5) (match_dup 4)))]
2282   ""
2283   {
2284      operands[2] = gen_reg_rtx (<MODE>mode);
2285      operands[3] = gen_reg_rtx (<MODE>mode);
2286      operands[4] = gen_reg_rtx (<MODE>mode);
2287      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2288   })
2289
2290 (define_insn "popcntb<mode>2"
2291   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2292         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2293                      UNSPEC_POPCNTB))]
2294   "TARGET_POPCNTB"
2295   "popcntb %0,%1")
2296
2297 (define_insn "popcntd<mode>2"
2298   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2299         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2300   "TARGET_POPCNTD"
2301   "popcnt<wd> %0,%1")
2302
2303 (define_expand "popcount<mode>2"
2304   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2305         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2306   "TARGET_POPCNTB || TARGET_POPCNTD"
2307   {
2308     rs6000_emit_popcount (operands[0], operands[1]);
2309     DONE;
2310   })
2311
2312 (define_insn "parity<mode>2_cmpb"
2313   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2314         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
2315   "TARGET_CMPB && TARGET_POPCNTB"
2316   "prty<wd> %0,%1")
2317
2318 (define_expand "parity<mode>2"
2319   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2320         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2321   "TARGET_POPCNTB"
2322   {
2323     rs6000_emit_parity (operands[0], operands[1]);
2324     DONE;
2325   })
2326
2327 ;; Since the hardware zeros the upper part of the register, save generating the
2328 ;; AND immediate if we are converting to unsigned
2329 (define_insn "*bswaphi2_extenddi"
2330   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2331         (zero_extend:DI
2332          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2333   "TARGET_POWERPC64"
2334   "lhbrx %0,%y1"
2335   [(set_attr "length" "4")
2336    (set_attr "type" "load")])
2337
2338 (define_insn "*bswaphi2_extendsi"
2339   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2340         (zero_extend:SI
2341          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2342   "TARGET_POWERPC"
2343   "lhbrx %0,%y1"
2344   [(set_attr "length" "4")
2345    (set_attr "type" "load")])
2346
2347 (define_expand "bswaphi2"
2348   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
2349                    (bswap:HI
2350                     (match_operand:HI 1 "reg_or_mem_operand" "")))
2351               (clobber (match_scratch:SI 2 ""))])]
2352   ""
2353 {
2354   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2355     operands[1] = force_reg (HImode, operands[1]);
2356 })
2357
2358 (define_insn "bswaphi2_internal"
2359   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
2360         (bswap:HI
2361          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
2362    (clobber (match_scratch:SI 2 "=X,X,&r"))]
2363   "TARGET_POWERPC"
2364   "@
2365    lhbrx %0,%y1
2366    sthbrx %1,%y0
2367    #"
2368   [(set_attr "length" "4,4,12")
2369    (set_attr "type" "load,store,*")])
2370
2371 (define_split
2372   [(set (match_operand:HI 0 "gpc_reg_operand" "")
2373         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
2374    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2375   "TARGET_POWERPC && reload_completed"
2376   [(set (match_dup 3)
2377         (zero_extract:SI (match_dup 4)
2378                          (const_int 8)
2379                          (const_int 16)))
2380    (set (match_dup 2)
2381         (and:SI (ashift:SI (match_dup 4)
2382                            (const_int 8))
2383                 (const_int 65280)))             ;; 0xff00
2384    (set (match_dup 3)
2385         (ior:SI (match_dup 3)
2386                 (match_dup 2)))]
2387   "
2388 {
2389   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2390   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2391 }")
2392
2393 (define_insn "*bswapsi2_extenddi"
2394   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2395         (zero_extend:DI
2396          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2397   "TARGET_POWERPC64"
2398   "lwbrx %0,%y1"
2399   [(set_attr "length" "4")
2400    (set_attr "type" "load")])
2401
2402 (define_expand "bswapsi2"
2403   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2404         (bswap:SI
2405          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2406   ""
2407 {
2408   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2409     operands[1] = force_reg (SImode, operands[1]);
2410 })
2411
2412 (define_insn "*bswapsi2_internal"
2413   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2414         (bswap:SI
2415          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2416   ""
2417   "@
2418    {lbrx|lwbrx} %0,%y1
2419    {stbrx|stwbrx} %1,%y0
2420    #"
2421   [(set_attr "length" "4,4,12")
2422    (set_attr "type" "load,store,*")])
2423
2424 (define_split
2425   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2426         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2427   "reload_completed"
2428   [(set (match_dup 0)
2429         (rotate:SI (match_dup 1) (const_int 8)))
2430    (set (zero_extract:SI (match_dup 0)
2431                          (const_int 8)
2432                          (const_int 0))
2433         (match_dup 1))
2434    (set (zero_extract:SI (match_dup 0)
2435                          (const_int 8)
2436                          (const_int 16))
2437         (rotate:SI (match_dup 1)
2438                    (const_int 16)))]
2439   "")
2440
2441 (define_expand "bswapdi2"
2442   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2443                    (bswap:DI
2444                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2445               (clobber (match_scratch:DI 2 ""))
2446               (clobber (match_scratch:DI 3 ""))
2447               (clobber (match_scratch:DI 4 ""))])]
2448   ""
2449 {
2450   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2451     operands[1] = force_reg (DImode, operands[1]);
2452
2453   if (!TARGET_POWERPC64)
2454     {
2455       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2456          that uses 64-bit registers needs the same scratch registers as 64-bit
2457          mode.  */
2458       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2459       DONE;
2460     }
2461 })
2462
2463 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2464 (define_insn "*bswapdi2_ldbrx"
2465   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2466         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2467    (clobber (match_scratch:DI 2 "=X,X,&r"))
2468    (clobber (match_scratch:DI 3 "=X,X,&r"))
2469    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2470   "TARGET_POWERPC64 && TARGET_LDBRX
2471    && (REG_P (operands[0]) || REG_P (operands[1]))"
2472   "@
2473    ldbrx %0,%y1
2474    stdbrx %1,%y0
2475    #"
2476   [(set_attr "length" "4,4,36")
2477    (set_attr "type" "load,store,*")])
2478
2479 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2480 (define_insn "*bswapdi2_64bit"
2481   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2482         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2483    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2484    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2485    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2486   "TARGET_POWERPC64 && !TARGET_LDBRX
2487    && (REG_P (operands[0]) || REG_P (operands[1]))"
2488   "#"
2489   [(set_attr "length" "16,12,36")])
2490
2491 (define_split
2492   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2493         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2494    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2495    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2496    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2497   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2498   [(const_int 0)]
2499   "
2500 {
2501   rtx dest   = operands[0];
2502   rtx src    = operands[1];
2503   rtx op2    = operands[2];
2504   rtx op3    = operands[3];
2505   rtx op4    = operands[4];
2506   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode, 4);
2507   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode, 4);
2508   rtx addr1;
2509   rtx addr2;
2510   rtx word_high;
2511   rtx word_low;
2512
2513   addr1 = XEXP (src, 0);
2514   if (GET_CODE (addr1) == PLUS)
2515     {
2516       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2517       addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2518     }
2519   else
2520     {
2521       emit_move_insn (op2, GEN_INT (4));
2522       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2523     }
2524
2525   if (BYTES_BIG_ENDIAN)
2526     {
2527       word_high = change_address (src, SImode, addr1);
2528       word_low  = change_address (src, SImode, addr2);
2529     }
2530   else
2531     {
2532       word_high = change_address (src, SImode, addr2);
2533       word_low  = change_address (src, SImode, addr1);
2534     }
2535
2536   emit_insn (gen_bswapsi2 (op3_32, word_low));
2537   emit_insn (gen_bswapsi2 (op4_32, word_high));
2538   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2539   emit_insn (gen_iordi3 (dest, dest, op4));
2540 }")
2541
2542 (define_split
2543   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2544         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2545    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2546    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2547    (clobber (match_operand:DI 4 "" ""))]
2548   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2549   [(const_int 0)]
2550   "
2551 {
2552   rtx dest   = operands[0];
2553   rtx src    = operands[1];
2554   rtx op2    = operands[2];
2555   rtx op3    = operands[3];
2556   rtx src_si = simplify_gen_subreg (SImode, src, DImode, 4);
2557   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode, 4);
2558   rtx addr1;
2559   rtx addr2;
2560   rtx word_high;
2561   rtx word_low;
2562
2563   addr1 = XEXP (dest, 0);
2564   if (GET_CODE (addr1) == PLUS)
2565     {
2566       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2567       addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2568     }
2569   else
2570     {
2571       emit_move_insn (op2, GEN_INT (4));
2572       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2573     }
2574
2575   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2576   if (BYTES_BIG_ENDIAN)
2577     {
2578       word_high = change_address (dest, SImode, addr1);
2579       word_low  = change_address (dest, SImode, addr2);
2580       emit_insn (gen_bswapsi2 (word_high, src_si));
2581       emit_insn (gen_bswapsi2 (word_low, op3_si));
2582     }
2583   else
2584     {
2585       word_high = change_address (dest, SImode, addr2);
2586       word_low  = change_address (dest, SImode, addr1);
2587       emit_insn (gen_bswapsi2 (word_low, src_si));
2588       emit_insn (gen_bswapsi2 (word_high, op3_si));
2589     }
2590 }")
2591
2592 (define_split
2593   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2594         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2595    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2596    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2597    (clobber (match_operand:DI 4 "" ""))]
2598   "TARGET_POWERPC64 && reload_completed"
2599   [(const_int 0)]
2600   "
2601 {
2602   rtx dest    = operands[0];
2603   rtx src     = operands[1];
2604   rtx op2     = operands[2];
2605   rtx op3     = operands[3];
2606   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, 4);
2607   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, 4);
2608   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, 4);
2609   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, 4);
2610
2611   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2612   emit_insn (gen_bswapsi2 (dest_si, src_si));
2613   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2614   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2615   emit_insn (gen_iordi3 (dest, dest, op3));
2616 }")
2617
2618 (define_insn "bswapdi2_32bit"
2619   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2620         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2621    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2622   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2623   "#"
2624   [(set_attr "length" "16,12,36")])
2625
2626 (define_split
2627   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2628         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2629    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2630   "!TARGET_POWERPC64 && reload_completed"
2631   [(const_int 0)]
2632   "
2633 {
2634   rtx dest   = operands[0];
2635   rtx src    = operands[1];
2636   rtx op2    = operands[2];
2637   rtx dest_hi = simplify_gen_subreg (SImode, dest, DImode, 0);
2638   rtx dest_lo = simplify_gen_subreg (SImode, dest, DImode, 4);
2639   rtx addr1;
2640   rtx addr2;
2641   rtx word_high;
2642   rtx word_low;
2643
2644   addr1 = XEXP (src, 0);
2645   if (GET_CODE (addr1) == PLUS)
2646     {
2647       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2648       addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2649     }
2650   else
2651     {
2652       emit_move_insn (op2, GEN_INT (4));
2653       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2654     }
2655
2656   if (BYTES_BIG_ENDIAN)
2657     {
2658       word_high = change_address (src, SImode, addr1);
2659       word_low  = change_address (src, SImode, addr2);
2660     }
2661   else
2662     {
2663       word_high = change_address (src, SImode, addr2);
2664       word_low  = change_address (src, SImode, addr1);
2665     }
2666
2667   emit_insn (gen_bswapsi2 (dest_hi, word_low));
2668   emit_insn (gen_bswapsi2 (dest_lo, word_high));
2669 }")
2670
2671 (define_split
2672   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2673         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2674    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2675   "!TARGET_POWERPC64 && reload_completed"
2676   [(const_int 0)]
2677   "
2678 {
2679   rtx dest     = operands[0];
2680   rtx src      = operands[1];
2681   rtx op2      = operands[2];
2682   rtx src_high = simplify_gen_subreg (SImode, src, DImode, 0);
2683   rtx src_low  = simplify_gen_subreg (SImode, src, DImode, 4);
2684   rtx addr1;
2685   rtx addr2;
2686   rtx word_high;
2687   rtx word_low;
2688
2689   addr1 = XEXP (dest, 0);
2690   if (GET_CODE (addr1) == PLUS)
2691     {
2692       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2693       addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2694     }
2695   else
2696     {
2697       emit_move_insn (op2, GEN_INT (4));
2698       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2699     }
2700
2701   if (BYTES_BIG_ENDIAN)
2702     {
2703       word_high = change_address (dest, SImode, addr1);
2704       word_low  = change_address (dest, SImode, addr2);
2705     }
2706   else
2707     {
2708       word_high = change_address (dest, SImode, addr2);
2709       word_low  = change_address (dest, SImode, addr1);
2710     }
2711
2712   emit_insn (gen_bswapsi2 (word_high, src_low));
2713   emit_insn (gen_bswapsi2 (word_low, src_high));
2714 }")
2715
2716 (define_split
2717   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2718         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2719    (clobber (match_operand:SI 2 "" ""))]
2720   "!TARGET_POWERPC64 && reload_completed"
2721   [(const_int 0)]
2722   "
2723 {
2724   rtx dest      = operands[0];
2725   rtx src       = operands[1];
2726   rtx src_high  = simplify_gen_subreg (SImode, src, DImode, 0);
2727   rtx src_low   = simplify_gen_subreg (SImode, src, DImode, 4);
2728   rtx dest_high = simplify_gen_subreg (SImode, dest, DImode, 0);
2729   rtx dest_low  = simplify_gen_subreg (SImode, dest, DImode, 4);
2730
2731   emit_insn (gen_bswapsi2 (dest_high, src_low));
2732   emit_insn (gen_bswapsi2 (dest_low, src_high));
2733 }")
2734
2735 (define_expand "mulsi3"
2736   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2737    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2738    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2739   ""
2740   "
2741 {
2742   if (TARGET_POWER)
2743     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2744   else
2745     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2746   DONE;
2747 }")
2748
2749 (define_insn "mulsi3_mq"
2750   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2751         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2752                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2753    (clobber (match_scratch:SI 3 "=q,q"))]
2754   "TARGET_POWER"
2755   "@
2756    {muls|mullw} %0,%1,%2
2757    {muli|mulli} %0,%1,%2"
2758    [(set (attr "type")
2759       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2760                 (const_string "imul3")
2761              (match_operand:SI 2 "short_cint_operand" "")
2762                 (const_string "imul2")]
2763         (const_string "imul")))])
2764
2765 (define_insn "mulsi3_no_mq"
2766   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2767         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2768                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2769   "! TARGET_POWER"
2770   "@
2771    {muls|mullw} %0,%1,%2
2772    {muli|mulli} %0,%1,%2"
2773    [(set (attr "type")
2774       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2775                 (const_string "imul3")
2776              (match_operand:SI 2 "short_cint_operand" "")
2777                 (const_string "imul2")]
2778         (const_string "imul")))])
2779
2780 (define_insn "*mulsi3_mq_internal1"
2781   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2782         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2783                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2784                     (const_int 0)))
2785    (clobber (match_scratch:SI 3 "=r,r"))
2786    (clobber (match_scratch:SI 4 "=q,q"))]
2787   "TARGET_POWER"
2788   "@
2789    {muls.|mullw.} %3,%1,%2
2790    #"
2791   [(set_attr "type" "imul_compare")
2792    (set_attr "length" "4,8")])
2793
2794 (define_split
2795   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2796         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2797                              (match_operand:SI 2 "gpc_reg_operand" ""))
2798                     (const_int 0)))
2799    (clobber (match_scratch:SI 3 ""))
2800    (clobber (match_scratch:SI 4 ""))]
2801   "TARGET_POWER && reload_completed"
2802   [(parallel [(set (match_dup 3)
2803         (mult:SI (match_dup 1) (match_dup 2)))
2804    (clobber (match_dup 4))])
2805    (set (match_dup 0)
2806         (compare:CC (match_dup 3)
2807                     (const_int 0)))]
2808   "")
2809
2810 (define_insn "*mulsi3_no_mq_internal1"
2811   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2812         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2813                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2814                     (const_int 0)))
2815    (clobber (match_scratch:SI 3 "=r,r"))]
2816   "! TARGET_POWER"
2817   "@
2818    {muls.|mullw.} %3,%1,%2
2819    #"
2820   [(set_attr "type" "imul_compare")
2821    (set_attr "length" "4,8")])
2822
2823 (define_split
2824   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2825         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2826                              (match_operand:SI 2 "gpc_reg_operand" ""))
2827                     (const_int 0)))
2828    (clobber (match_scratch:SI 3 ""))]
2829   "! TARGET_POWER && reload_completed"
2830   [(set (match_dup 3)
2831         (mult:SI (match_dup 1) (match_dup 2)))
2832    (set (match_dup 0)
2833         (compare:CC (match_dup 3)
2834                     (const_int 0)))]
2835   "")
2836
2837 (define_insn "*mulsi3_mq_internal2"
2838   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2839         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2840                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2841                     (const_int 0)))
2842    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2843         (mult:SI (match_dup 1) (match_dup 2)))
2844    (clobber (match_scratch:SI 4 "=q,q"))]
2845   "TARGET_POWER"
2846   "@
2847    {muls.|mullw.} %0,%1,%2
2848    #"
2849   [(set_attr "type" "imul_compare")
2850    (set_attr "length" "4,8")])
2851
2852 (define_split
2853   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2854         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2855                              (match_operand:SI 2 "gpc_reg_operand" ""))
2856                     (const_int 0)))
2857    (set (match_operand:SI 0 "gpc_reg_operand" "")
2858         (mult:SI (match_dup 1) (match_dup 2)))
2859    (clobber (match_scratch:SI 4 ""))]
2860   "TARGET_POWER && reload_completed"
2861   [(parallel [(set (match_dup 0)
2862         (mult:SI (match_dup 1) (match_dup 2)))
2863    (clobber (match_dup 4))])
2864    (set (match_dup 3)
2865         (compare:CC (match_dup 0)
2866                     (const_int 0)))]
2867   "")
2868
2869 (define_insn "*mulsi3_no_mq_internal2"
2870   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2871         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2872                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2873                     (const_int 0)))
2874    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2875         (mult:SI (match_dup 1) (match_dup 2)))]
2876   "! TARGET_POWER"
2877   "@
2878    {muls.|mullw.} %0,%1,%2
2879    #"
2880   [(set_attr "type" "imul_compare")
2881    (set_attr "length" "4,8")])
2882
2883 (define_split
2884   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2885         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2886                              (match_operand:SI 2 "gpc_reg_operand" ""))
2887                     (const_int 0)))
2888    (set (match_operand:SI 0 "gpc_reg_operand" "")
2889         (mult:SI (match_dup 1) (match_dup 2)))]
2890   "! TARGET_POWER && reload_completed"
2891   [(set (match_dup 0)
2892         (mult:SI (match_dup 1) (match_dup 2)))
2893    (set (match_dup 3)
2894         (compare:CC (match_dup 0)
2895                     (const_int 0)))]
2896   "")
2897
2898 ;; Operand 1 is divided by operand 2; quotient goes to operand
2899 ;; 0 and remainder to operand 3.
2900 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2901
2902 (define_expand "divmodsi4"
2903   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2904                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2905                            (match_operand:SI 2 "gpc_reg_operand" "")))
2906               (set (match_operand:SI 3 "register_operand" "")
2907                    (mod:SI (match_dup 1) (match_dup 2)))])]
2908   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2909   "
2910 {
2911   if (! TARGET_POWER && ! TARGET_POWERPC)
2912     {
2913       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2914       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2915       emit_insn (gen_divss_call ());
2916       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2917       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2918       DONE;
2919     }
2920 }")
2921
2922 (define_insn "*divmodsi4_internal"
2923   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2924         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2925                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2926    (set (match_operand:SI 3 "register_operand" "=q")
2927         (mod:SI (match_dup 1) (match_dup 2)))]
2928   "TARGET_POWER"
2929   "divs %0,%1,%2"
2930   [(set_attr "type" "idiv")])
2931
2932 (define_expand "udiv<mode>3"
2933   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2934         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2935                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2936   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2937   "
2938 {
2939   if (! TARGET_POWER && ! TARGET_POWERPC)
2940     {
2941       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2942       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2943       emit_insn (gen_quous_call ());
2944       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2945       DONE;
2946     }
2947   else if (TARGET_POWER)
2948     {
2949       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2950       DONE;
2951     }
2952 }")
2953
2954 (define_insn "udivsi3_mq"
2955   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2956         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2957                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2958    (clobber (match_scratch:SI 3 "=q"))]
2959   "TARGET_POWERPC && TARGET_POWER"
2960   "divwu %0,%1,%2"
2961   [(set_attr "type" "idiv")])
2962
2963 (define_insn "*udivsi3_no_mq"
2964   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2965         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2966                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2967   "TARGET_POWERPC && ! TARGET_POWER"
2968   "div<wd>u %0,%1,%2"
2969    [(set (attr "type")
2970       (cond [(match_operand:SI 0 "" "")
2971                 (const_string "idiv")]
2972         (const_string "ldiv")))])
2973
2974
2975 ;; For powers of two we can do srai/aze for divide and then adjust for
2976 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2977 ;; used; for PowerPC, force operands into register and do a normal divide;
2978 ;; for AIX common-mode, use quoss call on register operands.
2979 (define_expand "div<mode>3"
2980   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2981         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2982                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2983   ""
2984   "
2985 {
2986   if (GET_CODE (operands[2]) == CONST_INT
2987       && INTVAL (operands[2]) > 0
2988       && exact_log2 (INTVAL (operands[2])) >= 0)
2989     ;
2990   else if (TARGET_POWERPC)
2991     {
2992       operands[2] = force_reg (<MODE>mode, operands[2]);
2993       if (TARGET_POWER)
2994         {
2995           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2996           DONE;
2997         }
2998     }
2999   else if (TARGET_POWER)
3000     FAIL;
3001   else
3002     {
3003       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
3004       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
3005       emit_insn (gen_quoss_call ());
3006       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
3007       DONE;
3008     }
3009 }")
3010
3011 (define_insn "divsi3_mq"
3012   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3013         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3014                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3015    (clobber (match_scratch:SI 3 "=q"))]
3016   "TARGET_POWERPC && TARGET_POWER"
3017   "divw %0,%1,%2"
3018   [(set_attr "type" "idiv")])
3019
3020 (define_insn "*div<mode>3_no_mq"
3021   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3022         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3023                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
3024   "TARGET_POWERPC && ! TARGET_POWER"
3025   "div<wd> %0,%1,%2"
3026   [(set (attr "type")
3027      (cond [(match_operand:SI 0 "" "")
3028                 (const_string "idiv")]
3029         (const_string "ldiv")))])
3030
3031 (define_expand "mod<mode>3"
3032   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
3033    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
3034    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
3035   ""
3036   "
3037 {
3038   int i;
3039   rtx temp1;
3040   rtx temp2;
3041
3042   if (GET_CODE (operands[2]) != CONST_INT
3043       || INTVAL (operands[2]) <= 0
3044       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
3045     FAIL;
3046
3047   temp1 = gen_reg_rtx (<MODE>mode);
3048   temp2 = gen_reg_rtx (<MODE>mode);
3049
3050   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
3051   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
3052   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
3053   DONE;
3054 }")
3055
3056 (define_insn ""
3057   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3058         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3059                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
3060   ""
3061   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
3062   [(set_attr "type" "two")
3063    (set_attr "length" "8")])
3064
3065 (define_insn ""
3066   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3067         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
3068                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
3069                     (const_int 0)))
3070    (clobber (match_scratch:P 3 "=r,r"))]
3071   ""
3072   "@
3073    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
3074    #"
3075   [(set_attr "type" "compare")
3076    (set_attr "length" "8,12")
3077    (set_attr "cell_micro" "not")])
3078
3079 (define_split
3080   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3081         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3082                              (match_operand:GPR 2 "exact_log2_cint_operand"
3083                               ""))
3084                     (const_int 0)))
3085    (clobber (match_scratch:GPR 3 ""))]
3086   "reload_completed"
3087   [(set (match_dup 3)
3088         (div:<MODE> (match_dup 1) (match_dup 2)))
3089    (set (match_dup 0)
3090         (compare:CC (match_dup 3)
3091                     (const_int 0)))]
3092   "")
3093
3094 (define_insn ""
3095   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3096         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
3097                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
3098                     (const_int 0)))
3099    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
3100         (div:P (match_dup 1) (match_dup 2)))]
3101   ""
3102   "@
3103    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
3104    #"
3105   [(set_attr "type" "compare")
3106    (set_attr "length" "8,12")
3107    (set_attr "cell_micro" "not")])
3108
3109 (define_split
3110   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3111         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3112                              (match_operand:GPR 2 "exact_log2_cint_operand"
3113                               ""))
3114                     (const_int 0)))
3115    (set (match_operand:GPR 0 "gpc_reg_operand" "")
3116         (div:GPR (match_dup 1) (match_dup 2)))]
3117   "reload_completed"
3118   [(set (match_dup 0)
3119         (div:<MODE> (match_dup 1) (match_dup 2)))
3120    (set (match_dup 3)
3121         (compare:CC (match_dup 0)
3122                     (const_int 0)))]
3123   "")
3124
3125 (define_insn ""
3126   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3127         (udiv:SI
3128          (plus:DI (ashift:DI
3129                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
3130                    (const_int 32))
3131                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
3132          (match_operand:SI 3 "gpc_reg_operand" "r")))
3133    (set (match_operand:SI 2 "register_operand" "=*q")
3134         (umod:SI
3135          (plus:DI (ashift:DI
3136                    (zero_extend:DI (match_dup 1)) (const_int 32))
3137                   (zero_extend:DI (match_dup 4)))
3138          (match_dup 3)))]
3139   "TARGET_POWER"
3140   "div %0,%1,%3"
3141   [(set_attr "type" "idiv")])
3142
3143 ;; To do unsigned divide we handle the cases of the divisor looking like a
3144 ;; negative number.  If it is a constant that is less than 2**31, we don't
3145 ;; have to worry about the branches.  So make a few subroutines here.
3146 ;;
3147 ;; First comes the normal case.
3148 (define_expand "udivmodsi4_normal"
3149   [(set (match_dup 4) (const_int 0))
3150    (parallel [(set (match_operand:SI 0 "" "")
3151                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
3152                                                 (const_int 32))
3153                                      (zero_extend:DI (match_operand:SI 1 "" "")))
3154                             (match_operand:SI 2 "" "")))
3155               (set (match_operand:SI 3 "" "")
3156                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
3157                                                 (const_int 32))
3158                                      (zero_extend:DI (match_dup 1)))
3159                             (match_dup 2)))])]
3160   "TARGET_POWER"
3161   "
3162 { operands[4] = gen_reg_rtx (SImode); }")
3163
3164 ;; This handles the branches.
3165 (define_expand "udivmodsi4_tests"
3166   [(set (match_operand:SI 0 "" "") (const_int 0))
3167    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
3168    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
3169    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
3170                            (label_ref (match_operand:SI 4 "" "")) (pc)))
3171    (set (match_dup 0) (const_int 1))
3172    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
3173    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
3174    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
3175                            (label_ref (match_dup 4)) (pc)))]
3176   "TARGET_POWER"
3177   "
3178 { operands[5] = gen_reg_rtx (CCUNSmode);
3179   operands[6] = gen_reg_rtx (CCmode);
3180 }")
3181
3182 (define_expand "udivmodsi4"
3183   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
3184                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
3185                             (match_operand:SI 2 "reg_or_cint_operand" "")))
3186               (set (match_operand:SI 3 "gpc_reg_operand" "")
3187                    (umod:SI (match_dup 1) (match_dup 2)))])]
3188   ""
3189   "
3190 {
3191   rtx label = 0;
3192
3193   if (! TARGET_POWER)
3194     {
3195       if (! TARGET_POWERPC)
3196         {
3197           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
3198           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
3199           emit_insn (gen_divus_call ());
3200           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
3201           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
3202           DONE;
3203         }
3204       else
3205         FAIL;
3206     }
3207
3208   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
3209     {
3210       operands[2] = force_reg (SImode, operands[2]);
3211       label = gen_label_rtx ();
3212       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
3213                                   operands[3], label));
3214     }
3215   else
3216     operands[2] = force_reg (SImode, operands[2]);
3217
3218   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
3219                                operands[3]));
3220   if (label)
3221     emit_label (label);
3222
3223   DONE;
3224 }")
3225
3226 ;; AIX architecture-independent common-mode multiply (DImode),
3227 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
3228 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
3229 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
3230 ;; assumed unused if generating common-mode, so ignore.
3231 (define_insn "mulh_call"
3232   [(set (reg:SI 3)
3233         (truncate:SI
3234          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
3235                                (sign_extend:DI (reg:SI 4)))
3236                       (const_int 32))))
3237    (clobber (reg:SI LR_REGNO))]
3238   "! TARGET_POWER && ! TARGET_POWERPC"
3239   "bla __mulh"
3240   [(set_attr "type" "imul")])
3241
3242 (define_insn "mull_call"
3243   [(set (reg:DI 3)
3244         (mult:DI (sign_extend:DI (reg:SI 3))
3245                  (sign_extend:DI (reg:SI 4))))
3246    (clobber (reg:SI LR_REGNO))
3247    (clobber (reg:SI 0))]
3248   "! TARGET_POWER && ! TARGET_POWERPC"
3249   "bla __mull"
3250   [(set_attr "type" "imul")])
3251
3252 (define_insn "divss_call"
3253   [(set (reg:SI 3)
3254         (div:SI (reg:SI 3) (reg:SI 4)))
3255    (set (reg:SI 4)
3256         (mod:SI (reg:SI 3) (reg:SI 4)))
3257    (clobber (reg:SI LR_REGNO))
3258    (clobber (reg:SI 0))]
3259   "! TARGET_POWER && ! TARGET_POWERPC"
3260   "bla __divss"
3261   [(set_attr "type" "idiv")])
3262
3263 (define_insn "divus_call"
3264   [(set (reg:SI 3)
3265         (udiv:SI (reg:SI 3) (reg:SI 4)))
3266    (set (reg:SI 4)
3267         (umod:SI (reg:SI 3) (reg:SI 4)))
3268    (clobber (reg:SI LR_REGNO))
3269    (clobber (reg:SI 0))
3270    (clobber (match_scratch:CC 0 "=x"))
3271    (clobber (reg:CC CR1_REGNO))]
3272   "! TARGET_POWER && ! TARGET_POWERPC"
3273   "bla __divus"
3274   [(set_attr "type" "idiv")])
3275
3276 (define_insn "quoss_call"
3277   [(set (reg:SI 3)
3278         (div:SI (reg:SI 3) (reg:SI 4)))
3279    (clobber (reg:SI LR_REGNO))]
3280   "! TARGET_POWER && ! TARGET_POWERPC"
3281   "bla __quoss"
3282   [(set_attr "type" "idiv")])
3283
3284 (define_insn "quous_call"
3285   [(set (reg:SI 3)
3286         (udiv:SI (reg:SI 3) (reg:SI 4)))
3287    (clobber (reg:SI LR_REGNO))
3288    (clobber (reg:SI 0))
3289    (clobber (match_scratch:CC 0 "=x"))
3290    (clobber (reg:CC CR1_REGNO))]
3291   "! TARGET_POWER && ! TARGET_POWERPC"
3292   "bla __quous"
3293   [(set_attr "type" "idiv")])
3294 \f
3295 ;; Logical instructions
3296 ;; The logical instructions are mostly combined by using match_operator,
3297 ;; but the plain AND insns are somewhat different because there is no
3298 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
3299 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
3300
3301 (define_expand "andsi3"
3302   [(parallel
3303     [(set (match_operand:SI 0 "gpc_reg_operand" "")
3304           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3305                   (match_operand:SI 2 "and_operand" "")))
3306      (clobber (match_scratch:CC 3 ""))])]
3307   ""
3308   "")
3309
3310 (define_insn "andsi3_mc"
3311   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3312         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
3313                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
3314    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
3315   "rs6000_gen_cell_microcode"
3316   "@
3317    and %0,%1,%2
3318    {rlinm|rlwinm} %0,%1,0,%m2,%M2
3319    {andil.|andi.} %0,%1,%b2
3320    {andiu.|andis.} %0,%1,%u2"
3321   [(set_attr "type" "*,*,fast_compare,fast_compare")])
3322
3323 (define_insn "andsi3_nomc"
3324   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3325         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
3326                 (match_operand:SI 2 "and_operand" "?r,T")))
3327    (clobber (match_scratch:CC 3 "=X,X"))]
3328   "!rs6000_gen_cell_microcode"
3329   "@
3330    and %0,%1,%2
3331    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
3332
3333 (define_insn "andsi3_internal0_nomc"
3334   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3335         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
3336                 (match_operand:SI 2 "and_operand" "?r,T")))]
3337   "!rs6000_gen_cell_microcode"
3338   "@
3339    and %0,%1,%2
3340    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
3341
3342
3343 ;; Note to set cr's other than cr0 we do the and immediate and then
3344 ;; the test again -- this avoids a mfcr which on the higher end
3345 ;; machines causes an execution serialization
3346
3347 (define_insn "*andsi3_internal2_mc"
3348   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3349         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3350                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3351                     (const_int 0)))
3352    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
3353    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3354   "TARGET_32BIT && rs6000_gen_cell_microcode"
3355   "@
3356    and. %3,%1,%2
3357    {andil.|andi.} %3,%1,%b2
3358    {andiu.|andis.} %3,%1,%u2
3359    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
3360    #
3361    #
3362    #
3363    #"
3364   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
3365                      compare,compare,compare,compare")
3366    (set_attr "length" "4,4,4,4,8,8,8,8")])
3367
3368 (define_insn "*andsi3_internal3_mc"
3369   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3370         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3371                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3372                     (const_int 0)))
3373    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
3374    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3375   "TARGET_64BIT && rs6000_gen_cell_microcode"
3376   "@
3377    #
3378    {andil.|andi.} %3,%1,%b2
3379    {andiu.|andis.} %3,%1,%u2
3380    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
3381    #
3382    #
3383    #
3384    #"
3385   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
3386                      compare,compare,compare")
3387    (set_attr "length" "8,4,4,4,8,8,8,8")])
3388
3389 (define_split
3390   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3391         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3392                              (match_operand:GPR 2 "and_operand" ""))
3393                     (const_int 0)))
3394    (clobber (match_scratch:GPR 3 ""))
3395    (clobber (match_scratch:CC 4 ""))]
3396   "reload_completed"
3397   [(parallel [(set (match_dup 3)
3398                    (and:<MODE> (match_dup 1)
3399                                (match_dup 2)))
3400               (clobber (match_dup 4))])
3401    (set (match_dup 0)
3402         (compare:CC (match_dup 3)
3403                     (const_int 0)))]
3404   "")
3405
3406 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
3407 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
3408
3409 (define_split
3410   [(set (match_operand:CC 0 "cc_reg_operand" "")
3411         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3412                             (match_operand:SI 2 "gpc_reg_operand" ""))
3413                     (const_int 0)))
3414    (clobber (match_scratch:SI 3 ""))
3415    (clobber (match_scratch:CC 4 ""))]
3416   "TARGET_POWERPC64 && reload_completed"
3417   [(parallel [(set (match_dup 3)
3418                    (and:SI (match_dup 1)
3419                            (match_dup 2)))
3420               (clobber (match_dup 4))])
3421    (set (match_dup 0)
3422         (compare:CC (match_dup 3)
3423                     (const_int 0)))]
3424   "")
3425
3426 (define_insn "*andsi3_internal4"
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_32BIT && rs6000_gen_cell_microcode"
3436   "@
3437    and. %0,%1,%2
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" "fast_compare,fast_compare,fast_compare,delayed_compare,\
3446                      compare,compare,compare,compare")
3447    (set_attr "length" "4,4,4,4,8,8,8,8")])
3448
3449 (define_insn "*andsi3_internal5_mc"
3450   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3451         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3452                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3453                     (const_int 0)))
3454    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3455         (and:SI (match_dup 1)
3456                 (match_dup 2)))
3457    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3458   "TARGET_64BIT && rs6000_gen_cell_microcode"
3459   "@
3460    #
3461    {andil.|andi.} %0,%1,%b2
3462    {andiu.|andis.} %0,%1,%u2
3463    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3464    #
3465    #
3466    #
3467    #"
3468   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
3469                      compare,compare,compare")
3470    (set_attr "length" "8,4,4,4,8,8,8,8")])
3471
3472 (define_split
3473   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3474         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3475                             (match_operand:SI 2 "and_operand" ""))
3476                     (const_int 0)))
3477    (set (match_operand:SI 0 "gpc_reg_operand" "")
3478         (and:SI (match_dup 1)
3479                 (match_dup 2)))
3480    (clobber (match_scratch:CC 4 ""))]
3481   "reload_completed"
3482   [(parallel [(set (match_dup 0)
3483                    (and:SI (match_dup 1)
3484                            (match_dup 2)))
3485               (clobber (match_dup 4))])
3486    (set (match_dup 3)
3487         (compare:CC (match_dup 0)
3488                     (const_int 0)))]
3489   "")
3490
3491 (define_split
3492   [(set (match_operand:CC 3 "cc_reg_operand" "")
3493         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3494                             (match_operand:SI 2 "gpc_reg_operand" ""))
3495                     (const_int 0)))
3496    (set (match_operand:SI 0 "gpc_reg_operand" "")
3497         (and:SI (match_dup 1)
3498                 (match_dup 2)))
3499    (clobber (match_scratch:CC 4 ""))]
3500   "TARGET_POWERPC64 && reload_completed"
3501   [(parallel [(set (match_dup 0)
3502                    (and:SI (match_dup 1)
3503                            (match_dup 2)))
3504               (clobber (match_dup 4))])
3505    (set (match_dup 3)
3506         (compare:CC (match_dup 0)
3507                     (const_int 0)))]
3508   "")
3509
3510 ;; Handle the PowerPC64 rlwinm corner case
3511
3512 (define_insn_and_split "*andsi3_internal6"
3513   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3514         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3515                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3516   "TARGET_POWERPC64"
3517   "#"
3518   "TARGET_POWERPC64"
3519   [(set (match_dup 0)
3520         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3521                 (match_dup 4)))
3522    (set (match_dup 0)
3523         (rotate:SI (match_dup 0) (match_dup 5)))]
3524   "
3525 {
3526   int mb = extract_MB (operands[2]);
3527   int me = extract_ME (operands[2]);
3528   operands[3] = GEN_INT (me + 1);
3529   operands[5] = GEN_INT (32 - (me + 1));
3530   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3531 }"
3532   [(set_attr "length" "8")])
3533
3534 (define_expand "iorsi3"
3535   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3536         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3537                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3538   ""
3539   "
3540 {
3541   if (GET_CODE (operands[2]) == CONST_INT
3542       && ! logical_operand (operands[2], SImode))
3543     {
3544       HOST_WIDE_INT value = INTVAL (operands[2]);
3545       rtx tmp = ((!can_create_pseudo_p ()
3546                   || rtx_equal_p (operands[0], operands[1]))
3547                  ? operands[0] : gen_reg_rtx (SImode));
3548
3549       emit_insn (gen_iorsi3 (tmp, operands[1],
3550                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3551       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3552       DONE;
3553     }
3554 }")
3555
3556 (define_expand "xorsi3"
3557   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3558         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3559                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3560   ""
3561   "
3562 {
3563   if (GET_CODE (operands[2]) == CONST_INT
3564       && ! logical_operand (operands[2], SImode))
3565     {
3566       HOST_WIDE_INT value = INTVAL (operands[2]);
3567       rtx tmp = ((!can_create_pseudo_p ()
3568                   || rtx_equal_p (operands[0], operands[1]))
3569                  ? operands[0] : gen_reg_rtx (SImode));
3570
3571       emit_insn (gen_xorsi3 (tmp, operands[1],
3572                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3573       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3574       DONE;
3575     }
3576 }")
3577
3578 (define_insn "*boolsi3_internal1"
3579   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3580         (match_operator:SI 3 "boolean_or_operator"
3581          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3582           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3583   ""
3584   "@
3585    %q3 %0,%1,%2
3586    {%q3il|%q3i} %0,%1,%b2
3587    {%q3iu|%q3is} %0,%1,%u2")
3588
3589 (define_insn "*boolsi3_internal2"
3590   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3591         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3592          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3593           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3594          (const_int 0)))
3595    (clobber (match_scratch:SI 3 "=r,r"))]
3596   "TARGET_32BIT"
3597   "@
3598    %q4. %3,%1,%2
3599    #"
3600   [(set_attr "type" "fast_compare,compare")
3601    (set_attr "length" "4,8")])
3602
3603 (define_split
3604   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3605         (compare:CC (match_operator:SI 4 "boolean_operator"
3606          [(match_operand:SI 1 "gpc_reg_operand" "")
3607           (match_operand:SI 2 "gpc_reg_operand" "")])
3608          (const_int 0)))
3609    (clobber (match_scratch:SI 3 ""))]
3610   "TARGET_32BIT && reload_completed"
3611   [(set (match_dup 3) (match_dup 4))
3612    (set (match_dup 0)
3613         (compare:CC (match_dup 3)
3614                     (const_int 0)))]
3615   "")
3616
3617 (define_insn "*boolsi3_internal3"
3618   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3619         (compare:CC (match_operator:SI 4 "boolean_operator"
3620          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3621           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3622          (const_int 0)))
3623    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3624         (match_dup 4))]
3625   "TARGET_32BIT"
3626   "@
3627    %q4. %0,%1,%2
3628    #"
3629   [(set_attr "type" "fast_compare,compare")
3630    (set_attr "length" "4,8")])
3631
3632 (define_split
3633   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3634         (compare:CC (match_operator:SI 4 "boolean_operator"
3635          [(match_operand:SI 1 "gpc_reg_operand" "")
3636           (match_operand:SI 2 "gpc_reg_operand" "")])
3637          (const_int 0)))
3638    (set (match_operand:SI 0 "gpc_reg_operand" "")
3639         (match_dup 4))]
3640   "TARGET_32BIT && reload_completed"
3641   [(set (match_dup 0) (match_dup 4))
3642    (set (match_dup 3)
3643         (compare:CC (match_dup 0)
3644                     (const_int 0)))]
3645   "")
3646
3647 ;; Split a logical operation that we can't do in one insn into two insns,
3648 ;; each of which does one 16-bit part.  This is used by combine.
3649
3650 (define_split
3651   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3652         (match_operator:SI 3 "boolean_or_operator"
3653          [(match_operand:SI 1 "gpc_reg_operand" "")
3654           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3655   ""
3656   [(set (match_dup 0) (match_dup 4))
3657    (set (match_dup 0) (match_dup 5))]
3658 "
3659 {
3660   rtx i;
3661   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3662   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3663                                 operands[1], i);
3664   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3665   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3666                                 operands[0], i);
3667 }")
3668
3669 (define_insn "*boolcsi3_internal1"
3670   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3671         (match_operator:SI 3 "boolean_operator"
3672          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3673           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3674   ""
3675   "%q3 %0,%2,%1")
3676
3677 (define_insn "*boolcsi3_internal2"
3678   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3679         (compare:CC (match_operator:SI 4 "boolean_operator"
3680          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3681           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3682          (const_int 0)))
3683    (clobber (match_scratch:SI 3 "=r,r"))]
3684   "TARGET_32BIT"
3685   "@
3686    %q4. %3,%2,%1
3687    #"
3688   [(set_attr "type" "compare")
3689    (set_attr "length" "4,8")])
3690
3691 (define_split
3692   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3693         (compare:CC (match_operator:SI 4 "boolean_operator"
3694          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3695           (match_operand:SI 2 "gpc_reg_operand" "")])
3696          (const_int 0)))
3697    (clobber (match_scratch:SI 3 ""))]
3698   "TARGET_32BIT && reload_completed"
3699   [(set (match_dup 3) (match_dup 4))
3700    (set (match_dup 0)
3701         (compare:CC (match_dup 3)
3702                     (const_int 0)))]
3703   "")
3704
3705 (define_insn "*boolcsi3_internal3"
3706   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3707         (compare:CC (match_operator:SI 4 "boolean_operator"
3708          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3709           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3710          (const_int 0)))
3711    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3712         (match_dup 4))]
3713   "TARGET_32BIT"
3714   "@
3715    %q4. %0,%2,%1
3716    #"
3717   [(set_attr "type" "compare")
3718    (set_attr "length" "4,8")])
3719
3720 (define_split
3721   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3722         (compare:CC (match_operator:SI 4 "boolean_operator"
3723          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3724           (match_operand:SI 2 "gpc_reg_operand" "")])
3725          (const_int 0)))
3726    (set (match_operand:SI 0 "gpc_reg_operand" "")
3727         (match_dup 4))]
3728   "TARGET_32BIT && reload_completed"
3729   [(set (match_dup 0) (match_dup 4))
3730    (set (match_dup 3)
3731         (compare:CC (match_dup 0)
3732                     (const_int 0)))]
3733   "")
3734
3735 (define_insn "*boolccsi3_internal1"
3736   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3737         (match_operator:SI 3 "boolean_operator"
3738          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3739           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3740   ""
3741   "%q3 %0,%1,%2")
3742
3743 (define_insn "*boolccsi3_internal2"
3744   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3745         (compare:CC (match_operator:SI 4 "boolean_operator"
3746          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3747           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3748          (const_int 0)))
3749    (clobber (match_scratch:SI 3 "=r,r"))]
3750   "TARGET_32BIT"
3751   "@
3752    %q4. %3,%1,%2
3753    #"
3754   [(set_attr "type" "fast_compare,compare")
3755    (set_attr "length" "4,8")])
3756
3757 (define_split
3758   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3759         (compare:CC (match_operator:SI 4 "boolean_operator"
3760          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3761           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3762          (const_int 0)))
3763    (clobber (match_scratch:SI 3 ""))]
3764   "TARGET_32BIT && reload_completed"
3765   [(set (match_dup 3) (match_dup 4))
3766    (set (match_dup 0)
3767         (compare:CC (match_dup 3)
3768                     (const_int 0)))]
3769   "")
3770
3771 (define_insn "*boolccsi3_internal3"
3772   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3773         (compare:CC (match_operator:SI 4 "boolean_operator"
3774          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3775           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3776          (const_int 0)))
3777    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3778         (match_dup 4))]
3779   "TARGET_32BIT"
3780   "@
3781    %q4. %0,%1,%2
3782    #"
3783   [(set_attr "type" "fast_compare,compare")
3784    (set_attr "length" "4,8")])
3785
3786 (define_split
3787   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3788         (compare:CC (match_operator:SI 4 "boolean_operator"
3789          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3790           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3791          (const_int 0)))
3792    (set (match_operand:SI 0 "gpc_reg_operand" "")
3793         (match_dup 4))]
3794   "TARGET_32BIT && reload_completed"
3795   [(set (match_dup 0) (match_dup 4))
3796    (set (match_dup 3)
3797         (compare:CC (match_dup 0)
3798                     (const_int 0)))]
3799   "")
3800
3801 ;; maskir insn.  We need four forms because things might be in arbitrary
3802 ;; orders.  Don't define forms that only set CR fields because these
3803 ;; would modify an input register.
3804
3805 (define_insn "*maskir_internal1"
3806   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3807         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3808                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3809                 (and:SI (match_dup 2)
3810                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3811   "TARGET_POWER"
3812   "maskir %0,%3,%2")
3813
3814 (define_insn "*maskir_internal2"
3815   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3816         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3817                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3818                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3819                         (match_dup 2))))]
3820   "TARGET_POWER"
3821   "maskir %0,%3,%2")
3822
3823 (define_insn "*maskir_internal3"
3824   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3825         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3826                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3827                 (and:SI (not:SI (match_dup 2))
3828                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3829   "TARGET_POWER"
3830   "maskir %0,%3,%2")
3831
3832 (define_insn "*maskir_internal4"
3833   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3834         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3835                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3836                 (and:SI (not:SI (match_dup 2))
3837                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3838   "TARGET_POWER"
3839   "maskir %0,%3,%2")
3840
3841 (define_insn "*maskir_internal5"
3842   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3843         (compare:CC
3844          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3845                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3846                  (and:SI (match_dup 2)
3847                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3848          (const_int 0)))
3849    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3850         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3851                 (and:SI (match_dup 2) (match_dup 3))))]
3852   "TARGET_POWER"
3853   "@
3854    maskir. %0,%3,%2
3855    #"
3856   [(set_attr "type" "compare")
3857    (set_attr "length" "4,8")])
3858
3859 (define_split
3860   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3861         (compare:CC
3862          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3863                          (match_operand:SI 1 "gpc_reg_operand" ""))
3864                  (and:SI (match_dup 2)
3865                          (match_operand:SI 3 "gpc_reg_operand" "")))
3866          (const_int 0)))
3867    (set (match_operand:SI 0 "gpc_reg_operand" "")
3868         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3869                 (and:SI (match_dup 2) (match_dup 3))))]
3870   "TARGET_POWER && reload_completed"
3871   [(set (match_dup 0)
3872         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3873                 (and:SI (match_dup 2) (match_dup 3))))
3874    (set (match_dup 4)
3875         (compare:CC (match_dup 0)
3876                     (const_int 0)))]
3877   "")
3878
3879 (define_insn "*maskir_internal6"
3880   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3881         (compare:CC
3882          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3883                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3884                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3885                          (match_dup 2)))
3886          (const_int 0)))
3887    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3888         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3889                 (and:SI (match_dup 3) (match_dup 2))))]
3890   "TARGET_POWER"
3891   "@
3892    maskir. %0,%3,%2
3893    #"
3894   [(set_attr "type" "compare")
3895    (set_attr "length" "4,8")])
3896
3897 (define_split
3898   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3899         (compare:CC
3900          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3901                          (match_operand:SI 1 "gpc_reg_operand" ""))
3902                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3903                          (match_dup 2)))
3904          (const_int 0)))
3905    (set (match_operand:SI 0 "gpc_reg_operand" "")
3906         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3907                 (and:SI (match_dup 3) (match_dup 2))))]
3908   "TARGET_POWER && reload_completed"
3909   [(set (match_dup 0)
3910         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3911                 (and:SI (match_dup 3) (match_dup 2))))
3912    (set (match_dup 4)
3913         (compare:CC (match_dup 0)
3914                     (const_int 0)))]
3915   "")
3916
3917 (define_insn "*maskir_internal7"
3918   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3919         (compare:CC
3920          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3921                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3922                  (and:SI (not:SI (match_dup 2))
3923                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3924          (const_int 0)))
3925    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3926         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3927                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3928   "TARGET_POWER"
3929   "@
3930    maskir. %0,%3,%2
3931    #"
3932   [(set_attr "type" "compare")
3933    (set_attr "length" "4,8")])
3934
3935 (define_split
3936   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3937         (compare:CC
3938          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3939                          (match_operand:SI 3 "gpc_reg_operand" ""))
3940                  (and:SI (not:SI (match_dup 2))
3941                          (match_operand:SI 1 "gpc_reg_operand" "")))
3942          (const_int 0)))
3943    (set (match_operand:SI 0 "gpc_reg_operand" "")
3944         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3945                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3946   "TARGET_POWER && reload_completed"
3947   [(set (match_dup 0)
3948         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3949                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3950    (set (match_dup 4)
3951         (compare:CC (match_dup 0)
3952                     (const_int 0)))]
3953   "")
3954
3955 (define_insn "*maskir_internal8"
3956   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3957         (compare:CC
3958          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3959                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3960                  (and:SI (not:SI (match_dup 2))
3961                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3962          (const_int 0)))
3963    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3964         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3965                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3966   "TARGET_POWER"
3967   "@
3968    maskir. %0,%3,%2
3969    #"
3970   [(set_attr "type" "compare")
3971    (set_attr "length" "4,8")])
3972
3973 (define_split
3974   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3975         (compare:CC
3976          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3977                          (match_operand:SI 2 "gpc_reg_operand" ""))
3978                  (and:SI (not:SI (match_dup 2))
3979                          (match_operand:SI 1 "gpc_reg_operand" "")))
3980          (const_int 0)))
3981    (set (match_operand:SI 0 "gpc_reg_operand" "")
3982         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3983                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3984   "TARGET_POWER && reload_completed"
3985   [(set (match_dup 0)
3986         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3987                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3988    (set (match_dup 4)
3989         (compare:CC (match_dup 0)
3990                     (const_int 0)))]
3991   "")
3992 \f
3993 ;; Rotate and shift insns, in all their variants.  These support shifts,
3994 ;; field inserts and extracts, and various combinations thereof.
3995 (define_expand "insv"
3996   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3997                        (match_operand:SI 1 "const_int_operand" "")
3998                        (match_operand:SI 2 "const_int_operand" ""))
3999         (match_operand 3 "gpc_reg_operand" ""))]
4000   ""
4001   "
4002 {
4003   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
4004      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
4005      compiler if the address of the structure is taken later.  Likewise, do
4006      not handle invalid E500 subregs.  */
4007   if (GET_CODE (operands[0]) == SUBREG
4008       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
4009           || ((TARGET_E500_DOUBLE || TARGET_SPE)
4010               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
4011     FAIL;
4012
4013   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
4014     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
4015   else
4016     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
4017   DONE;
4018 }")
4019
4020 (define_insn "insvsi"
4021   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4022                          (match_operand:SI 1 "const_int_operand" "i")
4023                          (match_operand:SI 2 "const_int_operand" "i"))
4024         (match_operand:SI 3 "gpc_reg_operand" "r"))]
4025   ""
4026   "*
4027 {
4028   int start = INTVAL (operands[2]) & 31;
4029   int size = INTVAL (operands[1]) & 31;
4030
4031   operands[4] = GEN_INT (32 - start - size);
4032   operands[1] = GEN_INT (start + size - 1);
4033   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4034 }"
4035   [(set_attr "type" "insert_word")])
4036
4037 (define_insn "*insvsi_internal1"
4038   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4039                          (match_operand:SI 1 "const_int_operand" "i")
4040                          (match_operand:SI 2 "const_int_operand" "i"))
4041         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4042                    (match_operand:SI 4 "const_int_operand" "i")))]
4043   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4044   "*
4045 {
4046   int shift = INTVAL (operands[4]) & 31;
4047   int start = INTVAL (operands[2]) & 31;
4048   int size = INTVAL (operands[1]) & 31;
4049
4050   operands[4] = GEN_INT (shift - start - size);
4051   operands[1] = GEN_INT (start + size - 1);
4052   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4053 }"
4054   [(set_attr "type" "insert_word")])
4055
4056 (define_insn "*insvsi_internal2"
4057   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4058                          (match_operand:SI 1 "const_int_operand" "i")
4059                          (match_operand:SI 2 "const_int_operand" "i"))
4060         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4061                      (match_operand:SI 4 "const_int_operand" "i")))]
4062   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4063   "*
4064 {
4065   int shift = INTVAL (operands[4]) & 31;
4066   int start = INTVAL (operands[2]) & 31;
4067   int size = INTVAL (operands[1]) & 31;
4068
4069   operands[4] = GEN_INT (32 - shift - start - size);
4070   operands[1] = GEN_INT (start + size - 1);
4071   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4072 }"
4073   [(set_attr "type" "insert_word")])
4074
4075 (define_insn "*insvsi_internal3"
4076   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4077                          (match_operand:SI 1 "const_int_operand" "i")
4078                          (match_operand:SI 2 "const_int_operand" "i"))
4079         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4080                      (match_operand:SI 4 "const_int_operand" "i")))]
4081   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4082   "*
4083 {
4084   int shift = INTVAL (operands[4]) & 31;
4085   int start = INTVAL (operands[2]) & 31;
4086   int size = INTVAL (operands[1]) & 31;
4087
4088   operands[4] = GEN_INT (32 - shift - start - size);
4089   operands[1] = GEN_INT (start + size - 1);
4090   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4091 }"
4092   [(set_attr "type" "insert_word")])
4093
4094 (define_insn "*insvsi_internal4"
4095   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4096                          (match_operand:SI 1 "const_int_operand" "i")
4097                          (match_operand:SI 2 "const_int_operand" "i"))
4098         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4099                          (match_operand:SI 4 "const_int_operand" "i")
4100                          (match_operand:SI 5 "const_int_operand" "i")))]
4101   "INTVAL (operands[4]) >= INTVAL (operands[1])"
4102   "*
4103 {
4104   int extract_start = INTVAL (operands[5]) & 31;
4105   int extract_size = INTVAL (operands[4]) & 31;
4106   int insert_start = INTVAL (operands[2]) & 31;
4107   int insert_size = INTVAL (operands[1]) & 31;
4108
4109 /* Align extract field with insert field */
4110   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
4111   operands[1] = GEN_INT (insert_start + insert_size - 1);
4112   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
4113 }"
4114   [(set_attr "type" "insert_word")])
4115
4116 ;; combine patterns for rlwimi
4117 (define_insn "*insvsi_internal5"
4118   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4119         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
4120                         (match_operand:SI 1 "mask_operand" "i"))
4121                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4122                                      (match_operand:SI 2 "const_int_operand" "i"))
4123                         (match_operand:SI 5 "mask_operand" "i"))))]
4124   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
4125   "*
4126 {
4127  int me = extract_ME(operands[5]);
4128  int mb = extract_MB(operands[5]);
4129  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
4130  operands[2] = GEN_INT(mb);
4131  operands[1] = GEN_INT(me);
4132  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4133 }"
4134   [(set_attr "type" "insert_word")])
4135
4136 (define_insn "*insvsi_internal6"
4137   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4138         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4139                                      (match_operand:SI 2 "const_int_operand" "i"))
4140                         (match_operand:SI 5 "mask_operand" "i"))
4141                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
4142                         (match_operand:SI 1 "mask_operand" "i"))))]
4143   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
4144   "*
4145 {
4146  int me = extract_ME(operands[5]);
4147  int mb = extract_MB(operands[5]);
4148  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
4149  operands[2] = GEN_INT(mb);
4150  operands[1] = GEN_INT(me);
4151  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4152 }"
4153   [(set_attr "type" "insert_word")])
4154
4155 (define_insn "insvdi"
4156   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4157                          (match_operand:SI 1 "const_int_operand" "i")
4158                          (match_operand:SI 2 "const_int_operand" "i"))
4159         (match_operand:DI 3 "gpc_reg_operand" "r"))]
4160   "TARGET_POWERPC64"
4161   "*
4162 {
4163   int start = INTVAL (operands[2]) & 63;
4164   int size = INTVAL (operands[1]) & 63;
4165
4166   operands[1] = GEN_INT (64 - start - size);
4167   return \"rldimi %0,%3,%H1,%H2\";
4168 }"
4169   [(set_attr "type" "insert_dword")])
4170
4171 (define_insn "*insvdi_internal2"
4172   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4173                          (match_operand:SI 1 "const_int_operand" "i")
4174                          (match_operand:SI 2 "const_int_operand" "i"))
4175         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4176                      (match_operand:SI 4 "const_int_operand" "i")))]
4177   "TARGET_POWERPC64
4178    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
4179   "*
4180 {
4181   int shift = INTVAL (operands[4]) & 63;
4182   int start = (INTVAL (operands[2]) & 63) - 32;
4183   int size = INTVAL (operands[1]) & 63;
4184
4185   operands[4] = GEN_INT (64 - shift - start - size);
4186   operands[2] = GEN_INT (start);
4187   operands[1] = GEN_INT (start + size - 1);
4188   return \"rlwimi %0,%3,%h4,%h2,%h1\";
4189 }")
4190
4191 (define_insn "*insvdi_internal3"
4192   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4193                          (match_operand:SI 1 "const_int_operand" "i")
4194                          (match_operand:SI 2 "const_int_operand" "i"))
4195         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4196                      (match_operand:SI 4 "const_int_operand" "i")))]
4197   "TARGET_POWERPC64
4198    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
4199   "*
4200 {
4201   int shift = INTVAL (operands[4]) & 63;
4202   int start = (INTVAL (operands[2]) & 63) - 32;
4203   int size = INTVAL (operands[1]) & 63;
4204
4205   operands[4] = GEN_INT (64 - shift - start - size);
4206   operands[2] = GEN_INT (start);
4207   operands[1] = GEN_INT (start + size - 1);
4208   return \"rlwimi %0,%3,%h4,%h2,%h1\";
4209 }")
4210
4211 (define_expand "extzv"
4212   [(set (match_operand 0 "gpc_reg_operand" "")
4213         (zero_extract (match_operand 1 "gpc_reg_operand" "")
4214                        (match_operand:SI 2 "const_int_operand" "")
4215                        (match_operand:SI 3 "const_int_operand" "")))]
4216   ""
4217   "
4218 {
4219   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
4220      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
4221      compiler if the address of the structure is taken later.  */
4222   if (GET_CODE (operands[0]) == SUBREG
4223       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
4224     FAIL;
4225
4226   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
4227     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
4228   else
4229     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
4230   DONE;
4231 }")
4232
4233 (define_insn "extzvsi"
4234   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4235         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4236                          (match_operand:SI 2 "const_int_operand" "i")
4237                          (match_operand:SI 3 "const_int_operand" "i")))]
4238   ""
4239   "*
4240 {
4241   int start = INTVAL (operands[3]) & 31;
4242   int size = INTVAL (operands[2]) & 31;
4243
4244   if (start + size >= 32)
4245     operands[3] = const0_rtx;
4246   else
4247     operands[3] = GEN_INT (start + size);
4248   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
4249 }")
4250
4251 (define_insn "*extzvsi_internal1"
4252   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4253         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4254                          (match_operand:SI 2 "const_int_operand" "i,i")
4255                          (match_operand:SI 3 "const_int_operand" "i,i"))
4256                     (const_int 0)))
4257    (clobber (match_scratch:SI 4 "=r,r"))]
4258   ""
4259   "*
4260 {
4261   int start = INTVAL (operands[3]) & 31;
4262   int size = INTVAL (operands[2]) & 31;
4263
4264   /* Force split for non-cc0 compare.  */
4265   if (which_alternative == 1)
4266      return \"#\";
4267
4268   /* If the bit-field being tested fits in the upper or lower half of a
4269      word, it is possible to use andiu. or andil. to test it.  This is
4270      useful because the condition register set-use delay is smaller for
4271      andi[ul]. than for rlinm.  This doesn't work when the starting bit
4272      position is 0 because the LT and GT bits may be set wrong.  */
4273
4274   if ((start > 0 && start + size <= 16) || start >= 16)
4275     {
4276       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
4277                               - (1 << (16 - (start & 15) - size))));
4278       if (start < 16)
4279         return \"{andiu.|andis.} %4,%1,%3\";
4280       else
4281         return \"{andil.|andi.} %4,%1,%3\";
4282     }
4283
4284   if (start + size >= 32)
4285     operands[3] = const0_rtx;
4286   else
4287     operands[3] = GEN_INT (start + size);
4288   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
4289 }"
4290   [(set_attr "type" "delayed_compare")
4291    (set_attr "length" "4,8")])
4292
4293 (define_split
4294   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4295         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
4296                          (match_operand:SI 2 "const_int_operand" "")
4297                          (match_operand:SI 3 "const_int_operand" ""))
4298                     (const_int 0)))
4299    (clobber (match_scratch:SI 4 ""))]
4300   "reload_completed"
4301   [(set (match_dup 4)
4302         (zero_extract:SI (match_dup 1) (match_dup 2)
4303                          (match_dup 3)))
4304    (set (match_dup 0)
4305         (compare:CC (match_dup 4)
4306                     (const_int 0)))]
4307   "")
4308
4309 (define_insn "*extzvsi_internal2"
4310   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4311         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4312                          (match_operand:SI 2 "const_int_operand" "i,i")
4313                          (match_operand:SI 3 "const_int_operand" "i,i"))
4314                     (const_int 0)))
4315    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4316         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
4317   ""
4318   "*
4319 {
4320   int start = INTVAL (operands[3]) & 31;
4321   int size = INTVAL (operands[2]) & 31;
4322
4323   /* Force split for non-cc0 compare.  */
4324   if (which_alternative == 1)
4325      return \"#\";
4326
4327   /* Since we are using the output value, we can't ignore any need for
4328      a shift.  The bit-field must end at the LSB.  */
4329   if (start >= 16 && start + size == 32)
4330     {
4331       operands[3] = GEN_INT ((1 << size) - 1);
4332       return \"{andil.|andi.} %0,%1,%3\";
4333     }
4334
4335   if (start + size >= 32)
4336     operands[3] = const0_rtx;
4337   else
4338     operands[3] = GEN_INT (start + size);
4339   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
4340 }"
4341   [(set_attr "type" "delayed_compare")
4342    (set_attr "length" "4,8")])
4343
4344 (define_split
4345   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4346         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
4347                          (match_operand:SI 2 "const_int_operand" "")
4348                          (match_operand:SI 3 "const_int_operand" ""))
4349                     (const_int 0)))
4350    (set (match_operand:SI 0 "gpc_reg_operand" "")
4351         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
4352   "reload_completed"
4353   [(set (match_dup 0)
4354         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
4355    (set (match_dup 4)
4356         (compare:CC (match_dup 0)
4357                     (const_int 0)))]
4358   "")
4359
4360 (define_insn "extzvdi"
4361   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4362         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4363                          (match_operand:SI 2 "const_int_operand" "i")
4364                          (match_operand:SI 3 "const_int_operand" "i")))]
4365   "TARGET_POWERPC64"
4366   "*
4367 {
4368   int start = INTVAL (operands[3]) & 63;
4369   int size = INTVAL (operands[2]) & 63;
4370
4371   if (start + size >= 64)
4372     operands[3] = const0_rtx;
4373   else
4374     operands[3] = GEN_INT (start + size);
4375   operands[2] = GEN_INT (64 - size);
4376   return \"rldicl %0,%1,%3,%2\";
4377 }")
4378
4379 (define_insn "*extzvdi_internal1"
4380   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
4381         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4382                          (match_operand:SI 2 "const_int_operand" "i")
4383                          (match_operand:SI 3 "const_int_operand" "i"))
4384                     (const_int 0)))
4385    (clobber (match_scratch:DI 4 "=r"))]
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. %4,%1,%3,%2\";
4398 }"
4399   [(set_attr "type" "compare")])
4400
4401 (define_insn "*extzvdi_internal2"
4402   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
4403         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4404                          (match_operand:SI 2 "const_int_operand" "i")
4405                          (match_operand:SI 3 "const_int_operand" "i"))
4406                     (const_int 0)))
4407    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4408         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
4409   "TARGET_64BIT && rs6000_gen_cell_microcode"
4410   "*
4411 {
4412   int start = INTVAL (operands[3]) & 63;
4413   int size = INTVAL (operands[2]) & 63;
4414
4415   if (start + size >= 64)
4416     operands[3] = const0_rtx;
4417   else
4418     operands[3] = GEN_INT (start + size);
4419   operands[2] = GEN_INT (64 - size);
4420   return \"rldicl. %0,%1,%3,%2\";
4421 }"
4422   [(set_attr "type" "compare")])
4423
4424 (define_insn "rotlsi3"
4425   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4426         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4427                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4428   ""
4429   "@
4430    {rlnm|rlwnm} %0,%1,%2,0xffffffff
4431    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
4432   [(set_attr "type" "var_shift_rotate,integer")])
4433
4434 (define_insn "*rotlsi3_64"
4435   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4436         (zero_extend:DI
4437             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4438                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4439   "TARGET_64BIT"
4440   "@
4441    {rlnm|rlwnm} %0,%1,%2,0xffffffff
4442    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
4443   [(set_attr "type" "var_shift_rotate,integer")])
4444
4445 (define_insn "*rotlsi3_internal2"
4446   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4447         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4448                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4449                     (const_int 0)))
4450    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4451   ""
4452   "@
4453    {rlnm.|rlwnm.} %3,%1,%2,0xffffffff
4454    {rlinm.|rlwinm.} %3,%1,%h2,0xffffffff
4455    #
4456    #"
4457   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4458    (set_attr "length" "4,4,8,8")])
4459
4460 (define_split
4461   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4462         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4463                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4464                     (const_int 0)))
4465    (clobber (match_scratch:SI 3 ""))]
4466   "reload_completed"
4467   [(set (match_dup 3)
4468         (rotate:SI (match_dup 1) (match_dup 2)))
4469    (set (match_dup 0)
4470         (compare:CC (match_dup 3)
4471                     (const_int 0)))]
4472   "")
4473
4474 (define_insn "*rotlsi3_internal3"
4475   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4476         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4477                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4478                     (const_int 0)))
4479    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4480         (rotate:SI (match_dup 1) (match_dup 2)))]
4481   ""
4482   "@
4483    {rlnm.|rlwnm.} %0,%1,%2,0xffffffff
4484    {rlinm.|rlwinm.} %0,%1,%h2,0xffffffff
4485    #
4486    #"
4487   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4488    (set_attr "length" "4,4,8,8")])
4489
4490 (define_split
4491   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4492         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4493                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4494                     (const_int 0)))
4495    (set (match_operand:SI 0 "gpc_reg_operand" "")
4496         (rotate:SI (match_dup 1) (match_dup 2)))]
4497   "reload_completed"
4498   [(set (match_dup 0)
4499         (rotate:SI (match_dup 1) (match_dup 2)))
4500    (set (match_dup 3)
4501         (compare:CC (match_dup 0)
4502                     (const_int 0)))]
4503   "")
4504
4505 (define_insn "*rotlsi3_internal4"
4506   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4507         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4508                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
4509                 (match_operand:SI 3 "mask_operand" "n,n")))]
4510   ""
4511   "@
4512    {rlnm|rlwnm} %0,%1,%2,%m3,%M3
4513    {rlinm|rlwinm} %0,%1,%h2,%m3,%M3"
4514   [(set_attr "type" "var_shift_rotate,integer")])
4515
4516 (define_insn "*rotlsi3_internal5"
4517   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4518         (compare:CC (and:SI
4519                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4520                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4521                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4522                     (const_int 0)))
4523    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
4524   ""
4525   "@
4526    {rlnm.|rlwnm.} %4,%1,%2,%m3,%M3
4527    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4528    #
4529    #"
4530   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4531    (set_attr "length" "4,4,8,8")])
4532
4533 (define_split
4534   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4535         (compare:CC (and:SI
4536                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4537                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4538                      (match_operand:SI 3 "mask_operand" ""))
4539                     (const_int 0)))
4540    (clobber (match_scratch:SI 4 ""))]
4541   "reload_completed"
4542   [(set (match_dup 4)
4543         (and:SI (rotate:SI (match_dup 1)
4544                                 (match_dup 2))
4545                      (match_dup 3)))
4546    (set (match_dup 0)
4547         (compare:CC (match_dup 4)
4548                     (const_int 0)))]
4549   "")
4550
4551 (define_insn "*rotlsi3_internal6"
4552   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
4553         (compare:CC (and:SI
4554                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4555                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4556                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4557                     (const_int 0)))
4558    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4559         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4560   ""
4561   "@
4562    {rlnm.|rlwnm.} %0,%1,%2,%m3,%M3
4563    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4564    #
4565    #"
4566   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4567    (set_attr "length" "4,4,8,8")])
4568
4569 (define_split
4570   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4571         (compare:CC (and:SI
4572                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4573                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4574                      (match_operand:SI 3 "mask_operand" ""))
4575                     (const_int 0)))
4576    (set (match_operand:SI 0 "gpc_reg_operand" "")
4577         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4578   "reload_completed"
4579   [(set (match_dup 0)
4580         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4581    (set (match_dup 4)
4582         (compare:CC (match_dup 0)
4583                     (const_int 0)))]
4584   "")
4585
4586 (define_insn "*rotlsi3_internal7"
4587   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4588         (zero_extend:SI
4589          (subreg:QI
4590           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4591                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4592   ""
4593   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff"
4594   [(set (attr "cell_micro")
4595      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4596         (const_string "not")
4597         (const_string "always")))])
4598
4599 (define_insn "*rotlsi3_internal8"
4600   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4601         (compare:CC (zero_extend:SI
4602                      (subreg:QI
4603                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4604                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4605                     (const_int 0)))
4606    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4607   ""
4608   "@
4609    {rlnm.|rlwnm.} %3,%1,%2,0xff
4610    {rlinm.|rlwinm.} %3,%1,%h2,0xff
4611    #
4612    #"
4613   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4614    (set_attr "length" "4,4,8,8")])
4615
4616 (define_split
4617   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4618         (compare:CC (zero_extend:SI
4619                      (subreg:QI
4620                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4621                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4622                     (const_int 0)))
4623    (clobber (match_scratch:SI 3 ""))]
4624   "reload_completed"
4625   [(set (match_dup 3)
4626         (zero_extend:SI (subreg:QI
4627                       (rotate:SI (match_dup 1)
4628                                  (match_dup 2)) 0)))
4629    (set (match_dup 0)
4630         (compare:CC (match_dup 3)
4631                     (const_int 0)))]
4632   "")
4633
4634 (define_insn "*rotlsi3_internal9"
4635   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4636         (compare:CC (zero_extend:SI
4637                      (subreg:QI
4638                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4639                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4640                     (const_int 0)))
4641    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4642         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4643   ""
4644   "@
4645    {rlnm.|rlwnm.} %0,%1,%2,0xff
4646    {rlinm.|rlwinm.} %0,%1,%h2,0xff
4647    #
4648    #"
4649   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4650    (set_attr "length" "4,4,8,8")])
4651
4652 (define_split
4653   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4654         (compare:CC (zero_extend:SI
4655                      (subreg:QI
4656                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4657                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4658                     (const_int 0)))
4659    (set (match_operand:SI 0 "gpc_reg_operand" "")
4660         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4661   "reload_completed"
4662   [(set (match_dup 0)
4663         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4664    (set (match_dup 3)
4665         (compare:CC (match_dup 0)
4666                     (const_int 0)))]
4667   "")
4668
4669 (define_insn "*rotlsi3_internal10"
4670   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4671         (zero_extend:SI
4672          (subreg:HI
4673           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4674                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4675   ""
4676   "@
4677    {rlnm|rlwnm} %0,%1,%2,0xffff
4678    {rlinm|rlwinm} %0,%1,%h2,0xffff"
4679   [(set_attr "type" "var_shift_rotate,integer")])
4680
4681
4682 (define_insn "*rotlsi3_internal11"
4683   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4684         (compare:CC (zero_extend:SI
4685                      (subreg:HI
4686                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4687                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4688                     (const_int 0)))
4689    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4690   ""
4691   "@
4692    {rlnm.|rlwnm.} %3,%1,%2,0xffff
4693    {rlinm.|rlwinm.} %3,%1,%h2,0xffff
4694    #
4695    #"
4696   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4697    (set_attr "length" "4,4,8,8")])
4698
4699 (define_split
4700   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4701         (compare:CC (zero_extend:SI
4702                      (subreg:HI
4703                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4704                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4705                     (const_int 0)))
4706    (clobber (match_scratch:SI 3 ""))]
4707   "reload_completed"
4708   [(set (match_dup 3)
4709         (zero_extend:SI (subreg:HI
4710                       (rotate:SI (match_dup 1)
4711                                  (match_dup 2)) 0)))
4712    (set (match_dup 0)
4713         (compare:CC (match_dup 3)
4714                     (const_int 0)))]
4715   "")
4716
4717 (define_insn "*rotlsi3_internal12"
4718   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4719         (compare:CC (zero_extend:SI
4720                      (subreg:HI
4721                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4722                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4723                     (const_int 0)))
4724    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4725         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4726   ""
4727   "@
4728    {rlnm.|rlwnm.} %0,%1,%2,0xffff
4729    {rlinm.|rlwinm.} %0,%1,%h2,0xffff
4730    #
4731    #"
4732   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4733    (set_attr "length" "4,4,8,8")])
4734
4735 (define_split
4736   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4737         (compare:CC (zero_extend:SI
4738                      (subreg:HI
4739                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4740                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4741                     (const_int 0)))
4742    (set (match_operand:SI 0 "gpc_reg_operand" "")
4743         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4744   "reload_completed"
4745   [(set (match_dup 0)
4746         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4747    (set (match_dup 3)
4748         (compare:CC (match_dup 0)
4749                     (const_int 0)))]
4750   "")
4751
4752 ;; Note that we use "sle." instead of "sl." so that we can set
4753 ;; SHIFT_COUNT_TRUNCATED.
4754
4755 (define_expand "ashlsi3"
4756   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4757    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4758    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4759   ""
4760   "
4761 {
4762   if (TARGET_POWER)
4763     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4764   else
4765     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4766   DONE;
4767 }")
4768
4769 (define_insn "ashlsi3_power"
4770   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4771         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4772                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4773    (clobber (match_scratch:SI 3 "=q,X"))]
4774   "TARGET_POWER"
4775   "@
4776    sle %0,%1,%2
4777    {sli|slwi} %0,%1,%h2")
4778
4779 (define_insn "ashlsi3_no_power"
4780   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4781         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4782                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4783   "! TARGET_POWER"
4784   "@
4785    {sl|slw} %0,%1,%2
4786    {sli|slwi} %0,%1,%h2"
4787   [(set_attr "type" "var_shift_rotate,shift")])
4788
4789 (define_insn "*ashlsi3_64"
4790   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4791         (zero_extend:DI
4792             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4793                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4794   "TARGET_POWERPC64"
4795   "@
4796    {sl|slw} %0,%1,%2
4797    {sli|slwi} %0,%1,%h2"
4798   [(set_attr "type" "var_shift_rotate,shift")])
4799
4800 (define_insn ""
4801   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4802         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4803                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4804                     (const_int 0)))
4805    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4806    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4807   "TARGET_POWER"
4808   "@
4809    sle. %3,%1,%2
4810    {sli.|slwi.} %3,%1,%h2
4811    #
4812    #"
4813   [(set_attr "type" "delayed_compare")
4814    (set_attr "length" "4,4,8,8")])
4815
4816 (define_split
4817   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4818         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4819                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4820                     (const_int 0)))
4821    (clobber (match_scratch:SI 3 ""))
4822    (clobber (match_scratch:SI 4 ""))]
4823   "TARGET_POWER && reload_completed"
4824   [(parallel [(set (match_dup 3)
4825         (ashift:SI (match_dup 1) (match_dup 2)))
4826    (clobber (match_dup 4))])
4827    (set (match_dup 0)
4828         (compare:CC (match_dup 3)
4829                     (const_int 0)))]
4830   "")
4831
4832 (define_insn ""
4833   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4834         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4835                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4836                     (const_int 0)))
4837    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4838   "! TARGET_POWER && TARGET_32BIT"
4839   "@
4840    {sl.|slw.} %3,%1,%2
4841    {sli.|slwi.} %3,%1,%h2
4842    #
4843    #"
4844   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4845    (set_attr "length" "4,4,8,8")])
4846
4847 (define_split
4848   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4849         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4850                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4851                     (const_int 0)))
4852    (clobber (match_scratch:SI 3 ""))]
4853   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4854   [(set (match_dup 3)
4855         (ashift:SI (match_dup 1) (match_dup 2)))
4856    (set (match_dup 0)
4857         (compare:CC (match_dup 3)
4858                     (const_int 0)))]
4859   "")
4860
4861 (define_insn ""
4862   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4863         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4864                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4865                     (const_int 0)))
4866    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4867         (ashift:SI (match_dup 1) (match_dup 2)))
4868    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4869   "TARGET_POWER"
4870   "@
4871    sle. %0,%1,%2
4872    {sli.|slwi.} %0,%1,%h2
4873    #
4874    #"
4875   [(set_attr "type" "delayed_compare")
4876    (set_attr "length" "4,4,8,8")])
4877
4878 (define_split
4879   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4880         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4881                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4882                     (const_int 0)))
4883    (set (match_operand:SI 0 "gpc_reg_operand" "")
4884         (ashift:SI (match_dup 1) (match_dup 2)))
4885    (clobber (match_scratch:SI 4 ""))]
4886   "TARGET_POWER && reload_completed"
4887   [(parallel [(set (match_dup 0)
4888         (ashift:SI (match_dup 1) (match_dup 2)))
4889    (clobber (match_dup 4))])
4890    (set (match_dup 3)
4891         (compare:CC (match_dup 0)
4892                     (const_int 0)))]
4893   "")
4894
4895 (define_insn ""
4896   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4897         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4898                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4899                     (const_int 0)))
4900    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4901         (ashift:SI (match_dup 1) (match_dup 2)))]
4902   "! TARGET_POWER && TARGET_32BIT"
4903   "@
4904    {sl.|slw.} %0,%1,%2
4905    {sli.|slwi.} %0,%1,%h2
4906    #
4907    #"
4908   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4909    (set_attr "length" "4,4,8,8")])
4910
4911 (define_split
4912   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4913         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4914                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4915                     (const_int 0)))
4916    (set (match_operand:SI 0 "gpc_reg_operand" "")
4917         (ashift:SI (match_dup 1) (match_dup 2)))]
4918   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4919   [(set (match_dup 0)
4920         (ashift:SI (match_dup 1) (match_dup 2)))
4921    (set (match_dup 3)
4922         (compare:CC (match_dup 0)
4923                     (const_int 0)))]
4924   "")
4925
4926 (define_insn "rlwinm"
4927   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4928         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4929                            (match_operand:SI 2 "const_int_operand" "i"))
4930                 (match_operand:SI 3 "mask_operand" "n")))]
4931   "includes_lshift_p (operands[2], operands[3])"
4932   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4933
4934 (define_insn ""
4935   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4936         (compare:CC
4937          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4938                             (match_operand:SI 2 "const_int_operand" "i,i"))
4939                  (match_operand:SI 3 "mask_operand" "n,n"))
4940          (const_int 0)))
4941    (clobber (match_scratch:SI 4 "=r,r"))]
4942   "includes_lshift_p (operands[2], operands[3])"
4943   "@
4944    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4945    #"
4946   [(set_attr "type" "delayed_compare")
4947    (set_attr "length" "4,8")])
4948
4949 (define_split
4950   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4951         (compare:CC
4952          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4953                             (match_operand:SI 2 "const_int_operand" ""))
4954                  (match_operand:SI 3 "mask_operand" ""))
4955          (const_int 0)))
4956    (clobber (match_scratch:SI 4 ""))]
4957   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4958   [(set (match_dup 4)
4959         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4960                  (match_dup 3)))
4961    (set (match_dup 0)
4962         (compare:CC (match_dup 4)
4963                     (const_int 0)))]
4964   "")
4965
4966 (define_insn ""
4967   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4968         (compare:CC
4969          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4970                             (match_operand:SI 2 "const_int_operand" "i,i"))
4971                  (match_operand:SI 3 "mask_operand" "n,n"))
4972          (const_int 0)))
4973    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4974         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4975   "includes_lshift_p (operands[2], operands[3])"
4976   "@
4977    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4978    #"
4979   [(set_attr "type" "delayed_compare")
4980    (set_attr "length" "4,8")])
4981
4982 (define_split
4983   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4984         (compare:CC
4985          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4986                             (match_operand:SI 2 "const_int_operand" ""))
4987                  (match_operand:SI 3 "mask_operand" ""))
4988          (const_int 0)))
4989    (set (match_operand:SI 0 "gpc_reg_operand" "")
4990         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4991   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4992   [(set (match_dup 0)
4993         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4994    (set (match_dup 4)
4995         (compare:CC (match_dup 0)
4996                     (const_int 0)))]
4997   "")
4998
4999 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
5000 ;; "sli x,x,0".
5001 (define_expand "lshrsi3"
5002   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
5003    (use (match_operand:SI 1 "gpc_reg_operand" ""))
5004    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
5005   ""
5006   "
5007 {
5008   if (TARGET_POWER)
5009     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
5010   else
5011     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
5012   DONE;
5013 }")
5014
5015 (define_insn "lshrsi3_power"
5016   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
5017         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
5018                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
5019    (clobber (match_scratch:SI 3 "=q,X,X"))]
5020   "TARGET_POWER"
5021   "@
5022   sre %0,%1,%2
5023   mr %0,%1
5024   {s%A2i|s%A2wi} %0,%1,%h2")
5025
5026 (define_insn "lshrsi3_no_power"
5027   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
5028         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
5029                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
5030   "! TARGET_POWER"
5031   "@
5032   mr %0,%1
5033   {sr|srw} %0,%1,%2
5034   {sri|srwi} %0,%1,%h2"
5035   [(set_attr "type" "integer,var_shift_rotate,shift")])
5036
5037 (define_insn "*lshrsi3_64"
5038   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5039         (zero_extend:DI
5040             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5041                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5042   "TARGET_POWERPC64"
5043   "@
5044   {sr|srw} %0,%1,%2
5045   {sri|srwi} %0,%1,%h2"
5046   [(set_attr "type" "var_shift_rotate,shift")])
5047
5048 (define_insn ""
5049   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5050         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5051                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
5052                     (const_int 0)))
5053    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
5054    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
5055   "TARGET_POWER"
5056   "@
5057   sre. %3,%1,%2
5058   mr. %1,%1
5059   {s%A2i.|s%A2wi.} %3,%1,%h2
5060   #
5061   #
5062   #"
5063   [(set_attr "type" "delayed_compare")
5064    (set_attr "length" "4,4,4,8,8,8")])
5065
5066 (define_split
5067   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5068         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5069                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5070                     (const_int 0)))
5071    (clobber (match_scratch:SI 3 ""))
5072    (clobber (match_scratch:SI 4 ""))]
5073   "TARGET_POWER && reload_completed"
5074   [(parallel [(set (match_dup 3)
5075         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5076    (clobber (match_dup 4))])
5077    (set (match_dup 0)
5078         (compare:CC (match_dup 3)
5079                     (const_int 0)))]
5080   "")
5081
5082 (define_insn ""
5083   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5084         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5085                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
5086                     (const_int 0)))
5087    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
5088   "! TARGET_POWER && TARGET_32BIT"
5089   "@
5090    mr. %1,%1
5091    {sr.|srw.} %3,%1,%2
5092    {sri.|srwi.} %3,%1,%h2
5093    #
5094    #
5095    #"
5096   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5097    (set_attr "length" "4,4,4,8,8,8")])
5098
5099 (define_split
5100   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5101         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5102                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5103                     (const_int 0)))
5104    (clobber (match_scratch:SI 3 ""))]
5105   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5106   [(set (match_dup 3)
5107         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5108    (set (match_dup 0)
5109         (compare:CC (match_dup 3)
5110                     (const_int 0)))]
5111   "")
5112
5113 (define_insn ""
5114   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5115         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5116                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
5117                     (const_int 0)))
5118    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
5119         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5120    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
5121   "TARGET_POWER"
5122   "@
5123   sre. %0,%1,%2
5124   mr. %0,%1
5125   {s%A2i.|s%A2wi.} %0,%1,%h2
5126   #
5127   #
5128   #"
5129   [(set_attr "type" "delayed_compare")
5130    (set_attr "length" "4,4,4,8,8,8")])
5131
5132 (define_split
5133   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5134         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5135                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5136                     (const_int 0)))
5137    (set (match_operand:SI 0 "gpc_reg_operand" "")
5138         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5139    (clobber (match_scratch:SI 4 ""))]
5140   "TARGET_POWER && reload_completed"
5141   [(parallel [(set (match_dup 0)
5142         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5143    (clobber (match_dup 4))])
5144    (set (match_dup 3)
5145         (compare:CC (match_dup 0)
5146                     (const_int 0)))]
5147   "")
5148
5149 (define_insn ""
5150   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5151         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5152                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
5153                     (const_int 0)))
5154    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
5155         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
5156   "! TARGET_POWER && TARGET_32BIT"
5157   "@
5158    mr. %0,%1
5159    {sr.|srw.} %0,%1,%2
5160    {sri.|srwi.} %0,%1,%h2
5161    #
5162    #
5163    #"
5164   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5165    (set_attr "length" "4,4,4,8,8,8")])
5166
5167 (define_split
5168   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5169         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5170                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5171                     (const_int 0)))
5172    (set (match_operand:SI 0 "gpc_reg_operand" "")
5173         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
5174   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5175   [(set (match_dup 0)
5176         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5177    (set (match_dup 3)
5178         (compare:CC (match_dup 0)
5179                     (const_int 0)))]
5180   "")
5181
5182 (define_insn ""
5183   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5184         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5185                              (match_operand:SI 2 "const_int_operand" "i"))
5186                 (match_operand:SI 3 "mask_operand" "n")))]
5187   "includes_rshift_p (operands[2], operands[3])"
5188   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
5189
5190 (define_insn ""
5191   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5192         (compare:CC
5193          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5194                               (match_operand:SI 2 "const_int_operand" "i,i"))
5195                  (match_operand:SI 3 "mask_operand" "n,n"))
5196          (const_int 0)))
5197    (clobber (match_scratch:SI 4 "=r,r"))]
5198   "includes_rshift_p (operands[2], operands[3])"
5199   "@
5200    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
5201    #"
5202   [(set_attr "type" "delayed_compare")
5203    (set_attr "length" "4,8")])
5204
5205 (define_split
5206   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5207         (compare:CC
5208          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5209                               (match_operand:SI 2 "const_int_operand" ""))
5210                  (match_operand:SI 3 "mask_operand" ""))
5211          (const_int 0)))
5212    (clobber (match_scratch:SI 4 ""))]
5213   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
5214   [(set (match_dup 4)
5215         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
5216                  (match_dup 3)))
5217    (set (match_dup 0)
5218         (compare:CC (match_dup 4)
5219                     (const_int 0)))]
5220   "")
5221
5222 (define_insn ""
5223   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
5224         (compare:CC
5225          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5226                               (match_operand:SI 2 "const_int_operand" "i,i"))
5227                  (match_operand:SI 3 "mask_operand" "n,n"))
5228          (const_int 0)))
5229    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5230         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5231   "includes_rshift_p (operands[2], operands[3])"
5232   "@
5233    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
5234    #"
5235   [(set_attr "type" "delayed_compare")
5236    (set_attr "length" "4,8")])
5237
5238 (define_split
5239   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
5240         (compare:CC
5241          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5242                               (match_operand:SI 2 "const_int_operand" ""))
5243                  (match_operand:SI 3 "mask_operand" ""))
5244          (const_int 0)))
5245    (set (match_operand:SI 0 "gpc_reg_operand" "")
5246         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5247   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
5248   [(set (match_dup 0)
5249         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
5250    (set (match_dup 4)
5251         (compare:CC (match_dup 0)
5252                     (const_int 0)))]
5253   "")
5254
5255 (define_insn ""
5256   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5257         (zero_extend:SI
5258          (subreg:QI
5259           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5260                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
5261   "includes_rshift_p (operands[2], GEN_INT (255))"
5262   "{rlinm|rlwinm} %0,%1,%s2,0xff")
5263
5264 (define_insn ""
5265   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5266         (compare:CC
5267          (zero_extend:SI
5268           (subreg:QI
5269            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5270                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5271          (const_int 0)))
5272    (clobber (match_scratch:SI 3 "=r,r"))]
5273   "includes_rshift_p (operands[2], GEN_INT (255))"
5274   "@
5275    {rlinm.|rlwinm.} %3,%1,%s2,0xff
5276    #"
5277   [(set_attr "type" "delayed_compare")
5278    (set_attr "length" "4,8")])
5279
5280 (define_split
5281   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5282         (compare:CC
5283          (zero_extend:SI
5284           (subreg:QI
5285            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5286                         (match_operand:SI 2 "const_int_operand" "")) 0))
5287          (const_int 0)))
5288    (clobber (match_scratch:SI 3 ""))]
5289   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
5290   [(set (match_dup 3)
5291         (zero_extend:SI (subreg:QI
5292            (lshiftrt:SI (match_dup 1)
5293                         (match_dup 2)) 0)))
5294    (set (match_dup 0)
5295         (compare:CC (match_dup 3)
5296                     (const_int 0)))]
5297   "")
5298
5299 (define_insn ""
5300   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5301         (compare:CC
5302          (zero_extend:SI
5303           (subreg:QI
5304            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5305                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5306          (const_int 0)))
5307    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5308         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5309   "includes_rshift_p (operands[2], GEN_INT (255))"
5310   "@
5311    {rlinm.|rlwinm.} %0,%1,%s2,0xff
5312    #"
5313   [(set_attr "type" "delayed_compare")
5314    (set_attr "length" "4,8")])
5315
5316 (define_split
5317   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5318         (compare:CC
5319          (zero_extend:SI
5320           (subreg:QI
5321            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5322                         (match_operand:SI 2 "const_int_operand" "")) 0))
5323          (const_int 0)))
5324    (set (match_operand:SI 0 "gpc_reg_operand" "")
5325         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5326   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
5327   [(set (match_dup 0)
5328         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5329    (set (match_dup 3)
5330         (compare:CC (match_dup 0)
5331                     (const_int 0)))]
5332   "")
5333
5334 (define_insn ""
5335   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5336         (zero_extend:SI
5337          (subreg:HI
5338           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5339                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
5340   "includes_rshift_p (operands[2], GEN_INT (65535))"
5341   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
5342
5343 (define_insn ""
5344   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5345         (compare:CC
5346          (zero_extend:SI
5347           (subreg:HI
5348            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5349                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5350          (const_int 0)))
5351    (clobber (match_scratch:SI 3 "=r,r"))]
5352   "includes_rshift_p (operands[2], GEN_INT (65535))"
5353   "@
5354    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
5355    #"
5356   [(set_attr "type" "delayed_compare")
5357    (set_attr "length" "4,8")])
5358
5359 (define_split
5360   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5361         (compare:CC
5362          (zero_extend:SI
5363           (subreg:HI
5364            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5365                         (match_operand:SI 2 "const_int_operand" "")) 0))
5366          (const_int 0)))
5367    (clobber (match_scratch:SI 3 ""))]
5368   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5369   [(set (match_dup 3)
5370         (zero_extend:SI (subreg:HI
5371            (lshiftrt:SI (match_dup 1)
5372                         (match_dup 2)) 0)))
5373    (set (match_dup 0)
5374         (compare:CC (match_dup 3)
5375                     (const_int 0)))]
5376   "")
5377
5378 (define_insn ""
5379   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5380         (compare:CC
5381          (zero_extend:SI
5382           (subreg:HI
5383            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5384                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5385          (const_int 0)))
5386    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5387         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5388   "includes_rshift_p (operands[2], GEN_INT (65535))"
5389   "@
5390    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
5391    #"
5392   [(set_attr "type" "delayed_compare")
5393    (set_attr "length" "4,8")])
5394
5395 (define_split
5396   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5397         (compare:CC
5398          (zero_extend:SI
5399           (subreg:HI
5400            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5401                         (match_operand:SI 2 "const_int_operand" "")) 0))
5402          (const_int 0)))
5403    (set (match_operand:SI 0 "gpc_reg_operand" "")
5404         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5405   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5406   [(set (match_dup 0)
5407         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5408    (set (match_dup 3)
5409         (compare:CC (match_dup 0)
5410                     (const_int 0)))]
5411   "")
5412
5413 (define_insn ""
5414   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5415                          (const_int 1)
5416                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5417         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5418                      (const_int 31)))]
5419   "TARGET_POWER"
5420   "rrib %0,%1,%2")
5421
5422 (define_insn ""
5423   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5424                          (const_int 1)
5425                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5426         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5427                      (const_int 31)))]
5428   "TARGET_POWER"
5429   "rrib %0,%1,%2")
5430
5431 (define_insn ""
5432   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5433                          (const_int 1)
5434                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5435         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5436                          (const_int 1)
5437                          (const_int 0)))]
5438   "TARGET_POWER"
5439   "rrib %0,%1,%2")
5440
5441 (define_expand "ashrsi3"
5442   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5443         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5444                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
5445   ""
5446   "
5447 {
5448   if (TARGET_POWER)
5449     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
5450   else
5451     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
5452   DONE;
5453 }")
5454
5455 (define_insn "ashrsi3_power"
5456   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5457         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5458                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
5459    (clobber (match_scratch:SI 3 "=q,X"))]
5460   "TARGET_POWER"
5461   "@
5462    srea %0,%1,%2
5463    {srai|srawi} %0,%1,%h2"
5464   [(set_attr "type" "shift")])
5465
5466 (define_insn "ashrsi3_no_power"
5467   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5468         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5469                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
5470   "! TARGET_POWER"
5471   "@
5472    {sra|sraw} %0,%1,%2
5473    {srai|srawi} %0,%1,%h2"
5474   [(set_attr "type" "var_shift_rotate,shift")])
5475
5476 (define_insn "*ashrsi3_64"
5477   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5478         (sign_extend:DI
5479             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5480                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5481   "TARGET_POWERPC64"
5482   "@
5483    {sra|sraw} %0,%1,%2
5484    {srai|srawi} %0,%1,%h2"
5485   [(set_attr "type" "var_shift_rotate,shift")])
5486
5487 (define_insn ""
5488   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5489         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5490                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5491                     (const_int 0)))
5492    (clobber (match_scratch:SI 3 "=r,r,r,r"))
5493    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5494   "TARGET_POWER"
5495   "@
5496    srea. %3,%1,%2
5497    {srai.|srawi.} %3,%1,%h2
5498    #
5499    #"
5500   [(set_attr "type" "delayed_compare")
5501    (set_attr "length" "4,4,8,8")])
5502
5503 (define_split
5504   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5505         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5506                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5507                     (const_int 0)))
5508    (clobber (match_scratch:SI 3 ""))
5509    (clobber (match_scratch:SI 4 ""))]
5510   "TARGET_POWER && reload_completed"
5511   [(parallel [(set (match_dup 3)
5512         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5513    (clobber (match_dup 4))])
5514    (set (match_dup 0)
5515         (compare:CC (match_dup 3)
5516                     (const_int 0)))]
5517   "")
5518
5519 (define_insn ""
5520   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5521         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5522                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5523                     (const_int 0)))
5524    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
5525   "! TARGET_POWER"
5526   "@
5527    {sra.|sraw.} %3,%1,%2
5528    {srai.|srawi.} %3,%1,%h2
5529    #
5530    #"
5531   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5532    (set_attr "length" "4,4,8,8")])
5533
5534 (define_split
5535   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5536         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5537                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5538                     (const_int 0)))
5539    (clobber (match_scratch:SI 3 ""))]
5540   "! TARGET_POWER && reload_completed"
5541   [(set (match_dup 3)
5542         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5543    (set (match_dup 0)
5544         (compare:CC (match_dup 3)
5545                     (const_int 0)))]
5546   "")
5547
5548 (define_insn ""
5549   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5550         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5551                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5552                     (const_int 0)))
5553    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5554         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5555    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5556   "TARGET_POWER"
5557   "@
5558    srea. %0,%1,%2
5559    {srai.|srawi.} %0,%1,%h2
5560    #
5561    #"
5562   [(set_attr "type" "delayed_compare")
5563    (set_attr "length" "4,4,8,8")])
5564
5565 (define_split
5566   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5567         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5568                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5569                     (const_int 0)))
5570    (set (match_operand:SI 0 "gpc_reg_operand" "")
5571         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5572    (clobber (match_scratch:SI 4 ""))]
5573   "TARGET_POWER && reload_completed"
5574   [(parallel [(set (match_dup 0)
5575         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5576    (clobber (match_dup 4))])
5577    (set (match_dup 3)
5578         (compare:CC (match_dup 0)
5579                     (const_int 0)))]
5580   "")
5581
5582 (define_insn ""
5583   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5584         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5585                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5586                     (const_int 0)))
5587    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5588         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5589   "! TARGET_POWER"
5590   "@
5591    {sra.|sraw.} %0,%1,%2
5592    {srai.|srawi.} %0,%1,%h2
5593    #
5594    #"
5595   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5596    (set_attr "length" "4,4,8,8")])
5597 \f
5598 ;; Builtins to replace a division to generate FRE reciprocal estimate
5599 ;; instructions and the necessary fixup instructions
5600 (define_expand "recip<mode>3"
5601   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5602    (match_operand:RECIPF 1 "gpc_reg_operand" "")
5603    (match_operand:RECIPF 2 "gpc_reg_operand" "")]
5604   "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
5605 {
5606    rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
5607    DONE;
5608 })
5609
5610 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
5611 ;; hardware division.  This is only done before register allocation and with
5612 ;; -ffast-math.  This must appear before the divsf3/divdf3 insns.
5613 (define_split
5614   [(set (match_operand:RECIPF 0 "gpc_reg_operand" "")
5615         (div:RECIPF (match_operand 1 "gpc_reg_operand" "")
5616                     (match_operand 2 "gpc_reg_operand" "")))]
5617   "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
5618    && can_create_pseudo_p () && optimize_insn_for_speed_p ()
5619    && flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math"
5620   [(const_int 0)]
5621 {
5622   rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
5623   DONE;
5624 })
5625
5626 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
5627 ;; appropriate fixup.
5628 (define_expand "rsqrt<mode>2"
5629   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5630    (match_operand:RECIPF 1 "gpc_reg_operand" "")]
5631   "RS6000_RECIP_HAVE_RSQRT_P (<MODE>mode)"
5632 {
5633   rs6000_emit_swrsqrt (operands[0], operands[1]);
5634   DONE;
5635 })
5636 \f
5637 (define_split
5638   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5639         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5640                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5641                     (const_int 0)))
5642    (set (match_operand:SI 0 "gpc_reg_operand" "")
5643         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5644   "! TARGET_POWER && reload_completed"
5645   [(set (match_dup 0)
5646         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5647    (set (match_dup 3)
5648         (compare:CC (match_dup 0)
5649                     (const_int 0)))]
5650   "")
5651
5652 ;; Floating-point insns, excluding normal data motion.
5653 ;;
5654 ;; PowerPC has a full set of single-precision floating point instructions.
5655 ;;
5656 ;; For the POWER architecture, we pretend that we have both SFmode and
5657 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
5658 ;; The only conversions we will do will be when storing to memory.  In that
5659 ;; case, we will use the "frsp" instruction before storing.
5660 ;;
5661 ;; Note that when we store into a single-precision memory location, we need to
5662 ;; use the frsp insn first.  If the register being stored isn't dead, we
5663 ;; need a scratch register for the frsp.  But this is difficult when the store
5664 ;; is done by reload.  It is not incorrect to do the frsp on the register in
5665 ;; this case, we just lose precision that we would have otherwise gotten but
5666 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
5667
5668 (define_expand "extendsfdf2"
5669   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5670         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5671   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5672   "")
5673
5674 (define_insn_and_split "*extendsfdf2_fpr"
5675   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d")
5676         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
5677   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5678   "@
5679    #
5680    fmr %0,%1
5681    lfs%U1%X1 %0,%1"
5682   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5683   [(const_int 0)]
5684 {
5685   emit_note (NOTE_INSN_DELETED);
5686   DONE;
5687 }
5688   [(set_attr "type" "fp,fp,fpload")])
5689
5690 (define_expand "truncdfsf2"
5691   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5692         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5693   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5694   "")
5695
5696 (define_insn "*truncdfsf2_fpr"
5697   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5698         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5699   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5700   "frsp %0,%1"
5701   [(set_attr "type" "fp")])
5702
5703 (define_insn "aux_truncdfsf2"
5704   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5705         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
5706   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5707   "frsp %0,%1"
5708   [(set_attr "type" "fp")])
5709
5710 (define_expand "negsf2"
5711   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5712         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5713   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5714   "")
5715
5716 (define_insn "*negsf2"
5717   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5718         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5719   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5720   "fneg %0,%1"
5721   [(set_attr "type" "fp")])
5722
5723 (define_expand "abssf2"
5724   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5725         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5726   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5727   "")
5728
5729 (define_insn "*abssf2"
5730   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5731         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5732   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5733   "fabs %0,%1"
5734   [(set_attr "type" "fp")])
5735
5736 (define_insn ""
5737   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5738         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
5739   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5740   "fnabs %0,%1"
5741   [(set_attr "type" "fp")])
5742
5743 (define_expand "addsf3"
5744   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5745         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5746                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5747   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5748   "")
5749
5750 (define_insn ""
5751   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5752         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5753                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5754   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5755   "fadds %0,%1,%2"
5756   [(set_attr "type" "fp")
5757    (set_attr "fp_type" "fp_addsub_s")])
5758
5759 (define_insn ""
5760   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5761         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5762                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5763   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5764   "{fa|fadd} %0,%1,%2"
5765   [(set_attr "type" "fp")])
5766
5767 (define_expand "subsf3"
5768   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5769         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5770                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5771   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5772   "")
5773
5774 (define_insn ""
5775   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5776         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5777                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5778   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5779   "fsubs %0,%1,%2"
5780   [(set_attr "type" "fp")
5781    (set_attr "fp_type" "fp_addsub_s")])
5782
5783 (define_insn ""
5784   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5785         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5786                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5787   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5788   "{fs|fsub} %0,%1,%2"
5789   [(set_attr "type" "fp")])
5790
5791 (define_expand "mulsf3"
5792   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5793         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5794                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5795   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5796   "")
5797
5798 (define_insn ""
5799   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5800         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5801                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5802   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5803   "fmuls %0,%1,%2"
5804   [(set_attr "type" "fp")
5805    (set_attr "fp_type" "fp_mul_s")])
5806
5807 (define_insn ""
5808   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5809         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5810                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5811   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5812   "{fm|fmul} %0,%1,%2"
5813   [(set_attr "type" "dmul")])
5814
5815 (define_expand "divsf3"
5816   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5817         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5818                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5819   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5820   "")
5821
5822 (define_insn ""
5823   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5824         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5825                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5826   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS 
5827    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5828   "fdivs %0,%1,%2"
5829   [(set_attr "type" "sdiv")])
5830
5831 (define_insn ""
5832   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5833         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5834                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5835   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS 
5836    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5837   "{fd|fdiv} %0,%1,%2"
5838   [(set_attr "type" "ddiv")])
5839
5840 (define_insn "fres"
5841   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5842         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5843   "TARGET_FRES"
5844   "fres %0,%1"
5845   [(set_attr "type" "fp")])
5846
5847 ; builtin fmaf support
5848 ; If the user explicitly uses the fma builtin, don't convert this to
5849 ; (plus (mult op1 op2) op3)
5850 (define_expand "fmasf4"
5851   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5852         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "")
5853                 (match_operand:SF 2 "gpc_reg_operand" "")
5854                 (match_operand:SF 3 "gpc_reg_operand" "")))]
5855   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5856   "")
5857
5858 (define_insn "fmasf4_fpr"
5859   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5860         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5861                 (match_operand:SF 2 "gpc_reg_operand" "f")
5862                 (match_operand:SF 3 "gpc_reg_operand" "f")))]
5863   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5864   "*
5865 {
5866   return ((TARGET_POWERPC)
5867           ? \"fmadds %0,%1,%2,%3\"
5868           : \"{fma|fmadd} %0,%1,%2,%3\");
5869 }"
5870   [(set_attr "type" "fp")
5871    (set_attr "fp_type" "fp_maddsub_s")])
5872
5873 (define_insn "*fmssf4_fpr"
5874   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5875         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5876                 (match_operand:SF 2 "gpc_reg_operand" "f")
5877                 (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5878   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5879   "*
5880 {
5881   return ((TARGET_POWERPC)
5882           ? \"fmsubs %0,%1,%2,%3\"
5883           : \"{fms|fmsub} %0,%1,%2,%3\");
5884 }"
5885   [(set_attr "type" "fp")
5886    (set_attr "fp_type" "fp_maddsub_s")])
5887
5888 (define_insn "*fnmasf4_fpr"
5889   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5890         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5891                         (match_operand:SF 2 "gpc_reg_operand" "f")
5892                         (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5893   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5894   "*
5895 {
5896   return ((TARGET_POWERPC)
5897           ? \"fnmadds %0,%1,%2,%3\"
5898           : \"{fnma|fnmadd} %0,%1,%2,%3\");
5899 }"
5900   [(set_attr "type" "fp")
5901    (set_attr "fp_type" "fp_maddsub_s")])
5902
5903 (define_insn "*fnmssf4_fpr"
5904   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5905         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5906                         (match_operand:SF 2 "gpc_reg_operand" "f")
5907                         (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f")))))]
5908   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5909   "*
5910 {
5911   return ((TARGET_POWERPC)
5912           ? \"fnmsubs %0,%1,%2,%3\"
5913           : \"{fnms|fnmsub} %0,%1,%2,%3\");
5914 }"
5915   [(set_attr "type" "fp")
5916    (set_attr "fp_type" "fp_maddsub_s")])
5917
5918 ; Fused multiply/add ops created by the combiner
5919 (define_insn "*fmaddsf4_powerpc"
5920   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5921         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5922                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5923                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5924   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS
5925    && TARGET_SINGLE_FLOAT && TARGET_FUSED_MADD"
5926   "fmadds %0,%1,%2,%3"
5927   [(set_attr "type" "fp")
5928    (set_attr "fp_type" "fp_maddsub_s")])
5929  
5930 (define_insn "*fmaddsf4_power"
5931   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5932         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5933                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5934                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5935   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5936   "{fma|fmadd} %0,%1,%2,%3"
5937   [(set_attr "type" "dmul")])
5938
5939 (define_insn "*fmsubsf4_powerpc"
5940   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5941         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5942                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5943                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5944   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS
5945    && TARGET_SINGLE_FLOAT && TARGET_FUSED_MADD"
5946   "fmsubs %0,%1,%2,%3"
5947   [(set_attr "type" "fp")
5948    (set_attr "fp_type" "fp_maddsub_s")])
5949
5950 (define_insn "*fmsubsf4_power"
5951   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5952         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5953                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5954                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5955   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5956   "{fms|fmsub} %0,%1,%2,%3"
5957   [(set_attr "type" "dmul")])
5958
5959 (define_insn "*fnmaddsf4_powerpc_1"
5960   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5961         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5962                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5963                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5964   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5965    && TARGET_SINGLE_FLOAT"
5966   "fnmadds %0,%1,%2,%3"
5967   [(set_attr "type" "fp")
5968    (set_attr "fp_type" "fp_maddsub_s")])
5969
5970 (define_insn "*fnmaddsf4_powerpc_2"
5971   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5972         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5973                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5974                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5975   "TARGET_POWERPC && TARGET_SINGLE_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5976    && ! HONOR_SIGNED_ZEROS (SFmode)"
5977   "fnmadds %0,%1,%2,%3"
5978   [(set_attr "type" "fp")
5979    (set_attr "fp_type" "fp_maddsub_s")])
5980
5981 (define_insn "*fnmaddsf4_power_1"
5982   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5983         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5984                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5985                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5986   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5987   "{fnma|fnmadd} %0,%1,%2,%3"
5988   [(set_attr "type" "dmul")])
5989
5990 (define_insn "*fnmaddsf4_power_2"
5991   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5992         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5993                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5994                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5995   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5996    && ! HONOR_SIGNED_ZEROS (SFmode)"
5997   "{fnma|fnmadd} %0,%1,%2,%3"
5998   [(set_attr "type" "dmul")])
5999
6000 (define_insn "*fnmsubsf4_powerpc_1"
6001   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6002         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
6003                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
6004                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
6005   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
6006    && TARGET_SINGLE_FLOAT"
6007   "fnmsubs %0,%1,%2,%3"
6008   [(set_attr "type" "fp")
6009    (set_attr "fp_type" "fp_maddsub_s")])
6010
6011 (define_insn "*fnmsubsf4_powerpc_2"
6012   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6013         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
6014                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
6015                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
6016   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
6017    && TARGET_SINGLE_FLOAT && ! HONOR_SIGNED_ZEROS (SFmode)"
6018   "fnmsubs %0,%1,%2,%3"
6019   [(set_attr "type" "fp")
6020    (set_attr "fp_type" "fp_maddsub_s")])
6021
6022 (define_insn "*fnmsubsf4_power_1"
6023   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6024         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
6025                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
6026                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
6027   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
6028   "{fnms|fnmsub} %0,%1,%2,%3"
6029   [(set_attr "type" "dmul")])
6030
6031 (define_insn "*fnmsubsf4_power_2"
6032   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6033         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
6034                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
6035                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
6036   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
6037    && ! HONOR_SIGNED_ZEROS (SFmode)"
6038   "{fnms|fnmsub} %0,%1,%2,%3"
6039   [(set_attr "type" "dmul")])
6040
6041 (define_expand "sqrtsf2"
6042   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6043         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
6044   "(TARGET_PPC_GPOPT || TARGET_POWER2 || TARGET_XILINX_FPU)
6045    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6046    && !TARGET_SIMPLE_FPU"
6047   "")
6048
6049 (define_insn ""
6050   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6051         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
6052   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU) && TARGET_HARD_FLOAT
6053    && TARGET_FPRS && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
6054   "fsqrts %0,%1"
6055   [(set_attr "type" "ssqrt")])
6056
6057 (define_insn ""
6058   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6059         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
6060   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS 
6061    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
6062   "fsqrt %0,%1"
6063   [(set_attr "type" "dsqrt")])
6064
6065 (define_insn "*rsqrtsf_internal1"
6066   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6067         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
6068                    UNSPEC_RSQRT))]
6069   "TARGET_FRSQRTES"
6070   "frsqrtes %0,%1"
6071   [(set_attr "type" "fp")])
6072
6073 (define_expand "copysign<mode>3"
6074   [(set (match_dup 3)
6075         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))
6076    (set (match_dup 4)
6077         (neg:SFDF (abs:SFDF (match_dup 1))))
6078    (set (match_operand:SFDF 0 "gpc_reg_operand" "")
6079         (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand" "")
6080                                (match_dup 5))
6081                          (match_dup 3)
6082                          (match_dup 4)))]
6083   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
6084    && ((TARGET_PPC_GFXOPT
6085         && !HONOR_NANS (<MODE>mode)
6086         && !HONOR_SIGNED_ZEROS (<MODE>mode))
6087        || TARGET_CMPB
6088        || VECTOR_UNIT_VSX_P (<MODE>mode))"
6089 {
6090   if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
6091     {
6092       emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
6093                                              operands[2]));
6094       DONE;
6095     }
6096
6097    operands[3] = gen_reg_rtx (<MODE>mode);
6098    operands[4] = gen_reg_rtx (<MODE>mode);
6099    operands[5] = CONST0_RTX (<MODE>mode);
6100   })
6101
6102 ;; Use an unspec rather providing an if-then-else in RTL, to prevent the
6103 ;; compiler from optimizing -0.0
6104 (define_insn "copysign<mode>3_fcpsgn"
6105   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6106         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")
6107                       (match_operand:SFDF 2 "gpc_reg_operand" "<rreg2>")]
6108                      UNSPEC_COPYSIGN))]
6109   "TARGET_CMPB && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6110   "fcpsgn %0,%2,%1"
6111   [(set_attr "type" "fp")])
6112
6113 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
6114 ;; fsel instruction and some auxiliary computations.  Then we just have a
6115 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
6116 ;; combine.
6117 (define_expand "smaxsf3"
6118   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6119         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
6120                              (match_operand:SF 2 "gpc_reg_operand" ""))
6121                          (match_dup 1)
6122                          (match_dup 2)))]
6123   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6124    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6125   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
6126
6127 (define_expand "sminsf3"
6128   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6129         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
6130                              (match_operand:SF 2 "gpc_reg_operand" ""))
6131                          (match_dup 2)
6132                          (match_dup 1)))]
6133   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6134    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6135   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
6136
6137 (define_split
6138   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6139         (match_operator:SF 3 "min_max_operator"
6140          [(match_operand:SF 1 "gpc_reg_operand" "")
6141           (match_operand:SF 2 "gpc_reg_operand" "")]))]
6142   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6143    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6144   [(const_int 0)]
6145   "
6146 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
6147                       operands[1], operands[2]);
6148   DONE;
6149 }")
6150
6151 (define_expand "mov<mode>cc"
6152    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
6153          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
6154                            (match_operand:GPR 2 "gpc_reg_operand" "")
6155                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
6156   "TARGET_ISEL<sel>"
6157   "
6158 {
6159   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6160     DONE;
6161   else
6162     FAIL;
6163 }")
6164
6165 ;; We use the BASE_REGS for the isel input operands because, if rA is
6166 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
6167 ;; because we may switch the operands and rB may end up being rA.
6168 ;;
6169 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
6170 ;; leave out the mode in operand 4 and use one pattern, but reload can
6171 ;; change the mode underneath our feet and then gets confused trying
6172 ;; to reload the value.
6173 (define_insn "isel_signed_<mode>"
6174   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
6175         (if_then_else:GPR
6176          (match_operator 1 "scc_comparison_operator"
6177                          [(match_operand:CC 4 "cc_reg_operand" "y,y")
6178                           (const_int 0)])
6179          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
6180          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
6181   "TARGET_ISEL<sel>"
6182   "*
6183 { return output_isel (operands); }"
6184   [(set_attr "type" "isel")
6185    (set_attr "length" "4")])
6186
6187 (define_insn "isel_unsigned_<mode>"
6188   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
6189         (if_then_else:GPR
6190          (match_operator 1 "scc_comparison_operator"
6191                          [(match_operand:CCUNS 4 "cc_reg_operand" "y,y")
6192                           (const_int 0)])
6193          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
6194          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
6195   "TARGET_ISEL<sel>"
6196   "*
6197 { return output_isel (operands); }"
6198   [(set_attr "type" "isel")
6199    (set_attr "length" "4")])
6200
6201 ;; These patterns can be useful for combine; they let combine know that
6202 ;; isel can handle reversed comparisons so long as the operands are
6203 ;; registers.
6204
6205 (define_insn "*isel_reversed_signed_<mode>"
6206   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
6207         (if_then_else:GPR
6208          (match_operator 1 "scc_rev_comparison_operator"
6209                          [(match_operand:CC 4 "cc_reg_operand" "y")
6210                           (const_int 0)])
6211          (match_operand:GPR 2 "gpc_reg_operand" "b")
6212          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
6213   "TARGET_ISEL<sel>"
6214   "*
6215 { return output_isel (operands); }"
6216   [(set_attr "type" "isel")
6217    (set_attr "length" "4")])
6218
6219 (define_insn "*isel_reversed_unsigned_<mode>"
6220   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
6221         (if_then_else:GPR
6222          (match_operator 1 "scc_rev_comparison_operator"
6223                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
6224                           (const_int 0)])
6225          (match_operand:GPR 2 "gpc_reg_operand" "b")
6226          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
6227   "TARGET_ISEL<sel>"
6228   "*
6229 { return output_isel (operands); }"
6230   [(set_attr "type" "isel")
6231    (set_attr "length" "4")])
6232
6233 (define_expand "movsfcc"
6234    [(set (match_operand:SF 0 "gpc_reg_operand" "")
6235          (if_then_else:SF (match_operand 1 "comparison_operator" "")
6236                           (match_operand:SF 2 "gpc_reg_operand" "")
6237                           (match_operand:SF 3 "gpc_reg_operand" "")))]
6238   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6239   "
6240 {
6241   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6242     DONE;
6243   else
6244     FAIL;
6245 }")
6246
6247 (define_insn "*fselsfsf4"
6248   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6249         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
6250                              (match_operand:SF 4 "zero_fp_constant" "F"))
6251                          (match_operand:SF 2 "gpc_reg_operand" "f")
6252                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
6253   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6254   "fsel %0,%1,%2,%3"
6255   [(set_attr "type" "fp")])
6256
6257 (define_insn "*fseldfsf4"
6258   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6259         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
6260                              (match_operand:DF 4 "zero_fp_constant" "F"))
6261                          (match_operand:SF 2 "gpc_reg_operand" "f")
6262                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
6263   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
6264   "fsel %0,%1,%2,%3"
6265   [(set_attr "type" "fp")])
6266
6267 (define_expand "negdf2"
6268   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6269         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6270   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6271   "")
6272
6273 (define_insn "*negdf2_fpr"
6274   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6275         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6276   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6277    && !VECTOR_UNIT_VSX_P (DFmode)"
6278   "fneg %0,%1"
6279   [(set_attr "type" "fp")])
6280
6281 (define_expand "absdf2"
6282   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6283         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6284   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6285   "")
6286
6287 (define_insn "*absdf2_fpr"
6288   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6289         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6290   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6291    && !VECTOR_UNIT_VSX_P (DFmode)"
6292   "fabs %0,%1"
6293   [(set_attr "type" "fp")])
6294
6295 (define_insn "*nabsdf2_fpr"
6296   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6297         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d"))))]
6298   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6299    && !VECTOR_UNIT_VSX_P (DFmode)"
6300   "fnabs %0,%1"
6301   [(set_attr "type" "fp")])
6302
6303 (define_expand "adddf3"
6304   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6305         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
6306                  (match_operand:DF 2 "gpc_reg_operand" "")))]
6307   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6308   "")
6309
6310 (define_insn "*adddf3_fpr"
6311   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6312         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6313                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
6314   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6315    && !VECTOR_UNIT_VSX_P (DFmode)"
6316   "{fa|fadd} %0,%1,%2"
6317   [(set_attr "type" "fp")
6318    (set_attr "fp_type" "fp_addsub_d")])
6319
6320 (define_expand "subdf3"
6321   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6322         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
6323                   (match_operand:DF 2 "gpc_reg_operand" "")))]
6324   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6325   "")
6326
6327 (define_insn "*subdf3_fpr"
6328   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6329         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "d")
6330                   (match_operand:DF 2 "gpc_reg_operand" "d")))]
6331   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6332    && !VECTOR_UNIT_VSX_P (DFmode)"
6333   "{fs|fsub} %0,%1,%2"
6334   [(set_attr "type" "fp")
6335    (set_attr "fp_type" "fp_addsub_d")])
6336
6337 (define_expand "muldf3"
6338   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6339         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
6340                  (match_operand:DF 2 "gpc_reg_operand" "")))]
6341   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6342   "")
6343
6344 (define_insn "*muldf3_fpr"
6345   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6346         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6347                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
6348   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6349    && !VECTOR_UNIT_VSX_P (DFmode)"
6350   "{fm|fmul} %0,%1,%2"
6351   [(set_attr "type" "dmul")
6352    (set_attr "fp_type" "fp_mul_d")])
6353
6354 (define_expand "divdf3"
6355   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6356         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
6357                 (match_operand:DF 2 "gpc_reg_operand" "")))]
6358   "TARGET_HARD_FLOAT
6359    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)
6360    && !TARGET_SIMPLE_FPU"
6361   "")
6362
6363 (define_insn "*divdf3_fpr"
6364   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6365         (div:DF (match_operand:DF 1 "gpc_reg_operand" "d")
6366                 (match_operand:DF 2 "gpc_reg_operand" "d")))]
6367   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && !TARGET_SIMPLE_FPU
6368    && !VECTOR_UNIT_VSX_P (DFmode)"
6369   "{fd|fdiv} %0,%1,%2"
6370   [(set_attr "type" "ddiv")])
6371
6372 (define_insn "*fred_fpr"
6373   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6374         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
6375   "TARGET_FRE && !VECTOR_UNIT_VSX_P (DFmode)"
6376   "fre %0,%1"
6377   [(set_attr "type" "fp")])
6378
6379 (define_insn "*rsqrtdf_internal1"
6380   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6381         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")]
6382                    UNSPEC_RSQRT))]
6383   "TARGET_FRSQRTE && !VECTOR_UNIT_VSX_P (DFmode)"
6384   "frsqrte %0,%1"
6385   [(set_attr "type" "fp")])
6386
6387 ; builtin fma support
6388 ; If the user explicitly uses the fma builtin, don't convert this to
6389 ; (plus (mult op1 op2) op3)
6390 (define_expand "fmadf4"
6391   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6392         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "")
6393                 (match_operand:DF 2 "gpc_reg_operand" "")
6394                 (match_operand:DF 3 "gpc_reg_operand" "")))]
6395   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6396   "")
6397
6398 (define_insn "fmadf4_fpr"
6399   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6400         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
6401                 (match_operand:DF 2 "gpc_reg_operand" "f")
6402                 (match_operand:DF 3 "gpc_reg_operand" "f")))]
6403   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6404    && VECTOR_UNIT_NONE_P (DFmode)"
6405   "{fma|fmadd} %0,%1,%2,%3"
6406   [(set_attr "type" "fp")
6407    (set_attr "fp_type" "fp_maddsub_s")])
6408
6409 (define_insn "*fmsdf4_fpr"
6410   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6411         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
6412                 (match_operand:DF 2 "gpc_reg_operand" "f")
6413                 (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f"))))]
6414   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6415    && VECTOR_UNIT_NONE_P (DFmode)"
6416   "{fms|fmsub} %0,%1,%2,%3"
6417   [(set_attr "type" "fp")
6418    (set_attr "fp_type" "fp_maddsub_s")])
6419
6420 (define_insn "*fnmadf4_fpr"
6421   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6422         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
6423                         (match_operand:DF 2 "gpc_reg_operand" "f")
6424                         (match_operand:DF 3 "gpc_reg_operand" "f"))))]
6425   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6426    && VECTOR_UNIT_NONE_P (DFmode)"
6427   "{fnma|fnmadd} %0,%1,%2,%3"
6428   [(set_attr "type" "fp")
6429    (set_attr "fp_type" "fp_maddsub_s")])
6430
6431 (define_insn "*fnmsdf4_fpr"
6432   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6433         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
6434                         (match_operand:DF 2 "gpc_reg_operand" "f")
6435                         (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f")))))]
6436   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6437    && VECTOR_UNIT_NONE_P (DFmode)"
6438   "{fnms|fnmsub} %0,%1,%2,%3"
6439   [(set_attr "type" "fp")
6440    (set_attr "fp_type" "fp_maddsub_s")])
6441
6442 ; Fused multiply/add ops created by the combiner
6443 (define_insn "*fmadddf4_fpr"
6444   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6445         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6446                           (match_operand:DF 2 "gpc_reg_operand" "d"))
6447                  (match_operand:DF 3 "gpc_reg_operand" "d")))]
6448   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6449    && VECTOR_UNIT_NONE_P (DFmode)"
6450   "{fma|fmadd} %0,%1,%2,%3"
6451   [(set_attr "type" "dmul")
6452    (set_attr "fp_type" "fp_maddsub_d")])
6453
6454 (define_insn "*fmsubdf4_fpr"
6455   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6456         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6457                            (match_operand:DF 2 "gpc_reg_operand" "d"))
6458                   (match_operand:DF 3 "gpc_reg_operand" "d")))]
6459   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6460    && VECTOR_UNIT_NONE_P (DFmode)"
6461   "{fms|fmsub} %0,%1,%2,%3"
6462   [(set_attr "type" "dmul")
6463    (set_attr "fp_type" "fp_maddsub_d")])
6464
6465 (define_insn "*fnmadddf4_fpr_1"
6466   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6467         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6468                                   (match_operand:DF 2 "gpc_reg_operand" "d"))
6469                          (match_operand:DF 3 "gpc_reg_operand" "d"))))]
6470   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6471    && VECTOR_UNIT_NONE_P (DFmode)"
6472   "{fnma|fnmadd} %0,%1,%2,%3"
6473   [(set_attr "type" "dmul")
6474    (set_attr "fp_type" "fp_maddsub_d")])
6475
6476 (define_insn "*fnmadddf4_fpr_2"
6477   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6478         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d"))
6479                            (match_operand:DF 2 "gpc_reg_operand" "d"))
6480                   (match_operand:DF 3 "gpc_reg_operand" "d")))]
6481   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6482    && ! HONOR_SIGNED_ZEROS (DFmode) && VECTOR_UNIT_NONE_P (DFmode)"
6483   "{fnma|fnmadd} %0,%1,%2,%3"
6484   [(set_attr "type" "dmul")
6485    (set_attr "fp_type" "fp_maddsub_d")])
6486
6487 (define_insn "*fnmsubdf4_fpr_1"
6488   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6489         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6490                                    (match_operand:DF 2 "gpc_reg_operand" "d"))
6491                           (match_operand:DF 3 "gpc_reg_operand" "d"))))]
6492   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6493    && VECTOR_UNIT_NONE_P (DFmode)"
6494   "{fnms|fnmsub} %0,%1,%2,%3"
6495   [(set_attr "type" "dmul")
6496    (set_attr "fp_type" "fp_maddsub_d")])
6497
6498 (define_insn "*fnmsubdf4_fpr_2"
6499   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6500         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "d")
6501                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6502                            (match_operand:DF 2 "gpc_reg_operand" "d"))))]
6503   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD && TARGET_DOUBLE_FLOAT
6504    && ! HONOR_SIGNED_ZEROS (DFmode) && VECTOR_UNIT_NONE_P (DFmode)"
6505   "{fnms|fnmsub} %0,%1,%2,%3"
6506   [(set_attr "type" "dmul")
6507    (set_attr "fp_type" "fp_maddsub_d")])
6508
6509 (define_expand "sqrtdf2"
6510   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6511         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6512   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS 
6513    && TARGET_DOUBLE_FLOAT"
6514   "")
6515
6516 (define_insn "*sqrtdf2_fpr"
6517   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6518         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6519   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS 
6520    && TARGET_DOUBLE_FLOAT
6521    && !VECTOR_UNIT_VSX_P (DFmode)"
6522   "fsqrt %0,%1"
6523   [(set_attr "type" "dsqrt")])
6524
6525 ;; The conditional move instructions allow us to perform max and min
6526 ;; operations even when
6527
6528 (define_expand "smaxdf3"
6529   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6530         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
6531                              (match_operand:DF 2 "gpc_reg_operand" ""))
6532                          (match_dup 1)
6533                          (match_dup 2)))]
6534   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6535    && !flag_trapping_math"
6536   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
6537
6538 (define_expand "smindf3"
6539   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6540         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
6541                              (match_operand:DF 2 "gpc_reg_operand" ""))
6542                          (match_dup 2)
6543                          (match_dup 1)))]
6544   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6545    && !flag_trapping_math"
6546   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
6547
6548 (define_split
6549   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6550         (match_operator:DF 3 "min_max_operator"
6551          [(match_operand:DF 1 "gpc_reg_operand" "")
6552           (match_operand:DF 2 "gpc_reg_operand" "")]))]
6553   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6554    && !flag_trapping_math"
6555   [(const_int 0)]
6556   "
6557 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
6558                       operands[1], operands[2]);
6559   DONE;
6560 }")
6561
6562 (define_expand "movdfcc"
6563    [(set (match_operand:DF 0 "gpc_reg_operand" "")
6564          (if_then_else:DF (match_operand 1 "comparison_operator" "")
6565                           (match_operand:DF 2 "gpc_reg_operand" "")
6566                           (match_operand:DF 3 "gpc_reg_operand" "")))]
6567   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6568   "
6569 {
6570   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6571     DONE;
6572   else
6573     FAIL;
6574 }")
6575
6576 (define_insn "*fseldfdf4"
6577   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6578         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
6579                              (match_operand:DF 4 "zero_fp_constant" "F"))
6580                          (match_operand:DF 2 "gpc_reg_operand" "d")
6581                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
6582   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6583   "fsel %0,%1,%2,%3"
6584   [(set_attr "type" "fp")])
6585
6586 (define_insn "*fselsfdf4"
6587   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6588         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
6589                              (match_operand:SF 4 "zero_fp_constant" "F"))
6590                          (match_operand:DF 2 "gpc_reg_operand" "d")
6591                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
6592   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
6593   "fsel %0,%1,%2,%3"
6594   [(set_attr "type" "fp")])
6595 \f
6596 ;; Conversions to and from floating-point.
6597
6598 ; We don't define lfiwax/lfiwzx with the normal definition, because we
6599 ; don't want to support putting SImode in FPR registers.
6600 (define_insn "lfiwax"
6601   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6602         (unspec:DI [(match_operand:SI 1 "indexed_or_indirect_operand" "Z")]
6603                    UNSPEC_LFIWAX))]
6604   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX"
6605   "lfiwax %0,%y1"
6606   [(set_attr "type" "fpload")])
6607
6608 (define_insn_and_split "floatsi<mode>2_lfiwax"
6609   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>,<rreg2>")
6610         (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "Z,r")))
6611    (clobber (match_operand:SI 2 "indexed_or_indirect_operand" "=Z,Z"))
6612    (clobber (match_operand:DI 3 "gpc_reg_operand" "=d,d"))]
6613   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
6614    && <SI_CONVERT_FP>"
6615   "#"
6616   "MEM_P (operands[1]) || reload_completed"
6617   [(pc)]
6618   "
6619 {
6620   if (MEM_P (operands[1]))
6621     {
6622       operands[1] = rs6000_address_for_fpconvert (operands[1]);
6623       emit_insn (gen_lfiwax (operands[3], operands[1]));
6624     }
6625   else
6626     {
6627       emit_move_insn (operands[2], operands[1]);
6628       emit_insn (gen_lfiwax (operands[3], operands[2]));
6629     }
6630   emit_insn (gen_floatdi<mode>2 (operands[0], operands[3]));
6631   DONE;
6632 }"
6633   [(set_attr "length" "8,12")])
6634
6635 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
6636   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6637         (float:SFDF (match_operand:SI 1 "memory_operand" "Z")))
6638    (clobber (match_scratch:DI 2 "=d"))]
6639   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
6640    && <SI_CONVERT_FP>"
6641   "#"
6642   "&& reload_completed"
6643   [(pc)]
6644   "
6645 {
6646   emit_insn (gen_lfiwax (operands[2], operands[1]));
6647   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
6648   DONE;
6649 }"
6650   [(set_attr "length" "8")])
6651
6652 (define_insn_and_split "floatsi<mode>2_lfiwax_mem2"
6653   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6654         (float:SFDF
6655          (sign_extend:DI
6656           (match_operand:SI 1 "memory_operand" "Z"))))
6657    (clobber (match_scratch:DI 2 "=d"))]
6658   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
6659    && <SI_CONVERT_FP>"
6660   "#"
6661   "&& reload_completed"
6662   [(pc)]
6663   "
6664 {
6665   emit_insn (gen_lfiwax (operands[2], operands[1]));
6666   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
6667   DONE;
6668 }"
6669   [(set_attr "length" "8")])
6670
6671 (define_insn "lfiwzx"
6672   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6673         (unspec:DI [(match_operand:SI 1 "indexed_or_indirect_operand" "Z")]
6674                    UNSPEC_LFIWZX))]
6675   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX"
6676   "lfiwzx %0,%y1"
6677   [(set_attr "type" "fpload")])
6678
6679 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
6680   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>,<rreg2>")
6681         (unsigned_float:SFDF (match_operand:SI 1 "gpc_reg_operand" "Z,r")))
6682    (clobber (match_operand:SI 2 "indexed_or_indirect_operand" "=Z,Z"))
6683    (clobber (match_operand:DI 3 "gpc_reg_operand" "=d,d"))]
6684   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
6685    && <SI_CONVERT_FP>"
6686   "#"
6687   "MEM_P (operands[1]) || reload_completed"
6688   [(pc)]
6689   "
6690 {
6691   if (MEM_P (operands[1]))
6692     {
6693       operands[1] = rs6000_address_for_fpconvert (operands[1]);
6694       emit_insn (gen_lfiwzx (operands[3], operands[1]));
6695     }
6696   else
6697     {
6698       emit_move_insn (operands[2], operands[1]);
6699       emit_insn (gen_lfiwzx (operands[3], operands[2]));
6700     }
6701   emit_insn (gen_floatdi<mode>2 (operands[0], operands[3]));
6702   DONE;
6703 }"
6704   [(set_attr "length" "8,12")])
6705
6706 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
6707   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6708         (unsigned_float:SFDF (match_operand:SI 1 "memory_operand" "Z")))
6709    (clobber (match_scratch:DI 2 "=d"))]
6710   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
6711    && <SI_CONVERT_FP>"
6712   "#"
6713   "&& reload_completed"
6714   [(pc)]
6715   "
6716 {
6717   emit_insn (gen_lfiwzx (operands[2], operands[1]));
6718   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
6719   DONE;
6720 }"
6721   [(set_attr "length" "8")])
6722
6723 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem2"
6724   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6725         (unsigned_float:SFDF
6726          (zero_extend:DI
6727           (match_operand:SI 1 "memory_operand" "Z"))))
6728    (clobber (match_scratch:DI 2 "=d"))]
6729   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
6730    && <SI_CONVERT_FP>"
6731   "#"
6732   "&& reload_completed"
6733   [(pc)]
6734   "
6735 {
6736   emit_insn (gen_lfiwzx (operands[2], operands[1]));
6737   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
6738   DONE;
6739 }"
6740   [(set_attr "length" "8")])
6741
6742 ; For each of these conversions, there is a define_expand, a define_insn
6743 ; with a '#' template, and a define_split (with C code).  The idea is
6744 ; to allow constant folding with the template of the define_insn,
6745 ; then to have the insns split later (between sched1 and final).
6746
6747 (define_expand "floatsidf2"
6748   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
6749                    (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
6750               (use (match_dup 2))
6751               (use (match_dup 3))
6752               (clobber (match_dup 4))
6753               (clobber (match_dup 5))
6754               (clobber (match_dup 6))])]
6755   "TARGET_HARD_FLOAT 
6756    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6757   "
6758 {
6759   if (TARGET_E500_DOUBLE)
6760     {
6761       if (!REG_P (operands[1]))
6762         operands[1] = force_reg (SImode, operands[1]);
6763       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
6764       DONE;
6765     }
6766   else if (TARGET_LFIWAX && TARGET_FCFID)
6767     {
6768       rs6000_expand_convert_si_to_sfdf (operands[0], operands[1], false);
6769       DONE;
6770     }
6771   else if (TARGET_FCFID)
6772     {
6773       rtx dreg = operands[1];
6774       if (!REG_P (dreg))
6775         dreg = force_reg (SImode, dreg);
6776       dreg = convert_to_mode (DImode, dreg, false);
6777       emit_insn (gen_floatdidf2 (operands[0], dreg));
6778       DONE;
6779     }
6780
6781   if (!REG_P (operands[1]))
6782     operands[1] = force_reg (SImode, operands[1]);
6783   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6784   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
6785   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
6786   operands[5] = gen_reg_rtx (DFmode);
6787   operands[6] = gen_reg_rtx (SImode);
6788 }")
6789
6790 (define_insn_and_split "*floatsidf2_internal"
6791   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6792         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6793    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6794    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6795    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6796    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
6797    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
6798   "! TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6799   "#"
6800   ""
6801   [(pc)]
6802   "
6803 {
6804   rtx lowword, highword;
6805   gcc_assert (MEM_P (operands[4]));
6806   highword = adjust_address (operands[4], SImode, 0);
6807   lowword = adjust_address (operands[4], SImode, 4);
6808   if (! WORDS_BIG_ENDIAN)
6809     {
6810       rtx tmp;
6811       tmp = highword; highword = lowword; lowword = tmp;
6812     }
6813
6814   emit_insn (gen_xorsi3 (operands[6], operands[1],
6815                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
6816   emit_move_insn (lowword, operands[6]);
6817   emit_move_insn (highword, operands[2]);
6818   emit_move_insn (operands[5], operands[4]);
6819   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6820   DONE;
6821 }"
6822   [(set_attr "length" "24")])
6823
6824 ;; If we don't have a direct conversion to single precision, don't enable this
6825 ;; conversion for 32-bit without fast math, because we don't have the insn to
6826 ;; generate the fixup swizzle to avoid double rounding problems.
6827 (define_expand "floatunssisf2"
6828   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6829         (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
6830   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
6831    && (!TARGET_FPRS
6832        || (TARGET_FPRS
6833            && ((TARGET_FCFIDUS && TARGET_LFIWZX)
6834                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
6835                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
6836   "
6837 {
6838   if (!TARGET_FPRS)
6839     {
6840       if (!REG_P (operands[1]))
6841         operands[1] = force_reg (SImode, operands[1]);
6842     }
6843   else if (TARGET_LFIWZX && TARGET_FCFIDUS)
6844     {
6845       rs6000_expand_convert_si_to_sfdf (operands[0], operands[1], true);
6846       DONE;
6847     }
6848   else
6849     {
6850       rtx dreg = operands[1];
6851       if (!REG_P (dreg))
6852         dreg = force_reg (SImode, dreg);
6853       dreg = convert_to_mode (DImode, dreg, true);
6854       emit_insn (gen_floatdisf2 (operands[0], dreg));
6855       DONE;
6856     }
6857 }")
6858
6859 (define_expand "floatunssidf2"
6860   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
6861                    (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
6862               (use (match_dup 2))
6863               (use (match_dup 3))
6864               (clobber (match_dup 4))
6865               (clobber (match_dup 5))])]
6866   "TARGET_HARD_FLOAT
6867    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6868   "
6869 {
6870   if (TARGET_E500_DOUBLE)
6871     {
6872       if (!REG_P (operands[1]))
6873         operands[1] = force_reg (SImode, operands[1]);
6874       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
6875       DONE;
6876     }
6877   else if (TARGET_LFIWZX && TARGET_FCFID)
6878     {
6879        rs6000_expand_convert_si_to_sfdf (operands[0], operands[1], true);
6880        DONE;
6881     }
6882   else if (TARGET_FCFID)
6883     {
6884       rtx dreg = operands[1];
6885       if (!REG_P (dreg))
6886         dreg = force_reg (SImode, dreg);
6887       dreg = convert_to_mode (DImode, dreg, true);
6888       emit_insn (gen_floatdidf2 (operands[0], dreg));
6889       DONE;
6890     }
6891
6892   if (!REG_P (operands[1]))
6893     operands[1] = force_reg (SImode, operands[1]);
6894   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6895   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
6896   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
6897   operands[5] = gen_reg_rtx (DFmode);
6898 }")
6899
6900 (define_insn_and_split "*floatunssidf2_internal"
6901   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6902         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6903    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6904    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6905    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6906    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
6907   "! TARGET_FCFIDU && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6908    && !(TARGET_FCFID && TARGET_POWERPC64)"
6909   "#"
6910   ""
6911   [(pc)]
6912   "
6913 {
6914   rtx lowword, highword;
6915   gcc_assert (MEM_P (operands[4]));
6916   highword = adjust_address (operands[4], SImode, 0);
6917   lowword = adjust_address (operands[4], SImode, 4);
6918   if (! WORDS_BIG_ENDIAN)
6919     {
6920       rtx tmp;
6921       tmp = highword; highword = lowword; lowword = tmp;
6922     }
6923
6924   emit_move_insn (lowword, operands[1]);
6925   emit_move_insn (highword, operands[2]);
6926   emit_move_insn (operands[5], operands[4]);
6927   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6928   DONE;
6929 }"
6930   [(set_attr "length" "20")])
6931
6932 (define_expand "fix_trunc<mode>si2"
6933   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6934         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6935   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT
6936    && ((TARGET_FPRS && <TARGET_FLOAT>) || <E500_CONVERT>)"
6937   "
6938 {
6939   if (!<E500_CONVERT>)
6940     {
6941       rtx tmp, stack;
6942
6943       if (TARGET_STFIWX)
6944         {
6945           tmp = gen_reg_rtx (DImode);
6946           stack = rs6000_allocate_stack_temp (SImode, false, true);
6947           emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], operands[1],
6948                                                     tmp, stack));
6949         }
6950       else
6951         {
6952           tmp = gen_reg_rtx (DImode);
6953           stack = rs6000_allocate_stack_temp (DImode, true, false);
6954           emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], operands[1],
6955                                                       tmp, stack));
6956         }
6957       DONE;
6958     }
6959 }")
6960
6961 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
6962   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6963         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")))
6964    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))
6965    (clobber (match_operand:SI 3 "indexed_or_indirect_operand" "=Z"))]
6966   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6967    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
6968    && TARGET_STFIWX"
6969   "#"
6970   "&& reload_completed"
6971   [(pc)]
6972   "
6973 {
6974   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
6975   if (TARGET_MFPGPR && TARGET_POWERPC64 && REG_P (operands[0])
6976       && INT_REGNO_P (REGNO (operands[0])))
6977     {
6978       rtx reg = gen_lowpart (DImode, operands[0]);
6979       emit_move_insn (reg, operands[2]);
6980     }
6981   else
6982     {
6983       emit_insn (gen_stfiwx (operands[3], operands[2]));
6984       emit_move_insn (operands[0], operands[3]);
6985     }
6986   DONE;
6987 }"
6988   [(set_attr "length" "12")])
6989
6990 (define_insn_and_split "*fix_trunc<mode>si2_mem"
6991   [(set (match_operand:SI 0 "memory_operand" "=Z")
6992         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")))
6993    (clobber (match_scratch:DI 2 "=d"))]
6994   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6995    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
6996    && TARGET_STFIWX"
6997   "#"
6998   "&& reload_completed"
6999   [(pc)]
7000   "
7001 {
7002   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
7003   emit_insn (gen_stfiwx (operands[0], operands[2]));
7004   DONE;
7005 }"
7006   [(set_attr "length" "8")])
7007
7008 (define_insn_and_split "fix_trunc<mode>si2_internal"
7009   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7010         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "<rreg>")))
7011    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))
7012    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o"))]
7013   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
7014    && TARGET_DOUBLE_FLOAT"
7015   "#"
7016   ""
7017   [(pc)]
7018   "
7019 {
7020   rtx lowword;
7021   gcc_assert (MEM_P (operands[3]));
7022   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
7023
7024   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
7025   emit_move_insn (operands[3], operands[2]);
7026   emit_move_insn (operands[0], lowword);
7027   DONE;
7028 }"
7029   [(set_attr "length" "16")])
7030
7031 (define_expand "fix_trunc<mode>di2"
7032   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7033         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
7034   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
7035    && TARGET_FCFID"
7036   "")
7037
7038 (define_insn "*fix_trunc<mode>di2_fctidz"
7039   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
7040         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
7041   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
7042     && TARGET_FCFID && !VECTOR_UNIT_VSX_P (<MODE>mode)"
7043   "fctidz %0,%1"
7044   [(set_attr "type" "fp")])
7045
7046 (define_expand "fixuns_trunc<mode>si2"
7047   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7048         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
7049   "TARGET_HARD_FLOAT
7050    && ((TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ && TARGET_STFIWX)
7051        || <E500_CONVERT>)"
7052   "
7053 {
7054   if (!<E500_CONVERT>)
7055     {
7056       rtx tmp = gen_reg_rtx (DImode);
7057       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
7058       emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1],
7059                                                    tmp, stack));
7060       DONE;
7061     }
7062 }")
7063
7064 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
7065   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7066         (unsigned_fix:SI
7067          (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")))
7068    (clobber (match_operand:DI 2 "gpc_reg_operand" "=d"))
7069    (clobber (match_operand:SI 3 "indexed_or_indirect_operand" "=Z"))]
7070   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
7071    && TARGET_STFIWX"
7072   "#"
7073   "&& reload_completed"
7074   [(pc)]
7075   "
7076 {
7077   emit_insn (gen_fctiwuz_<mode> (operands[2], operands[1]));
7078   if (TARGET_MFPGPR && TARGET_POWERPC64 && REG_P (operands[0])
7079       && INT_REGNO_P (REGNO (operands[0])))
7080     {
7081       rtx reg = gen_lowpart (DImode, operands[0]);
7082       emit_move_insn (reg, operands[2]);
7083     }
7084   else
7085     {
7086       emit_insn (gen_stfiwx (operands[3], operands[2]));
7087       emit_move_insn (operands[0], operands[3]);
7088     }
7089   DONE;
7090 }"
7091   [(set_attr "length" "12")])
7092
7093 (define_insn_and_split "*fixuns_trunc<mode>si2_mem"
7094   [(set (match_operand:SI 0 "memory_operand" "=Z")
7095         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")))
7096    (clobber (match_scratch:DI 2 "=d"))]
7097   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
7098    && TARGET_STFIWX"
7099   "#"
7100   "&& reload_completed"
7101   [(pc)]
7102   "
7103 {
7104   emit_insn (gen_fctiwuz_<mode> (operands[2], operands[1]));
7105   emit_insn (gen_stfiwx (operands[0], operands[2]));
7106   DONE;
7107 }"
7108   [(set_attr "length" "8")])
7109
7110 (define_expand "fixuns_trunc<mode>di2"
7111   [(set (match_operand:DI 0 "register_operand" "")
7112         (unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
7113   "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
7114   "")
7115
7116 (define_insn "*fixuns_trunc<mode>di2_fctiduz"
7117   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
7118         (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
7119   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
7120     && TARGET_FCTIDUZ && !VECTOR_UNIT_VSX_P (<MODE>mode)"
7121   "fctiduz %0,%1"
7122   [(set_attr "type" "fp")])
7123
7124 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
7125 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
7126 ; because the first makes it clear that operand 0 is not live
7127 ; before the instruction.
7128 (define_insn "fctiwz_<mode>"
7129   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
7130         (unspec:DI [(fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))]
7131                    UNSPEC_FCTIWZ))]
7132   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
7133    && TARGET_DOUBLE_FLOAT"
7134   "{fcirz|fctiwz} %0,%1"
7135   [(set_attr "type" "fp")])
7136
7137 (define_insn "fctiwuz_<mode>"
7138   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
7139         (unspec:DI [(unsigned_fix:SI
7140                      (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>"))]
7141                    UNSPEC_FCTIWUZ))]
7142   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ"
7143   "fctiwuz %0,%1"
7144   [(set_attr "type" "fp")])
7145
7146 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
7147 ;; since the friz instruction does not truncate the value if the floating
7148 ;; point value is < LONG_MIN or > LONG_MAX.
7149 (define_insn "*friz"
7150   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7151         (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d"))))]
7152   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_POPCNTB
7153    && !VECTOR_UNIT_VSX_P (DFmode) && flag_unsafe_math_optimizations
7154    && !flag_trapping_math && TARGET_FRIZ"
7155   "friz %0,%1"
7156   [(set_attr "type" "fp")])
7157
7158 ;; No VSX equivalent to fctid
7159 (define_insn "lrint<mode>di2"
7160   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
7161         (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7162                    UNSPEC_FCTID))]
7163   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7164   "fctid %0,%1"
7165   [(set_attr "type" "fp")])
7166
7167 (define_expand "btrunc<mode>2"
7168   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
7169         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
7170                      UNSPEC_FRIZ))]
7171   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7172   "")
7173
7174 (define_insn "*btrunc<mode>2_fpr"
7175   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
7176         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7177                      UNSPEC_FRIZ))]
7178   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
7179    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
7180   "friz %0,%1"
7181   [(set_attr "type" "fp")])
7182
7183 (define_expand "ceil<mode>2"
7184   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
7185         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
7186                      UNSPEC_FRIP))]
7187   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7188   "")
7189
7190 (define_insn "*ceil<mode>2_fpr"
7191   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
7192         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7193                      UNSPEC_FRIP))]
7194   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
7195    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
7196   "frip %0,%1"
7197   [(set_attr "type" "fp")])
7198
7199 (define_expand "floor<mode>2"
7200   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
7201         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
7202                      UNSPEC_FRIM))]
7203   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7204   "")
7205
7206 (define_insn "*floor<mode>2_fpr"
7207   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
7208         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7209                      UNSPEC_FRIM))]
7210   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
7211    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
7212   "frim %0,%1"
7213   [(set_attr "type" "fp")])
7214
7215 ;; No VSX equivalent to frin
7216 (define_insn "round<mode>2"
7217   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
7218         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7219                      UNSPEC_FRIN))]
7220   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7221   "frin %0,%1"
7222   [(set_attr "type" "fp")])
7223
7224 ; An UNSPEC is used so we don't have to support SImode in FP registers.
7225 (define_insn "stfiwx"
7226   [(set (match_operand:SI 0 "memory_operand" "=Z")
7227         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
7228                    UNSPEC_STFIWX))]
7229   "TARGET_PPC_GFXOPT"
7230   "stfiwx %1,%y0"
7231   [(set_attr "type" "fpstore")])
7232
7233 ;; If we don't have a direct conversion to single precision, don't enable this
7234 ;; conversion for 32-bit without fast math, because we don't have the insn to
7235 ;; generate the fixup swizzle to avoid double rounding problems.
7236 (define_expand "floatsisf2"
7237   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7238         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
7239   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
7240    && (!TARGET_FPRS
7241        || (TARGET_FPRS
7242            && ((TARGET_FCFIDS && TARGET_LFIWAX)
7243                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
7244                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
7245   "
7246 {
7247   if (!TARGET_FPRS)
7248     {
7249       if (!REG_P (operands[1]))
7250         operands[1] = force_reg (SImode, operands[1]);
7251     }
7252   else if (TARGET_FCFIDS && TARGET_LFIWAX)
7253     {
7254       rs6000_expand_convert_si_to_sfdf (operands[0], operands[1], false);
7255       DONE;
7256     }
7257   else
7258     {
7259       rtx dreg = operands[1];
7260       if (!REG_P (dreg))
7261         dreg = force_reg (SImode, dreg);
7262       dreg = convert_to_mode (DImode, dreg, false);
7263       emit_insn (gen_floatdisf2 (operands[0], dreg));
7264       DONE;
7265     }
7266 }")
7267
7268 (define_expand "floatdidf2"
7269   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7270         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
7271   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
7272   "")
7273
7274 (define_insn "*floatdidf2_fpr"
7275   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7276         (float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
7277   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
7278    && !VECTOR_UNIT_VSX_P (DFmode)"
7279   "fcfid %0,%1"
7280   [(set_attr "type" "fp")])
7281
7282 ; Allow the combiner to merge source memory operands to the conversion so that
7283 ; the optimizer/register allocator doesn't try to load the value too early in a
7284 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
7285 ; hit.  We will split after reload to avoid the trip through the GPRs
7286
7287 (define_insn_and_split "*floatdidf2_mem"
7288   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7289         (float:DF (match_operand:DI 1 "memory_operand" "m")))
7290    (clobber (match_scratch:DI 2 "=d"))]
7291   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCFID"
7292   "#"
7293   "&& reload_completed"
7294   [(set (match_dup 2) (match_dup 1))
7295    (set (match_dup 0) (float:DF (match_dup 2)))]
7296   ""
7297   [(set_attr "length" "8")])
7298
7299 (define_expand "floatunsdidf2"
7300   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7301         (unsigned_float:DF
7302          (match_operand:DI 1 "gpc_reg_operand" "")))]
7303   "TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode)"
7304   "")
7305
7306 (define_insn "*floatunsdidf2_fcfidu"
7307   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7308         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
7309   "TARGET_FCFIDU && !VECTOR_UNIT_VSX_P (DFmode)"
7310   "fcfidu %0,%1"
7311   [(set_attr "type" "fp")
7312    (set_attr "length" "4")])
7313
7314 (define_insn_and_split "*floatunsdidf2_mem"
7315   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7316         (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m")))
7317    (clobber (match_scratch:DI 2 "=d"))]
7318   "TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode)"
7319   "#"
7320   "&& reload_completed"
7321   [(set (match_dup 2) (match_dup 1))
7322    (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
7323   ""
7324   [(set_attr "length" "8")])
7325
7326 (define_expand "floatdisf2"
7327   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7328         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
7329   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7330    && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
7331   "
7332 {
7333   if (!TARGET_FCFIDS)
7334     {
7335       rtx val = operands[1];
7336       if (!flag_unsafe_math_optimizations)
7337         {
7338           rtx label = gen_label_rtx ();
7339           val = gen_reg_rtx (DImode);
7340           emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
7341           emit_label (label);
7342         }
7343       emit_insn (gen_floatdisf2_internal1 (operands[0], val));
7344       DONE;
7345     }
7346 }")
7347
7348 (define_insn "floatdisf2_fcfids"
7349   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7350         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
7351   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7352    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
7353   "fcfids %0,%1"
7354   [(set_attr "type" "fp")])
7355
7356 (define_insn_and_split "*floatdisf2_mem"
7357   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7358         (float:SF (match_operand:DI 1 "memory_operand" "m")))
7359    (clobber (match_scratch:DI 2 "=f"))]
7360   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7361    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
7362   "#"
7363   "&& reload_completed"
7364   [(pc)]
7365   "
7366 {
7367   emit_move_insn (operands[2], operands[1]);
7368   emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
7369   DONE;
7370 }"
7371   [(set_attr "length" "8")])
7372
7373 ;; This is not IEEE compliant if rounding mode is "round to nearest".
7374 ;; If the DI->DF conversion is inexact, then it's possible to suffer
7375 ;; from double rounding.
7376 (define_insn_and_split "floatdisf2_internal1"
7377   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7378         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
7379    (clobber (match_scratch:DF 2 "=d"))]
7380   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
7381   "#"
7382   "&& reload_completed"
7383   [(set (match_dup 2)
7384         (float:DF (match_dup 1)))
7385    (set (match_dup 0)
7386         (float_truncate:SF (match_dup 2)))]
7387   "")
7388
7389 ;; Twiddles bits to avoid double rounding.
7390 ;; Bits that might be truncated when converting to DFmode are replaced
7391 ;; by a bit that won't be lost at that stage, but is below the SFmode
7392 ;; rounding position.
7393 (define_expand "floatdisf2_internal2"
7394   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
7395                                    (const_int 53)))
7396    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
7397                                                       (const_int 2047)))
7398               (clobber (scratch:CC))])
7399    (set (match_dup 3) (plus:DI (match_dup 3)
7400                                (const_int 1)))
7401    (set (match_dup 0) (plus:DI (match_dup 0)
7402                                (const_int 2047)))
7403    (set (match_dup 4) (compare:CCUNS (match_dup 3)
7404                                      (const_int 2)))
7405    (set (match_dup 0) (ior:DI (match_dup 0)
7406                               (match_dup 1)))
7407    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
7408                                          (const_int -2048)))
7409               (clobber (scratch:CC))])
7410    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
7411                            (label_ref (match_operand:DI 2 "" ""))
7412                            (pc)))
7413    (set (match_dup 0) (match_dup 1))]
7414   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
7415   "
7416 {
7417   operands[3] = gen_reg_rtx (DImode);
7418   operands[4] = gen_reg_rtx (CCUNSmode);
7419 }")
7420
7421 (define_expand "floatunsdisf2"
7422   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7423         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
7424   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7425    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
7426   "")
7427
7428 (define_insn "floatunsdisf2_fcfidus"
7429   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7430         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
7431   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7432    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
7433   "fcfidus %0,%1"
7434   [(set_attr "type" "fp")])
7435
7436 (define_insn_and_split "*floatunsdisf2_mem"
7437   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7438         (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m")))
7439    (clobber (match_scratch:DI 2 "=f"))]
7440   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7441    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
7442   "#"
7443   "&& reload_completed"
7444   [(pc)]
7445   "
7446 {
7447   emit_move_insn (operands[2], operands[1]);
7448   emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
7449   DONE;
7450 }"
7451   [(set_attr "length" "8")])
7452 \f
7453 ;; Define the DImode operations that can be done in a small number
7454 ;; of instructions.  The & constraints are to prevent the register
7455 ;; allocator from allocating registers that overlap with the inputs
7456 ;; (for example, having an input in 7,8 and an output in 6,7).  We
7457 ;; also allow for the output being the same as one of the inputs.
7458
7459 (define_insn "*adddi3_noppc64"
7460   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
7461         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
7462                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
7463   "! TARGET_POWERPC64"
7464   "*
7465 {
7466   if (WORDS_BIG_ENDIAN)
7467     return (GET_CODE (operands[2])) != CONST_INT
7468             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
7469             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
7470   else
7471     return (GET_CODE (operands[2])) != CONST_INT
7472             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
7473             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
7474 }"
7475   [(set_attr "type" "two")
7476    (set_attr "length" "8")])
7477
7478 (define_insn "*subdi3_noppc64"
7479   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
7480         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
7481                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
7482   "! TARGET_POWERPC64"
7483   "*
7484 {
7485   if (WORDS_BIG_ENDIAN)
7486     return (GET_CODE (operands[1]) != CONST_INT)
7487             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
7488             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
7489   else
7490     return (GET_CODE (operands[1]) != CONST_INT)
7491             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
7492             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
7493 }"
7494   [(set_attr "type" "two")
7495    (set_attr "length" "8")])
7496
7497 (define_insn "*negdi2_noppc64"
7498   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7499         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
7500   "! TARGET_POWERPC64"
7501   "*
7502 {
7503   return (WORDS_BIG_ENDIAN)
7504     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
7505     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
7506 }"
7507   [(set_attr "type" "two")
7508    (set_attr "length" "8")])
7509
7510 (define_expand "mulsidi3"
7511   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7512         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7513                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7514   "! TARGET_POWERPC64"
7515   "
7516 {
7517   if (! TARGET_POWER && ! TARGET_POWERPC)
7518     {
7519       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
7520       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
7521       emit_insn (gen_mull_call ());
7522       if (WORDS_BIG_ENDIAN)
7523         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
7524       else
7525         {
7526           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
7527                           gen_rtx_REG (SImode, 3));
7528           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
7529                           gen_rtx_REG (SImode, 4));
7530         }
7531       DONE;
7532     }
7533   else if (TARGET_POWER)
7534     {
7535       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
7536       DONE;
7537     }
7538 }")
7539
7540 (define_insn "mulsidi3_mq"
7541   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7542         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7543                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
7544    (clobber (match_scratch:SI 3 "=q"))]
7545   "TARGET_POWER"
7546   "mul %0,%1,%2\;mfmq %L0"
7547   [(set_attr "type" "imul")
7548    (set_attr "length" "8")])
7549
7550 (define_insn "*mulsidi3_no_mq"
7551   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7552         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7553                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
7554   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
7555   "*
7556 {
7557   return (WORDS_BIG_ENDIAN)
7558     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
7559     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
7560 }"
7561   [(set_attr "type" "imul")
7562    (set_attr "length" "8")])
7563
7564 (define_split
7565   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7566         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7567                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7568   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
7569   [(set (match_dup 3)
7570         (truncate:SI
7571          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
7572                                (sign_extend:DI (match_dup 2)))
7573                       (const_int 32))))
7574    (set (match_dup 4)
7575         (mult:SI (match_dup 1)
7576                  (match_dup 2)))]
7577   "
7578 {
7579   int endian = (WORDS_BIG_ENDIAN == 0);
7580   operands[3] = operand_subword (operands[0], endian, 0, DImode);
7581   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
7582 }")
7583
7584 (define_expand "umulsidi3"
7585   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7586         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7587                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7588   "TARGET_POWERPC && ! TARGET_POWERPC64"
7589   "
7590 {
7591   if (TARGET_POWER)
7592     {
7593       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
7594       DONE;
7595     }
7596 }")
7597
7598 (define_insn "umulsidi3_mq"
7599   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7600         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7601                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
7602    (clobber (match_scratch:SI 3 "=q"))]
7603   "TARGET_POWERPC && TARGET_POWER"
7604   "*
7605 {
7606   return (WORDS_BIG_ENDIAN)
7607     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
7608     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
7609 }"
7610   [(set_attr "type" "imul")
7611    (set_attr "length" "8")])
7612
7613 (define_insn "*umulsidi3_no_mq"
7614   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7615         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7616                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
7617   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
7618   "*
7619 {
7620   return (WORDS_BIG_ENDIAN)
7621     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
7622     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
7623 }"
7624   [(set_attr "type" "imul")
7625    (set_attr "length" "8")])
7626
7627 (define_split
7628   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7629         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7630                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7631   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
7632   [(set (match_dup 3)
7633         (truncate:SI
7634          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
7635                                (zero_extend:DI (match_dup 2)))
7636                       (const_int 32))))
7637    (set (match_dup 4)
7638         (mult:SI (match_dup 1)
7639                  (match_dup 2)))]
7640   "
7641 {
7642   int endian = (WORDS_BIG_ENDIAN == 0);
7643   operands[3] = operand_subword (operands[0], endian, 0, DImode);
7644   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
7645 }")
7646
7647 (define_expand "smulsi3_highpart"
7648   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7649         (truncate:SI
7650          (lshiftrt:DI (mult:DI (sign_extend:DI
7651                                 (match_operand:SI 1 "gpc_reg_operand" ""))
7652                                (sign_extend:DI
7653                                 (match_operand:SI 2 "gpc_reg_operand" "")))
7654                       (const_int 32))))]
7655   ""
7656   "
7657 {
7658   if (! TARGET_POWER && ! TARGET_POWERPC)
7659     {
7660       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
7661       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
7662       emit_insn (gen_mulh_call ());
7663       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
7664       DONE;
7665     }
7666   else if (TARGET_POWER)
7667     {
7668       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
7669       DONE;
7670     }
7671 }")
7672
7673 (define_insn "smulsi3_highpart_mq"
7674   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7675         (truncate:SI
7676          (lshiftrt:DI (mult:DI (sign_extend:DI
7677                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7678                                (sign_extend:DI
7679                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7680                       (const_int 32))))
7681    (clobber (match_scratch:SI 3 "=q"))]
7682   "TARGET_POWER"
7683   "mul %0,%1,%2"
7684   [(set_attr "type" "imul")])
7685
7686 (define_insn "*smulsi3_highpart_no_mq"
7687   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7688         (truncate:SI
7689          (lshiftrt:DI (mult:DI (sign_extend:DI
7690                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7691                                (sign_extend:DI
7692                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7693                       (const_int 32))))]
7694   "TARGET_POWERPC && ! TARGET_POWER"
7695   "mulhw %0,%1,%2"
7696   [(set_attr "type" "imul")])
7697
7698 (define_expand "umulsi3_highpart"
7699   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7700         (truncate:SI
7701          (lshiftrt:DI (mult:DI (zero_extend:DI
7702                                 (match_operand:SI 1 "gpc_reg_operand" ""))
7703                                (zero_extend:DI
7704                                 (match_operand:SI 2 "gpc_reg_operand" "")))
7705                       (const_int 32))))]
7706   "TARGET_POWERPC"
7707   "
7708 {
7709   if (TARGET_POWER)
7710     {
7711       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
7712       DONE;
7713     }
7714 }")
7715
7716 (define_insn "umulsi3_highpart_mq"
7717   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7718         (truncate:SI
7719          (lshiftrt:DI (mult:DI (zero_extend:DI
7720                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7721                                (zero_extend:DI
7722                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7723                       (const_int 32))))
7724    (clobber (match_scratch:SI 3 "=q"))]
7725   "TARGET_POWERPC && TARGET_POWER"
7726   "mulhwu %0,%1,%2"
7727   [(set_attr "type" "imul")])
7728
7729 (define_insn "*umulsi3_highpart_no_mq"
7730   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7731         (truncate:SI
7732          (lshiftrt:DI (mult:DI (zero_extend:DI
7733                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7734                                (zero_extend:DI
7735                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7736                       (const_int 32))))]
7737   "TARGET_POWERPC && ! TARGET_POWER"
7738   "mulhwu %0,%1,%2"
7739   [(set_attr "type" "imul")])
7740
7741 ;; If operands 0 and 2 are in the same register, we have a problem.  But
7742 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
7743 ;; why we have the strange constraints below.
7744 (define_insn "ashldi3_power"
7745   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
7746         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
7747                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
7748    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
7749   "TARGET_POWER"
7750   "@
7751    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
7752    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
7753    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
7754    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
7755   [(set_attr "length" "8")])
7756
7757 (define_insn "lshrdi3_power"
7758   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
7759         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
7760                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
7761    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
7762   "TARGET_POWER"
7763   "@
7764    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
7765    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
7766    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
7767    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
7768   [(set_attr "length" "8")])
7769
7770 ;; Shift by a variable amount is too complex to be worth open-coding.  We
7771 ;; just handle shifts by constants.
7772 (define_insn "ashrdi3_power"
7773   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7774         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7775                      (match_operand:SI 2 "const_int_operand" "M,i")))
7776    (clobber (match_scratch:SI 3 "=X,q"))]
7777   "TARGET_POWER"
7778   "@
7779    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
7780    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
7781   [(set_attr "type" "shift")
7782    (set_attr "length" "8")])
7783
7784 (define_insn "ashrdi3_no_power"
7785   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
7786         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7787                      (match_operand:SI 2 "const_int_operand" "M,i")))]
7788   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
7789   "@
7790    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
7791    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
7792   [(set_attr "type" "two,three")
7793    (set_attr "length" "8,12")])
7794
7795 (define_insn "*ashrdisi3_noppc64"
7796   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7797         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7798                                 (const_int 32)) 4))]
7799   "TARGET_32BIT && !TARGET_POWERPC64"
7800   "*
7801 {
7802   if (REGNO (operands[0]) == REGNO (operands[1]))
7803     return \"\";
7804   else
7805     return \"mr %0,%1\";
7806 }"
7807    [(set_attr "length" "4")])
7808
7809 \f
7810 ;; PowerPC64 DImode operations.
7811
7812 (define_expand "absdi2"
7813   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7814         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
7815   "TARGET_POWERPC64"
7816   "
7817 {
7818   if (TARGET_ISEL)
7819     emit_insn (gen_absdi2_isel (operands[0], operands[1]));
7820   else
7821     emit_insn (gen_absdi2_internal (operands[0], operands[1]));
7822   DONE;
7823 }")
7824
7825 (define_insn_and_split "absdi2_internal"
7826   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7827         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
7828    (clobber (match_scratch:DI 2 "=&r,&r"))]
7829   "TARGET_POWERPC64 && !TARGET_ISEL"
7830   "#"
7831   "&& reload_completed"
7832   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
7833    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
7834    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
7835   "")
7836
7837 (define_insn_and_split "*nabsdi2"
7838   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7839         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
7840    (clobber (match_scratch:DI 2 "=&r,&r"))]
7841   "TARGET_POWERPC64 && !TARGET_ISEL"
7842   "#"
7843   "&& reload_completed"
7844   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
7845    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
7846    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
7847   "")
7848
7849 (define_insn "muldi3"
7850   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7851         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7852                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
7853   "TARGET_POWERPC64"
7854   "@
7855    mulld %0,%1,%2
7856    mulli %0,%1,%2"
7857    [(set (attr "type")
7858       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
7859                 (const_string "imul3")
7860              (match_operand:SI 2 "short_cint_operand" "")
7861                 (const_string "imul2")]
7862         (const_string "lmul")))])
7863
7864 (define_insn "*muldi3_internal1"
7865   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7866         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7867                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
7868                     (const_int 0)))
7869    (clobber (match_scratch:DI 3 "=r,r"))]
7870   "TARGET_POWERPC64"
7871   "@
7872    mulld. %3,%1,%2
7873    #"
7874   [(set_attr "type" "lmul_compare")
7875    (set_attr "length" "4,8")])
7876
7877 (define_split
7878   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7879         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
7880                              (match_operand:DI 2 "gpc_reg_operand" ""))
7881                     (const_int 0)))
7882    (clobber (match_scratch:DI 3 ""))]
7883   "TARGET_POWERPC64 && reload_completed"
7884   [(set (match_dup 3)
7885         (mult:DI (match_dup 1) (match_dup 2)))
7886    (set (match_dup 0)
7887         (compare:CC (match_dup 3)
7888                     (const_int 0)))]
7889   "")
7890
7891 (define_insn "*muldi3_internal2"
7892   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7893         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7894                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
7895                     (const_int 0)))
7896    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7897         (mult:DI (match_dup 1) (match_dup 2)))]
7898   "TARGET_POWERPC64"
7899   "@
7900    mulld. %0,%1,%2
7901    #"
7902   [(set_attr "type" "lmul_compare")
7903    (set_attr "length" "4,8")])
7904
7905 (define_split
7906   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7907         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
7908                              (match_operand:DI 2 "gpc_reg_operand" ""))
7909                     (const_int 0)))
7910    (set (match_operand:DI 0 "gpc_reg_operand" "")
7911         (mult:DI (match_dup 1) (match_dup 2)))]
7912   "TARGET_POWERPC64 && reload_completed"
7913   [(set (match_dup 0)
7914         (mult:DI (match_dup 1) (match_dup 2)))
7915    (set (match_dup 3)
7916         (compare:CC (match_dup 0)
7917                     (const_int 0)))]
7918   "")
7919
7920 (define_insn "smuldi3_highpart"
7921   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7922         (truncate:DI
7923          (lshiftrt:TI (mult:TI (sign_extend:TI
7924                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
7925                                (sign_extend:TI
7926                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
7927                       (const_int 64))))]
7928   "TARGET_POWERPC64"
7929   "mulhd %0,%1,%2"
7930   [(set_attr "type" "lmul")])
7931
7932 (define_insn "umuldi3_highpart"
7933   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7934         (truncate:DI
7935          (lshiftrt:TI (mult:TI (zero_extend:TI
7936                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
7937                                (zero_extend:TI
7938                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
7939                       (const_int 64))))]
7940   "TARGET_POWERPC64"
7941   "mulhdu %0,%1,%2"
7942   [(set_attr "type" "lmul")])
7943
7944 (define_insn "rotldi3"
7945   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7946         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7947                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
7948   "TARGET_POWERPC64"
7949   "@
7950    rldcl %0,%1,%2,0
7951    rldicl %0,%1,%H2,0"
7952   [(set_attr "type" "var_shift_rotate,integer")])
7953
7954 (define_insn "*rotldi3_internal2"
7955   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7956         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7957                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7958                     (const_int 0)))
7959    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7960   "TARGET_64BIT"
7961   "@
7962    rldcl. %3,%1,%2,0
7963    rldicl. %3,%1,%H2,0
7964    #
7965    #"
7966   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7967    (set_attr "length" "4,4,8,8")])
7968
7969 (define_split
7970   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7971         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7972                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7973                     (const_int 0)))
7974    (clobber (match_scratch:DI 3 ""))]
7975   "TARGET_POWERPC64 && reload_completed"
7976   [(set (match_dup 3)
7977         (rotate:DI (match_dup 1) (match_dup 2)))
7978    (set (match_dup 0)
7979         (compare:CC (match_dup 3)
7980                     (const_int 0)))]
7981   "")
7982
7983 (define_insn "*rotldi3_internal3"
7984   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7985         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7986                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7987                     (const_int 0)))
7988    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7989         (rotate:DI (match_dup 1) (match_dup 2)))]
7990   "TARGET_64BIT"
7991   "@
7992    rldcl. %0,%1,%2,0
7993    rldicl. %0,%1,%H2,0
7994    #
7995    #"
7996   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7997    (set_attr "length" "4,4,8,8")])
7998
7999 (define_split
8000   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8001         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8002                                (match_operand:DI 2 "reg_or_cint_operand" ""))
8003                     (const_int 0)))
8004    (set (match_operand:DI 0 "gpc_reg_operand" "")
8005         (rotate:DI (match_dup 1) (match_dup 2)))]
8006   "TARGET_POWERPC64 && reload_completed"
8007   [(set (match_dup 0)
8008         (rotate:DI (match_dup 1) (match_dup 2)))
8009    (set (match_dup 3)
8010         (compare:CC (match_dup 0)
8011                     (const_int 0)))]
8012   "")
8013
8014 (define_insn "*rotldi3_internal4"
8015   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8016         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8017                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
8018                 (match_operand:DI 3 "mask64_operand" "n,n")))]
8019   "TARGET_POWERPC64"
8020   "@
8021    rldc%B3 %0,%1,%2,%S3
8022    rldic%B3 %0,%1,%H2,%S3"
8023   [(set_attr "type" "var_shift_rotate,integer")])
8024
8025 (define_insn "*rotldi3_internal5"
8026   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8027         (compare:CC (and:DI
8028                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8029                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
8030                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
8031                     (const_int 0)))
8032    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
8033   "TARGET_64BIT"
8034   "@
8035    rldc%B3. %4,%1,%2,%S3
8036    rldic%B3. %4,%1,%H2,%S3
8037    #
8038    #"
8039   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8040    (set_attr "length" "4,4,8,8")])
8041
8042 (define_split
8043   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8044         (compare:CC (and:DI
8045                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8046                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
8047                      (match_operand:DI 3 "mask64_operand" ""))
8048                     (const_int 0)))
8049    (clobber (match_scratch:DI 4 ""))]
8050   "TARGET_POWERPC64 && reload_completed"
8051   [(set (match_dup 4)
8052         (and:DI (rotate:DI (match_dup 1)
8053                                 (match_dup 2))
8054                      (match_dup 3)))
8055    (set (match_dup 0)
8056         (compare:CC (match_dup 4)
8057                     (const_int 0)))]
8058   "")
8059
8060 (define_insn "*rotldi3_internal6"
8061   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
8062         (compare:CC (and:DI
8063                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8064                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
8065                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
8066                     (const_int 0)))
8067    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8068         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8069   "TARGET_64BIT"
8070   "@
8071    rldc%B3. %0,%1,%2,%S3
8072    rldic%B3. %0,%1,%H2,%S3
8073    #
8074    #"
8075   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8076    (set_attr "length" "4,4,8,8")])
8077
8078 (define_split
8079   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
8080         (compare:CC (and:DI
8081                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8082                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
8083                      (match_operand:DI 3 "mask64_operand" ""))
8084                     (const_int 0)))
8085    (set (match_operand:DI 0 "gpc_reg_operand" "")
8086         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8087   "TARGET_POWERPC64 && reload_completed"
8088   [(set (match_dup 0)
8089         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
8090    (set (match_dup 4)
8091         (compare:CC (match_dup 0)
8092                     (const_int 0)))]
8093   "")
8094
8095 (define_insn "*rotldi3_internal7"
8096   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8097         (zero_extend:DI
8098          (subreg:QI
8099           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8100                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
8101   "TARGET_POWERPC64"
8102   "@
8103    rldcl %0,%1,%2,56
8104    rldicl %0,%1,%H2,56"
8105   [(set_attr "type" "var_shift_rotate,integer")])
8106
8107 (define_insn "*rotldi3_internal8"
8108   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8109         (compare:CC (zero_extend:DI
8110                      (subreg:QI
8111                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8112                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8113                     (const_int 0)))
8114    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8115   "TARGET_64BIT"
8116   "@
8117    rldcl. %3,%1,%2,56
8118    rldicl. %3,%1,%H2,56
8119    #
8120    #"
8121   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8122    (set_attr "length" "4,4,8,8")])
8123
8124 (define_split
8125   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8126         (compare:CC (zero_extend:DI
8127                      (subreg:QI
8128                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8129                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8130                     (const_int 0)))
8131    (clobber (match_scratch:DI 3 ""))]
8132   "TARGET_POWERPC64 && reload_completed"
8133   [(set (match_dup 3)
8134         (zero_extend:DI (subreg:QI
8135                       (rotate:DI (match_dup 1)
8136                                  (match_dup 2)) 0)))
8137    (set (match_dup 0)
8138         (compare:CC (match_dup 3)
8139                     (const_int 0)))]
8140   "")
8141
8142 (define_insn "*rotldi3_internal9"
8143   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8144         (compare:CC (zero_extend:DI
8145                      (subreg:QI
8146                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8147                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8148                     (const_int 0)))
8149    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8150         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8151   "TARGET_64BIT"
8152   "@
8153    rldcl. %0,%1,%2,56
8154    rldicl. %0,%1,%H2,56
8155    #
8156    #"
8157   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8158    (set_attr "length" "4,4,8,8")])
8159
8160 (define_split
8161   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8162         (compare:CC (zero_extend:DI
8163                      (subreg:QI
8164                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8165                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8166                     (const_int 0)))
8167    (set (match_operand:DI 0 "gpc_reg_operand" "")
8168         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8169   "TARGET_POWERPC64 && reload_completed"
8170   [(set (match_dup 0)
8171         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
8172    (set (match_dup 3)
8173         (compare:CC (match_dup 0)
8174                     (const_int 0)))]
8175   "")
8176
8177 (define_insn "*rotldi3_internal10"
8178   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8179         (zero_extend:DI
8180          (subreg:HI
8181           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8182                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
8183   "TARGET_POWERPC64"
8184   "@
8185    rldcl %0,%1,%2,48
8186    rldicl %0,%1,%H2,48"
8187   [(set_attr "type" "var_shift_rotate,integer")])
8188
8189 (define_insn "*rotldi3_internal11"
8190   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8191         (compare:CC (zero_extend:DI
8192                      (subreg:HI
8193                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8194                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8195                     (const_int 0)))
8196    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8197   "TARGET_64BIT"
8198   "@
8199    rldcl. %3,%1,%2,48
8200    rldicl. %3,%1,%H2,48
8201    #
8202    #"
8203   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8204    (set_attr "length" "4,4,8,8")])
8205
8206 (define_split
8207   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8208         (compare:CC (zero_extend:DI
8209                      (subreg:HI
8210                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8211                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8212                     (const_int 0)))
8213    (clobber (match_scratch:DI 3 ""))]
8214   "TARGET_POWERPC64 && reload_completed"
8215   [(set (match_dup 3)
8216         (zero_extend:DI (subreg:HI
8217                       (rotate:DI (match_dup 1)
8218                                  (match_dup 2)) 0)))
8219    (set (match_dup 0)
8220         (compare:CC (match_dup 3)
8221                     (const_int 0)))]
8222   "")
8223
8224 (define_insn "*rotldi3_internal12"
8225   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8226         (compare:CC (zero_extend:DI
8227                      (subreg:HI
8228                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8229                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8230                     (const_int 0)))
8231    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8232         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8233   "TARGET_64BIT"
8234   "@
8235    rldcl. %0,%1,%2,48
8236    rldicl. %0,%1,%H2,48
8237    #
8238    #"
8239   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8240    (set_attr "length" "4,4,8,8")])
8241
8242 (define_split
8243   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8244         (compare:CC (zero_extend:DI
8245                      (subreg:HI
8246                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8247                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8248                     (const_int 0)))
8249    (set (match_operand:DI 0 "gpc_reg_operand" "")
8250         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8251   "TARGET_POWERPC64 && reload_completed"
8252   [(set (match_dup 0)
8253         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
8254    (set (match_dup 3)
8255         (compare:CC (match_dup 0)
8256                     (const_int 0)))]
8257   "")
8258
8259 (define_insn "*rotldi3_internal13"
8260   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8261         (zero_extend:DI
8262          (subreg:SI
8263           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8264                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
8265   "TARGET_POWERPC64"
8266   "@
8267    rldcl %0,%1,%2,32
8268    rldicl %0,%1,%H2,32"
8269   [(set_attr "type" "var_shift_rotate,integer")])
8270
8271 (define_insn "*rotldi3_internal14"
8272   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8273         (compare:CC (zero_extend:DI
8274                      (subreg:SI
8275                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8276                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8277                     (const_int 0)))
8278    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8279   "TARGET_64BIT"
8280   "@
8281    rldcl. %3,%1,%2,32
8282    rldicl. %3,%1,%H2,32
8283    #
8284    #"
8285   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8286    (set_attr "length" "4,4,8,8")])
8287
8288 (define_split
8289   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8290         (compare:CC (zero_extend:DI
8291                      (subreg:SI
8292                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8293                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8294                     (const_int 0)))
8295    (clobber (match_scratch:DI 3 ""))]
8296   "TARGET_POWERPC64 && reload_completed"
8297   [(set (match_dup 3)
8298         (zero_extend:DI (subreg:SI
8299                       (rotate:DI (match_dup 1)
8300                                  (match_dup 2)) 0)))
8301    (set (match_dup 0)
8302         (compare:CC (match_dup 3)
8303                     (const_int 0)))]
8304   "")
8305
8306 (define_insn "*rotldi3_internal15"
8307   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8308         (compare:CC (zero_extend:DI
8309                      (subreg:SI
8310                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8311                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8312                     (const_int 0)))
8313    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8314         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8315   "TARGET_64BIT"
8316   "@
8317    rldcl. %0,%1,%2,32
8318    rldicl. %0,%1,%H2,32
8319    #
8320    #"
8321   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8322    (set_attr "length" "4,4,8,8")])
8323
8324 (define_split
8325   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8326         (compare:CC (zero_extend:DI
8327                      (subreg:SI
8328                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8329                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8330                     (const_int 0)))
8331    (set (match_operand:DI 0 "gpc_reg_operand" "")
8332         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8333   "TARGET_POWERPC64 && reload_completed"
8334   [(set (match_dup 0)
8335         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
8336    (set (match_dup 3)
8337         (compare:CC (match_dup 0)
8338                     (const_int 0)))]
8339   "")
8340
8341 (define_expand "ashldi3"
8342   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8343         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8344                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
8345   "TARGET_POWERPC64 || TARGET_POWER"
8346   "
8347 {
8348   if (TARGET_POWERPC64)
8349     ;
8350   else if (TARGET_POWER)
8351     {
8352       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
8353       DONE;
8354     }
8355   else
8356     FAIL;
8357 }")
8358
8359 (define_insn "*ashldi3_internal1"
8360   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8361         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8362                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8363   "TARGET_POWERPC64"
8364   "@
8365    sld %0,%1,%2
8366    sldi %0,%1,%H2"
8367   [(set_attr "type" "var_shift_rotate,shift")])
8368
8369 (define_insn "*ashldi3_internal2"
8370   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8371         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8372                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8373                     (const_int 0)))
8374    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8375   "TARGET_64BIT"
8376   "@
8377    sld. %3,%1,%2
8378    sldi. %3,%1,%H2
8379    #
8380    #"
8381   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8382    (set_attr "length" "4,4,8,8")])
8383
8384 (define_split
8385   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
8386         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8387                                (match_operand:SI 2 "reg_or_cint_operand" ""))
8388                     (const_int 0)))
8389    (clobber (match_scratch:DI 3 ""))]
8390   "TARGET_POWERPC64 && reload_completed"
8391   [(set (match_dup 3)
8392         (ashift:DI (match_dup 1) (match_dup 2)))
8393    (set (match_dup 0)
8394         (compare:CC (match_dup 3)
8395                     (const_int 0)))]
8396   "")
8397
8398 (define_insn "*ashldi3_internal3"
8399   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8400         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8401                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8402                     (const_int 0)))
8403    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8404         (ashift:DI (match_dup 1) (match_dup 2)))]
8405   "TARGET_64BIT"
8406   "@
8407    sld. %0,%1,%2
8408    sldi. %0,%1,%H2
8409    #
8410    #"
8411   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8412    (set_attr "length" "4,4,8,8")])
8413
8414 (define_split
8415   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
8416         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8417                                (match_operand:SI 2 "reg_or_cint_operand" ""))
8418                     (const_int 0)))
8419    (set (match_operand:DI 0 "gpc_reg_operand" "")
8420         (ashift:DI (match_dup 1) (match_dup 2)))]
8421   "TARGET_POWERPC64 && reload_completed"
8422   [(set (match_dup 0)
8423         (ashift:DI (match_dup 1) (match_dup 2)))
8424    (set (match_dup 3)
8425         (compare:CC (match_dup 0)
8426                     (const_int 0)))]
8427   "")
8428
8429 (define_insn "*ashldi3_internal4"
8430   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8431         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
8432                            (match_operand:SI 2 "const_int_operand" "i"))
8433                 (match_operand:DI 3 "const_int_operand" "n")))]
8434   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
8435   "rldic %0,%1,%H2,%W3")
8436
8437 (define_insn "ashldi3_internal5"
8438   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8439         (compare:CC
8440          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8441                             (match_operand:SI 2 "const_int_operand" "i,i"))
8442                  (match_operand:DI 3 "const_int_operand" "n,n"))
8443          (const_int 0)))
8444    (clobber (match_scratch:DI 4 "=r,r"))]
8445   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
8446   "@
8447    rldic. %4,%1,%H2,%W3
8448    #"
8449   [(set_attr "type" "compare")
8450    (set_attr "length" "4,8")])
8451
8452 (define_split
8453   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8454         (compare:CC
8455          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8456                             (match_operand:SI 2 "const_int_operand" ""))
8457                  (match_operand:DI 3 "const_int_operand" ""))
8458          (const_int 0)))
8459    (clobber (match_scratch:DI 4 ""))]
8460   "TARGET_POWERPC64 && reload_completed
8461    && includes_rldic_lshift_p (operands[2], operands[3])"
8462   [(set (match_dup 4)
8463         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8464                 (match_dup 3)))
8465    (set (match_dup 0)
8466         (compare:CC (match_dup 4)
8467                     (const_int 0)))]
8468   "")
8469
8470 (define_insn "*ashldi3_internal6"
8471   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
8472         (compare:CC
8473          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8474                             (match_operand:SI 2 "const_int_operand" "i,i"))
8475                     (match_operand:DI 3 "const_int_operand" "n,n"))
8476          (const_int 0)))
8477    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8478         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8479   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
8480   "@
8481    rldic. %0,%1,%H2,%W3
8482    #"
8483   [(set_attr "type" "compare")
8484    (set_attr "length" "4,8")])
8485
8486 (define_split
8487   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
8488         (compare:CC
8489          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8490                             (match_operand:SI 2 "const_int_operand" ""))
8491                  (match_operand:DI 3 "const_int_operand" ""))
8492          (const_int 0)))
8493    (set (match_operand:DI 0 "gpc_reg_operand" "")
8494         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8495   "TARGET_POWERPC64 && reload_completed
8496    && includes_rldic_lshift_p (operands[2], operands[3])"
8497   [(set (match_dup 0)
8498         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8499                 (match_dup 3)))
8500    (set (match_dup 4)
8501         (compare:CC (match_dup 0)
8502                     (const_int 0)))]
8503   "")
8504
8505 (define_insn "*ashldi3_internal7"
8506   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8507         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
8508                            (match_operand:SI 2 "const_int_operand" "i"))
8509                 (match_operand:DI 3 "mask64_operand" "n")))]
8510   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
8511   "rldicr %0,%1,%H2,%S3")
8512
8513 (define_insn "ashldi3_internal8"
8514   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8515         (compare:CC
8516          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8517                             (match_operand:SI 2 "const_int_operand" "i,i"))
8518                  (match_operand:DI 3 "mask64_operand" "n,n"))
8519          (const_int 0)))
8520    (clobber (match_scratch:DI 4 "=r,r"))]
8521   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
8522   "@
8523    rldicr. %4,%1,%H2,%S3
8524    #"
8525   [(set_attr "type" "compare")
8526    (set_attr "length" "4,8")])
8527
8528 (define_split
8529   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8530         (compare:CC
8531          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8532                             (match_operand:SI 2 "const_int_operand" ""))
8533                  (match_operand:DI 3 "mask64_operand" ""))
8534          (const_int 0)))
8535    (clobber (match_scratch:DI 4 ""))]
8536   "TARGET_POWERPC64 && reload_completed
8537    && includes_rldicr_lshift_p (operands[2], operands[3])"
8538   [(set (match_dup 4)
8539         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8540                 (match_dup 3)))
8541    (set (match_dup 0)
8542         (compare:CC (match_dup 4)
8543                     (const_int 0)))]
8544   "")
8545
8546 (define_insn "*ashldi3_internal9"
8547   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
8548         (compare:CC
8549          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8550                             (match_operand:SI 2 "const_int_operand" "i,i"))
8551                     (match_operand:DI 3 "mask64_operand" "n,n"))
8552          (const_int 0)))
8553    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8554         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8555   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
8556   "@
8557    rldicr. %0,%1,%H2,%S3
8558    #"
8559   [(set_attr "type" "compare")
8560    (set_attr "length" "4,8")])
8561
8562 (define_split
8563   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
8564         (compare:CC
8565          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8566                             (match_operand:SI 2 "const_int_operand" ""))
8567                  (match_operand:DI 3 "mask64_operand" ""))
8568          (const_int 0)))
8569    (set (match_operand:DI 0 "gpc_reg_operand" "")
8570         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8571   "TARGET_POWERPC64 && reload_completed
8572    && includes_rldicr_lshift_p (operands[2], operands[3])"
8573   [(set (match_dup 0)
8574         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8575                 (match_dup 3)))
8576    (set (match_dup 4)
8577         (compare:CC (match_dup 0)
8578                     (const_int 0)))]
8579   "")
8580
8581 (define_expand "lshrdi3"
8582   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8583         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8584                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
8585   "TARGET_POWERPC64 || TARGET_POWER"
8586   "
8587 {
8588   if (TARGET_POWERPC64)
8589     ;
8590   else if (TARGET_POWER)
8591     {
8592       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
8593       DONE;
8594     }
8595   else
8596     FAIL;
8597 }")
8598
8599 (define_insn "*lshrdi3_internal1"
8600   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8601         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8602                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8603   "TARGET_POWERPC64"
8604   "@
8605    srd %0,%1,%2
8606    srdi %0,%1,%H2"
8607   [(set_attr "type" "var_shift_rotate,shift")])
8608
8609 (define_insn "*lshrdi3_internal2"
8610   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8611         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8612                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8613                     (const_int 0)))
8614    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8615   "TARGET_64BIT "
8616   "@
8617    srd. %3,%1,%2
8618    srdi. %3,%1,%H2
8619    #
8620    #"
8621   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8622    (set_attr "length" "4,4,8,8")])
8623
8624 (define_split
8625   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8626         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8627                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8628                     (const_int 0)))
8629    (clobber (match_scratch:DI 3 ""))]
8630   "TARGET_POWERPC64 && reload_completed"
8631   [(set (match_dup 3)
8632         (lshiftrt:DI (match_dup 1) (match_dup 2)))
8633    (set (match_dup 0)
8634         (compare:CC (match_dup 3)
8635                     (const_int 0)))]
8636   "")
8637
8638 (define_insn "*lshrdi3_internal3"
8639   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8640         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8641                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8642                     (const_int 0)))
8643    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8644         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
8645   "TARGET_64BIT"
8646   "@
8647    srd. %0,%1,%2
8648    srdi. %0,%1,%H2
8649    #
8650    #"
8651   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8652    (set_attr "length" "4,4,8,8")])
8653
8654 (define_split
8655   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8656         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8657                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8658                     (const_int 0)))
8659    (set (match_operand:DI 0 "gpc_reg_operand" "")
8660         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
8661   "TARGET_POWERPC64 && reload_completed"
8662   [(set (match_dup 0)
8663         (lshiftrt:DI (match_dup 1) (match_dup 2)))
8664    (set (match_dup 3)
8665         (compare:CC (match_dup 0)
8666                     (const_int 0)))]
8667   "")
8668
8669 (define_expand "ashrdi3"
8670   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8671         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8672                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
8673   "WORDS_BIG_ENDIAN"
8674   "
8675 {
8676   if (TARGET_POWERPC64)
8677     ;
8678   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
8679     {
8680       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
8681       DONE;
8682     }
8683   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
8684            && WORDS_BIG_ENDIAN)
8685     {
8686       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
8687       DONE;
8688     }
8689   else
8690     FAIL;
8691 }")
8692
8693 (define_insn "*ashrdi3_internal1"
8694   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8695         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8696                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8697   "TARGET_POWERPC64"
8698   "@
8699    srad %0,%1,%2
8700    sradi %0,%1,%H2"
8701   [(set_attr "type" "var_shift_rotate,shift")])
8702
8703 (define_insn "*ashrdi3_internal2"
8704   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8705         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8706                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8707                     (const_int 0)))
8708    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8709   "TARGET_64BIT"
8710   "@
8711    srad. %3,%1,%2
8712    sradi. %3,%1,%H2
8713    #
8714    #"
8715   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8716    (set_attr "length" "4,4,8,8")])
8717
8718 (define_split
8719   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
8720         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8721                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8722                     (const_int 0)))
8723    (clobber (match_scratch:DI 3 ""))]
8724   "TARGET_POWERPC64 && reload_completed"
8725   [(set (match_dup 3)
8726         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8727    (set (match_dup 0)
8728         (compare:CC (match_dup 3)
8729                     (const_int 0)))]
8730   "")
8731
8732 (define_insn "*ashrdi3_internal3"
8733   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8734         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8735                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8736                     (const_int 0)))
8737    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8738         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8739   "TARGET_64BIT"
8740   "@
8741    srad. %0,%1,%2
8742    sradi. %0,%1,%H2
8743    #
8744    #"
8745   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8746    (set_attr "length" "4,4,8,8")])
8747
8748 (define_split
8749   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
8750         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8751                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8752                     (const_int 0)))
8753    (set (match_operand:DI 0 "gpc_reg_operand" "")
8754         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8755   "TARGET_POWERPC64 && reload_completed"
8756   [(set (match_dup 0)
8757         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8758    (set (match_dup 3)
8759         (compare:CC (match_dup 0)
8760                     (const_int 0)))]
8761   "")
8762
8763 (define_expand "anddi3"
8764   [(parallel
8765     [(set (match_operand:DI 0 "gpc_reg_operand" "")
8766           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8767                   (match_operand:DI 2 "and64_2_operand" "")))
8768      (clobber (match_scratch:CC 3 ""))])]
8769   "TARGET_POWERPC64"
8770   "")
8771
8772 (define_insn "anddi3_mc"
8773   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
8774         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
8775                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
8776    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
8777   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
8778   "@
8779    and %0,%1,%2
8780    rldic%B2 %0,%1,0,%S2
8781    rlwinm %0,%1,0,%m2,%M2
8782    andi. %0,%1,%b2
8783    andis. %0,%1,%u2
8784    #"
8785   [(set_attr "type" "*,*,*,fast_compare,fast_compare,*")
8786    (set_attr "length" "4,4,4,4,4,8")])
8787
8788 (define_insn "anddi3_nomc"
8789   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8790         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
8791                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
8792    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
8793   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
8794   "@
8795    and %0,%1,%2
8796    rldic%B2 %0,%1,0,%S2
8797    rlwinm %0,%1,0,%m2,%M2
8798    #"
8799   [(set_attr "length" "4,4,4,8")])
8800
8801 (define_split
8802   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8803         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8804                 (match_operand:DI 2 "mask64_2_operand" "")))
8805    (clobber (match_scratch:CC 3 ""))]
8806   "TARGET_POWERPC64
8807     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8808     && !mask_operand (operands[2], DImode)
8809     && !mask64_operand (operands[2], DImode)"
8810   [(set (match_dup 0)
8811         (and:DI (rotate:DI (match_dup 1)
8812                            (match_dup 4))
8813                 (match_dup 5)))
8814    (set (match_dup 0)
8815         (and:DI (rotate:DI (match_dup 0)
8816                            (match_dup 6))
8817                 (match_dup 7)))]
8818 {
8819   build_mask64_2_operands (operands[2], &operands[4]);
8820 })
8821
8822 (define_insn "*anddi3_internal2_mc"
8823   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8824         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8825                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8826                     (const_int 0)))
8827    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
8828    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8829   "TARGET_64BIT && rs6000_gen_cell_microcode"
8830   "@
8831    and. %3,%1,%2
8832    rldic%B2. %3,%1,0,%S2
8833    rlwinm. %3,%1,0,%m2,%M2
8834    andi. %3,%1,%b2
8835    andis. %3,%1,%u2
8836    #
8837    #
8838    #
8839    #
8840    #
8841    #
8842    #"
8843   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8844                      fast_compare,compare,compare,compare,compare,compare,\
8845                      compare,compare")
8846    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8847
8848 (define_split
8849   [(set (match_operand:CC 0 "cc_reg_operand" "")
8850         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8851                             (match_operand:DI 2 "mask64_2_operand" ""))
8852                     (const_int 0)))
8853    (clobber (match_scratch:DI 3 ""))
8854    (clobber (match_scratch:CC 4 ""))]
8855   "TARGET_64BIT && reload_completed
8856     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8857     && !mask_operand (operands[2], DImode)
8858     && !mask64_operand (operands[2], DImode)"
8859   [(set (match_dup 3)
8860         (and:DI (rotate:DI (match_dup 1)
8861                            (match_dup 5))
8862                 (match_dup 6)))
8863    (parallel [(set (match_dup 0)
8864                    (compare:CC (and:DI (rotate:DI (match_dup 3)
8865                                                   (match_dup 7))
8866                                        (match_dup 8))
8867                                (const_int 0)))
8868               (clobber (match_dup 3))])]
8869   "
8870 {
8871   build_mask64_2_operands (operands[2], &operands[5]);
8872 }")
8873
8874 (define_insn "*anddi3_internal3_mc"
8875   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8876         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8877                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8878                     (const_int 0)))
8879    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
8880         (and:DI (match_dup 1) (match_dup 2)))
8881    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8882   "TARGET_64BIT && rs6000_gen_cell_microcode"
8883   "@
8884    and. %0,%1,%2
8885    rldic%B2. %0,%1,0,%S2
8886    rlwinm. %0,%1,0,%m2,%M2
8887    andi. %0,%1,%b2
8888    andis. %0,%1,%u2
8889    #
8890    #
8891    #
8892    #
8893    #
8894    #
8895    #"
8896   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8897                      fast_compare,compare,compare,compare,compare,compare,\
8898                      compare,compare")
8899    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8900
8901 (define_split
8902   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8903         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8904                             (match_operand:DI 2 "and64_2_operand" ""))
8905                     (const_int 0)))
8906    (set (match_operand:DI 0 "gpc_reg_operand" "")
8907         (and:DI (match_dup 1) (match_dup 2)))
8908    (clobber (match_scratch:CC 4 ""))]
8909   "TARGET_64BIT && reload_completed"
8910   [(parallel [(set (match_dup 0)
8911                     (and:DI (match_dup 1) (match_dup 2)))
8912                (clobber (match_dup 4))])
8913    (set (match_dup 3)
8914         (compare:CC (match_dup 0)
8915                     (const_int 0)))]
8916   "")
8917
8918 (define_split
8919   [(set (match_operand:CC 3 "cc_reg_operand" "")
8920         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8921                             (match_operand:DI 2 "mask64_2_operand" ""))
8922                     (const_int 0)))
8923    (set (match_operand:DI 0 "gpc_reg_operand" "")
8924         (and:DI (match_dup 1) (match_dup 2)))
8925    (clobber (match_scratch:CC 4 ""))]
8926   "TARGET_64BIT && reload_completed
8927     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8928     && !mask_operand (operands[2], DImode)
8929     && !mask64_operand (operands[2], DImode)"
8930   [(set (match_dup 0)
8931         (and:DI (rotate:DI (match_dup 1)
8932                            (match_dup 5))
8933                 (match_dup 6)))
8934    (parallel [(set (match_dup 3)
8935                    (compare:CC (and:DI (rotate:DI (match_dup 0)
8936                                                   (match_dup 7))
8937                                        (match_dup 8))
8938                                (const_int 0)))
8939               (set (match_dup 0)
8940                    (and:DI (rotate:DI (match_dup 0)
8941                                       (match_dup 7))
8942                            (match_dup 8)))])]
8943   "
8944 {
8945   build_mask64_2_operands (operands[2], &operands[5]);
8946 }")
8947
8948 (define_expand "iordi3"
8949   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8950         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
8951                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8952   "TARGET_POWERPC64"
8953   "
8954 {
8955   if (non_logical_cint_operand (operands[2], DImode))
8956     {
8957       HOST_WIDE_INT value;
8958       rtx tmp = ((!can_create_pseudo_p ()
8959                   || rtx_equal_p (operands[0], operands[1]))
8960                  ? operands[0] : gen_reg_rtx (DImode));
8961
8962       if (GET_CODE (operands[2]) == CONST_INT)
8963         {
8964           value = INTVAL (operands[2]);
8965           emit_insn (gen_iordi3 (tmp, operands[1],
8966                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8967         }
8968       else
8969         {
8970           value = CONST_DOUBLE_LOW (operands[2]);
8971           emit_insn (gen_iordi3 (tmp, operands[1],
8972                                  immed_double_const (value
8973                                                      & (~ (HOST_WIDE_INT) 0xffff),
8974                                                      0, DImode)));
8975         }
8976
8977       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8978       DONE;
8979     }
8980 }")
8981
8982 (define_expand "xordi3"
8983   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8984         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
8985                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8986   "TARGET_POWERPC64"
8987   "
8988 {
8989   if (non_logical_cint_operand (operands[2], DImode))
8990     {
8991       HOST_WIDE_INT value;
8992       rtx tmp = ((!can_create_pseudo_p ()
8993                   || rtx_equal_p (operands[0], operands[1]))
8994                  ? operands[0] : gen_reg_rtx (DImode));
8995
8996       if (GET_CODE (operands[2]) == CONST_INT)
8997         {
8998           value = INTVAL (operands[2]);
8999           emit_insn (gen_xordi3 (tmp, operands[1],
9000                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
9001         }
9002       else
9003         {
9004           value = CONST_DOUBLE_LOW (operands[2]);
9005           emit_insn (gen_xordi3 (tmp, operands[1],
9006                                  immed_double_const (value
9007                                                      & (~ (HOST_WIDE_INT) 0xffff),
9008                                                      0, DImode)));
9009         }
9010
9011       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
9012       DONE;
9013     }
9014 }")
9015
9016 (define_insn "*booldi3_internal1"
9017   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
9018         (match_operator:DI 3 "boolean_or_operator"
9019          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
9020           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
9021   "TARGET_POWERPC64"
9022   "@
9023    %q3 %0,%1,%2
9024    %q3i %0,%1,%b2
9025    %q3is %0,%1,%u2")
9026
9027 (define_insn "*booldi3_internal2"
9028   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
9029         (compare:CC (match_operator:DI 4 "boolean_or_operator"
9030          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
9031           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
9032          (const_int 0)))
9033    (clobber (match_scratch:DI 3 "=r,r"))]
9034   "TARGET_64BIT"
9035   "@
9036    %q4. %3,%1,%2
9037    #"
9038   [(set_attr "type" "fast_compare,compare")
9039    (set_attr "length" "4,8")])
9040
9041 (define_split
9042   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
9043         (compare:CC (match_operator:DI 4 "boolean_operator"
9044          [(match_operand:DI 1 "gpc_reg_operand" "")
9045           (match_operand:DI 2 "gpc_reg_operand" "")])
9046          (const_int 0)))
9047    (clobber (match_scratch:DI 3 ""))]
9048   "TARGET_POWERPC64 && reload_completed"
9049   [(set (match_dup 3) (match_dup 4))
9050    (set (match_dup 0)
9051         (compare:CC (match_dup 3)
9052                     (const_int 0)))]
9053   "")
9054
9055 (define_insn "*booldi3_internal3"
9056   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
9057         (compare:CC (match_operator:DI 4 "boolean_or_operator"
9058          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
9059           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
9060          (const_int 0)))
9061    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
9062         (match_dup 4))]
9063   "TARGET_64BIT"
9064   "@
9065    %q4. %0,%1,%2
9066    #"
9067   [(set_attr "type" "fast_compare,compare")
9068    (set_attr "length" "4,8")])
9069
9070 (define_split
9071   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
9072         (compare:CC (match_operator:DI 4 "boolean_operator"
9073          [(match_operand:DI 1 "gpc_reg_operand" "")
9074           (match_operand:DI 2 "gpc_reg_operand" "")])
9075          (const_int 0)))
9076    (set (match_operand:DI 0 "gpc_reg_operand" "")
9077         (match_dup 4))]
9078   "TARGET_POWERPC64 && reload_completed"
9079   [(set (match_dup 0) (match_dup 4))
9080    (set (match_dup 3)
9081         (compare:CC (match_dup 0)
9082                     (const_int 0)))]
9083   "")
9084
9085 ;; Split a logical operation that we can't do in one insn into two insns,
9086 ;; each of which does one 16-bit part.  This is used by combine.
9087
9088 (define_split
9089   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9090         (match_operator:DI 3 "boolean_or_operator"
9091          [(match_operand:DI 1 "gpc_reg_operand" "")
9092           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
9093   "TARGET_POWERPC64"
9094   [(set (match_dup 0) (match_dup 4))
9095    (set (match_dup 0) (match_dup 5))]
9096 "
9097 {
9098   rtx i3,i4;
9099
9100   if (GET_CODE (operands[2]) == CONST_DOUBLE)
9101     {
9102       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
9103       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
9104                                         0, DImode);
9105       i4 = GEN_INT (value & 0xffff);
9106     }
9107   else
9108     {
9109       i3 = GEN_INT (INTVAL (operands[2])
9110                              & (~ (HOST_WIDE_INT) 0xffff));
9111       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
9112     }
9113   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
9114                                 operands[1], i3);
9115   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
9116                                 operands[0], i4);
9117 }")
9118
9119 (define_insn "*boolcdi3_internal1"
9120   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9121         (match_operator:DI 3 "boolean_operator"
9122          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
9123           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
9124   "TARGET_POWERPC64"
9125   "%q3 %0,%2,%1")
9126
9127 (define_insn "*boolcdi3_internal2"
9128   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
9129         (compare:CC (match_operator:DI 4 "boolean_operator"
9130          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
9131           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
9132          (const_int 0)))
9133    (clobber (match_scratch:DI 3 "=r,r"))]
9134   "TARGET_64BIT"
9135   "@
9136    %q4. %3,%2,%1
9137    #"
9138   [(set_attr "type" "fast_compare,compare")
9139    (set_attr "length" "4,8")])
9140
9141 (define_split
9142   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
9143         (compare:CC (match_operator:DI 4 "boolean_operator"
9144          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
9145           (match_operand:DI 2 "gpc_reg_operand" "")])
9146          (const_int 0)))
9147    (clobber (match_scratch:DI 3 ""))]
9148   "TARGET_POWERPC64 && reload_completed"
9149   [(set (match_dup 3) (match_dup 4))
9150    (set (match_dup 0)
9151         (compare:CC (match_dup 3)
9152                     (const_int 0)))]
9153   "")
9154
9155 (define_insn "*boolcdi3_internal3"
9156   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
9157         (compare:CC (match_operator:DI 4 "boolean_operator"
9158          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
9159           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
9160          (const_int 0)))
9161    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
9162         (match_dup 4))]
9163   "TARGET_64BIT"
9164   "@
9165    %q4. %0,%2,%1
9166    #"
9167   [(set_attr "type" "fast_compare,compare")
9168    (set_attr "length" "4,8")])
9169
9170 (define_split
9171   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
9172         (compare:CC (match_operator:DI 4 "boolean_operator"
9173          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
9174           (match_operand:DI 2 "gpc_reg_operand" "")])
9175          (const_int 0)))
9176    (set (match_operand:DI 0 "gpc_reg_operand" "")
9177         (match_dup 4))]
9178   "TARGET_POWERPC64 && reload_completed"
9179   [(set (match_dup 0) (match_dup 4))
9180    (set (match_dup 3)
9181         (compare:CC (match_dup 0)
9182                     (const_int 0)))]
9183   "")
9184
9185 (define_insn "*boolccdi3_internal1"
9186   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9187         (match_operator:DI 3 "boolean_operator"
9188          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
9189           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
9190   "TARGET_POWERPC64"
9191   "%q3 %0,%1,%2")
9192
9193 (define_insn "*boolccdi3_internal2"
9194   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
9195         (compare:CC (match_operator:DI 4 "boolean_operator"
9196          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
9197           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
9198          (const_int 0)))
9199    (clobber (match_scratch:DI 3 "=r,r"))]
9200   "TARGET_64BIT"
9201   "@
9202    %q4. %3,%1,%2
9203    #"
9204   [(set_attr "type" "fast_compare,compare")
9205    (set_attr "length" "4,8")])
9206
9207 (define_split
9208   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
9209         (compare:CC (match_operator:DI 4 "boolean_operator"
9210          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
9211           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
9212          (const_int 0)))
9213    (clobber (match_scratch:DI 3 ""))]
9214   "TARGET_POWERPC64 && reload_completed"
9215   [(set (match_dup 3) (match_dup 4))
9216    (set (match_dup 0)
9217         (compare:CC (match_dup 3)
9218                     (const_int 0)))]
9219   "")
9220
9221 (define_insn "*boolccdi3_internal3"
9222   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
9223         (compare:CC (match_operator:DI 4 "boolean_operator"
9224          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
9225           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
9226          (const_int 0)))
9227    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
9228         (match_dup 4))]
9229   "TARGET_64BIT"
9230   "@
9231    %q4. %0,%1,%2
9232    #"
9233   [(set_attr "type" "fast_compare,compare")
9234    (set_attr "length" "4,8")])
9235
9236 (define_split
9237   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
9238         (compare:CC (match_operator:DI 4 "boolean_operator"
9239          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
9240           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
9241          (const_int 0)))
9242    (set (match_operand:DI 0 "gpc_reg_operand" "")
9243         (match_dup 4))]
9244   "TARGET_POWERPC64 && reload_completed"
9245   [(set (match_dup 0) (match_dup 4))
9246    (set (match_dup 3)
9247         (compare:CC (match_dup 0)
9248                     (const_int 0)))]
9249   "")
9250
9251 (define_expand "smindi3"
9252   [(match_operand:DI 0 "gpc_reg_operand" "")
9253    (match_operand:DI 1 "gpc_reg_operand" "")
9254    (match_operand:DI 2 "gpc_reg_operand" "")]
9255   "TARGET_ISEL64"
9256   "
9257 {
9258   rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
9259   DONE;
9260 }")
9261
9262 (define_expand "smaxdi3"
9263   [(match_operand:DI 0 "gpc_reg_operand" "")
9264    (match_operand:DI 1 "gpc_reg_operand" "")
9265    (match_operand:DI 2 "gpc_reg_operand" "")]
9266   "TARGET_ISEL64"
9267   "
9268 {
9269   rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
9270   DONE;
9271 }")
9272
9273 (define_expand "umindi3"
9274   [(match_operand:DI 0 "gpc_reg_operand" "")
9275    (match_operand:DI 1 "gpc_reg_operand" "")
9276    (match_operand:DI 2 "gpc_reg_operand" "")]
9277   "TARGET_ISEL64"
9278   "
9279 {
9280   rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
9281   DONE;
9282 }")
9283
9284 (define_expand "umaxdi3"
9285   [(match_operand:DI 0 "gpc_reg_operand" "")
9286    (match_operand:DI 1 "gpc_reg_operand" "")
9287    (match_operand:DI 2 "gpc_reg_operand" "")]
9288   "TARGET_ISEL64"
9289   "
9290 {
9291   rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
9292   DONE;
9293 }")
9294
9295 \f
9296 ;; Now define ways of moving data around.
9297
9298 ;; Set up a register with a value from the GOT table
9299
9300 (define_expand "movsi_got"
9301   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9302         (unspec:SI [(match_operand:SI 1 "got_operand" "")
9303                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
9304   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
9305   "
9306 {
9307   if (GET_CODE (operands[1]) == CONST)
9308     {
9309       rtx offset = const0_rtx;
9310       HOST_WIDE_INT value;
9311
9312       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
9313       value = INTVAL (offset);
9314       if (value != 0)
9315         {
9316           rtx tmp = (!can_create_pseudo_p ()
9317                      ? operands[0]
9318                      : gen_reg_rtx (Pmode));
9319           emit_insn (gen_movsi_got (tmp, operands[1]));
9320           emit_insn (gen_addsi3 (operands[0], tmp, offset));
9321           DONE;
9322         }
9323     }
9324
9325   operands[2] = rs6000_got_register (operands[1]);
9326 }")
9327
9328 (define_insn "*movsi_got_internal"
9329   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9330         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
9331                     (match_operand:SI 2 "gpc_reg_operand" "b")]
9332                    UNSPEC_MOVSI_GOT))]
9333   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
9334   "{l|lwz} %0,%a1@got(%2)"
9335   [(set_attr "type" "load")])
9336
9337 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
9338 ;; didn't get allocated to a hard register.
9339 (define_split
9340   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9341         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
9342                     (match_operand:SI 2 "memory_operand" "")]
9343                    UNSPEC_MOVSI_GOT))]
9344   "DEFAULT_ABI == ABI_V4
9345     && flag_pic == 1
9346     && (reload_in_progress || reload_completed)"
9347   [(set (match_dup 0) (match_dup 2))
9348    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
9349                                  UNSPEC_MOVSI_GOT))]
9350   "")
9351
9352 ;; For SI, we special-case integers that can't be loaded in one insn.  We
9353 ;; do the load 16-bits at a time.  We could do this by loading from memory,
9354 ;; and this is even supposed to be faster, but it is simpler not to get
9355 ;; integers in the TOC.
9356 (define_insn "movsi_low"
9357   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9358         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
9359                            (match_operand 2 "" ""))))]
9360   "TARGET_MACHO && ! TARGET_64BIT"
9361   "{l|lwz} %0,lo16(%2)(%1)"
9362   [(set_attr "type" "load")
9363    (set_attr "length" "4")])
9364
9365 (define_insn "*movsi_internal1"
9366   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
9367         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
9368   "!TARGET_SINGLE_FPU &&
9369    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
9370   "@
9371    mr %0,%1
9372    {cal|la} %0,%a1
9373    {l%U1%X1|lwz%U1%X1} %0,%1
9374    {st%U0%X0|stw%U0%X0} %1,%0
9375    {lil|li} %0,%1
9376    {liu|lis} %0,%v1
9377    #
9378    {cal|la} %0,%a1
9379    mf%1 %0
9380    mt%0 %1
9381    mt%0 %1
9382    mt%0 %1
9383    {cror 0,0,0|nop}"
9384   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
9385    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
9386
9387 (define_insn "*movsi_internal1_single"
9388   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h,m,*f")
9389         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0,f,m"))]
9390   "TARGET_SINGLE_FPU &&
9391    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
9392   "@
9393    mr %0,%1
9394    {cal|la} %0,%a1
9395    {l%U1%X1|lwz%U1%X1} %0,%1
9396    {st%U0%X0|stw%U0%X0} %1,%0
9397    {lil|li} %0,%1
9398    {liu|lis} %0,%v1
9399    #
9400    {cal|la} %0,%a1
9401    mf%1 %0
9402    mt%0 %1
9403    mt%0 %1
9404    mt%0 %1
9405    {cror 0,0,0|nop}
9406    stfs%U0%X0 %1, %0
9407    lfs%U1%X1 %0, %1"
9408   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*,*,*")
9409    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4,4,4")])
9410
9411 ;; Split a load of a large constant into the appropriate two-insn
9412 ;; sequence.
9413
9414 (define_split
9415   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9416         (match_operand:SI 1 "const_int_operand" ""))]
9417   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
9418    && (INTVAL (operands[1]) & 0xffff) != 0"
9419   [(set (match_dup 0)
9420         (match_dup 2))
9421    (set (match_dup 0)
9422         (ior:SI (match_dup 0)
9423                 (match_dup 3)))]
9424   "
9425 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
9426
9427   if (tem == operands[0])
9428     DONE;
9429   else
9430     FAIL;
9431 }")
9432
9433 (define_insn "*mov<mode>_internal2"
9434   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
9435         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
9436                     (const_int 0)))
9437    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
9438   ""
9439   "@
9440    {cmpi|cmp<wd>i} %2,%0,0
9441    mr. %0,%1
9442    #"
9443   [(set_attr "type" "cmp,compare,cmp")
9444    (set_attr "length" "4,4,8")])
9445
9446 (define_split
9447   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
9448         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
9449                     (const_int 0)))
9450    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
9451   "reload_completed"
9452   [(set (match_dup 0) (match_dup 1))
9453    (set (match_dup 2)
9454         (compare:CC (match_dup 0)
9455                     (const_int 0)))]
9456   "")
9457 \f
9458 (define_insn "*movhi_internal"
9459   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
9460         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
9461   "gpc_reg_operand (operands[0], HImode)
9462    || gpc_reg_operand (operands[1], HImode)"
9463   "@
9464    mr %0,%1
9465    lhz%U1%X1 %0,%1
9466    sth%U0%X0 %1,%0
9467    {lil|li} %0,%w1
9468    mf%1 %0
9469    mt%0 %1
9470    mt%0 %1
9471    {cror 0,0,0|nop}"
9472   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
9473
9474 (define_expand "mov<mode>"
9475   [(set (match_operand:INT 0 "general_operand" "")
9476         (match_operand:INT 1 "any_operand" ""))]
9477   ""
9478   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9479
9480 (define_insn "*movqi_internal"
9481   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
9482         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
9483   "gpc_reg_operand (operands[0], QImode)
9484    || gpc_reg_operand (operands[1], QImode)"
9485   "@
9486    mr %0,%1
9487    lbz%U1%X1 %0,%1
9488    stb%U0%X0 %1,%0
9489    {lil|li} %0,%1
9490    mf%1 %0
9491    mt%0 %1
9492    mt%0 %1
9493    {cror 0,0,0|nop}"
9494   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
9495 \f
9496 ;; Here is how to move condition codes around.  When we store CC data in
9497 ;; an integer register or memory, we store just the high-order 4 bits.
9498 ;; This lets us not shift in the most common case of CR0.
9499 (define_expand "movcc"
9500   [(set (match_operand:CC 0 "nonimmediate_operand" "")
9501         (match_operand:CC 1 "nonimmediate_operand" ""))]
9502   ""
9503   "")
9504
9505 (define_insn "*movcc_internal1"
9506   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,q,cl,r,m")
9507         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,r,m,r"))]
9508   "register_operand (operands[0], CCmode)
9509    || register_operand (operands[1], CCmode)"
9510   "@
9511    mcrf %0,%1
9512    mtcrf 128,%1
9513    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
9514    crxor %0,%0,%0
9515    mfcr %0%Q1
9516    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
9517    mr %0,%1
9518    {lil|li} %0,%1
9519    mf%1 %0
9520    mt%0 %1
9521    mt%0 %1
9522    {l%U1%X1|lwz%U1%X1} %0,%1
9523    {st%U0%U1|stw%U0%U1} %1,%0"
9524   [(set (attr "type")
9525      (cond [(eq_attr "alternative" "0,3")
9526                 (const_string "cr_logical")
9527             (eq_attr "alternative" "1,2")
9528                 (const_string "mtcr")
9529             (eq_attr "alternative" "6,7,9")
9530                 (const_string "integer")
9531             (eq_attr "alternative" "8")
9532                 (const_string "mfjmpr")
9533             (eq_attr "alternative" "10")
9534                 (const_string "mtjmpr")
9535             (eq_attr "alternative" "11")
9536                 (const_string "load")
9537             (eq_attr "alternative" "12")
9538                 (const_string "store")
9539             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
9540                 (const_string "mfcrf")
9541            ]
9542         (const_string "mfcr")))
9543    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4,4")])
9544 \f
9545 ;; For floating-point, we normally deal with the floating-point registers
9546 ;; unless -msoft-float is used.  The sole exception is that parameter passing
9547 ;; can produce floating-point values in fixed-point registers.  Unless the
9548 ;; value is a simple constant or already in memory, we deal with this by
9549 ;; allocating memory and copying the value explicitly via that memory location.
9550 (define_expand "movsf"
9551   [(set (match_operand:SF 0 "nonimmediate_operand" "")
9552         (match_operand:SF 1 "any_operand" ""))]
9553   ""
9554   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
9555
9556 (define_split
9557   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9558         (match_operand:SF 1 "const_double_operand" ""))]
9559   "reload_completed
9560    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9561        || (GET_CODE (operands[0]) == SUBREG
9562            && GET_CODE (SUBREG_REG (operands[0])) == REG
9563            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9564   [(set (match_dup 2) (match_dup 3))]
9565   "
9566 {
9567   long l;
9568   REAL_VALUE_TYPE rv;
9569
9570   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9571   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9572
9573   if (! TARGET_POWERPC64)
9574     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
9575   else
9576     operands[2] = gen_lowpart (SImode, operands[0]);
9577
9578   operands[3] = gen_int_mode (l, SImode);
9579 }")
9580
9581 (define_insn "*movsf_hardfloat"
9582   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
9583         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
9584   "(gpc_reg_operand (operands[0], SFmode)
9585    || gpc_reg_operand (operands[1], SFmode))
9586    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
9587   "@
9588    mr %0,%1
9589    {l%U1%X1|lwz%U1%X1} %0,%1
9590    {st%U0%X0|stw%U0%X0} %1,%0
9591    fmr %0,%1
9592    lfs%U1%X1 %0,%1
9593    stfs%U0%X0 %1,%0
9594    mt%0 %1
9595    mt%0 %1
9596    mf%1 %0
9597    {cror 0,0,0|nop}
9598    #
9599    #"
9600   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
9601    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
9602
9603 (define_insn "*movsf_softfloat"
9604   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
9605         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
9606   "(gpc_reg_operand (operands[0], SFmode)
9607    || gpc_reg_operand (operands[1], SFmode))
9608    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
9609   "@
9610    mr %0,%1
9611    mt%0 %1
9612    mt%0 %1
9613    mf%1 %0
9614    {l%U1%X1|lwz%U1%X1} %0,%1
9615    {st%U0%X0|stw%U0%X0} %1,%0
9616    {lil|li} %0,%1
9617    {liu|lis} %0,%v1
9618    {cal|la} %0,%a1
9619    #
9620    #
9621    {cror 0,0,0|nop}"
9622   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
9623    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
9624
9625 \f
9626 (define_expand "movdf"
9627   [(set (match_operand:DF 0 "nonimmediate_operand" "")
9628         (match_operand:DF 1 "any_operand" ""))]
9629   ""
9630   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
9631
9632 (define_split
9633   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9634         (match_operand:DF 1 "const_int_operand" ""))]
9635   "! TARGET_POWERPC64 && reload_completed
9636    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9637        || (GET_CODE (operands[0]) == SUBREG
9638            && GET_CODE (SUBREG_REG (operands[0])) == REG
9639            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9640   [(set (match_dup 2) (match_dup 4))
9641    (set (match_dup 3) (match_dup 1))]
9642   "
9643 {
9644   int endian = (WORDS_BIG_ENDIAN == 0);
9645   HOST_WIDE_INT value = INTVAL (operands[1]);
9646
9647   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
9648   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
9649 #if HOST_BITS_PER_WIDE_INT == 32
9650   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
9651 #else
9652   operands[4] = GEN_INT (value >> 32);
9653   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9654 #endif
9655 }")
9656
9657 (define_split
9658   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9659         (match_operand:DF 1 "const_double_operand" ""))]
9660   "! TARGET_POWERPC64 && reload_completed
9661    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9662        || (GET_CODE (operands[0]) == SUBREG
9663            && GET_CODE (SUBREG_REG (operands[0])) == REG
9664            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9665   [(set (match_dup 2) (match_dup 4))
9666    (set (match_dup 3) (match_dup 5))]
9667   "
9668 {
9669   int endian = (WORDS_BIG_ENDIAN == 0);
9670   long l[2];
9671   REAL_VALUE_TYPE rv;
9672
9673   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9674   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
9675
9676   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
9677   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
9678   operands[4] = gen_int_mode (l[endian], SImode);
9679   operands[5] = gen_int_mode (l[1 - endian], SImode);
9680 }")
9681
9682 (define_split
9683   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9684         (match_operand:DF 1 "const_double_operand" ""))]
9685   "TARGET_POWERPC64 && reload_completed
9686    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9687        || (GET_CODE (operands[0]) == SUBREG
9688            && GET_CODE (SUBREG_REG (operands[0])) == REG
9689            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9690   [(set (match_dup 2) (match_dup 3))]
9691   "
9692 {
9693   int endian = (WORDS_BIG_ENDIAN == 0);
9694   long l[2];
9695   REAL_VALUE_TYPE rv;
9696 #if HOST_BITS_PER_WIDE_INT >= 64
9697   HOST_WIDE_INT val;
9698 #endif
9699
9700   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9701   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
9702
9703   operands[2] = gen_lowpart (DImode, operands[0]);
9704   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
9705 #if HOST_BITS_PER_WIDE_INT >= 64
9706   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
9707          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
9708
9709   operands[3] = gen_int_mode (val, DImode);
9710 #else
9711   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
9712 #endif
9713 }")
9714
9715 ;; Don't have reload use general registers to load a constant.  First,
9716 ;; it might not work if the output operand is the equivalent of
9717 ;; a non-offsettable memref, but also it is less efficient than loading
9718 ;; the constant into an FP register, since it will probably be used there.
9719 ;; The "??" is a kludge until we can figure out a more reasonable way
9720 ;; of handling these non-offsettable values.
9721 (define_insn "*movdf_hardfloat32"
9722   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,ws,?wa,ws,?wa,Z,?Z,d,d,m,wa,!r,!r,!r")
9723         (match_operand:DF 1 "input_operand" "r,m,r,ws,wa,Z,Z,ws,wa,d,m,d,j,G,H,F"))]
9724   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9725    && (gpc_reg_operand (operands[0], DFmode)
9726        || gpc_reg_operand (operands[1], DFmode))"
9727   "*
9728 {
9729   switch (which_alternative)
9730     {
9731     default:
9732       gcc_unreachable ();
9733     case 0:
9734     case 1:
9735     case 2:
9736       return \"#\";
9737     case 3:
9738     case 4:
9739       return \"xxlor %x0,%x1,%x1\";
9740     case 5:
9741     case 6:
9742       return \"lxsd%U1x %x0,%y1\";
9743     case 7:
9744     case 8:
9745       return \"stxsd%U0x %x1,%y0\";
9746     case 9:
9747       return \"fmr %0,%1\";
9748     case 10:
9749       return \"lfd%U1%X1 %0,%1\";
9750     case 11:
9751       return \"stfd%U0%X0 %1,%0\";
9752     case 12:
9753       return \"xxlxor %x0,%x0,%x0\";
9754     case 13:
9755     case 14:
9756     case 15:
9757       return \"#\";
9758     }
9759 }"
9760   [(set_attr "type" "two,load,store,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,*,*,*")
9761    (set_attr "length" "8,16,16,4,4,4,4,4,4,4,4,4,4,8,12,16")])
9762
9763 (define_insn "*movdf_softfloat32"
9764   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
9765         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
9766   "! TARGET_POWERPC64 
9767    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
9768        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
9769    && (gpc_reg_operand (operands[0], DFmode)
9770        || gpc_reg_operand (operands[1], DFmode))"
9771   "#"
9772   [(set_attr "type" "two,load,store,*,*,*")
9773    (set_attr "length" "8,8,8,8,12,16")])
9774
9775 ; ld/std require word-aligned displacements -> 'Y' constraint.
9776 ; List Y->r and r->Y before r->r for reload.
9777 (define_insn "*movdf_hardfloat64_mfpgpr"
9778   [(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")
9779         (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"))]
9780   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
9781    && TARGET_DOUBLE_FLOAT
9782    && (gpc_reg_operand (operands[0], DFmode)
9783        || gpc_reg_operand (operands[1], DFmode))"
9784   "@
9785    std%U0%X0 %1,%0
9786    ld%U1%X1 %0,%1
9787    mr %0,%1
9788    xxlor %x0,%x1,%x1
9789    xxlor %x0,%x1,%x1
9790    lxsd%U1x %x0,%y1
9791    lxsd%U1x %x0,%y1
9792    stxsd%U0x %x1,%y0
9793    stxsd%U0x %x1,%y0
9794    fmr %0,%1
9795    lfd%U1%X1 %0,%1
9796    stfd%U0%X0 %1,%0
9797    xxlxor %x0,%x0,%x0
9798    mt%0 %1
9799    mf%1 %0
9800    {cror 0,0,0|nop}
9801    #
9802    #
9803    #
9804    mftgpr %0,%1
9805    mffgpr %0,%1"
9806   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
9807    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
9808
9809 ; ld/std require word-aligned displacements -> 'Y' constraint.
9810 ; List Y->r and r->Y before r->r for reload.
9811 (define_insn "*movdf_hardfloat64"
9812   [(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")
9813         (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"))]
9814   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
9815    && TARGET_DOUBLE_FLOAT
9816    && (gpc_reg_operand (operands[0], DFmode)
9817        || gpc_reg_operand (operands[1], DFmode))"
9818   "@
9819    std%U0%X0 %1,%0
9820    ld%U1%X1 %0,%1
9821    mr %0,%1
9822    xxlor %x0,%x1,%x1
9823    xxlor %x0,%x1,%x1
9824    lxsd%U1x %x0,%y1
9825    lxsd%U1x %x0,%y1
9826    stxsd%U0x %x1,%y0
9827    stxsd%U0x %x1,%y0
9828    fmr %0,%1
9829    lfd%U1%X1 %0,%1
9830    stfd%U0%X0 %1,%0
9831    xxlxor %x0,%x0,%x0
9832    mt%0 %1
9833    mf%1 %0
9834    {cror 0,0,0|nop}
9835    #
9836    #
9837    #"
9838   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,mtjmpr,mfjmpr,*,*,*,*")
9839    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16")])
9840
9841 (define_insn "*movdf_softfloat64"
9842   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
9843         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
9844   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
9845    && (gpc_reg_operand (operands[0], DFmode)
9846        || gpc_reg_operand (operands[1], DFmode))"
9847   "@
9848    ld%U1%X1 %0,%1
9849    std%U0%X0 %1,%0
9850    mr %0,%1
9851    mt%0 %1
9852    mf%1 %0
9853    #
9854    #
9855    #
9856    {cror 0,0,0|nop}"
9857   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
9858    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
9859 \f
9860 (define_expand "movtf"
9861   [(set (match_operand:TF 0 "general_operand" "")
9862         (match_operand:TF 1 "any_operand" ""))]
9863   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
9864   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
9865
9866 ; It's important to list the o->f and f->o moves before f->f because
9867 ; otherwise reload, given m->f, will try to pick f->f and reload it,
9868 ; which doesn't make progress.  Likewise r->Y must be before r->r.
9869 (define_insn_and_split "*movtf_internal"
9870   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,d,d,r,Y,r")
9871         (match_operand:TF 1 "input_operand"         "d,o,d,YGHF,r,r"))]
9872   "!TARGET_IEEEQUAD
9873    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
9874    && (gpc_reg_operand (operands[0], TFmode)
9875        || gpc_reg_operand (operands[1], TFmode))"
9876   "#"
9877   "&& reload_completed"
9878   [(pc)]
9879 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9880   [(set_attr "length" "8,8,8,20,20,16")])
9881
9882 (define_insn_and_split "*movtf_softfloat"
9883   [(set (match_operand:TF 0 "rs6000_nonimmediate_operand" "=r,Y,r")
9884         (match_operand:TF 1 "input_operand"         "YGHF,r,r"))]
9885   "!TARGET_IEEEQUAD
9886    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
9887    && (gpc_reg_operand (operands[0], TFmode)
9888        || gpc_reg_operand (operands[1], TFmode))"
9889   "#"
9890   "&& reload_completed"
9891   [(pc)]
9892 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9893   [(set_attr "length" "20,20,16")])
9894
9895 (define_expand "extenddftf2"
9896   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9897         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
9898   "!TARGET_IEEEQUAD
9899    && TARGET_HARD_FLOAT
9900    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9901    && TARGET_LONG_DOUBLE_128"
9902 {
9903   if (TARGET_E500_DOUBLE)
9904     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
9905   else
9906     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
9907   DONE;
9908 })
9909
9910 (define_expand "extenddftf2_fprs"
9911   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9912                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
9913               (use (match_dup 2))])]
9914   "!TARGET_IEEEQUAD
9915    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9916    && TARGET_LONG_DOUBLE_128"
9917 {
9918   operands[2] = CONST0_RTX (DFmode);
9919   /* Generate GOT reference early for SVR4 PIC.  */
9920   if (DEFAULT_ABI == ABI_V4 && flag_pic)
9921     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
9922 })
9923
9924 (define_insn_and_split "*extenddftf2_internal"
9925   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,d,&d,r")
9926        (float_extend:TF (match_operand:DF 1 "input_operand" "dr,md,md,rmGHF")))
9927    (use (match_operand:DF 2 "zero_reg_mem_operand" "rd,m,d,n"))]
9928   "!TARGET_IEEEQUAD
9929    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9930    && TARGET_LONG_DOUBLE_128"
9931   "#"
9932   "&& reload_completed"
9933   [(pc)]
9934 {
9935   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
9936   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
9937   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
9938                   operands[1]);
9939   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
9940                   operands[2]);
9941   DONE;
9942 })
9943
9944 (define_expand "extendsftf2"
9945   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9946         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
9947   "!TARGET_IEEEQUAD
9948    && TARGET_HARD_FLOAT
9949    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9950    && TARGET_LONG_DOUBLE_128"
9951 {
9952   rtx tmp = gen_reg_rtx (DFmode);
9953   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
9954   emit_insn (gen_extenddftf2 (operands[0], tmp));
9955   DONE;
9956 })
9957
9958 (define_expand "trunctfdf2"
9959   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9960         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
9961   "!TARGET_IEEEQUAD
9962    && TARGET_HARD_FLOAT
9963    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9964    && TARGET_LONG_DOUBLE_128"
9965   "")
9966
9967 (define_insn_and_split "trunctfdf2_internal1"
9968   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
9969         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
9970   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
9971    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9972   "@
9973    #
9974    fmr %0,%1"
9975   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
9976   [(const_int 0)]
9977 {
9978   emit_note (NOTE_INSN_DELETED);
9979   DONE;
9980 }
9981   [(set_attr "type" "fp")])
9982
9983 (define_insn "trunctfdf2_internal2"
9984   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9985         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9986   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
9987    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9988    && TARGET_LONG_DOUBLE_128"
9989   "fadd %0,%1,%L1"
9990   [(set_attr "type" "fp")
9991    (set_attr "fp_type" "fp_addsub_d")])
9992
9993 (define_expand "trunctfsf2"
9994   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9995         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
9996   "!TARGET_IEEEQUAD
9997    && TARGET_HARD_FLOAT
9998    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9999    && TARGET_LONG_DOUBLE_128"
10000 {
10001   if (TARGET_E500_DOUBLE)
10002     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
10003   else
10004     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
10005   DONE;
10006 })
10007
10008 (define_insn_and_split "trunctfsf2_fprs"
10009   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
10010         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
10011    (clobber (match_scratch:DF 2 "=d"))]
10012   "!TARGET_IEEEQUAD
10013    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
10014    && TARGET_LONG_DOUBLE_128"
10015   "#"
10016   "&& reload_completed"
10017   [(set (match_dup 2)
10018         (float_truncate:DF (match_dup 1)))
10019    (set (match_dup 0)
10020         (float_truncate:SF (match_dup 2)))]
10021   "")
10022
10023 (define_expand "floatsitf2"
10024   [(set (match_operand:TF 0 "gpc_reg_operand" "")
10025         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
10026   "!TARGET_IEEEQUAD
10027    && TARGET_HARD_FLOAT
10028    && (TARGET_FPRS || TARGET_E500_DOUBLE)
10029    && TARGET_LONG_DOUBLE_128"
10030 {
10031   rtx tmp = gen_reg_rtx (DFmode);
10032   expand_float (tmp, operands[1], false);
10033   emit_insn (gen_extenddftf2 (operands[0], tmp));
10034   DONE;
10035 })
10036
10037 ; fadd, but rounding towards zero.
10038 ; This is probably not the optimal code sequence.
10039 (define_insn "fix_trunc_helper"
10040   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
10041         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
10042                    UNSPEC_FIX_TRUNC_TF))
10043    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
10044   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
10045   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
10046   [(set_attr "type" "fp")
10047    (set_attr "length" "20")])
10048
10049 (define_expand "fix_trunctfsi2"
10050   [(set (match_operand:SI 0 "gpc_reg_operand" "")
10051         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
10052   "!TARGET_IEEEQUAD
10053    && (TARGET_POWER2 || TARGET_POWERPC)
10054    && TARGET_HARD_FLOAT
10055    && (TARGET_FPRS || TARGET_E500_DOUBLE)
10056    && TARGET_LONG_DOUBLE_128"
10057 {
10058   if (TARGET_E500_DOUBLE)
10059     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
10060   else
10061     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
10062   DONE;
10063 })
10064
10065 (define_expand "fix_trunctfsi2_fprs"
10066   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
10067                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
10068               (clobber (match_dup 2))
10069               (clobber (match_dup 3))
10070               (clobber (match_dup 4))
10071               (clobber (match_dup 5))])]
10072   "!TARGET_IEEEQUAD
10073    && (TARGET_POWER2 || TARGET_POWERPC)
10074    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10075 {
10076   operands[2] = gen_reg_rtx (DFmode);
10077   operands[3] = gen_reg_rtx (DFmode);
10078   operands[4] = gen_reg_rtx (DImode);
10079   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
10080 })
10081
10082 (define_insn_and_split "*fix_trunctfsi2_internal"
10083   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10084         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
10085    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
10086    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
10087    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
10088    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
10089   "!TARGET_IEEEQUAD
10090    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10091   "#"
10092   ""
10093   [(pc)]
10094 {
10095   rtx lowword;
10096   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
10097
10098   gcc_assert (MEM_P (operands[5]));
10099   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
10100
10101   emit_insn (gen_fctiwz_df (operands[4], operands[2]));
10102   emit_move_insn (operands[5], operands[4]);
10103   emit_move_insn (operands[0], lowword);
10104   DONE;
10105 })
10106
10107 (define_expand "negtf2"
10108   [(set (match_operand:TF 0 "gpc_reg_operand" "")
10109         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
10110   "!TARGET_IEEEQUAD
10111    && TARGET_HARD_FLOAT
10112    && (TARGET_FPRS || TARGET_E500_DOUBLE)
10113    && TARGET_LONG_DOUBLE_128"
10114   "")
10115
10116 (define_insn "negtf2_internal"
10117   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
10118         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
10119   "!TARGET_IEEEQUAD
10120    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10121   "*
10122 {
10123   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
10124     return \"fneg %L0,%L1\;fneg %0,%1\";
10125   else
10126     return \"fneg %0,%1\;fneg %L0,%L1\";
10127 }"
10128   [(set_attr "type" "fp")
10129    (set_attr "length" "8")])
10130
10131 (define_expand "abstf2"
10132   [(set (match_operand:TF 0 "gpc_reg_operand" "")
10133         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
10134   "!TARGET_IEEEQUAD
10135    && TARGET_HARD_FLOAT
10136    && (TARGET_FPRS || TARGET_E500_DOUBLE)
10137    && TARGET_LONG_DOUBLE_128"
10138   "
10139 {
10140   rtx label = gen_label_rtx ();
10141   if (TARGET_E500_DOUBLE)
10142     {
10143       if (flag_finite_math_only && !flag_trapping_math)
10144         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
10145       else
10146         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
10147     }
10148   else
10149     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
10150   emit_label (label);
10151   DONE;
10152 }")
10153
10154 (define_expand "abstf2_internal"
10155   [(set (match_operand:TF 0 "gpc_reg_operand" "")
10156         (match_operand:TF 1 "gpc_reg_operand" ""))
10157    (set (match_dup 3) (match_dup 5))
10158    (set (match_dup 5) (abs:DF (match_dup 5)))
10159    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
10160    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
10161                            (label_ref (match_operand 2 "" ""))
10162                            (pc)))
10163    (set (match_dup 6) (neg:DF (match_dup 6)))]
10164   "!TARGET_IEEEQUAD
10165    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
10166    && TARGET_LONG_DOUBLE_128"
10167   "
10168 {
10169   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
10170   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
10171   operands[3] = gen_reg_rtx (DFmode);
10172   operands[4] = gen_reg_rtx (CCFPmode);
10173   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
10174   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
10175 }")
10176 \f
10177 ;; Next come the multi-word integer load and store and the load and store
10178 ;; multiple insns.
10179
10180 ; List r->r after r->"o<>", otherwise reload will try to reload a
10181 ; non-offsettable address by using r->r which won't make progress.
10182 (define_insn "*movdi_internal32"
10183   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=o<>,r,r,*d,*d,m,r")
10184         (match_operand:DI 1 "input_operand" "r,r,m,d,m,d,IJKnGHF"))]
10185   "! TARGET_POWERPC64
10186    && (gpc_reg_operand (operands[0], DImode)
10187        || gpc_reg_operand (operands[1], DImode))"
10188   "@
10189    #
10190    #
10191    #
10192    fmr %0,%1
10193    lfd%U1%X1 %0,%1
10194    stfd%U0%X0 %1,%0
10195    #"
10196   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
10197
10198 (define_split
10199   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10200         (match_operand:DI 1 "const_int_operand" ""))]
10201   "! TARGET_POWERPC64 && reload_completed"
10202   [(set (match_dup 2) (match_dup 4))
10203    (set (match_dup 3) (match_dup 1))]
10204   "
10205 {
10206   HOST_WIDE_INT value = INTVAL (operands[1]);
10207   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10208                                        DImode);
10209   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10210                                        DImode);
10211 #if HOST_BITS_PER_WIDE_INT == 32
10212   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
10213 #else
10214   operands[4] = GEN_INT (value >> 32);
10215   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
10216 #endif
10217 }")
10218
10219 (define_split
10220   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
10221         (match_operand:DIFD 1 "input_operand" ""))]
10222   "reload_completed && !TARGET_POWERPC64
10223    && gpr_or_gpr_p (operands[0], operands[1])"
10224   [(pc)]
10225 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10226
10227 (define_insn "*movdi_mfpgpr"
10228   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*d,*d,m,r,*h,*h,r,*d")
10229         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,d,m,d,*h,r,0,*d,r"))]
10230   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
10231    && (gpc_reg_operand (operands[0], DImode)
10232        || gpc_reg_operand (operands[1], DImode))"
10233   "@
10234    mr %0,%1
10235    ld%U1%X1 %0,%1
10236    std%U0%X0 %1,%0
10237    li %0,%1
10238    lis %0,%v1
10239    #
10240    {cal|la} %0,%a1
10241    fmr %0,%1
10242    lfd%U1%X1 %0,%1
10243    stfd%U0%X0 %1,%0
10244    mf%1 %0
10245    mt%0 %1
10246    {cror 0,0,0|nop}
10247    mftgpr %0,%1
10248    mffgpr %0,%1"
10249   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*,mftgpr,mffgpr")
10250    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4")])
10251
10252 (define_insn "*movdi_internal64"
10253   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*d,*d,m,r,*h,*h")
10254         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,d,m,d,*h,r,0"))]
10255   "TARGET_POWERPC64 && (!TARGET_MFPGPR || !TARGET_HARD_FLOAT || !TARGET_FPRS)
10256    && (gpc_reg_operand (operands[0], DImode)
10257        || gpc_reg_operand (operands[1], DImode))"
10258   "@
10259    mr %0,%1
10260    ld%U1%X1 %0,%1
10261    std%U0%X0 %1,%0
10262    li %0,%1
10263    lis %0,%v1
10264    #
10265    {cal|la} %0,%a1
10266    fmr %0,%1
10267    lfd%U1%X1 %0,%1
10268    stfd%U0%X0 %1,%0
10269    mf%1 %0
10270    mt%0 %1
10271    {cror 0,0,0|nop}"
10272   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
10273    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
10274
10275 ;; immediate value valid for a single instruction hiding in a const_double
10276 (define_insn ""
10277   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10278         (match_operand:DI 1 "const_double_operand" "F"))]
10279   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
10280    && GET_CODE (operands[1]) == CONST_DOUBLE
10281    && num_insns_constant (operands[1], DImode) == 1"
10282   "*
10283 {
10284   return ((unsigned HOST_WIDE_INT)
10285           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
10286          ? \"li %0,%1\" : \"lis %0,%v1\";
10287 }")
10288
10289 ;; Generate all one-bits and clear left or right.
10290 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
10291 (define_split
10292   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10293         (match_operand:DI 1 "mask64_operand" ""))]
10294   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10295   [(set (match_dup 0) (const_int -1))
10296    (set (match_dup 0)
10297         (and:DI (rotate:DI (match_dup 0)
10298                            (const_int 0))
10299                 (match_dup 1)))]
10300   "")
10301
10302 ;; Split a load of a large constant into the appropriate five-instruction
10303 ;; sequence.  Handle anything in a constant number of insns.
10304 ;; When non-easy constants can go in the TOC, this should use
10305 ;; easy_fp_constant predicate.
10306 (define_split
10307   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10308         (match_operand:DI 1 "const_int_operand" ""))]
10309   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10310   [(set (match_dup 0) (match_dup 2))
10311    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
10312   "
10313 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
10314
10315   if (tem == operands[0])
10316     DONE;
10317   else
10318     FAIL;
10319 }")
10320
10321 (define_split
10322   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10323         (match_operand:DI 1 "const_double_operand" ""))]
10324   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10325   [(set (match_dup 0) (match_dup 2))
10326    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
10327   "
10328 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
10329
10330   if (tem == operands[0])
10331     DONE;
10332   else
10333     FAIL;
10334 }")
10335 \f
10336 ;; TImode is similar, except that we usually want to compute the address into
10337 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
10338 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
10339
10340 ;; We say that MQ is clobbered in the last alternative because the first
10341 ;; alternative would never get used otherwise since it would need a reload
10342 ;; while the 2nd alternative would not.  We put memory cases first so they
10343 ;; are preferred.  Otherwise, we'd try to reload the output instead of
10344 ;; giving the SCRATCH mq.
10345
10346 (define_insn "*movti_power"
10347   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
10348         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
10349    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
10350   "TARGET_POWER && ! TARGET_POWERPC64
10351    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
10352   "*
10353 {
10354   switch (which_alternative)
10355     {
10356     default:
10357       gcc_unreachable ();
10358
10359     case 0:
10360       if (TARGET_STRING)
10361         return \"{stsi|stswi} %1,%P0,16\";
10362     case 1:
10363     case 2:
10364       return \"#\";
10365     case 3:
10366       /* If the address is not used in the output, we can use lsi.  Otherwise,
10367          fall through to generating four loads.  */
10368       if (TARGET_STRING
10369           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
10370         return \"{lsi|lswi} %0,%P1,16\";
10371       /* ... fall through ...  */
10372     case 4:
10373     case 5:
10374       return \"#\";
10375     }
10376 }"
10377   [(set_attr "type" "store,store,*,load,load,*")])
10378
10379 (define_insn "*movti_string"
10380   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
10381         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
10382   "! TARGET_POWER && ! TARGET_POWERPC64
10383    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
10384   "*
10385 {
10386   switch (which_alternative)
10387     {
10388     default:
10389       gcc_unreachable ();
10390     case 0:
10391       if (TARGET_STRING)
10392         return \"{stsi|stswi} %1,%P0,16\";
10393     case 1:
10394     case 2:
10395       return \"#\";
10396     case 3:
10397       /* If the address is not used in the output, we can use lsi.  Otherwise,
10398          fall through to generating four loads.  */
10399       if (TARGET_STRING
10400           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
10401         return \"{lsi|lswi} %0,%P1,16\";
10402       /* ... fall through ...  */
10403     case 4:
10404     case 5:
10405       return \"#\";
10406     }
10407 }"
10408   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")
10409    (set (attr "cell_micro") (if_then_else (eq (symbol_ref "TARGET_STRING") (const_int 1))
10410                                           (const_string "always")
10411                                           (const_string "conditional")))])
10412
10413 (define_insn "*movti_ppc64"
10414   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
10415         (match_operand:TI 1 "input_operand" "r,r,m"))]
10416   "(TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
10417     || gpc_reg_operand (operands[1], TImode)))
10418    && VECTOR_MEM_NONE_P (TImode)"
10419   "#"
10420   [(set_attr "type" "*,store,load")])
10421
10422 (define_split
10423   [(set (match_operand:TI 0 "gpc_reg_operand" "")
10424         (match_operand:TI 1 "const_double_operand" ""))]
10425   "TARGET_POWERPC64 && VECTOR_MEM_NONE_P (TImode)"
10426   [(set (match_dup 2) (match_dup 4))
10427    (set (match_dup 3) (match_dup 5))]
10428   "
10429 {
10430   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10431                                        TImode);
10432   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10433                                        TImode);
10434   if (GET_CODE (operands[1]) == CONST_DOUBLE)
10435     {
10436       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
10437       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
10438     }
10439   else if (GET_CODE (operands[1]) == CONST_INT)
10440     {
10441       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
10442       operands[5] = operands[1];
10443     }
10444   else
10445     FAIL;
10446 }")
10447
10448 (define_split
10449   [(set (match_operand:TI 0 "nonimmediate_operand" "")
10450         (match_operand:TI 1 "input_operand" ""))]
10451   "reload_completed && VECTOR_MEM_NONE_P (TImode)
10452    && gpr_or_gpr_p (operands[0], operands[1])"
10453   [(pc)]
10454 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10455 \f
10456 (define_expand "load_multiple"
10457   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10458                           (match_operand:SI 1 "" ""))
10459                      (use (match_operand:SI 2 "" ""))])]
10460   "TARGET_STRING && !TARGET_POWERPC64"
10461   "
10462 {
10463   int regno;
10464   int count;
10465   rtx op1;
10466   int i;
10467
10468   /* Support only loading a constant number of fixed-point registers from
10469      memory and only bother with this if more than two; the machine
10470      doesn't support more than eight.  */
10471   if (GET_CODE (operands[2]) != CONST_INT
10472       || INTVAL (operands[2]) <= 2
10473       || INTVAL (operands[2]) > 8
10474       || GET_CODE (operands[1]) != MEM
10475       || GET_CODE (operands[0]) != REG
10476       || REGNO (operands[0]) >= 32)
10477     FAIL;
10478
10479   count = INTVAL (operands[2]);
10480   regno = REGNO (operands[0]);
10481
10482   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
10483   op1 = replace_equiv_address (operands[1],
10484                                force_reg (SImode, XEXP (operands[1], 0)));
10485
10486   for (i = 0; i < count; i++)
10487     XVECEXP (operands[3], 0, i)
10488       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
10489                      adjust_address_nv (op1, SImode, i * 4));
10490 }")
10491
10492 (define_insn "*ldmsi8"
10493   [(match_parallel 0 "load_multiple_operation"
10494     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10495           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10496      (set (match_operand:SI 3 "gpc_reg_operand" "")
10497           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10498      (set (match_operand:SI 4 "gpc_reg_operand" "")
10499           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10500      (set (match_operand:SI 5 "gpc_reg_operand" "")
10501           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10502      (set (match_operand:SI 6 "gpc_reg_operand" "")
10503           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10504      (set (match_operand:SI 7 "gpc_reg_operand" "")
10505           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10506      (set (match_operand:SI 8 "gpc_reg_operand" "")
10507           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
10508      (set (match_operand:SI 9 "gpc_reg_operand" "")
10509           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
10510   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10511   "*
10512 { return rs6000_output_load_multiple (operands); }"
10513   [(set_attr "type" "load_ux")
10514    (set_attr "length" "32")])
10515
10516 (define_insn "*ldmsi7"
10517   [(match_parallel 0 "load_multiple_operation"
10518     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10519           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10520      (set (match_operand:SI 3 "gpc_reg_operand" "")
10521           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10522      (set (match_operand:SI 4 "gpc_reg_operand" "")
10523           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10524      (set (match_operand:SI 5 "gpc_reg_operand" "")
10525           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10526      (set (match_operand:SI 6 "gpc_reg_operand" "")
10527           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10528      (set (match_operand:SI 7 "gpc_reg_operand" "")
10529           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10530      (set (match_operand:SI 8 "gpc_reg_operand" "")
10531           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
10532   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10533   "*
10534 { return rs6000_output_load_multiple (operands); }"
10535   [(set_attr "type" "load_ux")
10536    (set_attr "length" "32")])
10537
10538 (define_insn "*ldmsi6"
10539   [(match_parallel 0 "load_multiple_operation"
10540     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10541           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10542      (set (match_operand:SI 3 "gpc_reg_operand" "")
10543           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10544      (set (match_operand:SI 4 "gpc_reg_operand" "")
10545           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10546      (set (match_operand:SI 5 "gpc_reg_operand" "")
10547           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10548      (set (match_operand:SI 6 "gpc_reg_operand" "")
10549           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10550      (set (match_operand:SI 7 "gpc_reg_operand" "")
10551           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
10552   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10553   "*
10554 { return rs6000_output_load_multiple (operands); }"
10555   [(set_attr "type" "load_ux")
10556    (set_attr "length" "32")])
10557
10558 (define_insn "*ldmsi5"
10559   [(match_parallel 0 "load_multiple_operation"
10560     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10561           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10562      (set (match_operand:SI 3 "gpc_reg_operand" "")
10563           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10564      (set (match_operand:SI 4 "gpc_reg_operand" "")
10565           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10566      (set (match_operand:SI 5 "gpc_reg_operand" "")
10567           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10568      (set (match_operand:SI 6 "gpc_reg_operand" "")
10569           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
10570   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10571   "*
10572 { return rs6000_output_load_multiple (operands); }"
10573   [(set_attr "type" "load_ux")
10574    (set_attr "length" "32")])
10575
10576 (define_insn "*ldmsi4"
10577   [(match_parallel 0 "load_multiple_operation"
10578     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10579           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10580      (set (match_operand:SI 3 "gpc_reg_operand" "")
10581           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10582      (set (match_operand:SI 4 "gpc_reg_operand" "")
10583           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10584      (set (match_operand:SI 5 "gpc_reg_operand" "")
10585           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
10586   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10587   "*
10588 { return rs6000_output_load_multiple (operands); }"
10589   [(set_attr "type" "load_ux")
10590    (set_attr "length" "32")])
10591
10592 (define_insn "*ldmsi3"
10593   [(match_parallel 0 "load_multiple_operation"
10594     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10595           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10596      (set (match_operand:SI 3 "gpc_reg_operand" "")
10597           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10598      (set (match_operand:SI 4 "gpc_reg_operand" "")
10599           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
10600   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
10601   "*
10602 { return rs6000_output_load_multiple (operands); }"
10603   [(set_attr "type" "load_ux")
10604    (set_attr "length" "32")])
10605
10606 (define_expand "store_multiple"
10607   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10608                           (match_operand:SI 1 "" ""))
10609                      (clobber (scratch:SI))
10610                      (use (match_operand:SI 2 "" ""))])]
10611   "TARGET_STRING && !TARGET_POWERPC64"
10612   "
10613 {
10614   int regno;
10615   int count;
10616   rtx to;
10617   rtx op0;
10618   int i;
10619
10620   /* Support only storing a constant number of fixed-point registers to
10621      memory and only bother with this if more than two; the machine
10622      doesn't support more than eight.  */
10623   if (GET_CODE (operands[2]) != CONST_INT
10624       || INTVAL (operands[2]) <= 2
10625       || INTVAL (operands[2]) > 8
10626       || GET_CODE (operands[0]) != MEM
10627       || GET_CODE (operands[1]) != REG
10628       || REGNO (operands[1]) >= 32)
10629     FAIL;
10630
10631   count = INTVAL (operands[2]);
10632   regno = REGNO (operands[1]);
10633
10634   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
10635   to = force_reg (SImode, XEXP (operands[0], 0));
10636   op0 = replace_equiv_address (operands[0], to);
10637
10638   XVECEXP (operands[3], 0, 0)
10639     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
10640   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
10641                                                  gen_rtx_SCRATCH (SImode));
10642
10643   for (i = 1; i < count; i++)
10644     XVECEXP (operands[3], 0, i + 1)
10645       = gen_rtx_SET (VOIDmode,
10646                      adjust_address_nv (op0, SImode, i * 4),
10647                      gen_rtx_REG (SImode, regno + i));
10648 }")
10649
10650 (define_insn "*stmsi8"
10651   [(match_parallel 0 "store_multiple_operation"
10652     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10653           (match_operand:SI 2 "gpc_reg_operand" "r"))
10654      (clobber (match_scratch:SI 3 "=X"))
10655      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10656           (match_operand:SI 4 "gpc_reg_operand" "r"))
10657      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10658           (match_operand:SI 5 "gpc_reg_operand" "r"))
10659      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10660           (match_operand:SI 6 "gpc_reg_operand" "r"))
10661      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10662           (match_operand:SI 7 "gpc_reg_operand" "r"))
10663      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10664           (match_operand:SI 8 "gpc_reg_operand" "r"))
10665      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10666           (match_operand:SI 9 "gpc_reg_operand" "r"))
10667      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10668           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10669   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
10670   "{stsi|stswi} %2,%1,%O0"
10671   [(set_attr "type" "store_ux")
10672    (set_attr "cell_micro" "always")])
10673
10674 (define_insn "*stmsi7"
10675   [(match_parallel 0 "store_multiple_operation"
10676     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10677           (match_operand:SI 2 "gpc_reg_operand" "r"))
10678      (clobber (match_scratch:SI 3 "=X"))
10679      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10680           (match_operand:SI 4 "gpc_reg_operand" "r"))
10681      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10682           (match_operand:SI 5 "gpc_reg_operand" "r"))
10683      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10684           (match_operand:SI 6 "gpc_reg_operand" "r"))
10685      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10686           (match_operand:SI 7 "gpc_reg_operand" "r"))
10687      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10688           (match_operand:SI 8 "gpc_reg_operand" "r"))
10689      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10690           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10691   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
10692   "{stsi|stswi} %2,%1,%O0"
10693   [(set_attr "type" "store_ux")
10694    (set_attr "cell_micro" "always")])
10695
10696 (define_insn "*stmsi6"
10697   [(match_parallel 0 "store_multiple_operation"
10698     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10699           (match_operand:SI 2 "gpc_reg_operand" "r"))
10700      (clobber (match_scratch:SI 3 "=X"))
10701      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10702           (match_operand:SI 4 "gpc_reg_operand" "r"))
10703      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10704           (match_operand:SI 5 "gpc_reg_operand" "r"))
10705      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10706           (match_operand:SI 6 "gpc_reg_operand" "r"))
10707      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10708           (match_operand:SI 7 "gpc_reg_operand" "r"))
10709      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10710           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10711   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
10712   "{stsi|stswi} %2,%1,%O0"
10713   [(set_attr "type" "store_ux")
10714    (set_attr "cell_micro" "always")])
10715
10716 (define_insn "*stmsi5"
10717   [(match_parallel 0 "store_multiple_operation"
10718     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10719           (match_operand:SI 2 "gpc_reg_operand" "r"))
10720      (clobber (match_scratch:SI 3 "=X"))
10721      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10722           (match_operand:SI 4 "gpc_reg_operand" "r"))
10723      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10724           (match_operand:SI 5 "gpc_reg_operand" "r"))
10725      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10726           (match_operand:SI 6 "gpc_reg_operand" "r"))
10727      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10728           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10729   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
10730   "{stsi|stswi} %2,%1,%O0"
10731   [(set_attr "type" "store_ux")
10732    (set_attr "cell_micro" "always")])
10733
10734 (define_insn "*stmsi4"
10735   [(match_parallel 0 "store_multiple_operation"
10736     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10737           (match_operand:SI 2 "gpc_reg_operand" "r"))
10738      (clobber (match_scratch:SI 3 "=X"))
10739      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10740           (match_operand:SI 4 "gpc_reg_operand" "r"))
10741      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10742           (match_operand:SI 5 "gpc_reg_operand" "r"))
10743      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10744           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10745   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
10746   "{stsi|stswi} %2,%1,%O0"
10747   [(set_attr "type" "store_ux")
10748    (set_attr "cell_micro" "always")])
10749
10750 (define_insn "*stmsi3"
10751   [(match_parallel 0 "store_multiple_operation"
10752     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10753           (match_operand:SI 2 "gpc_reg_operand" "r"))
10754      (clobber (match_scratch:SI 3 "=X"))
10755      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10756           (match_operand:SI 4 "gpc_reg_operand" "r"))
10757      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10758           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10759   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
10760   "{stsi|stswi} %2,%1,%O0"
10761   [(set_attr "type" "store_ux")
10762    (set_attr "cell_micro" "always")])
10763
10764 (define_insn "*stmsi8_power"
10765   [(match_parallel 0 "store_multiple_operation"
10766     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10767           (match_operand:SI 2 "gpc_reg_operand" "r"))
10768      (clobber (match_scratch:SI 3 "=q"))
10769      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10770           (match_operand:SI 4 "gpc_reg_operand" "r"))
10771      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10772           (match_operand:SI 5 "gpc_reg_operand" "r"))
10773      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10774           (match_operand:SI 6 "gpc_reg_operand" "r"))
10775      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10776           (match_operand:SI 7 "gpc_reg_operand" "r"))
10777      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10778           (match_operand:SI 8 "gpc_reg_operand" "r"))
10779      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10780           (match_operand:SI 9 "gpc_reg_operand" "r"))
10781      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10782           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10783   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 9"
10784   "{stsi|stswi} %2,%1,%O0"
10785   [(set_attr "type" "store_ux")
10786    (set_attr "cell_micro" "always")])
10787
10788 (define_insn "*stmsi7_power"
10789   [(match_parallel 0 "store_multiple_operation"
10790     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10791           (match_operand:SI 2 "gpc_reg_operand" "r"))
10792      (clobber (match_scratch:SI 3 "=q"))
10793      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10794           (match_operand:SI 4 "gpc_reg_operand" "r"))
10795      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10796           (match_operand:SI 5 "gpc_reg_operand" "r"))
10797      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10798           (match_operand:SI 6 "gpc_reg_operand" "r"))
10799      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10800           (match_operand:SI 7 "gpc_reg_operand" "r"))
10801      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10802           (match_operand:SI 8 "gpc_reg_operand" "r"))
10803      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10804           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10805   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 8"
10806   "{stsi|stswi} %2,%1,%O0"
10807   [(set_attr "type" "store_ux")
10808    (set_attr "cell_micro" "always")])
10809
10810 (define_insn "*stmsi6_power"
10811   [(match_parallel 0 "store_multiple_operation"
10812     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10813           (match_operand:SI 2 "gpc_reg_operand" "r"))
10814      (clobber (match_scratch:SI 3 "=q"))
10815      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10816           (match_operand:SI 4 "gpc_reg_operand" "r"))
10817      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10818           (match_operand:SI 5 "gpc_reg_operand" "r"))
10819      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10820           (match_operand:SI 6 "gpc_reg_operand" "r"))
10821      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10822           (match_operand:SI 7 "gpc_reg_operand" "r"))
10823      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10824           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10825   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 7"
10826   "{stsi|stswi} %2,%1,%O0"
10827   [(set_attr "type" "store_ux")
10828    (set_attr "cell_micro" "always")])
10829
10830 (define_insn "*stmsi5_power"
10831   [(match_parallel 0 "store_multiple_operation"
10832     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10833           (match_operand:SI 2 "gpc_reg_operand" "r"))
10834      (clobber (match_scratch:SI 3 "=q"))
10835      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10836           (match_operand:SI 4 "gpc_reg_operand" "r"))
10837      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10838           (match_operand:SI 5 "gpc_reg_operand" "r"))
10839      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10840           (match_operand:SI 6 "gpc_reg_operand" "r"))
10841      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10842           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10843   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 6"
10844   "{stsi|stswi} %2,%1,%O0"
10845   [(set_attr "type" "store_ux")
10846    (set_attr "cell_micro" "always")])
10847
10848 (define_insn "*stmsi4_power"
10849   [(match_parallel 0 "store_multiple_operation"
10850     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10851           (match_operand:SI 2 "gpc_reg_operand" "r"))
10852      (clobber (match_scratch:SI 3 "=q"))
10853      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10854           (match_operand:SI 4 "gpc_reg_operand" "r"))
10855      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10856           (match_operand:SI 5 "gpc_reg_operand" "r"))
10857      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10858           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10859   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 5"
10860   "{stsi|stswi} %2,%1,%O0"
10861   [(set_attr "type" "store_ux")
10862    (set_attr "cell_micro" "always")])
10863
10864 (define_insn "*stmsi3_power"
10865   [(match_parallel 0 "store_multiple_operation"
10866     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10867           (match_operand:SI 2 "gpc_reg_operand" "r"))
10868      (clobber (match_scratch:SI 3 "=q"))
10869      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10870           (match_operand:SI 4 "gpc_reg_operand" "r"))
10871      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10872           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10873   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 4"
10874   "{stsi|stswi} %2,%1,%O0"
10875   [(set_attr "type" "store_ux")
10876    (set_attr "cell_micro" "always")])
10877 \f
10878 (define_expand "setmemsi"
10879   [(parallel [(set (match_operand:BLK 0 "" "")
10880                    (match_operand 2 "const_int_operand" ""))
10881               (use (match_operand:SI 1 "" ""))
10882               (use (match_operand:SI 3 "" ""))])]
10883   ""
10884   "
10885 {
10886   /* If value to set is not zero, use the library routine.  */
10887   if (operands[2] != const0_rtx)
10888     FAIL;
10889
10890   if (expand_block_clear (operands))
10891     DONE;
10892   else
10893     FAIL;
10894 }")
10895
10896 ;; String/block move insn.
10897 ;; Argument 0 is the destination
10898 ;; Argument 1 is the source
10899 ;; Argument 2 is the length
10900 ;; Argument 3 is the alignment
10901
10902 (define_expand "movmemsi"
10903   [(parallel [(set (match_operand:BLK 0 "" "")
10904                    (match_operand:BLK 1 "" ""))
10905               (use (match_operand:SI 2 "" ""))
10906               (use (match_operand:SI 3 "" ""))])]
10907   ""
10908   "
10909 {
10910   if (expand_block_move (operands))
10911     DONE;
10912   else
10913     FAIL;
10914 }")
10915
10916 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
10917 ;; register allocator doesn't have a clue about allocating 8 word registers.
10918 ;; rD/rS = r5 is preferred, efficient form.
10919 (define_expand "movmemsi_8reg"
10920   [(parallel [(set (match_operand 0 "" "")
10921                    (match_operand 1 "" ""))
10922               (use (match_operand 2 "" ""))
10923               (use (match_operand 3 "" ""))
10924               (clobber (reg:SI  5))
10925               (clobber (reg:SI  6))
10926               (clobber (reg:SI  7))
10927               (clobber (reg:SI  8))
10928               (clobber (reg:SI  9))
10929               (clobber (reg:SI 10))
10930               (clobber (reg:SI 11))
10931               (clobber (reg:SI 12))
10932               (clobber (match_scratch:SI 4 ""))])]
10933   "TARGET_STRING"
10934   "")
10935
10936 (define_insn ""
10937   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10938         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10939    (use (match_operand:SI 2 "immediate_operand" "i"))
10940    (use (match_operand:SI 3 "immediate_operand" "i"))
10941    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10942    (clobber (reg:SI  6))
10943    (clobber (reg:SI  7))
10944    (clobber (reg:SI  8))
10945    (clobber (reg:SI  9))
10946    (clobber (reg:SI 10))
10947    (clobber (reg:SI 11))
10948    (clobber (reg:SI 12))
10949    (clobber (match_scratch:SI 5 "=q"))]
10950   "TARGET_STRING && TARGET_POWER
10951    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10952        || INTVAL (operands[2]) == 0)
10953    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10954    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10955    && REGNO (operands[4]) == 5"
10956   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10957   [(set_attr "type" "store_ux")
10958    (set_attr "cell_micro" "always")
10959    (set_attr "length" "8")])
10960
10961 (define_insn ""
10962   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10963         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10964    (use (match_operand:SI 2 "immediate_operand" "i"))
10965    (use (match_operand:SI 3 "immediate_operand" "i"))
10966    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10967    (clobber (reg:SI  6))
10968    (clobber (reg:SI  7))
10969    (clobber (reg:SI  8))
10970    (clobber (reg:SI  9))
10971    (clobber (reg:SI 10))
10972    (clobber (reg:SI 11))
10973    (clobber (reg:SI 12))
10974    (clobber (match_scratch:SI 5 "=X"))]
10975   "TARGET_STRING && ! TARGET_POWER
10976    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10977        || INTVAL (operands[2]) == 0)
10978    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10979    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10980    && REGNO (operands[4]) == 5"
10981   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10982   [(set_attr "type" "store_ux")
10983    (set_attr "cell_micro" "always")
10984    (set_attr "length" "8")])
10985
10986 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
10987 ;; register allocator doesn't have a clue about allocating 6 word registers.
10988 ;; rD/rS = r5 is preferred, efficient form.
10989 (define_expand "movmemsi_6reg"
10990   [(parallel [(set (match_operand 0 "" "")
10991                    (match_operand 1 "" ""))
10992               (use (match_operand 2 "" ""))
10993               (use (match_operand 3 "" ""))
10994               (clobber (reg:SI  5))
10995               (clobber (reg:SI  6))
10996               (clobber (reg:SI  7))
10997               (clobber (reg:SI  8))
10998               (clobber (reg:SI  9))
10999               (clobber (reg:SI 10))
11000               (clobber (match_scratch:SI 4 ""))])]
11001   "TARGET_STRING"
11002   "")
11003
11004 (define_insn ""
11005   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11006         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11007    (use (match_operand:SI 2 "immediate_operand" "i"))
11008    (use (match_operand:SI 3 "immediate_operand" "i"))
11009    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
11010    (clobber (reg:SI  6))
11011    (clobber (reg:SI  7))
11012    (clobber (reg:SI  8))
11013    (clobber (reg:SI  9))
11014    (clobber (reg:SI 10))
11015    (clobber (match_scratch:SI 5 "=q"))]
11016   "TARGET_STRING && TARGET_POWER
11017    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
11018    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
11019    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
11020    && REGNO (operands[4]) == 5"
11021   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11022   [(set_attr "type" "store_ux")
11023    (set_attr "cell_micro" "always")
11024    (set_attr "length" "8")])
11025
11026 (define_insn ""
11027   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
11028         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
11029    (use (match_operand:SI 2 "immediate_operand" "i"))
11030    (use (match_operand:SI 3 "immediate_operand" "i"))
11031    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
11032    (clobber (reg:SI  6))
11033    (clobber (reg:SI  7))
11034    (clobber (reg:SI  8))
11035    (clobber (reg:SI  9))
11036    (clobber (reg:SI 10))
11037    (clobber (match_scratch:SI 5 "=X"))]
11038   "TARGET_STRING && ! TARGET_POWER
11039    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
11040    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
11041    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
11042    && REGNO (operands[4]) == 5"
11043   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11044   [(set_attr "type" "store_ux")
11045    (set_attr "cell_micro" "always")
11046    (set_attr "length" "8")])
11047
11048 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
11049 ;; problems with TImode.
11050 ;; rD/rS = r5 is preferred, efficient form.
11051 (define_expand "movmemsi_4reg"
11052   [(parallel [(set (match_operand 0 "" "")
11053                    (match_operand 1 "" ""))
11054               (use (match_operand 2 "" ""))
11055               (use (match_operand 3 "" ""))
11056               (clobber (reg:SI 5))
11057               (clobber (reg:SI 6))
11058               (clobber (reg:SI 7))
11059               (clobber (reg:SI 8))
11060               (clobber (match_scratch:SI 4 ""))])]
11061   "TARGET_STRING"
11062   "")
11063
11064 (define_insn ""
11065   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11066         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11067    (use (match_operand:SI 2 "immediate_operand" "i"))
11068    (use (match_operand:SI 3 "immediate_operand" "i"))
11069    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
11070    (clobber (reg:SI 6))
11071    (clobber (reg:SI 7))
11072    (clobber (reg:SI 8))
11073    (clobber (match_scratch:SI 5 "=q"))]
11074   "TARGET_STRING && TARGET_POWER
11075    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
11076    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
11077    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
11078    && REGNO (operands[4]) == 5"
11079   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11080   [(set_attr "type" "store_ux")
11081    (set_attr "cell_micro" "always")
11082    (set_attr "length" "8")])
11083
11084 (define_insn ""
11085   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
11086         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
11087    (use (match_operand:SI 2 "immediate_operand" "i"))
11088    (use (match_operand:SI 3 "immediate_operand" "i"))
11089    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
11090    (clobber (reg:SI 6))
11091    (clobber (reg:SI 7))
11092    (clobber (reg:SI 8))
11093    (clobber (match_scratch:SI 5 "=X"))]
11094   "TARGET_STRING && ! TARGET_POWER
11095    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
11096    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
11097    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
11098    && REGNO (operands[4]) == 5"
11099   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11100   [(set_attr "type" "store_ux")
11101    (set_attr "cell_micro" "always")
11102    (set_attr "length" "8")])
11103
11104 ;; Move up to 8 bytes at a time.
11105 (define_expand "movmemsi_2reg"
11106   [(parallel [(set (match_operand 0 "" "")
11107                    (match_operand 1 "" ""))
11108               (use (match_operand 2 "" ""))
11109               (use (match_operand 3 "" ""))
11110               (clobber (match_scratch:DI 4 ""))
11111               (clobber (match_scratch:SI 5 ""))])]
11112   "TARGET_STRING && ! TARGET_POWERPC64"
11113   "")
11114
11115 (define_insn ""
11116   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11117         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11118    (use (match_operand:SI 2 "immediate_operand" "i"))
11119    (use (match_operand:SI 3 "immediate_operand" "i"))
11120    (clobber (match_scratch:DI 4 "=&r"))
11121    (clobber (match_scratch:SI 5 "=q"))]
11122   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
11123    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
11124   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11125   [(set_attr "type" "store_ux")
11126    (set_attr "cell_micro" "always")
11127    (set_attr "length" "8")])
11128
11129 (define_insn ""
11130   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11131         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11132    (use (match_operand:SI 2 "immediate_operand" "i"))
11133    (use (match_operand:SI 3 "immediate_operand" "i"))
11134    (clobber (match_scratch:DI 4 "=&r"))
11135    (clobber (match_scratch:SI 5 "=X"))]
11136   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
11137    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
11138   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11139   [(set_attr "type" "store_ux")
11140    (set_attr "cell_micro" "always")
11141    (set_attr "length" "8")])
11142
11143 ;; Move up to 4 bytes at a time.
11144 (define_expand "movmemsi_1reg"
11145   [(parallel [(set (match_operand 0 "" "")
11146                    (match_operand 1 "" ""))
11147               (use (match_operand 2 "" ""))
11148               (use (match_operand 3 "" ""))
11149               (clobber (match_scratch:SI 4 ""))
11150               (clobber (match_scratch:SI 5 ""))])]
11151   "TARGET_STRING"
11152   "")
11153
11154 (define_insn ""
11155   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11156         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11157    (use (match_operand:SI 2 "immediate_operand" "i"))
11158    (use (match_operand:SI 3 "immediate_operand" "i"))
11159    (clobber (match_scratch:SI 4 "=&r"))
11160    (clobber (match_scratch:SI 5 "=q"))]
11161   "TARGET_STRING && TARGET_POWER
11162    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
11163   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11164   [(set_attr "type" "store_ux")
11165    (set_attr "cell_micro" "always")
11166    (set_attr "length" "8")])
11167
11168 (define_insn ""
11169   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
11170         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
11171    (use (match_operand:SI 2 "immediate_operand" "i"))
11172    (use (match_operand:SI 3 "immediate_operand" "i"))
11173    (clobber (match_scratch:SI 4 "=&r"))
11174    (clobber (match_scratch:SI 5 "=X"))]
11175   "TARGET_STRING && ! TARGET_POWER
11176    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
11177   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11178   [(set_attr "type" "store_ux")
11179    (set_attr "cell_micro" "always")
11180    (set_attr "length" "8")])
11181 \f
11182 ;; Define insns that do load or store with update.  Some of these we can
11183 ;; get by using pre-decrement or pre-increment, but the hardware can also
11184 ;; do cases where the increment is not the size of the object.
11185 ;;
11186 ;; In all these cases, we use operands 0 and 1 for the register being
11187 ;; incremented because those are the operands that local-alloc will
11188 ;; tie and these are the pair most likely to be tieable (and the ones
11189 ;; that will benefit the most).
11190
11191 (define_insn "*movdi_update1"
11192   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
11193         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
11194                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
11195    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
11196         (plus:DI (match_dup 1) (match_dup 2)))]
11197   "TARGET_POWERPC64 && TARGET_UPDATE
11198    && (!avoiding_indexed_address_p (DImode)
11199        || !gpc_reg_operand (operands[2], DImode))"
11200   "@
11201    ldux %3,%0,%2
11202    ldu %3,%2(%0)"
11203   [(set_attr "type" "load_ux,load_u")])
11204
11205 (define_insn "movdi_<mode>_update"
11206   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
11207                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
11208         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
11209    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
11210         (plus:P (match_dup 1) (match_dup 2)))]
11211   "TARGET_POWERPC64 && TARGET_UPDATE
11212    && (!avoiding_indexed_address_p (Pmode)
11213        || !gpc_reg_operand (operands[2], Pmode)
11214        || (REG_P (operands[0])
11215            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
11216   "@
11217    stdux %3,%0,%2
11218    stdu %3,%2(%0)"
11219   [(set_attr "type" "store_ux,store_u")])
11220
11221 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
11222 ;; needed for stack allocation, even if the user passes -mno-update.
11223 (define_insn "movdi_<mode>_update_stack"
11224   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
11225                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
11226         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
11227    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
11228         (plus:P (match_dup 1) (match_dup 2)))]
11229   "TARGET_POWERPC64"
11230   "@
11231    stdux %3,%0,%2
11232    stdu %3,%2(%0)"
11233   [(set_attr "type" "store_ux,store_u")])
11234
11235 (define_insn "*movsi_update1"
11236   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11237         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11238                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11239    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11240         (plus:SI (match_dup 1) (match_dup 2)))]
11241   "TARGET_UPDATE
11242    && (!avoiding_indexed_address_p (SImode)
11243        || !gpc_reg_operand (operands[2], SImode))"
11244   "@
11245    {lux|lwzux} %3,%0,%2
11246    {lu|lwzu} %3,%2(%0)"
11247   [(set_attr "type" "load_ux,load_u")])
11248
11249 (define_insn "*movsi_update2"
11250   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
11251         (sign_extend:DI
11252          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
11253                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
11254    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
11255         (plus:DI (match_dup 1) (match_dup 2)))]
11256   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
11257    && !avoiding_indexed_address_p (DImode)"
11258   "lwaux %3,%0,%2"
11259   [(set_attr "type" "load_ext_ux")])
11260
11261 (define_insn "movsi_update"
11262   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11263                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11264         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
11265    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11266         (plus:SI (match_dup 1) (match_dup 2)))]
11267   "TARGET_UPDATE
11268    && (!avoiding_indexed_address_p (SImode)
11269        || !gpc_reg_operand (operands[2], SImode)
11270        || (REG_P (operands[0])
11271            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
11272   "@
11273    {stux|stwux} %3,%0,%2
11274    {stu|stwu} %3,%2(%0)"
11275   [(set_attr "type" "store_ux,store_u")])
11276
11277 ;; This is an unconditional pattern; needed for stack allocation, even
11278 ;; if the user passes -mno-update.
11279 (define_insn "movsi_update_stack"
11280   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11281                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11282         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
11283    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11284         (plus:SI (match_dup 1) (match_dup 2)))]
11285   ""
11286   "@
11287    {stux|stwux} %3,%0,%2
11288    {stu|stwu} %3,%2(%0)"
11289   [(set_attr "type" "store_ux,store_u")])
11290
11291 (define_insn "*movhi_update1"
11292   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
11293         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11294                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11295    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11296         (plus:SI (match_dup 1) (match_dup 2)))]
11297   "TARGET_UPDATE
11298    && (!avoiding_indexed_address_p (SImode)
11299        || !gpc_reg_operand (operands[2], SImode))"
11300   "@
11301    lhzux %3,%0,%2
11302    lhzu %3,%2(%0)"
11303   [(set_attr "type" "load_ux,load_u")])
11304
11305 (define_insn "*movhi_update2"
11306   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11307         (zero_extend:SI
11308          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11309                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
11310    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11311         (plus:SI (match_dup 1) (match_dup 2)))]
11312   "TARGET_UPDATE
11313    && (!avoiding_indexed_address_p (SImode)
11314        || !gpc_reg_operand (operands[2], SImode))"
11315   "@
11316    lhzux %3,%0,%2
11317    lhzu %3,%2(%0)"
11318   [(set_attr "type" "load_ux,load_u")])
11319
11320 (define_insn "*movhi_update3"
11321   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11322         (sign_extend:SI
11323          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11324                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
11325    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11326         (plus:SI (match_dup 1) (match_dup 2)))]
11327   "TARGET_UPDATE && rs6000_gen_cell_microcode
11328    && (!avoiding_indexed_address_p (SImode)
11329        || !gpc_reg_operand (operands[2], SImode))"
11330   "@
11331    lhaux %3,%0,%2
11332    lhau %3,%2(%0)"
11333   [(set_attr "type" "load_ext_ux,load_ext_u")])
11334
11335 (define_insn "*movhi_update4"
11336   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11337                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11338         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
11339    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11340         (plus:SI (match_dup 1) (match_dup 2)))]
11341   "TARGET_UPDATE
11342    && (!avoiding_indexed_address_p (SImode)
11343        || !gpc_reg_operand (operands[2], SImode))"
11344   "@
11345    sthux %3,%0,%2
11346    sthu %3,%2(%0)"
11347   [(set_attr "type" "store_ux,store_u")])
11348
11349 (define_insn "*movqi_update1"
11350   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
11351         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11352                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11353    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11354         (plus:SI (match_dup 1) (match_dup 2)))]
11355   "TARGET_UPDATE
11356    && (!avoiding_indexed_address_p (SImode)
11357        || !gpc_reg_operand (operands[2], SImode))"
11358   "@
11359    lbzux %3,%0,%2
11360    lbzu %3,%2(%0)"
11361   [(set_attr "type" "load_ux,load_u")])
11362
11363 (define_insn "*movqi_update2"
11364   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11365         (zero_extend:SI
11366          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11367                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
11368    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11369         (plus:SI (match_dup 1) (match_dup 2)))]
11370   "TARGET_UPDATE
11371    && (!avoiding_indexed_address_p (SImode)
11372        || !gpc_reg_operand (operands[2], SImode))"
11373   "@
11374    lbzux %3,%0,%2
11375    lbzu %3,%2(%0)"
11376   [(set_attr "type" "load_ux,load_u")])
11377
11378 (define_insn "*movqi_update3"
11379   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11380                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11381         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
11382    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11383         (plus:SI (match_dup 1) (match_dup 2)))]
11384   "TARGET_UPDATE
11385    && (!avoiding_indexed_address_p (SImode)
11386        || !gpc_reg_operand (operands[2], SImode))"
11387   "@
11388    stbux %3,%0,%2
11389    stbu %3,%2(%0)"
11390   [(set_attr "type" "store_ux,store_u")])
11391
11392 (define_insn "*movsf_update1"
11393   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
11394         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11395                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11396    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11397         (plus:SI (match_dup 1) (match_dup 2)))]
11398   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
11399    && (!avoiding_indexed_address_p (SImode)
11400        || !gpc_reg_operand (operands[2], SImode))"
11401   "@
11402    lfsux %3,%0,%2
11403    lfsu %3,%2(%0)"
11404   [(set_attr "type" "fpload_ux,fpload_u")])
11405
11406 (define_insn "*movsf_update2"
11407   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11408                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11409         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
11410    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11411         (plus:SI (match_dup 1) (match_dup 2)))]
11412   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
11413    && (!avoiding_indexed_address_p (SImode)
11414        || !gpc_reg_operand (operands[2], SImode))"
11415   "@
11416    stfsux %3,%0,%2
11417    stfsu %3,%2(%0)"
11418   [(set_attr "type" "fpstore_ux,fpstore_u")])
11419
11420 (define_insn "*movsf_update3"
11421   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
11422         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11423                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11424    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11425         (plus:SI (match_dup 1) (match_dup 2)))]
11426   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
11427    && (!avoiding_indexed_address_p (SImode)
11428        || !gpc_reg_operand (operands[2], SImode))"
11429   "@
11430    {lux|lwzux} %3,%0,%2
11431    {lu|lwzu} %3,%2(%0)"
11432   [(set_attr "type" "load_ux,load_u")])
11433
11434 (define_insn "*movsf_update4"
11435   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11436                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11437         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
11438    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11439         (plus:SI (match_dup 1) (match_dup 2)))]
11440   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
11441    && (!avoiding_indexed_address_p (SImode)
11442        || !gpc_reg_operand (operands[2], SImode))"
11443   "@
11444    {stux|stwux} %3,%0,%2
11445    {stu|stwu} %3,%2(%0)"
11446   [(set_attr "type" "store_ux,store_u")])
11447
11448 (define_insn "*movdf_update1"
11449   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
11450         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11451                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11452    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11453         (plus:SI (match_dup 1) (match_dup 2)))]
11454   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
11455    && (!avoiding_indexed_address_p (SImode)
11456        || !gpc_reg_operand (operands[2], SImode))"
11457   "@
11458    lfdux %3,%0,%2
11459    lfdu %3,%2(%0)"
11460   [(set_attr "type" "fpload_ux,fpload_u")])
11461
11462 (define_insn "*movdf_update2"
11463   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11464                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11465         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
11466    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11467         (plus:SI (match_dup 1) (match_dup 2)))]
11468   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
11469    && (!avoiding_indexed_address_p (SImode)
11470        || !gpc_reg_operand (operands[2], SImode))"
11471   "@
11472    stfdux %3,%0,%2
11473    stfdu %3,%2(%0)"
11474   [(set_attr "type" "fpstore_ux,fpstore_u")])
11475
11476 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
11477
11478 (define_insn "*lfq_power2"
11479   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
11480         (match_operand:V2DF 1 "memory_operand" ""))]
11481   "TARGET_POWER2
11482    && TARGET_HARD_FLOAT && TARGET_FPRS"
11483   "lfq%U1%X1 %0,%1")
11484
11485 (define_peephole2
11486   [(set (match_operand:DF 0 "gpc_reg_operand" "")
11487         (match_operand:DF 1 "memory_operand" ""))
11488    (set (match_operand:DF 2 "gpc_reg_operand" "")
11489         (match_operand:DF 3 "memory_operand" ""))]
11490   "TARGET_POWER2
11491    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
11492    && registers_ok_for_quad_peep (operands[0], operands[2])
11493    && mems_ok_for_quad_peep (operands[1], operands[3])"
11494   [(set (match_dup 0)
11495         (match_dup 1))]
11496   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
11497    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
11498
11499 (define_insn "*stfq_power2"
11500   [(set (match_operand:V2DF 0 "memory_operand" "")
11501         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
11502   "TARGET_POWER2
11503    && TARGET_HARD_FLOAT && TARGET_FPRS"
11504   "stfq%U0%X0 %1,%0")
11505
11506
11507 (define_peephole2
11508   [(set (match_operand:DF 0 "memory_operand" "")
11509         (match_operand:DF 1 "gpc_reg_operand" ""))
11510    (set (match_operand:DF 2 "memory_operand" "")
11511         (match_operand:DF 3 "gpc_reg_operand" ""))]
11512   "TARGET_POWER2
11513    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
11514    && registers_ok_for_quad_peep (operands[1], operands[3])
11515    && mems_ok_for_quad_peep (operands[0], operands[2])"
11516   [(set (match_dup 0)
11517         (match_dup 1))]
11518   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
11519    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
11520
11521 ;; After inserting conditional returns we can sometimes have
11522 ;; unnecessary register moves.  Unfortunately we cannot have a
11523 ;; modeless peephole here, because some single SImode sets have early
11524 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
11525 ;; sequences, using get_attr_length here will smash the operands
11526 ;; array.  Neither is there an early_cobbler_p predicate.
11527 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
11528 (define_peephole2
11529   [(set (match_operand:DF 0 "gpc_reg_operand" "")
11530         (match_operand:DF 1 "any_operand" ""))
11531    (set (match_operand:DF 2 "gpc_reg_operand" "")
11532         (match_dup 0))]
11533   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
11534    && peep2_reg_dead_p (2, operands[0])"
11535   [(set (match_dup 2) (match_dup 1))])
11536
11537 (define_peephole2
11538   [(set (match_operand:SF 0 "gpc_reg_operand" "")
11539         (match_operand:SF 1 "any_operand" ""))
11540    (set (match_operand:SF 2 "gpc_reg_operand" "")
11541         (match_dup 0))]
11542   "peep2_reg_dead_p (2, operands[0])"
11543   [(set (match_dup 2) (match_dup 1))])
11544
11545 \f
11546 ;; TLS support.
11547
11548 ;; Mode attributes for different ABIs.
11549 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
11550 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
11551 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
11552 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
11553
11554 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
11555   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11556         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11557               (match_operand 4 "" "g")))
11558    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11559                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11560                    UNSPEC_TLSGD)
11561    (clobber (reg:SI LR_REGNO))]
11562   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11563 {
11564   if (TARGET_CMODEL != CMODEL_SMALL)
11565     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;bl %z3\;%.";
11566   else
11567     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;%.";
11568 }
11569   "&& TARGET_TLS_MARKERS"
11570   [(set (match_dup 0)
11571         (unspec:TLSmode [(match_dup 1)
11572                          (match_dup 2)]
11573                         UNSPEC_TLSGD))
11574    (parallel [(set (match_dup 0)
11575                    (call (mem:TLSmode (match_dup 3))
11576                          (match_dup 4)))
11577               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11578               (clobber (reg:SI LR_REGNO))])]
11579   ""
11580   [(set_attr "type" "two")
11581    (set (attr "length")
11582      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11583                    (const_int 16)
11584                    (const_int 12)))])
11585
11586 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
11587   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11588         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11589               (match_operand 4 "" "g")))
11590    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11591                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11592                    UNSPEC_TLSGD)
11593    (clobber (reg:SI LR_REGNO))]
11594   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11595 {
11596   if (flag_pic)
11597     {
11598       if (TARGET_SECURE_PLT && flag_pic == 2)
11599         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
11600       else
11601         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
11602     }
11603   else
11604     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
11605 }
11606   "&& TARGET_TLS_MARKERS"
11607   [(set (match_dup 0)
11608         (unspec:TLSmode [(match_dup 1)
11609                          (match_dup 2)]
11610                         UNSPEC_TLSGD))
11611    (parallel [(set (match_dup 0)
11612                    (call (mem:TLSmode (match_dup 3))
11613                          (match_dup 4)))
11614               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11615               (clobber (reg:SI LR_REGNO))])]
11616   ""
11617   [(set_attr "type" "two")
11618    (set_attr "length" "8")])
11619
11620 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
11621   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11622         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11623                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11624                         UNSPEC_TLSGD))]
11625   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11626   "addi %0,%1,%2@got@tlsgd"
11627   "&& TARGET_CMODEL != CMODEL_SMALL"
11628   [(set (match_dup 3)
11629         (plus:TLSmode (match_dup 1)
11630           (high:TLSmode
11631             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD))))
11632    (set (match_dup 0)
11633         (lo_sum:TLSmode (match_dup 3)
11634             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)))]
11635   "
11636 {
11637   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11638 }"
11639   [(set (attr "length")
11640      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11641                    (const_int 8)
11642                    (const_int 4)))])
11643
11644 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
11645   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11646      (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11647        (high:TLSmode
11648           (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11649                           UNSPEC_TLSGD))))]
11650   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11651   "addis %0,%1,%2@got@tlsgd@ha"
11652   [(set_attr "length" "4")])
11653
11654 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
11655   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11656      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11657        (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11658                        UNSPEC_TLSGD)))]
11659   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11660   "addi %0,%1,%2@got@tlsgd@l"
11661   [(set_attr "length" "4")])
11662
11663 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
11664   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11665         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11666               (match_operand 2 "" "g")))
11667    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11668                    UNSPEC_TLSGD)
11669    (clobber (reg:SI LR_REGNO))]
11670   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11671   "bl %z1(%3@tlsgd)\;%."
11672   [(set_attr "type" "branch")
11673    (set_attr "length" "8")])
11674
11675 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
11676   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11677         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11678               (match_operand 2 "" "g")))
11679    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11680                    UNSPEC_TLSGD)
11681    (clobber (reg:SI LR_REGNO))]
11682   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11683 {
11684   if (flag_pic)
11685     {
11686       if (TARGET_SECURE_PLT && flag_pic == 2)
11687         return "bl %z1+32768(%3@tlsgd)@plt";
11688       return "bl %z1(%3@tlsgd)@plt";
11689     }
11690   return "bl %z1(%3@tlsgd)";
11691 }
11692   [(set_attr "type" "branch")
11693    (set_attr "length" "4")])
11694
11695 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
11696   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11697         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11698               (match_operand 3 "" "g")))
11699    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11700                    UNSPEC_TLSLD)
11701    (clobber (reg:SI LR_REGNO))]
11702   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11703 {
11704   if (TARGET_CMODEL != CMODEL_SMALL)
11705     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;bl %z2\;%.";
11706   else
11707     return "addi %0,%1,%&@got@tlsld\;bl %z2\;%.";
11708 }
11709   "&& TARGET_TLS_MARKERS"
11710   [(set (match_dup 0)
11711         (unspec:TLSmode [(match_dup 1)]
11712                         UNSPEC_TLSLD))
11713    (parallel [(set (match_dup 0)
11714                    (call (mem:TLSmode (match_dup 2))
11715                          (match_dup 3)))
11716               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11717               (clobber (reg:SI LR_REGNO))])]
11718   ""
11719   [(set_attr "type" "two")
11720    (set (attr "length")
11721      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11722                    (const_int 16)
11723                    (const_int 12)))])
11724
11725 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
11726   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11727         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11728               (match_operand 3 "" "g")))
11729    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11730                    UNSPEC_TLSLD)
11731    (clobber (reg:SI LR_REGNO))]
11732   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11733 {
11734   if (flag_pic)
11735     {
11736       if (TARGET_SECURE_PLT && flag_pic == 2)
11737         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11738       else
11739         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11740     }
11741   else
11742     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11743 }
11744   "&& TARGET_TLS_MARKERS"
11745   [(set (match_dup 0)
11746         (unspec:TLSmode [(match_dup 1)]
11747                         UNSPEC_TLSLD))
11748    (parallel [(set (match_dup 0)
11749                    (call (mem:TLSmode (match_dup 2))
11750                          (match_dup 3)))
11751               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11752               (clobber (reg:SI LR_REGNO))])]
11753   ""
11754   [(set_attr "length" "8")])
11755
11756 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
11757   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11758         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11759                         UNSPEC_TLSLD))]
11760   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11761   "addi %0,%1,%&@got@tlsld"
11762   "&& TARGET_CMODEL != CMODEL_SMALL"
11763   [(set (match_dup 2)
11764         (plus:TLSmode (match_dup 1)
11765           (high:TLSmode
11766             (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD))))
11767    (set (match_dup 0)
11768         (lo_sum:TLSmode (match_dup 2)
11769             (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
11770   "
11771 {
11772   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11773 }"
11774   [(set (attr "length")
11775      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11776                    (const_int 8)
11777                    (const_int 4)))])
11778
11779 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
11780   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11781      (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11782        (high:TLSmode
11783           (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD))))]
11784   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11785   "addis %0,%1,%&@got@tlsld@ha"
11786   [(set_attr "length" "4")])
11787
11788 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
11789   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11790      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11791        (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
11792   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11793   "addi %0,%1,%&@got@tlsld@l"
11794   [(set_attr "length" "4")])
11795
11796 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11797   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11798         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11799               (match_operand 2 "" "g")))
11800    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11801    (clobber (reg:SI LR_REGNO))]
11802   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11803   "bl %z1(%&@tlsld)\;%."
11804   [(set_attr "type" "branch")
11805    (set_attr "length" "8")])
11806
11807 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11808   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11809         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11810               (match_operand 2 "" "g")))
11811    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11812    (clobber (reg:SI LR_REGNO))]
11813   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11814 {
11815   if (flag_pic)
11816     {
11817       if (TARGET_SECURE_PLT && flag_pic == 2)
11818         return "bl %z1+32768(%&@tlsld)@plt";
11819       return "bl %z1(%&@tlsld)@plt";
11820     }
11821   return "bl %z1(%&@tlsld)";
11822 }
11823   [(set_attr "type" "branch")
11824    (set_attr "length" "4")])
11825
11826 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11827   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11828         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11829                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11830                         UNSPEC_TLSDTPREL))]
11831   "HAVE_AS_TLS"
11832   "addi %0,%1,%2@dtprel")
11833
11834 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11835   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11836         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11837                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11838                         UNSPEC_TLSDTPRELHA))]
11839   "HAVE_AS_TLS"
11840   "addis %0,%1,%2@dtprel@ha")
11841
11842 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11843   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11844         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11845                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11846                         UNSPEC_TLSDTPRELLO))]
11847   "HAVE_AS_TLS"
11848   "addi %0,%1,%2@dtprel@l")
11849
11850 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11851   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11852         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11853                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11854                         UNSPEC_TLSGOTDTPREL))]
11855   "HAVE_AS_TLS"
11856   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
11857   "&& TARGET_CMODEL != CMODEL_SMALL"
11858   [(set (match_dup 3)
11859         (plus:TLSmode (match_dup 1)
11860           (high:TLSmode
11861             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL))))
11862    (set (match_dup 0)
11863         (lo_sum:TLSmode (match_dup 3)
11864             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
11865   "
11866 {
11867   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11868 }"
11869   [(set (attr "length")
11870      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11871                    (const_int 8)
11872                    (const_int 4)))])
11873
11874 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
11875   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11876      (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11877        (high:TLSmode
11878          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11879                          UNSPEC_TLSGOTDTPREL))))]
11880   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11881   "addis %0,%1,%2@got@dtprel@ha"
11882   [(set_attr "length" "4")])
11883
11884 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
11885   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11886      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11887          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11888                          UNSPEC_TLSGOTDTPREL)))]
11889   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11890   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
11891   [(set_attr "length" "4")])
11892
11893 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11894   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11895         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11896                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11897                         UNSPEC_TLSTPREL))]
11898   "HAVE_AS_TLS"
11899   "addi %0,%1,%2@tprel")
11900
11901 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11902   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11903         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11904                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11905                         UNSPEC_TLSTPRELHA))]
11906   "HAVE_AS_TLS"
11907   "addis %0,%1,%2@tprel@ha")
11908
11909 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11910   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11911         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11912                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11913                         UNSPEC_TLSTPRELLO))]
11914   "HAVE_AS_TLS"
11915   "addi %0,%1,%2@tprel@l")
11916
11917 ;; "b" output constraint here and on tls_tls input to support linker tls
11918 ;; optimization.  The linker may edit the instructions emitted by a
11919 ;; tls_got_tprel/tls_tls pair to addis,addi.
11920 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11921   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11922         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11923                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11924                         UNSPEC_TLSGOTTPREL))]
11925   "HAVE_AS_TLS"
11926   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
11927   "&& TARGET_CMODEL != CMODEL_SMALL"
11928   [(set (match_dup 3)
11929         (plus:TLSmode (match_dup 1)
11930           (high:TLSmode
11931             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL))))
11932    (set (match_dup 0)
11933         (lo_sum:TLSmode (match_dup 3)
11934             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL)))]
11935   "
11936 {
11937   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11938 }"
11939   [(set (attr "length")
11940      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11941                    (const_int 8)
11942                    (const_int 4)))])
11943
11944 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
11945   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11946      (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11947        (high:TLSmode
11948          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11949                          UNSPEC_TLSGOTTPREL))))]
11950   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11951   "addis %0,%1,%2@got@tprel@ha"
11952   [(set_attr "length" "4")])
11953
11954 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
11955   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11956      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11957          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11958                          UNSPEC_TLSGOTTPREL)))]
11959   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11960   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
11961   [(set_attr "length" "4")])
11962
11963 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11964   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11965         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11966                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11967                         UNSPEC_TLSTLS))]
11968   "HAVE_AS_TLS"
11969   "add %0,%1,%2@tls")
11970 \f
11971 ;; Next come insns related to the calling sequence.
11972 ;;
11973 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11974 ;; We move the back-chain and decrement the stack pointer.
11975
11976 (define_expand "allocate_stack"
11977   [(set (match_operand 0 "gpc_reg_operand" "")
11978         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11979    (set (reg 1)
11980         (minus (reg 1) (match_dup 1)))]
11981   ""
11982   "
11983 { rtx chain = gen_reg_rtx (Pmode);
11984   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11985   rtx neg_op0;
11986   rtx insn, par, set, mem;
11987
11988   emit_move_insn (chain, stack_bot);
11989
11990   /* Check stack bounds if necessary.  */
11991   if (crtl->limit_stack)
11992     {
11993       rtx available;
11994       available = expand_binop (Pmode, sub_optab,
11995                                 stack_pointer_rtx, stack_limit_rtx,
11996                                 NULL_RTX, 1, OPTAB_WIDEN);
11997       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11998     }
11999
12000   if (GET_CODE (operands[1]) != CONST_INT
12001       || INTVAL (operands[1]) < -32767
12002       || INTVAL (operands[1]) > 32768)
12003     {
12004       neg_op0 = gen_reg_rtx (Pmode);
12005       if (TARGET_32BIT)
12006         emit_insn (gen_negsi2 (neg_op0, operands[1]));
12007       else
12008         emit_insn (gen_negdi2 (neg_op0, operands[1]));
12009     }
12010   else
12011     neg_op0 = GEN_INT (- INTVAL (operands[1]));
12012
12013   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
12014                                        : gen_movdi_di_update_stack))
12015                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
12016                          chain));
12017   /* Since we didn't use gen_frame_mem to generate the MEM, grab
12018      it now and set the alias set/attributes. The above gen_*_update
12019      calls will generate a PARALLEL with the MEM set being the first
12020      operation. */
12021   par = PATTERN (insn);
12022   gcc_assert (GET_CODE (par) == PARALLEL);
12023   set = XVECEXP (par, 0, 0);
12024   gcc_assert (GET_CODE (set) == SET);
12025   mem = SET_DEST (set);
12026   gcc_assert (MEM_P (mem));
12027   MEM_NOTRAP_P (mem) = 1;
12028   set_mem_alias_set (mem, get_frame_alias_set ());
12029
12030   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
12031   DONE;
12032 }")
12033
12034 ;; These patterns say how to save and restore the stack pointer.  We need not
12035 ;; save the stack pointer at function level since we are careful to
12036 ;; preserve the backchain.  At block level, we have to restore the backchain
12037 ;; when we restore the stack pointer.
12038 ;;
12039 ;; For nonlocal gotos, we must save both the stack pointer and its
12040 ;; backchain and restore both.  Note that in the nonlocal case, the
12041 ;; save area is a memory location.
12042
12043 (define_expand "save_stack_function"
12044   [(match_operand 0 "any_operand" "")
12045    (match_operand 1 "any_operand" "")]
12046   ""
12047   "DONE;")
12048
12049 (define_expand "restore_stack_function"
12050   [(match_operand 0 "any_operand" "")
12051    (match_operand 1 "any_operand" "")]
12052   ""
12053   "DONE;")
12054
12055 ;; Adjust stack pointer (op0) to a new value (op1).
12056 ;; First copy old stack backchain to new location, and ensure that the
12057 ;; scheduler won't reorder the sp assignment before the backchain write.
12058 (define_expand "restore_stack_block"
12059   [(set (match_dup 2) (match_dup 3))
12060    (set (match_dup 4) (match_dup 2))
12061    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
12062    (set (match_operand 0 "register_operand" "")
12063         (match_operand 1 "register_operand" ""))]
12064   ""
12065   "
12066 {
12067   operands[1] = force_reg (Pmode, operands[1]);
12068   operands[2] = gen_reg_rtx (Pmode);
12069   operands[3] = gen_frame_mem (Pmode, operands[0]);
12070   operands[4] = gen_frame_mem (Pmode, operands[1]);
12071   operands[5] = gen_frame_mem (BLKmode, operands[0]);
12072 }")
12073
12074 (define_expand "save_stack_nonlocal"
12075   [(set (match_dup 3) (match_dup 4))
12076    (set (match_operand 0 "memory_operand" "") (match_dup 3))
12077    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
12078   ""
12079   "
12080 {
12081   int units_per_word = (TARGET_32BIT) ? 4 : 8;
12082
12083   /* Copy the backchain to the first word, sp to the second.  */
12084   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
12085   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
12086   operands[3] = gen_reg_rtx (Pmode);
12087   operands[4] = gen_frame_mem (Pmode, operands[1]);
12088 }")
12089
12090 (define_expand "restore_stack_nonlocal"
12091   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
12092    (set (match_dup 3) (match_dup 4))
12093    (set (match_dup 5) (match_dup 2))
12094    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
12095    (set (match_operand 0 "register_operand" "") (match_dup 3))]
12096   ""
12097   "
12098 {
12099   int units_per_word = (TARGET_32BIT) ? 4 : 8;
12100
12101   /* Restore the backchain from the first word, sp from the second.  */
12102   operands[2] = gen_reg_rtx (Pmode);
12103   operands[3] = gen_reg_rtx (Pmode);
12104   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
12105   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
12106   operands[5] = gen_frame_mem (Pmode, operands[3]);
12107   operands[6] = gen_frame_mem (BLKmode, operands[0]);
12108 }")
12109 \f
12110 ;; TOC register handling.
12111
12112 ;; Code to initialize the TOC register...
12113
12114 (define_insn "load_toc_aix_si"
12115   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12116                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
12117               (use (reg:SI 2))])]
12118   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
12119   "*
12120 {
12121   char buf[30];
12122   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
12123   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12124   operands[2] = gen_rtx_REG (Pmode, 2);
12125   return \"{l|lwz} %0,%1(%2)\";
12126 }"
12127   [(set_attr "type" "load")])
12128
12129 (define_insn "load_toc_aix_di"
12130   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12131                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
12132               (use (reg:DI 2))])]
12133   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
12134   "*
12135 {
12136   char buf[30];
12137 #ifdef TARGET_RELOCATABLE
12138   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
12139                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
12140 #else
12141   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
12142 #endif
12143   if (TARGET_ELF)
12144     strcat (buf, \"@toc\");
12145   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12146   operands[2] = gen_rtx_REG (Pmode, 2);
12147   return \"ld %0,%1(%2)\";
12148 }"
12149   [(set_attr "type" "load")])
12150
12151 (define_insn "load_toc_v4_pic_si"
12152   [(set (reg:SI LR_REGNO)
12153         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
12154   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
12155   "bl _GLOBAL_OFFSET_TABLE_@local-4"
12156   [(set_attr "type" "branch")
12157    (set_attr "length" "4")])
12158
12159 (define_insn "load_toc_v4_PIC_1"
12160   [(set (reg:SI LR_REGNO)
12161         (match_operand:SI 0 "immediate_operand" "s"))
12162    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
12163   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
12164    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
12165   "bcl 20,31,%0\\n%0:"
12166   [(set_attr "type" "branch")
12167    (set_attr "length" "4")])
12168
12169 (define_insn "load_toc_v4_PIC_1b"
12170   [(set (reg:SI LR_REGNO)
12171         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
12172                     (label_ref (match_operand 1 "" ""))]
12173                 UNSPEC_TOCPTR))
12174    (match_dup 1)]
12175   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
12176   "bcl 20,31,$+8\;.long %0-$"
12177   [(set_attr "type" "branch")
12178    (set_attr "length" "8")])
12179
12180 (define_insn "load_toc_v4_PIC_2"
12181   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12182         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
12183                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
12184                              (match_operand:SI 3 "immediate_operand" "s")))))]
12185   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
12186   "{l|lwz} %0,%2-%3(%1)"
12187   [(set_attr "type" "load")])
12188
12189 (define_insn "load_toc_v4_PIC_3b"
12190   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
12191         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12192                  (high:SI
12193                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
12194                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
12195   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
12196   "{cau|addis} %0,%1,%2-%3@ha")
12197
12198 (define_insn "load_toc_v4_PIC_3c"
12199   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12200         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
12201                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
12202                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
12203   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
12204   "{cal %0,%2-%3@l(%1)|addi %0,%1,%2-%3@l}")
12205
12206 ;; If the TOC is shared over a translation unit, as happens with all
12207 ;; the kinds of PIC that we support, we need to restore the TOC
12208 ;; pointer only when jumping over units of translation.
12209 ;; On Darwin, we need to reload the picbase.
12210
12211 (define_expand "builtin_setjmp_receiver"
12212   [(use (label_ref (match_operand 0 "" "")))]
12213   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
12214    || (TARGET_TOC && TARGET_MINIMAL_TOC)
12215    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
12216   "
12217 {
12218 #if TARGET_MACHO
12219   if (DEFAULT_ABI == ABI_DARWIN)
12220     {
12221       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
12222       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
12223       rtx tmplabrtx;
12224       char tmplab[20];
12225
12226       crtl->uses_pic_offset_table = 1;
12227       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
12228                                   CODE_LABEL_NUMBER (operands[0]));
12229       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
12230
12231       emit_insn (gen_load_macho_picbase (tmplabrtx));
12232       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
12233       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
12234     }
12235   else
12236 #endif
12237     rs6000_emit_load_toc_table (FALSE);
12238   DONE;
12239 }")
12240
12241 ;; Elf specific ways of loading addresses for non-PIC code.
12242 ;; The output of this could be r0, but we make a very strong
12243 ;; preference for a base register because it will usually
12244 ;; be needed there.
12245 (define_insn "elf_high"
12246   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
12247         (high:SI (match_operand 1 "" "")))]
12248   "TARGET_ELF && ! TARGET_64BIT"
12249   "{liu|lis} %0,%1@ha")
12250
12251 (define_insn "elf_low"
12252   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12253         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
12254                    (match_operand 2 "" "")))]
12255    "TARGET_ELF && ! TARGET_64BIT"
12256    "@
12257     {cal|la} %0,%2@l(%1)
12258     {ai|addic} %0,%1,%K2")
12259
12260 ;; Largetoc support
12261 (define_insn "largetoc_high"
12262   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
12263         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "b")
12264                  (high:DI (match_operand:DI 2 "" ""))))]
12265    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
12266    "{cau|addis} %0,%1,%2@ha")
12267
12268 (define_insn "largetoc_low"
12269   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12270         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b")
12271                    (match_operand:DI 2 "" "")))]
12272    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
12273    "{cal %0,%2@l(%1)|addi %0,%1,%2@l}")
12274 \f
12275 ;; A function pointer under AIX is a pointer to a data area whose first word
12276 ;; contains the actual address of the function, whose second word contains a
12277 ;; pointer to its TOC, and whose third word contains a value to place in the
12278 ;; static chain register (r11).  Note that if we load the static chain, our
12279 ;; "trampoline" need not have any executable code.
12280
12281 (define_expand "call_indirect_aix32"
12282   [(set (match_dup 2)
12283         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
12284    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
12285         (reg:SI 2))
12286    (set (reg:SI 11)
12287         (mem:SI (plus:SI (match_dup 0)
12288                          (const_int 8))))
12289    (parallel [(call (mem:SI (match_dup 2))
12290                     (match_operand 1 "" ""))
12291               (use (mem:SI (plus:SI (match_dup 0) (const_int 4))))
12292               (use (reg:SI 11))
12293               (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12294               (clobber (reg:SI LR_REGNO))])]
12295   "TARGET_32BIT"
12296   "
12297 { operands[2] = gen_reg_rtx (SImode); }")
12298
12299 (define_expand "call_indirect_aix64"
12300   [(set (match_dup 2)
12301         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
12302    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
12303         (reg:DI 2))
12304    (set (reg:DI 11)
12305         (mem:DI (plus:DI (match_dup 0)
12306                          (const_int 16))))
12307    (parallel [(call (mem:SI (match_dup 2))
12308                     (match_operand 1 "" ""))
12309               (use (mem:DI (plus:DI (match_dup 0) (const_int 8))))
12310               (use (reg:DI 11))
12311               (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12312               (clobber (reg:SI LR_REGNO))])]
12313   "TARGET_64BIT"
12314   "
12315 { operands[2] = gen_reg_rtx (DImode); }")
12316
12317 (define_expand "call_value_indirect_aix32"
12318   [(set (match_dup 3)
12319         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12320    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
12321         (reg:SI 2))
12322    (set (reg:SI 11)
12323         (mem:SI (plus:SI (match_dup 1)
12324                          (const_int 8))))
12325    (parallel [(set (match_operand 0 "" "")
12326                    (call (mem:SI (match_dup 3))
12327                          (match_operand 2 "" "")))
12328               (use (mem:SI (plus:SI (match_dup 1) (const_int 4))))
12329               (use (reg:SI 11))
12330               (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12331               (clobber (reg:SI LR_REGNO))])]
12332   "TARGET_32BIT"
12333   "
12334 { operands[3] = gen_reg_rtx (SImode); }")
12335
12336 (define_expand "call_value_indirect_aix64"
12337   [(set (match_dup 3)
12338         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12339    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
12340         (reg:DI 2))
12341    (set (reg:DI 11)
12342         (mem:DI (plus:DI (match_dup 1)
12343                          (const_int 16))))
12344    (parallel [(set (match_operand 0 "" "")
12345                    (call (mem:SI (match_dup 3))
12346                          (match_operand 2 "" "")))
12347               (use (mem:DI (plus:DI (match_dup 1) (const_int 8))))
12348               (use (reg:DI 11))
12349               (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12350               (clobber (reg:SI LR_REGNO))])]
12351   "TARGET_64BIT"
12352   "
12353 { operands[3] = gen_reg_rtx (DImode); }")
12354
12355 ;; Now the definitions for the call and call_value insns
12356 (define_expand "call"
12357   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12358                     (match_operand 1 "" ""))
12359               (use (match_operand 2 "" ""))
12360               (clobber (reg:SI LR_REGNO))])]
12361   ""
12362   "
12363 {
12364 #if TARGET_MACHO
12365   if (MACHOPIC_INDIRECT)
12366     operands[0] = machopic_indirect_call_target (operands[0]);
12367 #endif
12368
12369   gcc_assert (GET_CODE (operands[0]) == MEM);
12370   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12371
12372   operands[0] = XEXP (operands[0], 0);
12373
12374   if (GET_CODE (operands[0]) != SYMBOL_REF
12375       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
12376       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
12377     {
12378       if (INTVAL (operands[2]) & CALL_LONG)
12379         operands[0] = rs6000_longcall_ref (operands[0]);
12380
12381       switch (DEFAULT_ABI)
12382         {
12383         case ABI_V4:
12384         case ABI_DARWIN:
12385           operands[0] = force_reg (Pmode, operands[0]);
12386           break;
12387
12388         case ABI_AIX:
12389           /* AIX function pointers are really pointers to a three word
12390              area.  */
12391           emit_call_insn (TARGET_32BIT
12392                           ? gen_call_indirect_aix32 (force_reg (SImode,
12393                                                                 operands[0]),
12394                                                      operands[1])
12395                           : gen_call_indirect_aix64 (force_reg (DImode,
12396                                                                 operands[0]),
12397                                                      operands[1]));
12398           DONE;
12399
12400         default:
12401           gcc_unreachable ();
12402         }
12403     }
12404 }")
12405
12406 (define_expand "call_value"
12407   [(parallel [(set (match_operand 0 "" "")
12408                    (call (mem:SI (match_operand 1 "address_operand" ""))
12409                          (match_operand 2 "" "")))
12410               (use (match_operand 3 "" ""))
12411               (clobber (reg:SI LR_REGNO))])]
12412   ""
12413   "
12414 {
12415 #if TARGET_MACHO
12416   if (MACHOPIC_INDIRECT)
12417     operands[1] = machopic_indirect_call_target (operands[1]);
12418 #endif
12419
12420   gcc_assert (GET_CODE (operands[1]) == MEM);
12421   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12422
12423   operands[1] = XEXP (operands[1], 0);
12424
12425   if (GET_CODE (operands[1]) != SYMBOL_REF
12426       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
12427       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
12428     {
12429       if (INTVAL (operands[3]) & CALL_LONG)
12430         operands[1] = rs6000_longcall_ref (operands[1]);
12431
12432       switch (DEFAULT_ABI)
12433         {
12434         case ABI_V4:
12435         case ABI_DARWIN:
12436           operands[1] = force_reg (Pmode, operands[1]);
12437           break;
12438
12439         case ABI_AIX:
12440           /* AIX function pointers are really pointers to a three word
12441              area.  */
12442           emit_call_insn (TARGET_32BIT
12443                           ? gen_call_value_indirect_aix32 (operands[0],
12444                                                            force_reg (SImode,
12445                                                                       operands[1]),
12446                                                            operands[2])
12447                           : gen_call_value_indirect_aix64 (operands[0],
12448                                                            force_reg (DImode,
12449                                                                       operands[1]),
12450                                                            operands[2]));
12451           DONE;
12452
12453         default:
12454           gcc_unreachable ();
12455         }
12456     }
12457 }")
12458
12459 ;; Call to function in current module.  No TOC pointer reload needed.
12460 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12461 ;; either the function was not prototyped, or it was prototyped as a
12462 ;; variable argument function.  It is > 0 if FP registers were passed
12463 ;; and < 0 if they were not.
12464
12465 (define_insn "*call_local32"
12466   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12467          (match_operand 1 "" "g,g"))
12468    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12469    (clobber (reg:SI LR_REGNO))]
12470   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12471   "*
12472 {
12473   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12474     output_asm_insn (\"crxor 6,6,6\", operands);
12475
12476   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12477     output_asm_insn (\"creqv 6,6,6\", operands);
12478
12479   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12480 }"
12481   [(set_attr "type" "branch")
12482    (set_attr "length" "4,8")])
12483
12484 (define_insn "*call_local64"
12485   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12486          (match_operand 1 "" "g,g"))
12487    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12488    (clobber (reg:SI LR_REGNO))]
12489   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12490   "*
12491 {
12492   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12493     output_asm_insn (\"crxor 6,6,6\", operands);
12494
12495   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12496     output_asm_insn (\"creqv 6,6,6\", operands);
12497
12498   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12499 }"
12500   [(set_attr "type" "branch")
12501    (set_attr "length" "4,8")])
12502
12503 (define_insn "*call_value_local32"
12504   [(set (match_operand 0 "" "")
12505         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12506               (match_operand 2 "" "g,g")))
12507    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12508    (clobber (reg:SI LR_REGNO))]
12509   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12510   "*
12511 {
12512   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12513     output_asm_insn (\"crxor 6,6,6\", operands);
12514
12515   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12516     output_asm_insn (\"creqv 6,6,6\", operands);
12517
12518   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12519 }"
12520   [(set_attr "type" "branch")
12521    (set_attr "length" "4,8")])
12522
12523
12524 (define_insn "*call_value_local64"
12525   [(set (match_operand 0 "" "")
12526         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12527               (match_operand 2 "" "g,g")))
12528    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12529    (clobber (reg:SI LR_REGNO))]
12530   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12531   "*
12532 {
12533   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12534     output_asm_insn (\"crxor 6,6,6\", operands);
12535
12536   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12537     output_asm_insn (\"creqv 6,6,6\", operands);
12538
12539   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12540 }"
12541   [(set_attr "type" "branch")
12542    (set_attr "length" "4,8")])
12543
12544 ;; Call to function which may be in another module.  Restore the TOC
12545 ;; pointer (r2) after the call unless this is System V.
12546 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12547 ;; either the function was not prototyped, or it was prototyped as a
12548 ;; variable argument function.  It is > 0 if FP registers were passed
12549 ;; and < 0 if they were not.
12550
12551 (define_insn_and_split "*call_indirect_nonlocal_aix32_internal"
12552   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
12553                  (match_operand 1 "" "g,g"))
12554    (use (mem:SI (plus:SI (match_operand:SI 2 "register_operand" "b,b") (const_int 4))))
12555    (use (reg:SI 11))
12556    (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12557    (clobber (reg:SI LR_REGNO))]
12558   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
12559   "#"
12560   "&& reload_completed"
12561   [(set (reg:SI 2)
12562         (mem:SI (plus:SI (match_dup 2) (const_int 4))))
12563    (parallel [(call (mem:SI (match_dup 0))
12564                     (match_dup 1))
12565               (use (reg:SI 2))
12566               (use (reg:SI 11))
12567               (set (reg:SI 2)
12568                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12569               (clobber (reg:SI LR_REGNO))])]
12570   ""
12571   [(set_attr "type" "jmpreg")
12572    (set_attr "length" "12")])
12573
12574 (define_insn "*call_indirect_nonlocal_aix32"
12575   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
12576          (match_operand 1 "" "g,g"))
12577    (use (reg:SI 2))
12578    (use (reg:SI 11))
12579    (set (reg:SI 2)
12580         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12581    (clobber (reg:SI LR_REGNO))]
12582   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12583   "b%T0l\;{l|lwz} 2,20(1)"
12584   [(set_attr "type" "jmpreg")
12585    (set_attr "length" "8")])
12586
12587 (define_insn "*call_nonlocal_aix32"
12588   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
12589          (match_operand 1 "" "g"))
12590    (use (match_operand:SI 2 "immediate_operand" "O"))
12591    (clobber (reg:SI LR_REGNO))]
12592   "TARGET_32BIT
12593    && DEFAULT_ABI == ABI_AIX
12594    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12595   "bl %z0\;%."
12596   [(set_attr "type" "branch")
12597    (set_attr "length" "8")])
12598    
12599 (define_insn_and_split "*call_indirect_nonlocal_aix64_internal"
12600   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
12601                  (match_operand 1 "" "g,g"))
12602    (use (mem:DI (plus:DI (match_operand:DI 2 "register_operand" "b,b")
12603                          (const_int 8))))
12604    (use (reg:DI 11))
12605    (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12606    (clobber (reg:SI LR_REGNO))]
12607   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
12608   "#"
12609   "&& reload_completed"
12610   [(set (reg:DI 2)
12611         (mem:DI (plus:DI (match_dup 2) (const_int 8))))
12612    (parallel [(call (mem:SI (match_dup 0))
12613                     (match_dup 1))
12614               (use (reg:DI 2))
12615               (use (reg:DI 11))
12616               (set (reg:DI 2)
12617                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12618               (clobber (reg:SI LR_REGNO))])]
12619   ""
12620   [(set_attr "type" "jmpreg")
12621    (set_attr "length" "12")])
12622
12623 (define_insn "*call_indirect_nonlocal_aix64"
12624   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
12625          (match_operand 1 "" "g,g"))
12626    (use (reg:DI 2))
12627    (use (reg:DI 11))
12628    (set (reg:DI 2)
12629         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12630    (clobber (reg:SI LR_REGNO))]
12631   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12632   "b%T0l\;ld 2,40(1)"
12633   [(set_attr "type" "jmpreg")
12634    (set_attr "length" "8")])
12635
12636 (define_insn "*call_nonlocal_aix64"
12637   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
12638          (match_operand 1 "" "g"))
12639    (use (match_operand:SI 2 "immediate_operand" "O"))
12640    (clobber (reg:SI LR_REGNO))]
12641   "TARGET_64BIT
12642    && DEFAULT_ABI == ABI_AIX
12643    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12644   "bl %z0\;%."
12645   [(set_attr "type" "branch")
12646    (set_attr "length" "8")])
12647
12648 (define_insn_and_split "*call_value_indirect_nonlocal_aix32_internal"
12649   [(set (match_operand 0 "" "")
12650         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
12651                       (match_operand 2 "" "g,g")))
12652         (use (mem:SI (plus:SI (match_operand:SI 3 "register_operand" "b,b")
12653                               (const_int 4))))
12654         (use (reg:SI 11))
12655         (use (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12656         (clobber (reg:SI LR_REGNO))]
12657   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
12658   "#"
12659   "&& reload_completed"
12660   [(set (reg:SI 2)
12661         (mem:SI (plus:SI (match_dup 3) (const_int 4))))
12662    (parallel [(set (match_dup 0) (call (mem:SI (match_dup 1))
12663                                        (match_dup 2)))
12664               (use (reg:SI 2))
12665               (use (reg:SI 11))
12666               (set (reg:SI 2)
12667                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12668               (clobber (reg:SI LR_REGNO))])]
12669   ""
12670   [(set_attr "type" "jmpreg")
12671    (set_attr "length" "12")])
12672
12673 (define_insn "*call_value_indirect_nonlocal_aix32"
12674   [(set (match_operand 0 "" "")
12675         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
12676               (match_operand 2 "" "g,g")))
12677    (use (reg:SI 2))
12678    (use (reg:SI 11))
12679    (set (reg:SI 2)
12680         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
12681    (clobber (reg:SI LR_REGNO))]
12682   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12683   "b%T1l\;{l|lwz} 2,20(1)"
12684   [(set_attr "type" "jmpreg")
12685    (set_attr "length" "8")])
12686
12687 (define_insn "*call_value_nonlocal_aix32"
12688   [(set (match_operand 0 "" "")
12689         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12690               (match_operand 2 "" "g")))
12691    (use (match_operand:SI 3 "immediate_operand" "O"))
12692    (clobber (reg:SI LR_REGNO))]
12693   "TARGET_32BIT
12694    && DEFAULT_ABI == ABI_AIX
12695    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12696   "bl %z1\;%."
12697   [(set_attr "type" "branch")
12698    (set_attr "length" "8")])
12699
12700 (define_insn_and_split "*call_value_indirect_nonlocal_aix64_internal"
12701   [(set (match_operand 0 "" "")
12702         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
12703                       (match_operand 2 "" "g,g")))
12704         (use (mem:DI (plus:DI (match_operand:DI 3 "register_operand" "b,b")
12705                               (const_int 8))))
12706         (use (reg:DI 11))
12707         (use (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12708         (clobber (reg:SI LR_REGNO))]
12709   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
12710   "#"
12711   "&& reload_completed"
12712   [(set (reg:DI 2)
12713         (mem:DI (plus:DI (match_dup 3) (const_int 8))))
12714    (parallel [(set (match_dup 0) (call (mem:SI (match_dup 1))
12715                                        (match_dup 2)))
12716               (use (reg:DI 2))
12717               (use (reg:DI 11))
12718               (set (reg:DI 2)
12719                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12720               (clobber (reg:SI LR_REGNO))])]
12721   ""
12722   [(set_attr "type" "jmpreg")
12723    (set_attr "length" "12")])
12724
12725 (define_insn "*call_value_indirect_nonlocal_aix64"
12726   [(set (match_operand 0 "" "")
12727         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
12728               (match_operand 2 "" "g,g")))
12729    (use (reg:DI 2))
12730    (use (reg:DI 11))
12731    (set (reg:DI 2)
12732         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
12733    (clobber (reg:SI LR_REGNO))]
12734   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX && reload_completed"
12735   "b%T1l\;ld 2,40(1)"
12736   [(set_attr "type" "jmpreg")
12737    (set_attr "length" "8")])
12738
12739 (define_insn "*call_value_nonlocal_aix64"
12740   [(set (match_operand 0 "" "")
12741         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12742               (match_operand 2 "" "g")))
12743    (use (match_operand:SI 3 "immediate_operand" "O"))
12744    (clobber (reg:SI LR_REGNO))]
12745   "TARGET_64BIT
12746    && DEFAULT_ABI == ABI_AIX
12747    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12748   "bl %z1\;%."
12749   [(set_attr "type" "branch")
12750    (set_attr "length" "8")])
12751
12752 ;; A function pointer under System V is just a normal pointer
12753 ;; operands[0] is the function pointer
12754 ;; operands[1] is the stack size to clean up
12755 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12756 ;; which indicates how to set cr1
12757
12758 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12759   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12760          (match_operand 1 "" "g,g,g,g"))
12761    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12762    (clobber (reg:SI LR_REGNO))]
12763   "DEFAULT_ABI == ABI_V4
12764    || DEFAULT_ABI == ABI_DARWIN"
12765 {
12766   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12767     output_asm_insn ("crxor 6,6,6", operands);
12768
12769   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12770     output_asm_insn ("creqv 6,6,6", operands);
12771
12772   return "b%T0l";
12773 }
12774   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12775    (set_attr "length" "4,4,8,8")])
12776
12777 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12778   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12779          (match_operand 1 "" "g,g"))
12780    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12781    (clobber (reg:SI LR_REGNO))]
12782   "(DEFAULT_ABI == ABI_DARWIN
12783    || (DEFAULT_ABI == ABI_V4
12784        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12785 {
12786   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12787     output_asm_insn ("crxor 6,6,6", operands);
12788
12789   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12790     output_asm_insn ("creqv 6,6,6", operands);
12791
12792 #if TARGET_MACHO
12793   return output_call(insn, operands, 0, 2);
12794 #else
12795   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12796     {
12797       gcc_assert (!TARGET_SECURE_PLT);
12798       return "bl %z0@plt";
12799     }
12800   else
12801     return "bl %z0";
12802 #endif
12803 }
12804   "DEFAULT_ABI == ABI_V4
12805    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12806    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12807   [(parallel [(call (mem:SI (match_dup 0))
12808                     (match_dup 1))
12809               (use (match_dup 2))
12810               (use (match_dup 3))
12811               (clobber (reg:SI LR_REGNO))])]
12812 {
12813   operands[3] = pic_offset_table_rtx;
12814 }
12815   [(set_attr "type" "branch,branch")
12816    (set_attr "length" "4,8")])
12817
12818 (define_insn "*call_nonlocal_sysv_secure<mode>"
12819   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12820          (match_operand 1 "" "g,g"))
12821    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12822    (use (match_operand:SI 3 "register_operand" "r,r"))
12823    (clobber (reg:SI LR_REGNO))]
12824   "(DEFAULT_ABI == ABI_V4
12825     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12826     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
12827 {
12828   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12829     output_asm_insn ("crxor 6,6,6", operands);
12830
12831   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12832     output_asm_insn ("creqv 6,6,6", operands);
12833
12834   if (flag_pic == 2)
12835     /* The magic 32768 offset here and in the other sysv call insns
12836        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12837        See sysv4.h:toc_section.  */
12838     return "bl %z0+32768@plt";
12839   else
12840     return "bl %z0@plt";
12841 }
12842   [(set_attr "type" "branch,branch")
12843    (set_attr "length" "4,8")])
12844
12845 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12846   [(set (match_operand 0 "" "")
12847         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12848               (match_operand 2 "" "g,g,g,g")))
12849    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12850    (clobber (reg:SI LR_REGNO))]
12851   "DEFAULT_ABI == ABI_V4
12852    || DEFAULT_ABI == ABI_DARWIN"
12853 {
12854   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12855     output_asm_insn ("crxor 6,6,6", operands);
12856
12857   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12858     output_asm_insn ("creqv 6,6,6", operands);
12859
12860   return "b%T1l";
12861 }
12862   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12863    (set_attr "length" "4,4,8,8")])
12864
12865 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12866   [(set (match_operand 0 "" "")
12867         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12868               (match_operand 2 "" "g,g")))
12869    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12870    (clobber (reg:SI LR_REGNO))]
12871   "(DEFAULT_ABI == ABI_DARWIN
12872    || (DEFAULT_ABI == ABI_V4
12873        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12874 {
12875   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12876     output_asm_insn ("crxor 6,6,6", operands);
12877
12878   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12879     output_asm_insn ("creqv 6,6,6", operands);
12880
12881 #if TARGET_MACHO
12882   return output_call(insn, operands, 1, 3);
12883 #else
12884   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12885     {
12886       gcc_assert (!TARGET_SECURE_PLT);
12887       return "bl %z1@plt";
12888     }
12889   else
12890     return "bl %z1";
12891 #endif
12892 }
12893   "DEFAULT_ABI == ABI_V4
12894    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12895    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12896   [(parallel [(set (match_dup 0)
12897                    (call (mem:SI (match_dup 1))
12898                          (match_dup 2)))
12899               (use (match_dup 3))
12900               (use (match_dup 4))
12901               (clobber (reg:SI LR_REGNO))])]
12902 {
12903   operands[4] = pic_offset_table_rtx;
12904 }
12905   [(set_attr "type" "branch,branch")
12906    (set_attr "length" "4,8")])
12907
12908 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12909   [(set (match_operand 0 "" "")
12910         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12911               (match_operand 2 "" "g,g")))
12912    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12913    (use (match_operand:SI 4 "register_operand" "r,r"))
12914    (clobber (reg:SI LR_REGNO))]
12915   "(DEFAULT_ABI == ABI_V4
12916     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12917     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12918 {
12919   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12920     output_asm_insn ("crxor 6,6,6", operands);
12921
12922   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12923     output_asm_insn ("creqv 6,6,6", operands);
12924
12925   if (flag_pic == 2)
12926     return "bl %z1+32768@plt";
12927   else
12928     return "bl %z1@plt";
12929 }
12930   [(set_attr "type" "branch,branch")
12931    (set_attr "length" "4,8")])
12932
12933 ;; Call subroutine returning any type.
12934 (define_expand "untyped_call"
12935   [(parallel [(call (match_operand 0 "" "")
12936                     (const_int 0))
12937               (match_operand 1 "" "")
12938               (match_operand 2 "" "")])]
12939   ""
12940   "
12941 {
12942   int i;
12943
12944   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12945
12946   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12947     {
12948       rtx set = XVECEXP (operands[2], 0, i);
12949       emit_move_insn (SET_DEST (set), SET_SRC (set));
12950     }
12951
12952   /* The optimizer does not know that the call sets the function value
12953      registers we stored in the result block.  We avoid problems by
12954      claiming that all hard registers are used and clobbered at this
12955      point.  */
12956   emit_insn (gen_blockage ());
12957
12958   DONE;
12959 }")
12960
12961 ;; sibling call patterns
12962 (define_expand "sibcall"
12963   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12964                     (match_operand 1 "" ""))
12965               (use (match_operand 2 "" ""))
12966               (use (reg:SI LR_REGNO))
12967               (return)])]
12968   ""
12969   "
12970 {
12971 #if TARGET_MACHO
12972   if (MACHOPIC_INDIRECT)
12973     operands[0] = machopic_indirect_call_target (operands[0]);
12974 #endif
12975
12976   gcc_assert (GET_CODE (operands[0]) == MEM);
12977   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12978
12979   operands[0] = XEXP (operands[0], 0);
12980 }")
12981
12982 ;; this and similar patterns must be marked as using LR, otherwise
12983 ;; dataflow will try to delete the store into it.  This is true
12984 ;; even when the actual reg to jump to is in CTR, when LR was
12985 ;; saved and restored around the PIC-setting BCL.
12986 (define_insn "*sibcall_local32"
12987   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12988          (match_operand 1 "" "g,g"))
12989    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12990    (use (reg:SI LR_REGNO))
12991    (return)]
12992   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12993   "*
12994 {
12995   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12996     output_asm_insn (\"crxor 6,6,6\", operands);
12997
12998   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12999     output_asm_insn (\"creqv 6,6,6\", operands);
13000
13001   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
13002 }"
13003   [(set_attr "type" "branch")
13004    (set_attr "length" "4,8")])
13005
13006 (define_insn "*sibcall_local64"
13007   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
13008          (match_operand 1 "" "g,g"))
13009    (use (match_operand:SI 2 "immediate_operand" "O,n"))
13010    (use (reg:SI LR_REGNO))
13011    (return)]
13012   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
13013   "*
13014 {
13015   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
13016     output_asm_insn (\"crxor 6,6,6\", operands);
13017
13018   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
13019     output_asm_insn (\"creqv 6,6,6\", operands);
13020
13021   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
13022 }"
13023   [(set_attr "type" "branch")
13024    (set_attr "length" "4,8")])
13025
13026 (define_insn "*sibcall_value_local32"
13027   [(set (match_operand 0 "" "")
13028         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
13029               (match_operand 2 "" "g,g")))
13030    (use (match_operand:SI 3 "immediate_operand" "O,n"))
13031    (use (reg:SI LR_REGNO))
13032    (return)]
13033   "(INTVAL (operands[3]) & CALL_LONG) == 0"
13034   "*
13035 {
13036   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
13037     output_asm_insn (\"crxor 6,6,6\", operands);
13038
13039   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
13040     output_asm_insn (\"creqv 6,6,6\", operands);
13041
13042   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
13043 }"
13044   [(set_attr "type" "branch")
13045    (set_attr "length" "4,8")])
13046
13047
13048 (define_insn "*sibcall_value_local64"
13049   [(set (match_operand 0 "" "")
13050         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
13051               (match_operand 2 "" "g,g")))
13052    (use (match_operand:SI 3 "immediate_operand" "O,n"))
13053    (use (reg:SI LR_REGNO))
13054    (return)]
13055   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
13056   "*
13057 {
13058   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
13059     output_asm_insn (\"crxor 6,6,6\", operands);
13060
13061   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
13062     output_asm_insn (\"creqv 6,6,6\", operands);
13063
13064   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
13065 }"
13066   [(set_attr "type" "branch")
13067    (set_attr "length" "4,8")])
13068
13069 (define_insn "*sibcall_nonlocal_aix32"
13070   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
13071          (match_operand 1 "" "g"))
13072    (use (match_operand:SI 2 "immediate_operand" "O"))
13073    (use (reg:SI LR_REGNO))
13074    (return)]
13075   "TARGET_32BIT
13076    && DEFAULT_ABI == ABI_AIX
13077    && (INTVAL (operands[2]) & CALL_LONG) == 0"
13078   "b %z0"
13079   [(set_attr "type" "branch")
13080    (set_attr "length" "4")])
13081
13082 (define_insn "*sibcall_nonlocal_aix64"
13083   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
13084          (match_operand 1 "" "g"))
13085    (use (match_operand:SI 2 "immediate_operand" "O"))
13086    (use (reg:SI LR_REGNO))
13087    (return)]
13088   "TARGET_64BIT
13089    && DEFAULT_ABI == ABI_AIX
13090    && (INTVAL (operands[2]) & CALL_LONG) == 0"
13091   "b %z0"
13092   [(set_attr "type" "branch")
13093    (set_attr "length" "4")])
13094
13095 (define_insn "*sibcall_value_nonlocal_aix32"
13096   [(set (match_operand 0 "" "")
13097         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
13098               (match_operand 2 "" "g")))
13099    (use (match_operand:SI 3 "immediate_operand" "O"))
13100    (use (reg:SI LR_REGNO))
13101    (return)]
13102   "TARGET_32BIT
13103    && DEFAULT_ABI == ABI_AIX
13104    && (INTVAL (operands[3]) & CALL_LONG) == 0"
13105   "b %z1"
13106   [(set_attr "type" "branch")
13107    (set_attr "length" "4")])
13108
13109 (define_insn "*sibcall_value_nonlocal_aix64"
13110   [(set (match_operand 0 "" "")
13111         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
13112               (match_operand 2 "" "g")))
13113    (use (match_operand:SI 3 "immediate_operand" "O"))
13114    (use (reg:SI LR_REGNO))
13115    (return)]
13116   "TARGET_64BIT
13117    && DEFAULT_ABI == ABI_AIX
13118    && (INTVAL (operands[3]) & CALL_LONG) == 0"
13119   "b %z1"
13120   [(set_attr "type" "branch")
13121    (set_attr "length" "4")])
13122
13123 (define_insn "*sibcall_nonlocal_sysv<mode>"
13124   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
13125          (match_operand 1 "" ""))
13126    (use (match_operand 2 "immediate_operand" "O,n"))
13127    (use (reg:SI LR_REGNO))
13128    (return)]
13129   "(DEFAULT_ABI == ABI_DARWIN
13130      || DEFAULT_ABI == ABI_V4)
13131    && (INTVAL (operands[2]) & CALL_LONG) == 0"
13132   "*
13133 {
13134   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
13135     output_asm_insn (\"crxor 6,6,6\", operands);
13136
13137   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
13138     output_asm_insn (\"creqv 6,6,6\", operands);
13139
13140   if (DEFAULT_ABI == ABI_V4 && flag_pic)
13141     {
13142       gcc_assert (!TARGET_SECURE_PLT);
13143       return \"b %z0@plt\";
13144     }
13145   else
13146     return \"b %z0\";
13147 }"
13148   [(set_attr "type" "branch,branch")
13149    (set_attr "length" "4,8")])
13150
13151 (define_expand "sibcall_value"
13152   [(parallel [(set (match_operand 0 "register_operand" "")
13153                 (call (mem:SI (match_operand 1 "address_operand" ""))
13154                       (match_operand 2 "" "")))
13155               (use (match_operand 3 "" ""))
13156               (use (reg:SI LR_REGNO))
13157               (return)])]
13158   ""
13159   "
13160 {
13161 #if TARGET_MACHO
13162   if (MACHOPIC_INDIRECT)
13163     operands[1] = machopic_indirect_call_target (operands[1]);
13164 #endif
13165
13166   gcc_assert (GET_CODE (operands[1]) == MEM);
13167   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
13168
13169   operands[1] = XEXP (operands[1], 0);
13170 }")
13171
13172 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
13173   [(set (match_operand 0 "" "")
13174         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
13175               (match_operand 2 "" "")))
13176    (use (match_operand:SI 3 "immediate_operand" "O,n"))
13177    (use (reg:SI LR_REGNO))
13178    (return)]
13179   "(DEFAULT_ABI == ABI_DARWIN
13180        || DEFAULT_ABI == ABI_V4)
13181    && (INTVAL (operands[3]) & CALL_LONG) == 0"
13182   "*
13183 {
13184   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
13185     output_asm_insn (\"crxor 6,6,6\", operands);
13186
13187   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
13188     output_asm_insn (\"creqv 6,6,6\", operands);
13189
13190   if (DEFAULT_ABI == ABI_V4 && flag_pic)
13191     {
13192       gcc_assert (!TARGET_SECURE_PLT);
13193       return \"b %z1@plt\";
13194     }
13195   else
13196     return \"b %z1\";
13197 }"
13198   [(set_attr "type" "branch,branch")
13199    (set_attr "length" "4,8")])
13200
13201 (define_expand "sibcall_epilogue"
13202   [(use (const_int 0))]
13203   "TARGET_SCHED_PROLOG"
13204   "
13205 {
13206       rs6000_emit_epilogue (TRUE);
13207       DONE;
13208 }")
13209
13210 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
13211 ;; all of memory.  This blocks insns from being moved across this point.
13212
13213 (define_insn "blockage"
13214   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
13215   ""
13216   "")
13217
13218 (define_insn "probe_stack"
13219   [(set (match_operand 0 "memory_operand" "=m")
13220         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
13221   ""
13222   "{st%U0%X0|stw%U0%X0} 0,%0"
13223   [(set_attr "type" "store")
13224    (set_attr "length" "4")])
13225
13226 (define_insn "probe_stack_range<P:mode>"
13227   [(set (match_operand:P 0 "register_operand" "=r")
13228         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
13229                             (match_operand:P 2 "register_operand" "r")]
13230                            UNSPECV_PROBE_STACK_RANGE))]
13231   ""
13232   "* return output_probe_stack_range (operands[0], operands[2]);"
13233   [(set_attr "type" "three")])
13234 \f
13235 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
13236 ;; signed & unsigned, and one type of branch.
13237 ;;
13238 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
13239 ;; insns, and branches.
13240
13241 (define_expand "cbranch<mode>4"
13242   [(use (match_operator 0 "rs6000_cbranch_operator"
13243          [(match_operand:GPR 1 "gpc_reg_operand" "")
13244           (match_operand:GPR 2 "reg_or_short_operand" "")]))
13245    (use (match_operand 3 ""))]
13246   ""
13247   "
13248 {
13249   /* Take care of the possibility that operands[2] might be negative but
13250      this might be a logical operation.  That insn doesn't exist.  */
13251   if (GET_CODE (operands[2]) == CONST_INT
13252       && INTVAL (operands[2]) < 0)
13253     {
13254       operands[2] = force_reg (<MODE>mode, operands[2]);
13255       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
13256                                     GET_MODE (operands[0]),
13257                                     operands[1], operands[2]);
13258    }
13259
13260   rs6000_emit_cbranch (<MODE>mode, operands);
13261   DONE;
13262 }")
13263
13264 (define_expand "cbranch<mode>4"
13265   [(use (match_operator 0 "rs6000_cbranch_operator"
13266          [(match_operand:FP 1 "gpc_reg_operand" "")
13267           (match_operand:FP 2 "gpc_reg_operand" "")]))
13268    (use (match_operand 3 ""))]
13269   ""
13270   "
13271 {
13272   rs6000_emit_cbranch (<MODE>mode, operands);
13273   DONE;
13274 }")
13275
13276 (define_expand "cstore<mode>4"
13277   [(use (match_operator 1 "rs6000_cbranch_operator"
13278          [(match_operand:GPR 2 "gpc_reg_operand" "")
13279           (match_operand:GPR 3 "reg_or_short_operand" "")]))
13280    (clobber (match_operand:SI 0 "register_operand"))]
13281   ""
13282   "
13283 {
13284   /* Take care of the possibility that operands[3] might be negative but
13285      this might be a logical operation.  That insn doesn't exist.  */
13286   if (GET_CODE (operands[3]) == CONST_INT
13287       && INTVAL (operands[3]) < 0)
13288     {
13289       operands[3] = force_reg (<MODE>mode, operands[3]);
13290       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
13291                                     GET_MODE (operands[1]),
13292                                     operands[2], operands[3]);
13293     }
13294
13295   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
13296      For SEQ, likewise, except that comparisons with zero should be done
13297      with an scc insns.  However, due to the order that combine see the
13298      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
13299      the cases we don't want to handle or are best handled by portable
13300      code.  */
13301   if (GET_CODE (operands[1]) == NE)
13302     FAIL;
13303   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
13304        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
13305       && operands[3] == const0_rtx)
13306     FAIL;
13307   rs6000_emit_sCOND (<MODE>mode, operands);
13308   DONE;
13309 }")
13310
13311 (define_expand "cstore<mode>4"
13312   [(use (match_operator 1 "rs6000_cbranch_operator"
13313          [(match_operand:FP 2 "gpc_reg_operand" "")
13314           (match_operand:FP 3 "gpc_reg_operand" "")]))
13315    (clobber (match_operand:SI 0 "register_operand"))]
13316   ""
13317   "
13318 {
13319   rs6000_emit_sCOND (<MODE>mode, operands);
13320   DONE;
13321 }")
13322
13323
13324 (define_expand "stack_protect_set"
13325   [(match_operand 0 "memory_operand" "")
13326    (match_operand 1 "memory_operand" "")]
13327   ""
13328 {
13329 #ifdef TARGET_THREAD_SSP_OFFSET
13330   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
13331   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
13332   operands[1] = gen_rtx_MEM (Pmode, addr);
13333 #endif
13334   if (TARGET_64BIT)
13335     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
13336   else
13337     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
13338   DONE;
13339 })
13340
13341 (define_insn "stack_protect_setsi"
13342   [(set (match_operand:SI 0 "memory_operand" "=m")
13343         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
13344    (set (match_scratch:SI 2 "=&r") (const_int 0))]
13345   "TARGET_32BIT"
13346   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
13347   [(set_attr "type" "three")
13348    (set_attr "length" "12")])
13349
13350 (define_insn "stack_protect_setdi"
13351   [(set (match_operand:DI 0 "memory_operand" "=m")
13352         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
13353    (set (match_scratch:DI 2 "=&r") (const_int 0))]
13354   "TARGET_64BIT"
13355   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
13356   [(set_attr "type" "three")
13357    (set_attr "length" "12")])
13358
13359 (define_expand "stack_protect_test"
13360   [(match_operand 0 "memory_operand" "")
13361    (match_operand 1 "memory_operand" "")
13362    (match_operand 2 "" "")]
13363   ""
13364 {
13365   rtx test, op0, op1;
13366 #ifdef TARGET_THREAD_SSP_OFFSET
13367   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
13368   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
13369   operands[1] = gen_rtx_MEM (Pmode, addr);
13370 #endif
13371   op0 = operands[0];
13372   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
13373   test = gen_rtx_EQ (VOIDmode, op0, op1);
13374   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
13375   DONE;
13376 })
13377
13378 (define_insn "stack_protect_testsi"
13379   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13380         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
13381                       (match_operand:SI 2 "memory_operand" "m,m")]
13382                      UNSPEC_SP_TEST))
13383    (set (match_scratch:SI 4 "=r,r") (const_int 0))
13384    (clobber (match_scratch:SI 3 "=&r,&r"))]
13385   "TARGET_32BIT"
13386   "@
13387    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
13388    {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"
13389   [(set_attr "length" "16,20")])
13390
13391 (define_insn "stack_protect_testdi"
13392   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13393         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
13394                       (match_operand:DI 2 "memory_operand" "m,m")]
13395                      UNSPEC_SP_TEST))
13396    (set (match_scratch:DI 4 "=r,r") (const_int 0))
13397    (clobber (match_scratch:DI 3 "=&r,&r"))]
13398   "TARGET_64BIT"
13399   "@
13400    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
13401    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
13402   [(set_attr "length" "16,20")])
13403
13404 \f
13405 ;; Here are the actual compare insns.
13406 (define_insn "*cmp<mode>_internal1"
13407   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
13408         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
13409                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
13410   ""
13411   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
13412   [(set_attr "type" "cmp")])
13413
13414 ;; If we are comparing a register for equality with a large constant,
13415 ;; we can do this with an XOR followed by a compare.  But this is profitable
13416 ;; only if the large constant is only used for the comparison (and in this
13417 ;; case we already have a register to reuse as scratch).
13418 ;;
13419 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
13420 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
13421
13422 (define_peephole2
13423   [(set (match_operand:SI 0 "register_operand")
13424         (match_operand:SI 1 "logical_const_operand" ""))
13425    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
13426                        [(match_dup 0)
13427                         (match_operand:SI 2 "logical_const_operand" "")]))
13428    (set (match_operand:CC 4 "cc_reg_operand" "")
13429         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
13430                     (match_dup 0)))
13431    (set (pc)
13432         (if_then_else (match_operator 6 "equality_operator"
13433                        [(match_dup 4) (const_int 0)])
13434                       (match_operand 7 "" "")
13435                       (match_operand 8 "" "")))]
13436   "peep2_reg_dead_p (3, operands[0])
13437    && peep2_reg_dead_p (4, operands[4])"
13438  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
13439   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
13440   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
13441  
13442 {
13443   /* Get the constant we are comparing against, and see what it looks like
13444      when sign-extended from 16 to 32 bits.  Then see what constant we could
13445      XOR with SEXTC to get the sign-extended value.  */
13446   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
13447                                               SImode,
13448                                               operands[1], operands[2]);
13449   HOST_WIDE_INT c = INTVAL (cnst);
13450   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
13451   HOST_WIDE_INT xorv = c ^ sextc;
13452
13453   operands[9] = GEN_INT (xorv);
13454   operands[10] = GEN_INT (sextc);
13455 })
13456
13457 (define_insn "*cmpsi_internal2"
13458   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13459         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13460                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
13461   ""
13462   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
13463   [(set_attr "type" "cmp")])
13464
13465 (define_insn "*cmpdi_internal2"
13466   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13467         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
13468                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
13469   ""
13470   "cmpld%I2 %0,%1,%b2"
13471   [(set_attr "type" "cmp")])
13472
13473 ;; The following two insns don't exist as single insns, but if we provide
13474 ;; them, we can swap an add and compare, which will enable us to overlap more
13475 ;; of the required delay between a compare and branch.  We generate code for
13476 ;; them by splitting.
13477
13478 (define_insn ""
13479   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13480         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
13481                     (match_operand:SI 2 "short_cint_operand" "i")))
13482    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13483         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13484   ""
13485   "#"
13486   [(set_attr "length" "8")])
13487
13488 (define_insn ""
13489   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
13490         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13491                        (match_operand:SI 2 "u_short_cint_operand" "i")))
13492    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13493         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13494   ""
13495   "#"
13496   [(set_attr "length" "8")])
13497
13498 (define_split
13499   [(set (match_operand:CC 3 "cc_reg_operand" "")
13500         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
13501                     (match_operand:SI 2 "short_cint_operand" "")))
13502    (set (match_operand:SI 0 "gpc_reg_operand" "")
13503         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13504   ""
13505   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
13506    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13507
13508 (define_split
13509   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
13510         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
13511                        (match_operand:SI 2 "u_short_cint_operand" "")))
13512    (set (match_operand:SI 0 "gpc_reg_operand" "")
13513         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13514   ""
13515   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
13516    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13517
13518 (define_insn "*cmpsf_internal1"
13519   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13520         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
13521                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
13522   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
13523   "fcmpu %0,%1,%2"
13524   [(set_attr "type" "fpcompare")])
13525
13526 (define_insn "*cmpdf_internal1"
13527   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13528         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
13529                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
13530   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
13531    && !VECTOR_UNIT_VSX_P (DFmode)"
13532   "fcmpu %0,%1,%2"
13533   [(set_attr "type" "fpcompare")])
13534
13535 ;; Only need to compare second words if first words equal
13536 (define_insn "*cmptf_internal1"
13537   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13538         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13539                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
13540   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
13541    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13542   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
13543   [(set_attr "type" "fpcompare")
13544    (set_attr "length" "12")])
13545
13546 (define_insn_and_split "*cmptf_internal2"
13547   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13548         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13549                       (match_operand:TF 2 "gpc_reg_operand" "d")))
13550     (clobber (match_scratch:DF 3 "=d"))
13551     (clobber (match_scratch:DF 4 "=d"))
13552     (clobber (match_scratch:DF 5 "=d"))
13553     (clobber (match_scratch:DF 6 "=d"))
13554     (clobber (match_scratch:DF 7 "=d"))
13555     (clobber (match_scratch:DF 8 "=d"))
13556     (clobber (match_scratch:DF 9 "=d"))
13557     (clobber (match_scratch:DF 10 "=d"))
13558     (clobber (match_scratch:GPR 11 "=b"))]
13559   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
13560    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13561   "#"
13562   "&& reload_completed"
13563   [(set (match_dup 3) (match_dup 14))
13564    (set (match_dup 4) (match_dup 15))
13565    (set (match_dup 9) (abs:DF (match_dup 5)))
13566    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
13567    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
13568                            (label_ref (match_dup 12))
13569                            (pc)))
13570    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
13571    (set (pc) (label_ref (match_dup 13)))
13572    (match_dup 12)
13573    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
13574    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
13575    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
13576    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
13577    (match_dup 13)]
13578 {
13579   REAL_VALUE_TYPE rv;
13580   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
13581   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
13582
13583   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
13584   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
13585   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
13586   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
13587   operands[12] = gen_label_rtx ();
13588   operands[13] = gen_label_rtx ();
13589   real_inf (&rv);
13590   operands[14] = force_const_mem (DFmode,
13591                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
13592   operands[15] = force_const_mem (DFmode,
13593                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
13594                                                                 DFmode));
13595   if (TARGET_TOC)
13596     {
13597       rtx tocref;
13598       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
13599       operands[14] = gen_const_mem (DFmode, tocref);
13600       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
13601       operands[15] = gen_const_mem (DFmode, tocref);
13602       set_mem_alias_set (operands[14], get_TOC_alias_set ());
13603       set_mem_alias_set (operands[15], get_TOC_alias_set ());
13604     }
13605 })
13606 \f
13607 ;; Now we have the scc insns.  We can do some combinations because of the
13608 ;; way the machine works.
13609 ;;
13610 ;; Note that this is probably faster if we can put an insn between the
13611 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
13612 ;; cases the insns below which don't use an intermediate CR field will
13613 ;; be used instead.
13614 (define_insn ""
13615   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13616         (match_operator:SI 1 "scc_comparison_operator"
13617                            [(match_operand 2 "cc_reg_operand" "y")
13618                             (const_int 0)]))]
13619   ""
13620   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
13621   [(set (attr "type")
13622      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
13623                 (const_string "mfcrf")
13624            ]
13625         (const_string "mfcr")))
13626    (set_attr "length" "8")])
13627
13628 ;; Same as above, but get the GT bit.
13629 (define_insn "move_from_CR_gt_bit"
13630   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13631         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
13632   "TARGET_HARD_FLOAT && !TARGET_FPRS"
13633   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
13634   [(set_attr "type" "mfcr")
13635    (set_attr "length" "8")])
13636
13637 ;; Same as above, but get the OV/ORDERED bit.
13638 (define_insn "move_from_CR_ov_bit"
13639   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13640         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
13641   "TARGET_ISEL"
13642   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
13643   [(set_attr "type" "mfcr")
13644    (set_attr "length" "8")])
13645
13646 (define_insn ""
13647   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13648         (match_operator:DI 1 "scc_comparison_operator"
13649                            [(match_operand 2 "cc_reg_operand" "y")
13650                             (const_int 0)]))]
13651   "TARGET_POWERPC64"
13652   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
13653   [(set (attr "type")
13654      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
13655                 (const_string "mfcrf")
13656            ]
13657         (const_string "mfcr")))
13658    (set_attr "length" "8")])
13659
13660 (define_insn ""
13661   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13662         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13663                                        [(match_operand 2 "cc_reg_operand" "y,y")
13664                                         (const_int 0)])
13665                     (const_int 0)))
13666    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
13667         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13668   "TARGET_32BIT"
13669   "@
13670    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
13671    #"
13672   [(set_attr "type" "delayed_compare")
13673    (set_attr "length" "8,16")])
13674
13675 (define_split
13676   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13677         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13678                                        [(match_operand 2 "cc_reg_operand" "")
13679                                         (const_int 0)])
13680                     (const_int 0)))
13681    (set (match_operand:SI 3 "gpc_reg_operand" "")
13682         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13683   "TARGET_32BIT && reload_completed"
13684   [(set (match_dup 3)
13685         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
13686    (set (match_dup 0)
13687         (compare:CC (match_dup 3)
13688                     (const_int 0)))]
13689   "")
13690
13691 (define_insn ""
13692   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13693         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13694                                       [(match_operand 2 "cc_reg_operand" "y")
13695                                        (const_int 0)])
13696                    (match_operand:SI 3 "const_int_operand" "n")))]
13697   ""
13698   "*
13699 {
13700   int is_bit = ccr_bit (operands[1], 1);
13701   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13702   int count;
13703
13704   if (is_bit >= put_bit)
13705     count = is_bit - put_bit;
13706   else
13707     count = 32 - (put_bit - is_bit);
13708
13709   operands[4] = GEN_INT (count);
13710   operands[5] = GEN_INT (put_bit);
13711
13712   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
13713 }"
13714   [(set (attr "type")
13715      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
13716                 (const_string "mfcrf")
13717            ]
13718         (const_string "mfcr")))
13719    (set_attr "length" "8")])
13720
13721 (define_insn ""
13722   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13723         (compare:CC
13724          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13725                                        [(match_operand 2 "cc_reg_operand" "y,y")
13726                                         (const_int 0)])
13727                     (match_operand:SI 3 "const_int_operand" "n,n"))
13728          (const_int 0)))
13729    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
13730         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13731                    (match_dup 3)))]
13732   ""
13733   "*
13734 {
13735   int is_bit = ccr_bit (operands[1], 1);
13736   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13737   int count;
13738
13739   /* Force split for non-cc0 compare.  */
13740   if (which_alternative == 1)
13741      return \"#\";
13742
13743   if (is_bit >= put_bit)
13744     count = is_bit - put_bit;
13745   else
13746     count = 32 - (put_bit - is_bit);
13747
13748   operands[5] = GEN_INT (count);
13749   operands[6] = GEN_INT (put_bit);
13750
13751   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
13752 }"
13753   [(set_attr "type" "delayed_compare")
13754    (set_attr "length" "8,16")])
13755
13756 (define_split
13757   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13758         (compare:CC
13759          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13760                                        [(match_operand 2 "cc_reg_operand" "")
13761                                         (const_int 0)])
13762                     (match_operand:SI 3 "const_int_operand" ""))
13763          (const_int 0)))
13764    (set (match_operand:SI 4 "gpc_reg_operand" "")
13765         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13766                    (match_dup 3)))]
13767   "reload_completed"
13768   [(set (match_dup 4)
13769         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13770                    (match_dup 3)))
13771    (set (match_dup 0)
13772         (compare:CC (match_dup 4)
13773                     (const_int 0)))]
13774   "")
13775
13776 ;; There is a 3 cycle delay between consecutive mfcr instructions
13777 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13778
13779 (define_peephole
13780   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13781         (match_operator:SI 1 "scc_comparison_operator"
13782                            [(match_operand 2 "cc_reg_operand" "y")
13783                             (const_int 0)]))
13784    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13785         (match_operator:SI 4 "scc_comparison_operator"
13786                            [(match_operand 5 "cc_reg_operand" "y")
13787                             (const_int 0)]))]
13788   "REGNO (operands[2]) != REGNO (operands[5])"
13789   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13790   [(set_attr "type" "mfcr")
13791    (set_attr "length" "12")])
13792
13793 (define_peephole
13794   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13795         (match_operator:DI 1 "scc_comparison_operator"
13796                            [(match_operand 2 "cc_reg_operand" "y")
13797                             (const_int 0)]))
13798    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13799         (match_operator:DI 4 "scc_comparison_operator"
13800                            [(match_operand 5 "cc_reg_operand" "y")
13801                             (const_int 0)]))]
13802   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13803   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13804   [(set_attr "type" "mfcr")
13805    (set_attr "length" "12")])
13806
13807 ;; There are some scc insns that can be done directly, without a compare.
13808 ;; These are faster because they don't involve the communications between
13809 ;; the FXU and branch units.   In fact, we will be replacing all of the
13810 ;; integer scc insns here or in the portable methods in emit_store_flag.
13811 ;;
13812 ;; Also support (neg (scc ..)) since that construct is used to replace
13813 ;; branches, (plus (scc ..) ..) since that construct is common and
13814 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13815 ;; cases where it is no more expensive than (neg (scc ..)).
13816
13817 ;; Have reload force a constant into a register for the simple insns that
13818 ;; otherwise won't accept constants.  We do this because it is faster than
13819 ;; the cmp/mfcr sequence we would otherwise generate.
13820
13821 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13822                               (DI "rKJI")])
13823
13824 (define_insn_and_split "*eq<mode>"
13825   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13826         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13827                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13828   "!TARGET_POWER"
13829   "#"
13830   "!TARGET_POWER"
13831   [(set (match_dup 0)
13832         (clz:GPR (match_dup 3)))
13833    (set (match_dup 0)
13834         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13835   {
13836     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13837       {
13838         /* Use output operand as intermediate.  */
13839         operands[3] = operands[0];
13840
13841         if (logical_operand (operands[2], <MODE>mode))
13842           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13843                                   gen_rtx_XOR (<MODE>mode,
13844                                                operands[1], operands[2])));
13845         else
13846           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13847                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13848                                                 negate_rtx (<MODE>mode,
13849                                                             operands[2]))));
13850       }
13851     else
13852       operands[3] = operands[1];
13853
13854     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13855   })
13856
13857 (define_insn_and_split "*eq<mode>_compare"
13858   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13859         (compare:CC
13860          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13861                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13862          (const_int 0)))
13863    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13864         (eq:P (match_dup 1) (match_dup 2)))]
13865   "!TARGET_POWER && optimize_size"
13866   "#"
13867   "!TARGET_POWER && optimize_size"
13868   [(set (match_dup 0)
13869         (clz:P (match_dup 4)))
13870    (parallel [(set (match_dup 3)
13871                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13872                                (const_int 0)))
13873               (set (match_dup 0)
13874                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13875   {
13876     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13877       {
13878         /* Use output operand as intermediate.  */
13879         operands[4] = operands[0];
13880
13881         if (logical_operand (operands[2], <MODE>mode))
13882           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13883                                   gen_rtx_XOR (<MODE>mode,
13884                                                operands[1], operands[2])));
13885         else
13886           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13887                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13888                                                 negate_rtx (<MODE>mode,
13889                                                             operands[2]))));
13890       }
13891     else
13892       operands[4] = operands[1];
13893
13894     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13895   })
13896
13897 (define_insn "*eqsi_power"
13898   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
13899         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13900                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
13901    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
13902   "TARGET_POWER"
13903   "@
13904    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13905    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
13906    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13907    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13908    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
13909   [(set_attr "type" "three,two,three,three,three")
13910    (set_attr "length" "12,8,12,12,12")])
13911
13912 ;; We have insns of the form shown by the first define_insn below.  If
13913 ;; there is something inside the comparison operation, we must split it.
13914 (define_split
13915   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13916         (plus:SI (match_operator 1 "comparison_operator"
13917                                  [(match_operand:SI 2 "" "")
13918                                   (match_operand:SI 3
13919                                                     "reg_or_cint_operand" "")])
13920                  (match_operand:SI 4 "gpc_reg_operand" "")))
13921    (clobber (match_operand:SI 5 "register_operand" ""))]
13922   "! gpc_reg_operand (operands[2], SImode)"
13923   [(set (match_dup 5) (match_dup 2))
13924    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
13925                                (match_dup 4)))])
13926
13927 (define_insn "*plus_eqsi"
13928   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13929         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13930                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13931                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13932   "TARGET_32BIT"
13933   "@
13934    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13935    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
13936    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13937    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13938    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
13939   [(set_attr "type" "three,two,three,three,three")
13940    (set_attr "length" "12,8,12,12,12")])
13941
13942 (define_insn "*compare_plus_eqsi"
13943   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13944         (compare:CC
13945          (plus:SI
13946           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13947                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13948           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13949          (const_int 0)))
13950    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13951   "TARGET_32BIT && optimize_size"
13952   "@
13953    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13954    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
13955    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13956    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13957    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13958    #
13959    #
13960    #
13961    #
13962    #"
13963   [(set_attr "type" "compare")
13964    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13965
13966 (define_split
13967   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13968         (compare:CC
13969          (plus:SI
13970           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13971                  (match_operand:SI 2 "scc_eq_operand" ""))
13972           (match_operand:SI 3 "gpc_reg_operand" ""))
13973          (const_int 0)))
13974    (clobber (match_scratch:SI 4 ""))]
13975   "TARGET_32BIT && optimize_size && reload_completed"
13976   [(set (match_dup 4)
13977         (plus:SI (eq:SI (match_dup 1)
13978                  (match_dup 2))
13979           (match_dup 3)))
13980    (set (match_dup 0)
13981         (compare:CC (match_dup 4)
13982                     (const_int 0)))]
13983   "")
13984
13985 (define_insn "*plus_eqsi_compare"
13986   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13987         (compare:CC
13988          (plus:SI
13989           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13990                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13991           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13992          (const_int 0)))
13993    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13994         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13995   "TARGET_32BIT && optimize_size"
13996   "@
13997    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13998    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
13999    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14000    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14001    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14002    #
14003    #
14004    #
14005    #
14006    #"
14007   [(set_attr "type" "compare")
14008    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
14009
14010 (define_split
14011   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14012         (compare:CC
14013          (plus:SI
14014           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
14015                  (match_operand:SI 2 "scc_eq_operand" ""))
14016           (match_operand:SI 3 "gpc_reg_operand" ""))
14017          (const_int 0)))
14018    (set (match_operand:SI 0 "gpc_reg_operand" "")
14019         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14020   "TARGET_32BIT && optimize_size && reload_completed"
14021   [(set (match_dup 0)
14022         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14023    (set (match_dup 4)
14024         (compare:CC (match_dup 0)
14025                     (const_int 0)))]
14026   "")
14027
14028 (define_insn "*neg_eq0<mode>"
14029   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14030         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
14031                      (const_int 0))))]
14032   ""
14033   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
14034   [(set_attr "type" "two")
14035    (set_attr "length" "8")])
14036
14037 (define_insn_and_split "*neg_eq<mode>"
14038   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14039         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
14040                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
14041   ""
14042   "#"
14043   ""
14044   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
14045   {
14046     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
14047       {
14048         /* Use output operand as intermediate.  */
14049         operands[3] = operands[0];
14050
14051         if (logical_operand (operands[2], <MODE>mode))
14052           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
14053                                   gen_rtx_XOR (<MODE>mode,
14054                                                operands[1], operands[2])));
14055         else
14056           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
14057                                   gen_rtx_PLUS (<MODE>mode, operands[1],
14058                                                 negate_rtx (<MODE>mode,
14059                                                             operands[2]))));
14060       }
14061     else
14062       operands[3] = operands[1];
14063   })
14064
14065 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
14066 ;; since it nabs/sr is just as fast.
14067 (define_insn "*ne0si"
14068   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14069         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
14070                      (const_int 31)))
14071    (clobber (match_scratch:SI 2 "=&r"))]
14072   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
14073   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
14074   [(set_attr "type" "two")
14075    (set_attr "length" "8")])
14076
14077 (define_insn "*ne0di"
14078   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
14079         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
14080                      (const_int 63)))
14081    (clobber (match_scratch:DI 2 "=&r"))]
14082   "TARGET_64BIT"
14083   "addic %2,%1,-1\;subfe %0,%2,%1"
14084   [(set_attr "type" "two")
14085    (set_attr "length" "8")])
14086
14087 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
14088 (define_insn "*plus_ne0si"
14089   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14090         (plus:SI (lshiftrt:SI
14091                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
14092                   (const_int 31))
14093                  (match_operand:SI 2 "gpc_reg_operand" "r")))
14094    (clobber (match_scratch:SI 3 "=&r"))]
14095   "TARGET_32BIT"
14096   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
14097   [(set_attr "type" "two")
14098    (set_attr "length" "8")])
14099
14100 (define_insn "*plus_ne0di"
14101   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
14102         (plus:DI (lshiftrt:DI
14103                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
14104                   (const_int 63))
14105                  (match_operand:DI 2 "gpc_reg_operand" "r")))
14106    (clobber (match_scratch:DI 3 "=&r"))]
14107   "TARGET_64BIT"
14108   "addic %3,%1,-1\;addze %0,%2"
14109   [(set_attr "type" "two")
14110    (set_attr "length" "8")])
14111
14112 (define_insn "*compare_plus_ne0si"
14113   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14114         (compare:CC
14115          (plus:SI (lshiftrt:SI
14116                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
14117                    (const_int 31))
14118                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14119          (const_int 0)))
14120    (clobber (match_scratch:SI 3 "=&r,&r"))
14121    (clobber (match_scratch:SI 4 "=X,&r"))]
14122   "TARGET_32BIT"
14123   "@
14124    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
14125    #"
14126   [(set_attr "type" "compare")
14127    (set_attr "length" "8,12")])
14128
14129 (define_split
14130   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14131         (compare:CC
14132          (plus:SI (lshiftrt:SI
14133                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
14134                    (const_int 31))
14135                   (match_operand:SI 2 "gpc_reg_operand" ""))
14136          (const_int 0)))
14137    (clobber (match_scratch:SI 3 ""))
14138    (clobber (match_scratch:SI 4 ""))]
14139   "TARGET_32BIT && reload_completed"
14140   [(parallel [(set (match_dup 3)
14141                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
14142                                          (const_int 31))
14143                             (match_dup 2)))
14144               (clobber (match_dup 4))])
14145    (set (match_dup 0)
14146         (compare:CC (match_dup 3)
14147                     (const_int 0)))]
14148   "")
14149
14150 (define_insn "*compare_plus_ne0di"
14151   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14152         (compare:CC
14153          (plus:DI (lshiftrt:DI
14154                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
14155                    (const_int 63))
14156                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14157          (const_int 0)))
14158    (clobber (match_scratch:DI 3 "=&r,&r"))]
14159   "TARGET_64BIT"
14160   "@
14161    addic %3,%1,-1\;addze. %3,%2
14162    #"
14163   [(set_attr "type" "compare")
14164    (set_attr "length" "8,12")])
14165
14166 (define_split
14167   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14168         (compare:CC
14169          (plus:DI (lshiftrt:DI
14170                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
14171                    (const_int 63))
14172                   (match_operand:DI 2 "gpc_reg_operand" ""))
14173          (const_int 0)))
14174    (clobber (match_scratch:DI 3 ""))]
14175   "TARGET_64BIT && reload_completed"
14176   [(set (match_dup 3)
14177         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
14178                    (const_int 63))
14179                   (match_dup 2)))
14180    (set (match_dup 0)
14181         (compare:CC (match_dup 3)
14182                     (const_int 0)))]
14183   "")
14184
14185 (define_insn "*plus_ne0si_compare"
14186   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14187         (compare:CC
14188          (plus:SI (lshiftrt:SI
14189                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
14190                    (const_int 31))
14191                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14192          (const_int 0)))
14193    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14194         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14195                  (match_dup 2)))
14196    (clobber (match_scratch:SI 3 "=&r,&r"))]
14197   "TARGET_32BIT"
14198   "@
14199    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
14200    #"
14201   [(set_attr "type" "compare")
14202    (set_attr "length" "8,12")])
14203
14204 (define_split
14205   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14206         (compare:CC
14207          (plus:SI (lshiftrt:SI
14208                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
14209                    (const_int 31))
14210                   (match_operand:SI 2 "gpc_reg_operand" ""))
14211          (const_int 0)))
14212    (set (match_operand:SI 0 "gpc_reg_operand" "")
14213         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14214                  (match_dup 2)))
14215    (clobber (match_scratch:SI 3 ""))]
14216   "TARGET_32BIT && reload_completed"
14217   [(parallel [(set (match_dup 0)
14218         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14219                  (match_dup 2)))
14220    (clobber (match_dup 3))])
14221    (set (match_dup 4)
14222         (compare:CC (match_dup 0)
14223                     (const_int 0)))]
14224   "")
14225
14226 (define_insn "*plus_ne0di_compare"
14227   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14228         (compare:CC
14229          (plus:DI (lshiftrt:DI
14230                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
14231                    (const_int 63))
14232                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14233          (const_int 0)))
14234    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
14235         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14236                  (match_dup 2)))
14237    (clobber (match_scratch:DI 3 "=&r,&r"))]
14238   "TARGET_64BIT"
14239   "@
14240    addic %3,%1,-1\;addze. %0,%2
14241    #"
14242   [(set_attr "type" "compare")
14243    (set_attr "length" "8,12")])
14244
14245 (define_split
14246   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
14247         (compare:CC
14248          (plus:DI (lshiftrt:DI
14249                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
14250                    (const_int 63))
14251                   (match_operand:DI 2 "gpc_reg_operand" ""))
14252          (const_int 0)))
14253    (set (match_operand:DI 0 "gpc_reg_operand" "")
14254         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14255                  (match_dup 2)))
14256    (clobber (match_scratch:DI 3 ""))]
14257   "TARGET_64BIT && reload_completed"
14258   [(parallel [(set (match_dup 0)
14259         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14260                  (match_dup 2)))
14261    (clobber (match_dup 3))])
14262    (set (match_dup 4)
14263         (compare:CC (match_dup 0)
14264                     (const_int 0)))]
14265   "")
14266
14267 (define_insn ""
14268   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14269         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14270                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
14271    (clobber (match_scratch:SI 3 "=r,X"))]
14272   "TARGET_POWER"
14273   "@
14274    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
14275    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
14276   [(set_attr "length" "12")])
14277
14278 (define_insn ""
14279   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14280         (compare:CC
14281          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14282                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14283          (const_int 0)))
14284    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
14285         (le:SI (match_dup 1) (match_dup 2)))
14286    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
14287   "TARGET_POWER"
14288   "@
14289    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14290    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
14291    #
14292    #"
14293   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
14294    (set_attr "length" "12,12,16,16")])
14295
14296 (define_split
14297   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14298         (compare:CC
14299          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14300                 (match_operand:SI 2 "reg_or_short_operand" ""))
14301          (const_int 0)))
14302    (set (match_operand:SI 0 "gpc_reg_operand" "")
14303         (le:SI (match_dup 1) (match_dup 2)))
14304    (clobber (match_scratch:SI 3 ""))]
14305   "TARGET_POWER && reload_completed"
14306   [(parallel [(set (match_dup 0)
14307         (le:SI (match_dup 1) (match_dup 2)))
14308    (clobber (match_dup 3))])
14309    (set (match_dup 4)
14310         (compare:CC (match_dup 0)
14311                     (const_int 0)))]
14312   "")
14313
14314 (define_insn ""
14315   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14316         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14317                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
14318                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
14319   "TARGET_POWER"
14320   "@
14321    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
14322    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
14323   [(set_attr "length" "12")])
14324
14325 (define_insn ""
14326   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14327         (compare:CC
14328          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14329                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14330                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14331          (const_int 0)))
14332    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14333   "TARGET_POWER"
14334   "@
14335    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14336    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
14337    #
14338    #"
14339   [(set_attr "type" "compare")
14340    (set_attr "length" "12,12,16,16")])
14341
14342 (define_split
14343   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14344         (compare:CC
14345          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14346                          (match_operand:SI 2 "reg_or_short_operand" ""))
14347                   (match_operand:SI 3 "gpc_reg_operand" ""))
14348          (const_int 0)))
14349    (clobber (match_scratch:SI 4 ""))]
14350   "TARGET_POWER && reload_completed"
14351   [(set (match_dup 4)
14352         (plus:SI (le:SI (match_dup 1) (match_dup 2))
14353                  (match_dup 3)))
14354    (set (match_dup 0)
14355         (compare:CC (match_dup 4)
14356                     (const_int 0)))]
14357   "")
14358
14359 (define_insn ""
14360   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14361         (compare:CC
14362          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14363                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14364                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14365          (const_int 0)))
14366    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14367         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14368   "TARGET_POWER"
14369   "@
14370    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14371    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
14372    #
14373    #"
14374   [(set_attr "type" "compare")
14375    (set_attr "length" "12,12,16,16")])
14376
14377 (define_split
14378   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14379         (compare:CC
14380          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14381                          (match_operand:SI 2 "reg_or_short_operand" ""))
14382                   (match_operand:SI 3 "gpc_reg_operand" ""))
14383          (const_int 0)))
14384    (set (match_operand:SI 0 "gpc_reg_operand" "")
14385         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14386   "TARGET_POWER && reload_completed"
14387   [(set (match_dup 0)
14388         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14389    (set (match_dup 4)
14390         (compare:CC (match_dup 0)
14391                     (const_int 0)))]
14392   "")
14393
14394 (define_insn ""
14395   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14396         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14397                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
14398   "TARGET_POWER"
14399   "@
14400    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
14401    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
14402   [(set_attr "length" "12")])
14403
14404 (define_insn "*leu<mode>"
14405   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14406         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14407                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14408   ""
14409   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14410   [(set_attr "type" "three")
14411    (set_attr "length" "12")])
14412
14413 (define_insn "*leu<mode>_compare"
14414   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14415         (compare:CC
14416          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14417                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14418          (const_int 0)))
14419    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14420         (leu:P (match_dup 1) (match_dup 2)))]
14421   ""
14422   "@
14423    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14424    #"
14425   [(set_attr "type" "compare")
14426    (set_attr "length" "12,16")])
14427
14428 (define_split
14429   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14430         (compare:CC
14431          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
14432                 (match_operand:P 2 "reg_or_short_operand" ""))
14433          (const_int 0)))
14434    (set (match_operand:P 0 "gpc_reg_operand" "")
14435         (leu:P (match_dup 1) (match_dup 2)))]
14436   "reload_completed"
14437   [(set (match_dup 0)
14438         (leu:P (match_dup 1) (match_dup 2)))
14439    (set (match_dup 3)
14440         (compare:CC (match_dup 0)
14441                     (const_int 0)))]
14442   "")
14443
14444 (define_insn "*plus_leu<mode>"
14445   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14446         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14447                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14448                 (match_operand:P 3 "gpc_reg_operand" "r")))]
14449   ""
14450   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
14451   [(set_attr "type" "two")
14452    (set_attr "length" "8")])
14453
14454 (define_insn ""
14455   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14456         (compare:CC
14457          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14458                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14459                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14460          (const_int 0)))
14461    (clobber (match_scratch:SI 4 "=&r,&r"))]
14462   "TARGET_32BIT"
14463   "@
14464    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
14465    #"
14466   [(set_attr "type" "compare")
14467    (set_attr "length" "8,12")])
14468
14469 (define_split
14470   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14471         (compare:CC
14472          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14473                           (match_operand:SI 2 "reg_or_short_operand" ""))
14474                   (match_operand:SI 3 "gpc_reg_operand" ""))
14475          (const_int 0)))
14476    (clobber (match_scratch:SI 4 ""))]
14477   "TARGET_32BIT && reload_completed"
14478   [(set (match_dup 4)
14479         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
14480                   (match_dup 3)))
14481    (set (match_dup 0)
14482         (compare:CC (match_dup 4)
14483                     (const_int 0)))]
14484   "")
14485
14486 (define_insn ""
14487   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14488         (compare:CC
14489          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14490                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14491                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14492          (const_int 0)))
14493    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14494         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14495   "TARGET_32BIT"
14496   "@
14497    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
14498    #"
14499   [(set_attr "type" "compare")
14500    (set_attr "length" "8,12")])
14501
14502 (define_split
14503   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14504         (compare:CC
14505          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14506                           (match_operand:SI 2 "reg_or_short_operand" ""))
14507                   (match_operand:SI 3 "gpc_reg_operand" ""))
14508          (const_int 0)))
14509    (set (match_operand:SI 0 "gpc_reg_operand" "")
14510         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14511   "TARGET_32BIT && reload_completed"
14512   [(set (match_dup 0)
14513         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14514    (set (match_dup 4)
14515         (compare:CC (match_dup 0)
14516                     (const_int 0)))]
14517   "")
14518
14519 (define_insn "*neg_leu<mode>"
14520   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14521         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14522                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14523   ""
14524   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
14525    [(set_attr "type" "three")
14526     (set_attr "length" "12")])
14527
14528 (define_insn "*and_neg_leu<mode>"
14529   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14530         (and:P (neg:P
14531                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14532                         (match_operand:P 2 "reg_or_short_operand" "rI")))
14533                 (match_operand:P 3 "gpc_reg_operand" "r")))]
14534   ""
14535   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
14536   [(set_attr "type" "three")
14537    (set_attr "length" "12")])
14538
14539 (define_insn ""
14540   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14541         (compare:CC
14542          (and:SI (neg:SI
14543                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14544                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
14545                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14546          (const_int 0)))
14547    (clobber (match_scratch:SI 4 "=&r,&r"))]
14548   "TARGET_32BIT"
14549   "@
14550    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14551    #"
14552   [(set_attr "type" "compare")
14553    (set_attr "length" "12,16")])
14554
14555 (define_split
14556   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14557         (compare:CC
14558          (and:SI (neg:SI
14559                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14560                           (match_operand:SI 2 "reg_or_short_operand" "")))
14561                  (match_operand:SI 3 "gpc_reg_operand" ""))
14562          (const_int 0)))
14563    (clobber (match_scratch:SI 4 ""))]
14564   "TARGET_32BIT && reload_completed"
14565   [(set (match_dup 4)
14566         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
14567                 (match_dup 3)))
14568    (set (match_dup 0)
14569         (compare:CC (match_dup 4)
14570                     (const_int 0)))]
14571   "")
14572
14573 (define_insn ""
14574   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14575         (compare:CC
14576          (and:SI (neg:SI
14577                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14578                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
14579                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14580          (const_int 0)))
14581    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14582         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14583   "TARGET_32BIT"
14584   "@
14585    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14586    #"
14587   [(set_attr "type" "compare")
14588    (set_attr "length" "12,16")])
14589
14590 (define_split
14591   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14592         (compare:CC
14593          (and:SI (neg:SI
14594                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14595                           (match_operand:SI 2 "reg_or_short_operand" "")))
14596                  (match_operand:SI 3 "gpc_reg_operand" ""))
14597          (const_int 0)))
14598    (set (match_operand:SI 0 "gpc_reg_operand" "")
14599         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14600   "TARGET_32BIT && reload_completed"
14601   [(set (match_dup 0)
14602         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
14603                 (match_dup 3)))
14604    (set (match_dup 4)
14605         (compare:CC (match_dup 0)
14606                     (const_int 0)))]
14607   "")
14608
14609 (define_insn ""
14610   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14611         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14612                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
14613   "TARGET_POWER"
14614   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
14615    [(set_attr "length" "12")])
14616
14617 (define_insn ""
14618   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14619         (compare:CC
14620          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14621                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14622          (const_int 0)))
14623    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14624         (lt:SI (match_dup 1) (match_dup 2)))]
14625   "TARGET_POWER"
14626   "@
14627    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
14628    #"
14629   [(set_attr "type" "delayed_compare")
14630    (set_attr "length" "12,16")])
14631
14632 (define_split
14633   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14634         (compare:CC
14635          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14636                 (match_operand:SI 2 "reg_or_short_operand" ""))
14637          (const_int 0)))
14638    (set (match_operand:SI 0 "gpc_reg_operand" "")
14639         (lt:SI (match_dup 1) (match_dup 2)))]
14640   "TARGET_POWER && reload_completed"
14641   [(set (match_dup 0)
14642         (lt:SI (match_dup 1) (match_dup 2)))
14643    (set (match_dup 3)
14644         (compare:CC (match_dup 0)
14645                     (const_int 0)))]
14646   "")
14647
14648 (define_insn ""
14649   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14650         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14651                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14652                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14653   "TARGET_POWER"
14654   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
14655   [(set_attr "length" "12")])
14656
14657 (define_insn ""
14658   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14659         (compare:CC
14660          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14661                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14662                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14663          (const_int 0)))
14664    (clobber (match_scratch:SI 4 "=&r,&r"))]
14665   "TARGET_POWER"
14666   "@
14667    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
14668    #"
14669   [(set_attr "type" "compare")
14670    (set_attr "length" "12,16")])
14671
14672 (define_split
14673   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14674         (compare:CC
14675          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14676                          (match_operand:SI 2 "reg_or_short_operand" ""))
14677                   (match_operand:SI 3 "gpc_reg_operand" ""))
14678          (const_int 0)))
14679    (clobber (match_scratch:SI 4 ""))]
14680   "TARGET_POWER && reload_completed"
14681   [(set (match_dup 4)
14682         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
14683                  (match_dup 3)))
14684    (set (match_dup 0)
14685         (compare:CC (match_dup 4)
14686                     (const_int 0)))]
14687   "")
14688
14689 (define_insn ""
14690   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14691         (compare:CC
14692          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14693                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14694                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14695          (const_int 0)))
14696    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14697         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14698   "TARGET_POWER"
14699   "@
14700    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
14701    #"
14702   [(set_attr "type" "compare")
14703    (set_attr "length" "12,16")])
14704
14705 (define_split
14706   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14707         (compare:CC
14708          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14709                          (match_operand:SI 2 "reg_or_short_operand" ""))
14710                   (match_operand:SI 3 "gpc_reg_operand" ""))
14711          (const_int 0)))
14712    (set (match_operand:SI 0 "gpc_reg_operand" "")
14713         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14714   "TARGET_POWER && reload_completed"
14715   [(set (match_dup 0)
14716         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14717    (set (match_dup 4)
14718         (compare:CC (match_dup 0)
14719                     (const_int 0)))]
14720   "")
14721
14722 (define_insn ""
14723   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14724         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14725                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14726   "TARGET_POWER"
14727   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
14728   [(set_attr "length" "12")])
14729
14730 (define_insn_and_split "*ltu<mode>"
14731   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14732         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14733                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14734   ""
14735   "#"
14736   ""
14737   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14738    (set (match_dup 0) (neg:P (match_dup 0)))]
14739   "")
14740
14741 (define_insn_and_split "*ltu<mode>_compare"
14742   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14743         (compare:CC
14744          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14745                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14746          (const_int 0)))
14747    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14748         (ltu:P (match_dup 1) (match_dup 2)))]
14749   ""
14750   "#"
14751   ""
14752   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14753    (parallel [(set (match_dup 3)
14754                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14755               (set (match_dup 0) (neg:P (match_dup 0)))])]
14756   "")
14757
14758 (define_insn_and_split "*plus_ltu<mode>"
14759   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
14760         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14761                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14762                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
14763   ""
14764   "#"
14765   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14766   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14767    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14768   "")
14769
14770 (define_insn_and_split "*plus_ltu<mode>_compare"
14771   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14772         (compare:CC
14773          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14774                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14775                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14776          (const_int 0)))
14777    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14778         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14779   ""
14780   "#"
14781   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14782   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14783    (parallel [(set (match_dup 4)
14784                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14785                                (const_int 0)))
14786               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14787   "")
14788
14789 (define_insn "*neg_ltu<mode>"
14790   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14791         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14792                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
14793   ""
14794   "@
14795    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
14796    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
14797   [(set_attr "type" "two")
14798    (set_attr "length" "8")])
14799
14800 (define_insn ""
14801   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14802         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14803                (match_operand:SI 2 "reg_or_short_operand" "rI")))
14804    (clobber (match_scratch:SI 3 "=r"))]
14805   "TARGET_POWER"
14806   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
14807    [(set_attr "length" "12")])
14808
14809 (define_insn ""
14810   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14811         (compare:CC
14812          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14813                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14814          (const_int 0)))
14815    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14816         (ge:SI (match_dup 1) (match_dup 2)))
14817    (clobber (match_scratch:SI 3 "=r,r"))]
14818   "TARGET_POWER"
14819   "@
14820    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14821    #"
14822   [(set_attr "type" "compare")
14823    (set_attr "length" "12,16")])
14824
14825 (define_split
14826   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14827         (compare:CC
14828          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14829                 (match_operand:SI 2 "reg_or_short_operand" ""))
14830          (const_int 0)))
14831    (set (match_operand:SI 0 "gpc_reg_operand" "")
14832         (ge:SI (match_dup 1) (match_dup 2)))
14833    (clobber (match_scratch:SI 3 ""))]
14834   "TARGET_POWER && reload_completed"
14835   [(parallel [(set (match_dup 0)
14836                    (ge:SI (match_dup 1) (match_dup 2)))
14837               (clobber (match_dup 3))])
14838    (set (match_dup 4)
14839         (compare:CC (match_dup 0)
14840                     (const_int 0)))]
14841   "")
14842
14843 (define_insn ""
14844   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14845         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14846                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14847                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14848   "TARGET_POWER"
14849   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
14850   [(set_attr "length" "12")])
14851
14852 (define_insn ""
14853   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14854         (compare:CC
14855          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14856                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14857                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14858          (const_int 0)))
14859    (clobber (match_scratch:SI 4 "=&r,&r"))]
14860   "TARGET_POWER"
14861   "@
14862    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14863    #"
14864   [(set_attr "type" "compare")
14865    (set_attr "length" "12,16")])
14866
14867 (define_split
14868   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14869         (compare:CC
14870          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14871                          (match_operand:SI 2 "reg_or_short_operand" ""))
14872                   (match_operand:SI 3 "gpc_reg_operand" ""))
14873          (const_int 0)))
14874    (clobber (match_scratch:SI 4 ""))]
14875   "TARGET_POWER && reload_completed"
14876   [(set (match_dup 4)
14877         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
14878                  (match_dup 3)))
14879    (set (match_dup 0)
14880         (compare:CC (match_dup 4)
14881                     (const_int 0)))]
14882   "")
14883
14884 (define_insn ""
14885   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14886         (compare:CC
14887          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14888                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14889                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14890          (const_int 0)))
14891    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14892         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14893   "TARGET_POWER"
14894   "@
14895    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14896    #"
14897   [(set_attr "type" "compare")
14898    (set_attr "length" "12,16")])
14899
14900 (define_split
14901   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14902         (compare:CC
14903          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14904                          (match_operand:SI 2 "reg_or_short_operand" ""))
14905                   (match_operand:SI 3 "gpc_reg_operand" ""))
14906          (const_int 0)))
14907    (set (match_operand:SI 0 "gpc_reg_operand" "")
14908         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14909   "TARGET_POWER && reload_completed"
14910   [(set (match_dup 0)
14911         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14912    (set (match_dup 4)
14913         (compare:CC (match_dup 0)
14914                     (const_int 0)))]
14915   "")
14916
14917 (define_insn ""
14918   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14919         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14920                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14921   "TARGET_POWER"
14922   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
14923   [(set_attr "length" "12")])
14924
14925 (define_insn "*geu<mode>"
14926   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14927         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14928                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14929   ""
14930   "@
14931    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
14932    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14933   [(set_attr "type" "three")
14934    (set_attr "length" "12")])
14935
14936 (define_insn "*geu<mode>_compare"
14937   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14938         (compare:CC
14939          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14940                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14941          (const_int 0)))
14942    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14943         (geu:P (match_dup 1) (match_dup 2)))]
14944   ""
14945   "@
14946    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14947    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14948    #
14949    #"
14950   [(set_attr "type" "compare")
14951    (set_attr "length" "12,12,16,16")])
14952
14953 (define_split
14954   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14955         (compare:CC
14956          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
14957                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
14958          (const_int 0)))
14959    (set (match_operand:P 0 "gpc_reg_operand" "")
14960         (geu:P (match_dup 1) (match_dup 2)))]
14961   "reload_completed"
14962   [(set (match_dup 0)
14963         (geu:P (match_dup 1) (match_dup 2)))
14964    (set (match_dup 3)
14965         (compare:CC (match_dup 0)
14966                     (const_int 0)))]
14967   "")
14968
14969 (define_insn "*plus_geu<mode>"
14970   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14971         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14972                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14973                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14974   ""
14975   "@
14976    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
14977    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
14978   [(set_attr "type" "two")
14979    (set_attr "length" "8")])
14980
14981 (define_insn ""
14982   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14983         (compare:CC
14984          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14985                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14986                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14987          (const_int 0)))
14988    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14989   "TARGET_32BIT"
14990   "@
14991    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
14992    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
14993    #
14994    #"
14995   [(set_attr "type" "compare")
14996    (set_attr "length" "8,8,12,12")])
14997
14998 (define_split
14999   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15000         (compare:CC
15001          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
15002                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
15003                   (match_operand:SI 3 "gpc_reg_operand" ""))
15004          (const_int 0)))
15005    (clobber (match_scratch:SI 4 ""))]
15006   "TARGET_32BIT && reload_completed"
15007   [(set (match_dup 4)
15008         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
15009                   (match_dup 3)))
15010    (set (match_dup 0)
15011         (compare:CC (match_dup 4)
15012                     (const_int 0)))]
15013   "")
15014
15015 (define_insn ""
15016   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
15017         (compare:CC
15018          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
15019                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
15020                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
15021          (const_int 0)))
15022    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
15023         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15024   "TARGET_32BIT"
15025   "@
15026    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
15027    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
15028    #
15029    #"
15030   [(set_attr "type" "compare")
15031    (set_attr "length" "8,8,12,12")])
15032
15033 (define_split
15034   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
15035         (compare:CC
15036          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
15037                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
15038                   (match_operand:SI 3 "gpc_reg_operand" ""))
15039          (const_int 0)))
15040    (set (match_operand:SI 0 "gpc_reg_operand" "")
15041         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15042   "TARGET_32BIT && reload_completed"
15043   [(set (match_dup 0)
15044         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
15045    (set (match_dup 4)
15046         (compare:CC (match_dup 0)
15047                     (const_int 0)))]
15048   "")
15049
15050 (define_insn "*neg_geu<mode>"
15051   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
15052         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
15053                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
15054   ""
15055   "@
15056    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
15057    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
15058   [(set_attr "type" "three")
15059    (set_attr "length" "12")])
15060
15061 (define_insn "*and_neg_geu<mode>"
15062   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
15063         (and:P (neg:P
15064                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
15065                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
15066                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
15067   ""
15068   "@
15069    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
15070    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
15071   [(set_attr "type" "three")
15072    (set_attr "length" "12")])
15073
15074 (define_insn ""
15075   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
15076         (compare:CC
15077          (and:SI (neg:SI
15078                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
15079                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
15080                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
15081          (const_int 0)))
15082    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
15083   "TARGET_32BIT"
15084   "@
15085    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
15086    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
15087    #
15088    #"
15089   [(set_attr "type" "compare")
15090    (set_attr "length" "12,12,16,16")])
15091
15092 (define_split
15093   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15094         (compare:CC
15095          (and:SI (neg:SI
15096                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
15097                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
15098                  (match_operand:SI 3 "gpc_reg_operand" ""))
15099          (const_int 0)))
15100    (clobber (match_scratch:SI 4 ""))]
15101   "TARGET_32BIT && reload_completed"
15102   [(set (match_dup 4)
15103         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
15104                 (match_dup 3)))
15105    (set (match_dup 0)
15106         (compare:CC (match_dup 4)
15107                     (const_int 0)))]
15108   "")
15109
15110 (define_insn ""
15111   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
15112         (compare:CC
15113          (and:SI (neg:SI
15114                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
15115                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
15116                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
15117          (const_int 0)))
15118    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
15119         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
15120   "TARGET_32BIT"
15121   "@
15122    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
15123    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
15124    #
15125    #"
15126   [(set_attr "type" "compare")
15127    (set_attr "length" "12,12,16,16")])
15128
15129 (define_split
15130   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
15131         (compare:CC
15132          (and:SI (neg:SI
15133                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
15134                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
15135                  (match_operand:SI 3 "gpc_reg_operand" ""))
15136          (const_int 0)))
15137    (set (match_operand:SI 0 "gpc_reg_operand" "")
15138         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
15139   "TARGET_32BIT && reload_completed"
15140   [(set (match_dup 0)
15141         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
15142    (set (match_dup 4)
15143         (compare:CC (match_dup 0)
15144                     (const_int 0)))]
15145   "")
15146
15147 (define_insn ""
15148   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15149         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
15150                (match_operand:SI 2 "reg_or_short_operand" "r")))]
15151   "TARGET_POWER"
15152   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
15153   [(set_attr "length" "12")])
15154
15155 (define_insn ""
15156   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15157         (compare:CC
15158          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15159                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15160          (const_int 0)))
15161    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
15162         (gt:SI (match_dup 1) (match_dup 2)))]
15163   "TARGET_POWER"
15164   "@
15165    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
15166    #"
15167   [(set_attr "type" "delayed_compare")
15168    (set_attr "length" "12,16")])
15169
15170 (define_split
15171   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
15172         (compare:CC
15173          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15174                 (match_operand:SI 2 "reg_or_short_operand" ""))
15175          (const_int 0)))
15176    (set (match_operand:SI 0 "gpc_reg_operand" "")
15177         (gt:SI (match_dup 1) (match_dup 2)))]
15178   "TARGET_POWER && reload_completed"
15179   [(set (match_dup 0)
15180         (gt:SI (match_dup 1) (match_dup 2)))
15181    (set (match_dup 3)
15182         (compare:CC (match_dup 0)
15183                     (const_int 0)))]
15184   "")
15185
15186 (define_insn "*plus_gt0<mode>"
15187   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
15188         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
15189                       (const_int 0))
15190                  (match_operand:P 2 "gpc_reg_operand" "r")))]
15191   ""
15192   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
15193   [(set_attr "type" "three")
15194    (set_attr "length" "12")])
15195
15196 (define_insn ""
15197   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15198         (compare:CC
15199          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15200                          (const_int 0))
15201                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
15202          (const_int 0)))
15203    (clobber (match_scratch:SI 3 "=&r,&r"))]
15204   "TARGET_32BIT"
15205   "@
15206    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
15207    #"
15208   [(set_attr "type" "compare")
15209    (set_attr "length" "12,16")])
15210
15211 (define_split
15212   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15213         (compare:CC
15214          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15215                          (const_int 0))
15216                   (match_operand:SI 2 "gpc_reg_operand" ""))
15217          (const_int 0)))
15218    (clobber (match_scratch:SI 3 ""))]
15219   "TARGET_32BIT && reload_completed"
15220   [(set (match_dup 3)
15221         (plus:SI (gt:SI (match_dup 1) (const_int 0))
15222                   (match_dup 2)))
15223    (set (match_dup 0)
15224         (compare:CC (match_dup 3)
15225                     (const_int 0)))]
15226   "")
15227
15228 (define_insn ""
15229   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15230         (compare:CC
15231          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
15232                          (const_int 0))
15233                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
15234          (const_int 0)))
15235    (clobber (match_scratch:DI 3 "=&r,&r"))]
15236   "TARGET_64BIT"
15237   "@
15238    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
15239    #"
15240   [(set_attr "type" "compare")
15241    (set_attr "length" "12,16")])
15242
15243 (define_split
15244   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
15245         (compare:CC
15246          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
15247                          (const_int 0))
15248                   (match_operand:DI 2 "gpc_reg_operand" ""))
15249          (const_int 0)))
15250    (clobber (match_scratch:DI 3 ""))]
15251   "TARGET_64BIT && reload_completed"
15252   [(set (match_dup 3)
15253         (plus:DI (gt:DI (match_dup 1) (const_int 0))
15254                  (match_dup 2)))
15255    (set (match_dup 0)
15256         (compare:CC (match_dup 3)
15257                     (const_int 0)))]
15258   "")
15259
15260 (define_insn ""
15261   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15262         (compare:CC
15263          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15264                          (const_int 0))
15265                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
15266          (const_int 0)))
15267    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
15268         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
15269   "TARGET_32BIT"
15270   "@
15271    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
15272    #"
15273   [(set_attr "type" "compare")
15274    (set_attr "length" "12,16")])
15275
15276 (define_split
15277   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
15278         (compare:CC
15279          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15280                          (const_int 0))
15281                   (match_operand:SI 2 "gpc_reg_operand" ""))
15282          (const_int 0)))
15283    (set (match_operand:SI 0 "gpc_reg_operand" "")
15284         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
15285   "TARGET_32BIT && reload_completed"
15286   [(set (match_dup 0)
15287         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
15288    (set (match_dup 3)
15289         (compare:CC (match_dup 0)
15290                     (const_int 0)))]
15291   "")
15292
15293 (define_insn ""
15294   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15295         (compare:CC
15296          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
15297                          (const_int 0))
15298                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
15299          (const_int 0)))
15300    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
15301         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
15302   "TARGET_64BIT"
15303   "@
15304    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
15305    #"
15306   [(set_attr "type" "compare")
15307    (set_attr "length" "12,16")])
15308
15309 (define_split
15310   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
15311         (compare:CC
15312          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
15313                          (const_int 0))
15314                   (match_operand:DI 2 "gpc_reg_operand" ""))
15315          (const_int 0)))
15316    (set (match_operand:DI 0 "gpc_reg_operand" "")
15317         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
15318   "TARGET_64BIT && reload_completed"
15319   [(set (match_dup 0)
15320         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
15321    (set (match_dup 3)
15322         (compare:CC (match_dup 0)
15323                     (const_int 0)))]
15324   "")
15325
15326 (define_insn ""
15327   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
15328         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
15329                         (match_operand:SI 2 "reg_or_short_operand" "r"))
15330                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
15331   "TARGET_POWER"
15332   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
15333   [(set_attr "length" "12")])
15334
15335 (define_insn ""
15336   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15337         (compare:CC
15338          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15339                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15340                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
15341          (const_int 0)))
15342    (clobber (match_scratch:SI 4 "=&r,&r"))]
15343   "TARGET_POWER"
15344   "@
15345    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
15346    #"
15347   [(set_attr "type" "compare")
15348    (set_attr "length" "12,16")])
15349
15350 (define_split
15351   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15352         (compare:CC
15353          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15354                          (match_operand:SI 2 "reg_or_short_operand" ""))
15355                   (match_operand:SI 3 "gpc_reg_operand" ""))
15356          (const_int 0)))
15357    (clobber (match_scratch:SI 4 ""))]
15358   "TARGET_POWER && reload_completed"
15359   [(set (match_dup 4)
15360         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
15361    (set (match_dup 0)
15362         (compare:CC (match_dup 4)
15363                     (const_int 0)))]
15364   "")
15365
15366 (define_insn ""
15367   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
15368         (compare:CC
15369          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15370                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15371                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
15372          (const_int 0)))
15373    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
15374         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15375   "TARGET_POWER"
15376   "@
15377    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
15378    #"
15379   [(set_attr "type" "compare")
15380    (set_attr "length" "12,16")])
15381
15382 (define_split
15383   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
15384         (compare:CC
15385          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15386                          (match_operand:SI 2 "reg_or_short_operand" ""))
15387                   (match_operand:SI 3 "gpc_reg_operand" ""))
15388          (const_int 0)))
15389    (set (match_operand:SI 0 "gpc_reg_operand" "")
15390         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15391   "TARGET_POWER && reload_completed"
15392   [(set (match_dup 0)
15393         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
15394    (set (match_dup 4)
15395         (compare:CC (match_dup 0)
15396                     (const_int 0)))]
15397   "")
15398
15399 (define_insn ""
15400   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15401         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
15402                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
15403   "TARGET_POWER"
15404   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
15405   [(set_attr "length" "12")])
15406
15407 (define_insn_and_split "*gtu<mode>"
15408   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15409         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15410                (match_operand:P 2 "reg_or_short_operand" "rI")))]
15411   ""
15412   "#"
15413   ""
15414   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15415    (set (match_dup 0) (neg:P (match_dup 0)))]
15416   "")
15417
15418 (define_insn_and_split "*gtu<mode>_compare"
15419   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15420         (compare:CC
15421          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
15422                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
15423          (const_int 0)))
15424    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
15425         (gtu:P (match_dup 1) (match_dup 2)))]
15426   ""
15427   "#"
15428   ""
15429   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15430    (parallel [(set (match_dup 3)
15431                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
15432               (set (match_dup 0) (neg:P (match_dup 0)))])]
15433   "")
15434
15435 (define_insn_and_split "*plus_gtu<mode>"
15436   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
15437         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15438                        (match_operand:P 2 "reg_or_short_operand" "rI"))
15439                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
15440   ""
15441   "#"
15442   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
15443   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15444    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
15445   "")
15446
15447 (define_insn_and_split "*plus_gtu<mode>_compare"
15448   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
15449         (compare:CC
15450          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
15451                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
15452                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
15453          (const_int 0)))
15454    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
15455         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
15456   ""
15457   "#"
15458   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
15459   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15460    (parallel [(set (match_dup 4)
15461                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
15462                                (const_int 0)))
15463               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
15464   "")
15465
15466 (define_insn "*neg_gtu<mode>"
15467   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15468         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15469                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
15470   ""
15471   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
15472   [(set_attr "type" "two")
15473    (set_attr "length" "8")])
15474
15475 \f
15476 ;; Define both directions of branch and return.  If we need a reload
15477 ;; register, we'd rather use CR0 since it is much easier to copy a
15478 ;; register CC value to there.
15479
15480 (define_insn ""
15481   [(set (pc)
15482         (if_then_else (match_operator 1 "branch_comparison_operator"
15483                                       [(match_operand 2
15484                                                       "cc_reg_operand" "y")
15485                                        (const_int 0)])
15486                       (label_ref (match_operand 0 "" ""))
15487                       (pc)))]
15488   ""
15489   "*
15490 {
15491   return output_cbranch (operands[1], \"%l0\", 0, insn);
15492 }"
15493   [(set_attr "type" "branch")])
15494
15495 (define_insn ""
15496   [(set (pc)
15497         (if_then_else (match_operator 0 "branch_comparison_operator"
15498                                       [(match_operand 1
15499                                                       "cc_reg_operand" "y")
15500                                        (const_int 0)])
15501                       (return)
15502                       (pc)))]
15503   "direct_return ()"
15504   "*
15505 {
15506   return output_cbranch (operands[0], NULL, 0, insn);
15507 }"
15508   [(set_attr "type" "jmpreg")
15509    (set_attr "length" "4")])
15510
15511 (define_insn ""
15512   [(set (pc)
15513         (if_then_else (match_operator 1 "branch_comparison_operator"
15514                                       [(match_operand 2
15515                                                       "cc_reg_operand" "y")
15516                                        (const_int 0)])
15517                       (pc)
15518                       (label_ref (match_operand 0 "" ""))))]
15519   ""
15520   "*
15521 {
15522   return output_cbranch (operands[1], \"%l0\", 1, insn);
15523 }"
15524   [(set_attr "type" "branch")])
15525
15526 (define_insn ""
15527   [(set (pc)
15528         (if_then_else (match_operator 0 "branch_comparison_operator"
15529                                       [(match_operand 1
15530                                                       "cc_reg_operand" "y")
15531                                        (const_int 0)])
15532                       (pc)
15533                       (return)))]
15534   "direct_return ()"
15535   "*
15536 {
15537   return output_cbranch (operands[0], NULL, 1, insn);
15538 }"
15539   [(set_attr "type" "jmpreg")
15540    (set_attr "length" "4")])
15541
15542 ;; Logic on condition register values.
15543
15544 ; This pattern matches things like
15545 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
15546 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
15547 ;                                  (const_int 1)))
15548 ; which are generated by the branch logic.
15549 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
15550
15551 (define_insn "*cceq_ior_compare"
15552   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15553         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
15554                         [(match_operator:SI 2
15555                                       "branch_positive_comparison_operator"
15556                                       [(match_operand 3
15557                                                       "cc_reg_operand" "y,y")
15558                                        (const_int 0)])
15559                          (match_operator:SI 4
15560                                       "branch_positive_comparison_operator"
15561                                       [(match_operand 5
15562                                                       "cc_reg_operand" "0,y")
15563                                        (const_int 0)])])
15564                       (const_int 1)))]
15565   ""
15566   "cr%q1 %E0,%j2,%j4"
15567   [(set_attr "type" "cr_logical,delayed_cr")])
15568
15569 ; Why is the constant -1 here, but 1 in the previous pattern?
15570 ; Because ~1 has all but the low bit set.
15571 (define_insn ""
15572   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15573         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
15574                         [(not:SI (match_operator:SI 2
15575                                       "branch_positive_comparison_operator"
15576                                       [(match_operand 3
15577                                                       "cc_reg_operand" "y,y")
15578                                        (const_int 0)]))
15579                          (match_operator:SI 4
15580                                 "branch_positive_comparison_operator"
15581                                 [(match_operand 5
15582                                                 "cc_reg_operand" "0,y")
15583                                  (const_int 0)])])
15584                       (const_int -1)))]
15585   ""
15586   "cr%q1 %E0,%j2,%j4"
15587   [(set_attr "type" "cr_logical,delayed_cr")])
15588
15589 (define_insn "*cceq_rev_compare"
15590   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15591         (compare:CCEQ (match_operator:SI 1
15592                                       "branch_positive_comparison_operator"
15593                                       [(match_operand 2
15594                                                       "cc_reg_operand" "0,y")
15595                                        (const_int 0)])
15596                       (const_int 0)))]
15597   ""
15598   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
15599   [(set_attr "type" "cr_logical,delayed_cr")])
15600
15601 ;; If we are comparing the result of two comparisons, this can be done
15602 ;; using creqv or crxor.
15603
15604 (define_insn_and_split ""
15605   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
15606         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
15607                               [(match_operand 2 "cc_reg_operand" "y")
15608                                (const_int 0)])
15609                       (match_operator 3 "branch_comparison_operator"
15610                               [(match_operand 4 "cc_reg_operand" "y")
15611                                (const_int 0)])))]
15612   ""
15613   "#"
15614   ""
15615   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
15616                                     (match_dup 5)))]
15617   "
15618 {
15619   int positive_1, positive_2;
15620
15621   positive_1 = branch_positive_comparison_operator (operands[1],
15622                                                     GET_MODE (operands[1]));
15623   positive_2 = branch_positive_comparison_operator (operands[3],
15624                                                     GET_MODE (operands[3]));
15625
15626   if (! positive_1)
15627     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
15628                                                             GET_CODE (operands[1])),
15629                                   SImode,
15630                                   operands[2], const0_rtx);
15631   else if (GET_MODE (operands[1]) != SImode)
15632     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
15633                                   operands[2], const0_rtx);
15634
15635   if (! positive_2)
15636     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
15637                                                             GET_CODE (operands[3])),
15638                                   SImode,
15639                                   operands[4], const0_rtx);
15640   else if (GET_MODE (operands[3]) != SImode)
15641     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
15642                                   operands[4], const0_rtx);
15643
15644   if (positive_1 == positive_2)
15645     {
15646       operands[1] = gen_rtx_NOT (SImode, operands[1]);
15647       operands[5] = constm1_rtx;
15648     }
15649   else
15650     {
15651       operands[5] = const1_rtx;
15652     }
15653 }")
15654
15655 ;; Unconditional branch and return.
15656
15657 (define_insn "jump"
15658   [(set (pc)
15659         (label_ref (match_operand 0 "" "")))]
15660   ""
15661   "b %l0"
15662   [(set_attr "type" "branch")])
15663
15664 (define_insn "return"
15665   [(return)]
15666   "direct_return ()"
15667   "{br|blr}"
15668   [(set_attr "type" "jmpreg")])
15669
15670 (define_expand "indirect_jump"
15671   [(set (pc) (match_operand 0 "register_operand" ""))])
15672
15673 (define_insn "*indirect_jump<mode>"
15674   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
15675   ""
15676   "@
15677    bctr
15678    {br|blr}"
15679   [(set_attr "type" "jmpreg")])
15680
15681 ;; Table jump for switch statements:
15682 (define_expand "tablejump"
15683   [(use (match_operand 0 "" ""))
15684    (use (label_ref (match_operand 1 "" "")))]
15685   ""
15686   "
15687 {
15688   if (TARGET_32BIT)
15689     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
15690   else
15691     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
15692   DONE;
15693 }")
15694
15695 (define_expand "tablejumpsi"
15696   [(set (match_dup 3)
15697         (plus:SI (match_operand:SI 0 "" "")
15698                  (match_dup 2)))
15699    (parallel [(set (pc) (match_dup 3))
15700               (use (label_ref (match_operand 1 "" "")))])]
15701   "TARGET_32BIT"
15702   "
15703 { operands[0] = force_reg (SImode, operands[0]);
15704   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
15705   operands[3] = gen_reg_rtx (SImode);
15706 }")
15707
15708 (define_expand "tablejumpdi"
15709   [(set (match_dup 4)
15710         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
15711    (set (match_dup 3)
15712         (plus:DI (match_dup 4)
15713                  (match_dup 2)))
15714    (parallel [(set (pc) (match_dup 3))
15715               (use (label_ref (match_operand 1 "" "")))])]
15716   "TARGET_64BIT"
15717   "
15718 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
15719   operands[3] = gen_reg_rtx (DImode);
15720   operands[4] = gen_reg_rtx (DImode);
15721 }")
15722
15723 (define_insn "*tablejump<mode>_internal1"
15724   [(set (pc)
15725         (match_operand:P 0 "register_operand" "c,*l"))
15726    (use (label_ref (match_operand 1 "" "")))]
15727   ""
15728   "@
15729    bctr
15730    {br|blr}"
15731   [(set_attr "type" "jmpreg")])
15732
15733 (define_insn "nop"
15734   [(const_int 0)]
15735   ""
15736   "{cror 0,0,0|nop}")
15737 \f
15738 ;; Define the subtract-one-and-jump insns, starting with the template
15739 ;; so loop.c knows what to generate.
15740
15741 (define_expand "doloop_end"
15742   [(use (match_operand 0 "" ""))        ; loop pseudo
15743    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
15744    (use (match_operand 2 "" ""))        ; max iterations
15745    (use (match_operand 3 "" ""))        ; loop level
15746    (use (match_operand 4 "" ""))]       ; label
15747   ""
15748   "
15749 {
15750   /* Only use this on innermost loops.  */
15751   if (INTVAL (operands[3]) > 1)
15752     FAIL;
15753   if (TARGET_64BIT)
15754     {
15755       if (GET_MODE (operands[0]) != DImode)
15756         FAIL;
15757       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
15758     }
15759   else
15760     {
15761       if (GET_MODE (operands[0]) != SImode)
15762         FAIL;
15763       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
15764     }
15765   DONE;
15766 }")
15767
15768 (define_expand "ctr<mode>"
15769   [(parallel [(set (pc)
15770                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
15771                                      (const_int 1))
15772                                  (label_ref (match_operand 1 "" ""))
15773                                  (pc)))
15774               (set (match_dup 0)
15775                    (plus:P (match_dup 0)
15776                             (const_int -1)))
15777               (clobber (match_scratch:CC 2 ""))
15778               (clobber (match_scratch:P 3 ""))])]
15779   ""
15780   "")
15781
15782 ;; We need to be able to do this for any operand, including MEM, or we
15783 ;; will cause reload to blow up since we don't allow output reloads on
15784 ;; JUMP_INSNs.
15785 ;; For the length attribute to be calculated correctly, the
15786 ;; label MUST be operand 0.
15787
15788 (define_insn "*ctr<mode>_internal1"
15789   [(set (pc)
15790         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15791                           (const_int 1))
15792                       (label_ref (match_operand 0 "" ""))
15793                       (pc)))
15794    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15795         (plus:P (match_dup 1)
15796                  (const_int -1)))
15797    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15798    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15799   ""
15800   "*
15801 {
15802   if (which_alternative != 0)
15803     return \"#\";
15804   else if (get_attr_length (insn) == 4)
15805     return \"{bdn|bdnz} %l0\";
15806   else
15807     return \"bdz $+8\;b %l0\";
15808 }"
15809   [(set_attr "type" "branch")
15810    (set_attr "length" "*,12,16,16")])
15811
15812 (define_insn "*ctr<mode>_internal2"
15813   [(set (pc)
15814         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15815                           (const_int 1))
15816                       (pc)
15817                       (label_ref (match_operand 0 "" ""))))
15818    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15819         (plus:P (match_dup 1)
15820                  (const_int -1)))
15821    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15822    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15823   ""
15824   "*
15825 {
15826   if (which_alternative != 0)
15827     return \"#\";
15828   else if (get_attr_length (insn) == 4)
15829     return \"bdz %l0\";
15830   else
15831     return \"{bdn|bdnz} $+8\;b %l0\";
15832 }"
15833   [(set_attr "type" "branch")
15834    (set_attr "length" "*,12,16,16")])
15835
15836 ;; Similar but use EQ
15837
15838 (define_insn "*ctr<mode>_internal5"
15839   [(set (pc)
15840         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15841                           (const_int 1))
15842                       (label_ref (match_operand 0 "" ""))
15843                       (pc)))
15844    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15845         (plus:P (match_dup 1)
15846                  (const_int -1)))
15847    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15848    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15849   ""
15850   "*
15851 {
15852   if (which_alternative != 0)
15853     return \"#\";
15854   else if (get_attr_length (insn) == 4)
15855     return \"bdz %l0\";
15856   else
15857     return \"{bdn|bdnz} $+8\;b %l0\";
15858 }"
15859   [(set_attr "type" "branch")
15860    (set_attr "length" "*,12,16,16")])
15861
15862 (define_insn "*ctr<mode>_internal6"
15863   [(set (pc)
15864         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15865                           (const_int 1))
15866                       (pc)
15867                       (label_ref (match_operand 0 "" ""))))
15868    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15869         (plus:P (match_dup 1)
15870                  (const_int -1)))
15871    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15872    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15873   ""
15874   "*
15875 {
15876   if (which_alternative != 0)
15877     return \"#\";
15878   else if (get_attr_length (insn) == 4)
15879     return \"{bdn|bdnz} %l0\";
15880   else
15881     return \"bdz $+8\;b %l0\";
15882 }"
15883   [(set_attr "type" "branch")
15884    (set_attr "length" "*,12,16,16")])
15885
15886 ;; Now the splitters if we could not allocate the CTR register
15887
15888 (define_split
15889   [(set (pc)
15890         (if_then_else (match_operator 2 "comparison_operator"
15891                                       [(match_operand:P 1 "gpc_reg_operand" "")
15892                                        (const_int 1)])
15893                       (match_operand 5 "" "")
15894                       (match_operand 6 "" "")))
15895    (set (match_operand:P 0 "gpc_reg_operand" "")
15896         (plus:P (match_dup 1) (const_int -1)))
15897    (clobber (match_scratch:CC 3 ""))
15898    (clobber (match_scratch:P 4 ""))]
15899   "reload_completed"
15900   [(parallel [(set (match_dup 3)
15901                    (compare:CC (plus:P (match_dup 1)
15902                                         (const_int -1))
15903                                (const_int 0)))
15904               (set (match_dup 0)
15905                    (plus:P (match_dup 1)
15906                             (const_int -1)))])
15907    (set (pc) (if_then_else (match_dup 7)
15908                            (match_dup 5)
15909                            (match_dup 6)))]
15910   "
15911 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15912                                 operands[3], const0_rtx); }")
15913
15914 (define_split
15915   [(set (pc)
15916         (if_then_else (match_operator 2 "comparison_operator"
15917                                       [(match_operand:P 1 "gpc_reg_operand" "")
15918                                        (const_int 1)])
15919                       (match_operand 5 "" "")
15920                       (match_operand 6 "" "")))
15921    (set (match_operand:P 0 "nonimmediate_operand" "")
15922         (plus:P (match_dup 1) (const_int -1)))
15923    (clobber (match_scratch:CC 3 ""))
15924    (clobber (match_scratch:P 4 ""))]
15925   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
15926   [(parallel [(set (match_dup 3)
15927                    (compare:CC (plus:P (match_dup 1)
15928                                         (const_int -1))
15929                                (const_int 0)))
15930               (set (match_dup 4)
15931                    (plus:P (match_dup 1)
15932                             (const_int -1)))])
15933    (set (match_dup 0)
15934         (match_dup 4))
15935    (set (pc) (if_then_else (match_dup 7)
15936                            (match_dup 5)
15937                            (match_dup 6)))]
15938   "
15939 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15940                                 operands[3], const0_rtx); }")
15941 \f
15942 (define_insn "trap"
15943   [(trap_if (const_int 1) (const_int 0))]
15944   ""
15945   "{t 31,0,0|trap}"
15946   [(set_attr "type" "trap")])
15947
15948 (define_expand "ctrap<mode>4"
15949   [(trap_if (match_operator 0 "ordered_comparison_operator"
15950                             [(match_operand:GPR 1 "register_operand")
15951                              (match_operand:GPR 2 "reg_or_short_operand")])
15952             (match_operand 3 "zero_constant" ""))]
15953   ""
15954   "")
15955
15956 (define_insn ""
15957   [(trap_if (match_operator 0 "ordered_comparison_operator"
15958                             [(match_operand:GPR 1 "register_operand" "r")
15959                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
15960             (const_int 0))]
15961   ""
15962   "{t|t<wd>}%V0%I2 %1,%2"
15963   [(set_attr "type" "trap")])
15964 \f
15965 ;; Insns related to generating the function prologue and epilogue.
15966
15967 (define_expand "prologue"
15968   [(use (const_int 0))]
15969   "TARGET_SCHED_PROLOG"
15970   "
15971 {
15972       rs6000_emit_prologue ();
15973       DONE;
15974 }")
15975
15976 (define_insn "*movesi_from_cr_one"
15977   [(match_parallel 0 "mfcr_operation"
15978                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15979                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
15980                                      (match_operand 3 "immediate_operand" "n")]
15981                           UNSPEC_MOVESI_FROM_CR))])]
15982   "TARGET_MFCRF"
15983   "*
15984 {
15985   int mask = 0;
15986   int i;
15987   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15988   {
15989     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15990     operands[4] = GEN_INT (mask);
15991     output_asm_insn (\"mfcr %1,%4\", operands);
15992   }
15993   return \"\";
15994 }"
15995   [(set_attr "type" "mfcrf")])
15996
15997 (define_insn "movesi_from_cr"
15998   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15999         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
16000                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
16001                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
16002                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
16003                    UNSPEC_MOVESI_FROM_CR))]
16004   ""
16005   "mfcr %0"
16006   [(set_attr "type" "mfcr")])
16007
16008 (define_insn "*stmw"
16009   [(match_parallel 0 "stmw_operation"
16010                    [(set (match_operand:SI 1 "memory_operand" "=m")
16011                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
16012   "TARGET_MULTIPLE"
16013   "{stm|stmw} %2,%1"
16014   [(set_attr "type" "store_ux")])
16015
16016 (define_insn "*save_gpregs_<mode>"
16017   [(match_parallel 0 "any_parallel_operand"
16018                    [(clobber (reg:P 65))
16019                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
16020                     (use (match_operand:P 2 "gpc_reg_operand" "r"))
16021                     (set (match_operand:P 3 "memory_operand" "=m")
16022                          (match_operand:P 4 "gpc_reg_operand" "r"))])]
16023   ""
16024   "bl %1"
16025   [(set_attr "type" "branch")
16026    (set_attr "length" "4")])
16027
16028 (define_insn "*save_fpregs_<mode>"
16029   [(match_parallel 0 "any_parallel_operand"
16030                    [(clobber (reg:P 65))
16031                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
16032                     (use (match_operand:P 2 "gpc_reg_operand" "r"))
16033                     (set (match_operand:DF 3 "memory_operand" "=m")
16034                          (match_operand:DF 4 "gpc_reg_operand" "d"))])]
16035   ""
16036   "bl %1"
16037   [(set_attr "type" "branch")
16038    (set_attr "length" "4")])
16039
16040 ; These are to explain that changes to the stack pointer should
16041 ; not be moved over stores to stack memory.
16042 (define_insn "stack_tie"
16043   [(set (match_operand:BLK 0 "memory_operand" "+m")
16044         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
16045   ""
16046   ""
16047   [(set_attr "length" "0")])
16048
16049 ; Like stack_tie, but depend on both fp and sp based memory.
16050 (define_insn "frame_tie"
16051   [(set (match_operand:BLK 0 "memory_operand" "+m")
16052         (unspec:BLK [(match_dup 0)
16053                      (match_operand:BLK 1 "memory_operand" "m")] UNSPEC_TIE))]
16054   ""
16055   ""
16056   [(set_attr "length" "0")])
16057
16058
16059 (define_expand "epilogue"
16060   [(use (const_int 0))]
16061   "TARGET_SCHED_PROLOG"
16062   "
16063 {
16064       rs6000_emit_epilogue (FALSE);
16065       DONE;
16066 }")
16067
16068 ; On some processors, doing the mtcrf one CC register at a time is
16069 ; faster (like on the 604e).  On others, doing them all at once is
16070 ; faster; for instance, on the 601 and 750.
16071
16072 (define_expand "movsi_to_cr_one"
16073   [(set (match_operand:CC 0 "cc_reg_operand" "")
16074         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
16075                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
16076   ""
16077   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
16078
16079 (define_insn "*movsi_to_cr"
16080   [(match_parallel 0 "mtcrf_operation"
16081                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
16082                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
16083                                      (match_operand 3 "immediate_operand" "n")]
16084                                     UNSPEC_MOVESI_TO_CR))])]
16085  ""
16086  "*
16087 {
16088   int mask = 0;
16089   int i;
16090   for (i = 0; i < XVECLEN (operands[0], 0); i++)
16091     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
16092   operands[4] = GEN_INT (mask);
16093   return \"mtcrf %4,%2\";
16094 }"
16095   [(set_attr "type" "mtcr")])
16096
16097 (define_insn "*mtcrfsi"
16098   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
16099         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
16100                     (match_operand 2 "immediate_operand" "n")]
16101                    UNSPEC_MOVESI_TO_CR))]
16102   "GET_CODE (operands[0]) == REG
16103    && CR_REGNO_P (REGNO (operands[0]))
16104    && GET_CODE (operands[2]) == CONST_INT
16105    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
16106   "mtcrf %R0,%1"
16107   [(set_attr "type" "mtcr")])
16108
16109 ; The load-multiple instructions have similar properties.
16110 ; Note that "load_multiple" is a name known to the machine-independent
16111 ; code that actually corresponds to the PowerPC load-string.
16112
16113 (define_insn "*lmw"
16114   [(match_parallel 0 "lmw_operation"
16115                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
16116                          (match_operand:SI 2 "memory_operand" "m"))])]
16117   "TARGET_MULTIPLE"
16118   "{lm|lmw} %1,%2"
16119   [(set_attr "type" "load_ux")
16120    (set_attr "cell_micro" "always")])
16121
16122 (define_insn "*return_internal_<mode>"
16123   [(return)
16124    (use (match_operand:P 0 "register_operand" "lc"))]
16125   ""
16126   "b%T0"
16127   [(set_attr "type" "jmpreg")])
16128
16129 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
16130 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
16131
16132 (define_insn "*restore_gpregs_<mode>"
16133  [(match_parallel 0 "any_parallel_operand"
16134                   [(clobber (match_operand:P 1 "register_operand" "=l"))
16135                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16136                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
16137                    (set (match_operand:P 4 "gpc_reg_operand" "=r")
16138                         (match_operand:P 5 "memory_operand" "m"))])]
16139  ""
16140  "bl %2"
16141  [(set_attr "type" "branch")
16142   (set_attr "length" "4")])
16143
16144 (define_insn "*return_and_restore_gpregs_<mode>"
16145  [(match_parallel 0 "any_parallel_operand"
16146                   [(return)
16147                    (clobber (match_operand:P 1 "register_operand" "=l"))
16148                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16149                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
16150                    (set (match_operand:P 4 "gpc_reg_operand" "=r")
16151                         (match_operand:P 5 "memory_operand" "m"))])]
16152  ""
16153  "b %2"
16154  [(set_attr "type" "branch")
16155   (set_attr "length" "4")])
16156
16157 (define_insn "*return_and_restore_fpregs_<mode>"
16158  [(match_parallel 0 "any_parallel_operand"
16159                   [(return)
16160                    (clobber (match_operand:P 1 "register_operand" "=l"))
16161                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16162                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
16163                    (set (match_operand:DF 4 "gpc_reg_operand" "=d")
16164                         (match_operand:DF 5 "memory_operand" "m"))])]
16165  ""
16166  "b %2"
16167  [(set_attr "type" "branch")
16168   (set_attr "length" "4")])
16169
16170 (define_insn "*return_and_restore_fpregs_aix_<mode>"
16171  [(match_parallel 0 "any_parallel_operand"
16172                   [(return)
16173                    (use (match_operand:P 1 "register_operand" "l"))
16174                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16175                    (use (match_operand:P 3 "gpc_reg_operand" "r"))
16176                    (set (match_operand:DF 4 "gpc_reg_operand" "=d")
16177                         (match_operand:DF 5 "memory_operand" "m"))])]
16178  ""
16179  "b %2"
16180  [(set_attr "type" "branch")
16181   (set_attr "length" "4")])
16182
16183 ; This is used in compiling the unwind routines.
16184 (define_expand "eh_return"
16185   [(use (match_operand 0 "general_operand" ""))]
16186   ""
16187   "
16188 {
16189   if (TARGET_32BIT)
16190     emit_insn (gen_eh_set_lr_si (operands[0]));
16191   else
16192     emit_insn (gen_eh_set_lr_di (operands[0]));
16193   DONE;
16194 }")
16195
16196 ; We can't expand this before we know where the link register is stored.
16197 (define_insn "eh_set_lr_<mode>"
16198   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
16199                     UNSPECV_EH_RR)
16200    (clobber (match_scratch:P 1 "=&b"))]
16201   ""
16202   "#")
16203
16204 (define_split
16205   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
16206    (clobber (match_scratch 1 ""))]
16207   "reload_completed"
16208   [(const_int 0)]
16209   "
16210 {
16211   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
16212   DONE;
16213 }")
16214
16215 (define_insn "prefetch"
16216   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
16217              (match_operand:SI 1 "const_int_operand" "n")
16218              (match_operand:SI 2 "const_int_operand" "n"))]
16219   "TARGET_POWERPC"
16220   "*
16221 {
16222   if (GET_CODE (operands[0]) == REG)
16223     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
16224   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
16225 }"
16226   [(set_attr "type" "load")])
16227 \f
16228 (define_insn "bpermd_<mode>"
16229   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
16230         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
16231                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
16232   "TARGET_POPCNTD"
16233   "bpermd %0,%1,%2"
16234   [(set_attr "type" "integer")])
16235
16236 \f
16237
16238 (include "sync.md")
16239 (include "vector.md")
16240 (include "vsx.md")
16241 (include "altivec.md")
16242 (include "spe.md")
16243 (include "dfp.md")
16244 (include "paired.md")