OSDN Git Service

Latest updates from FSF 4.7 branch
[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, 2011
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   [(STACK_POINTER_REGNUM        1)
31    (TOC_REGNUM                  2)
32    (STATIC_CHAIN_REGNUM         11)
33    (HARD_FRAME_POINTER_REGNUM   31)
34    (MQ_REGNO                    64)
35    (LR_REGNO                    65)
36    (CTR_REGNO                   66)
37    (ARG_POINTER_REGNUM          67)
38    (CR0_REGNO                   68)
39    (CR1_REGNO                   69)
40    (CR2_REGNO                   70)
41    (CR3_REGNO                   71)
42    (CR4_REGNO                   72)
43    (CR5_REGNO                   73)
44    (CR6_REGNO                   74)
45    (CR7_REGNO                   75)
46    (MAX_CR_REGNO                75)
47    (CA_REGNO                    76)
48    (FIRST_ALTIVEC_REGNO         77)
49    (LAST_ALTIVEC_REGNO          108)
50    (VRSAVE_REGNO                109)
51    (VSCR_REGNO                  110)
52    (SPE_ACC_REGNO               111)
53    (SPEFSCR_REGNO               112)
54    (FRAME_POINTER_REGNUM        113)
55
56    ; ABI defined stack offsets for storing the TOC pointer with AIX calls.
57    (TOC_SAVE_OFFSET_32BIT       20)
58    (TOC_SAVE_OFFSET_64BIT       40)
59
60    ; Function TOC offset in the AIX function descriptor.
61    (AIX_FUNC_DESC_TOC_32BIT     4)
62    (AIX_FUNC_DESC_TOC_64BIT     8)
63
64    ; Static chain offset in the AIX function descriptor.
65    (AIX_FUNC_DESC_SC_32BIT      8)
66    (AIX_FUNC_DESC_SC_64BIT      16)
67   ])
68
69 ;;
70 ;; UNSPEC usage
71 ;;
72
73 (define_c_enum "unspec"
74   [UNSPEC_FRSP                  ; frsp for POWER machines
75    UNSPEC_PROBE_STACK           ; probe stack memory reference
76    UNSPEC_TIE                   ; tie stack contents and stack pointer
77    UNSPEC_TOCPTR                ; address of a word pointing to the TOC
78    UNSPEC_TOC                   ; address of the TOC (more-or-less)
79    UNSPEC_MOVSI_GOT
80    UNSPEC_MV_CR_OV              ; move_from_CR_ov_bit
81    UNSPEC_FCTIWZ
82    UNSPEC_FRIM
83    UNSPEC_FRIN
84    UNSPEC_FRIP
85    UNSPEC_FRIZ
86    UNSPEC_LD_MPIC               ; load_macho_picbase
87    UNSPEC_MPIC_CORRECT          ; macho_correct_pic
88    UNSPEC_TLSGD
89    UNSPEC_TLSLD
90    UNSPEC_MOVESI_FROM_CR
91    UNSPEC_MOVESI_TO_CR
92    UNSPEC_TLSDTPREL
93    UNSPEC_TLSDTPRELHA
94    UNSPEC_TLSDTPRELLO
95    UNSPEC_TLSGOTDTPREL
96    UNSPEC_TLSTPREL
97    UNSPEC_TLSTPRELHA
98    UNSPEC_TLSTPRELLO
99    UNSPEC_TLSGOTTPREL
100    UNSPEC_TLSTLS
101    UNSPEC_FIX_TRUNC_TF          ; fadd, rounding towards zero
102    UNSPEC_MV_CR_GT              ; move_from_CR_gt_bit
103    UNSPEC_STFIWX
104    UNSPEC_POPCNTB
105    UNSPEC_FRES
106    UNSPEC_SP_SET
107    UNSPEC_SP_TEST
108    UNSPEC_SYNC
109    UNSPEC_LWSYNC
110    UNSPEC_SYNC_OP
111    UNSPEC_ATOMIC
112    UNSPEC_CMPXCHG
113    UNSPEC_XCHG
114    UNSPEC_AND
115    UNSPEC_DLMZB
116    UNSPEC_DLMZB_CR
117    UNSPEC_DLMZB_STRLEN
118    UNSPEC_RSQRT
119    UNSPEC_TOCREL
120    UNSPEC_MACHOPIC_OFFSET
121    UNSPEC_BPERM
122    UNSPEC_COPYSIGN
123    UNSPEC_PARITY
124    UNSPEC_FCTIW
125    UNSPEC_FCTID
126    UNSPEC_LFIWAX
127    UNSPEC_LFIWZX
128    UNSPEC_FCTIWUZ
129    UNSPEC_GRP_END_NOP
130   ])
131
132 ;;
133 ;; UNSPEC_VOLATILE usage
134 ;;
135
136 (define_c_enum "unspecv"
137   [UNSPECV_BLOCK
138    UNSPECV_LL                   ; load-locked
139    UNSPECV_SC                   ; store-conditional
140    UNSPECV_PROBE_STACK_RANGE    ; probe range of stack addresses
141    UNSPECV_EH_RR                ; eh_reg_restore
142    UNSPECV_ISYNC                ; isync instruction
143   ])
144
145 \f
146 ;; Define an insn type attribute.  This is used in function unit delay
147 ;; computations.
148 (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,vecdouble,isync,sync,load_l,store_c,shift,trap,insert_dword,var_shift_rotate,cntlz,exts,mffgpr,mftgpr,isel"
149   (const_string "integer"))
150
151 ;; Define floating point instruction sub-types for use with Xfpu.md
152 (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"))
153
154 ;; Length (in bytes).
155 ; '(pc)' in the following doesn't include the instruction itself; it is
156 ; calculated as if the instruction had zero size.
157 (define_attr "length" ""
158   (if_then_else (eq_attr "type" "branch")
159                 (if_then_else (and (ge (minus (match_dup 0) (pc))
160                                        (const_int -32768))
161                                    (lt (minus (match_dup 0) (pc))
162                                        (const_int 32764)))
163                               (const_int 4)
164                               (const_int 8))
165                 (const_int 4)))
166
167 ;; Processor type -- this attribute must exactly match the processor_type
168 ;; enumeration in rs6000.h.
169
170 (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"
171   (const (symbol_ref "rs6000_cpu_attr")))
172
173
174 ;; If this instruction is microcoded on the CELL processor
175 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
176 (define_attr "cell_micro" "not,conditional,always"
177   (if_then_else (eq_attr "type" "compare,delayed_compare,imul_compare,lmul_compare,load_ext,load_ext_ux,var_shift_rotate,var_delayed_compare")
178                 (const_string "always")
179                 (const_string "not")))
180
181 (automata_option "ndfa")
182
183 (include "rios1.md")
184 (include "rios2.md")
185 (include "rs64.md")
186 (include "mpc.md")
187 (include "40x.md")
188 (include "440.md")
189 (include "476.md")
190 (include "603.md")
191 (include "6xx.md")
192 (include "7xx.md")
193 (include "7450.md")
194 (include "8540.md")
195 (include "e300c2c3.md")
196 (include "e500mc.md")
197 (include "e500mc64.md")
198 (include "power4.md")
199 (include "power5.md")
200 (include "power6.md")
201 (include "power7.md")
202 (include "cell.md")
203 (include "xfpu.md")
204 (include "a2.md")
205 (include "titan.md")
206
207 (include "predicates.md")
208 (include "constraints.md")
209
210 (include "darwin.md")
211
212 \f
213 ;; Mode iterators
214
215 ; This mode iterator allows :GPR to be used to indicate the allowable size
216 ; of whole values in GPRs.
217 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
218
219 ; Any supported integer mode.
220 (define_mode_iterator INT [QI HI SI DI TI])
221
222 ; Any supported integer mode that fits in one register.
223 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
224
225 ; extend modes for DImode
226 (define_mode_iterator QHSI [QI HI SI])
227
228 ; SImode or DImode, even if DImode doesn't fit in GPRs.
229 (define_mode_iterator SDI [SI DI])
230
231 ; The size of a pointer.  Also, the size of the value that a record-condition
232 ; (one with a '.') will compare; and the size used for arithmetic carries.
233 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
234
235 ; Any hardware-supported floating-point mode
236 (define_mode_iterator FP [
237   (SF "TARGET_HARD_FLOAT 
238    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) || TARGET_E500_SINGLE)")
239   (DF "TARGET_HARD_FLOAT 
240    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)")
241   (TF "!TARGET_IEEEQUAD
242    && TARGET_HARD_FLOAT
243    && (TARGET_FPRS || TARGET_E500_DOUBLE)
244    && TARGET_LONG_DOUBLE_128")
245   (DD "TARGET_DFP")
246   (TD "TARGET_DFP")])
247
248 ; Any fma capable floating-point mode.
249 (define_mode_iterator FMA_F [
250   (SF "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT")
251   (DF "(TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
252        || VECTOR_UNIT_VSX_P (DFmode)")
253   (V2SF "TARGET_PAIRED_FLOAT")
254   (V4SF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)")
255   (V2DF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)")
256   ])
257
258 ; These modes do not fit in integer registers in 32-bit mode.
259 ; but on e500v2, the gpr are 64 bit registers
260 (define_mode_iterator DIFD [DI (DF "!TARGET_E500_DOUBLE") DD])
261
262 ; Iterator for reciprocal estimate instructions
263 (define_mode_iterator RECIPF [SF DF V4SF V2DF])
264
265 ; Iterator for just SF/DF
266 (define_mode_iterator SFDF [SF DF])
267
268 ; Conditional returns.
269 (define_code_iterator any_return [return simple_return])
270 (define_code_attr return_pred [(return "direct_return ()")
271                                (simple_return "")])
272 (define_code_attr return_str [(return "") (simple_return "simple_")])
273
274 ; Various instructions that come in SI and DI forms.
275 ; A generic w/d attribute, for things like cmpw/cmpd.
276 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
277
278 ; DImode bits
279 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
280
281 ;; ISEL/ISEL64 target selection
282 (define_mode_attr sel [(SI "") (DI "64")])
283
284 ;; Suffix for reload patterns
285 (define_mode_attr ptrsize [(SI "32bit")
286                            (DI "64bit")])
287
288 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
289                             (DI "TARGET_64BIT")])
290
291 (define_mode_attr mptrsize [(SI "si")
292                             (DI "di")])
293
294 (define_mode_attr ptrload [(SI "{l|lwz}")
295                            (DI "ld")])
296
297 (define_mode_attr rreg [(SF   "f")
298                         (DF   "ws")
299                         (V4SF "wf")
300                         (V2DF "wd")])
301
302 (define_mode_attr rreg2 [(SF   "f")
303                          (DF   "d")])
304
305 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
306                                  (DF "TARGET_FCFID")])
307
308 (define_mode_attr E500_CONVERT [(SF "!TARGET_FPRS")
309                                 (DF "TARGET_E500_DOUBLE")])
310
311 (define_mode_attr TARGET_FLOAT [(SF "TARGET_SINGLE_FLOAT")
312                                 (DF "TARGET_DOUBLE_FLOAT")])
313 \f
314 ;; Start with fixed-point load and store insns.  Here we put only the more
315 ;; complex forms.  Basic data transfer is done later.
316
317 (define_expand "zero_extend<mode>di2"
318   [(set (match_operand:DI 0 "gpc_reg_operand" "")
319         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
320   "TARGET_POWERPC64"
321   "")
322
323 (define_insn "*zero_extend<mode>di2_internal1"
324   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
325         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
326   "TARGET_POWERPC64"
327   "@
328    l<wd>z%U1%X1 %0,%1
329    rldicl %0,%1,0,<dbits>"
330   [(set_attr "type" "load,*")])
331
332 (define_insn "*zero_extend<mode>di2_internal2"
333   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
334         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
335                     (const_int 0)))
336    (clobber (match_scratch:DI 2 "=r,r"))]
337   "TARGET_64BIT"
338   "@
339    rldicl. %2,%1,0,<dbits>
340    #"
341   [(set_attr "type" "compare")
342    (set_attr "length" "4,8")])
343
344 (define_split
345   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
346         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
347                     (const_int 0)))
348    (clobber (match_scratch:DI 2 ""))]
349   "TARGET_POWERPC64 && reload_completed"
350   [(set (match_dup 2)
351         (zero_extend:DI (match_dup 1)))
352    (set (match_dup 0)
353         (compare:CC (match_dup 2)
354                     (const_int 0)))]
355   "")
356
357 (define_insn "*zero_extend<mode>di2_internal3"
358   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
359         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
360                     (const_int 0)))
361    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
362         (zero_extend:DI (match_dup 1)))]
363   "TARGET_64BIT"
364   "@
365    rldicl. %0,%1,0,<dbits>
366    #"
367   [(set_attr "type" "compare")
368    (set_attr "length" "4,8")])
369
370 (define_split
371   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
372         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
373                     (const_int 0)))
374    (set (match_operand:DI 0 "gpc_reg_operand" "")
375         (zero_extend:DI (match_dup 1)))]
376   "TARGET_POWERPC64 && reload_completed"
377   [(set (match_dup 0)
378         (zero_extend:DI (match_dup 1)))
379    (set (match_dup 2)
380         (compare:CC (match_dup 0)
381                     (const_int 0)))]
382   "")
383
384 (define_insn "extendqidi2"
385   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
386         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
387   "TARGET_POWERPC64"
388   "extsb %0,%1"
389   [(set_attr "type" "exts")])
390
391 (define_insn ""
392   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
393         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
394                     (const_int 0)))
395    (clobber (match_scratch:DI 2 "=r,r"))]
396   "TARGET_64BIT"
397   "@
398    extsb. %2,%1
399    #"
400   [(set_attr "type" "compare")
401    (set_attr "length" "4,8")])
402
403 (define_split
404   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
405         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
406                     (const_int 0)))
407    (clobber (match_scratch:DI 2 ""))]
408   "TARGET_POWERPC64 && reload_completed"
409   [(set (match_dup 2)
410         (sign_extend:DI (match_dup 1)))
411    (set (match_dup 0)
412         (compare:CC (match_dup 2)
413                     (const_int 0)))]
414   "")
415
416 (define_insn ""
417   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
418         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
419                     (const_int 0)))
420    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
421         (sign_extend:DI (match_dup 1)))]
422   "TARGET_64BIT"
423   "@
424    extsb. %0,%1
425    #"
426   [(set_attr "type" "compare")
427    (set_attr "length" "4,8")])
428
429 (define_split
430   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
431         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
432                     (const_int 0)))
433    (set (match_operand:DI 0 "gpc_reg_operand" "")
434         (sign_extend:DI (match_dup 1)))]
435   "TARGET_POWERPC64 && reload_completed"
436   [(set (match_dup 0)
437         (sign_extend:DI (match_dup 1)))
438    (set (match_dup 2)
439         (compare:CC (match_dup 0)
440                     (const_int 0)))]
441   "")
442
443 (define_expand "extendhidi2"
444   [(set (match_operand:DI 0 "gpc_reg_operand" "")
445         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
446   "TARGET_POWERPC64"
447   "")
448
449 (define_insn ""
450   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
451         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
452   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
453   "@
454    lha%U1%X1 %0,%1
455    extsh %0,%1"
456   [(set_attr "type" "load_ext,exts")])
457
458 (define_insn ""
459   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
460         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
461   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
462   "extsh %0,%1"
463   [(set_attr "type" "exts")])
464
465 (define_insn ""
466   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
467         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
468                     (const_int 0)))
469    (clobber (match_scratch:DI 2 "=r,r"))]
470   "TARGET_64BIT"
471   "@
472    extsh. %2,%1
473    #"
474   [(set_attr "type" "compare")
475    (set_attr "length" "4,8")])
476
477 (define_split
478   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
479         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
480                     (const_int 0)))
481    (clobber (match_scratch:DI 2 ""))]
482   "TARGET_POWERPC64 && reload_completed"
483   [(set (match_dup 2)
484         (sign_extend:DI (match_dup 1)))
485    (set (match_dup 0)
486         (compare:CC (match_dup 2)
487                     (const_int 0)))]
488   "")
489
490 (define_insn ""
491   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
492         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
493                     (const_int 0)))
494    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
495         (sign_extend:DI (match_dup 1)))]
496   "TARGET_64BIT"
497   "@
498    extsh. %0,%1
499    #"
500   [(set_attr "type" "compare")
501    (set_attr "length" "4,8")])
502
503 (define_split
504   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
505         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
506                     (const_int 0)))
507    (set (match_operand:DI 0 "gpc_reg_operand" "")
508         (sign_extend:DI (match_dup 1)))]
509   "TARGET_POWERPC64 && reload_completed"
510   [(set (match_dup 0)
511         (sign_extend:DI (match_dup 1)))
512    (set (match_dup 2)
513         (compare:CC (match_dup 0)
514                     (const_int 0)))]
515   "")
516
517 (define_expand "extendsidi2"
518   [(set (match_operand:DI 0 "gpc_reg_operand" "")
519         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
520   "TARGET_POWERPC64"
521   "")
522
523 (define_insn ""
524   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
525         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
526   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
527   "@
528    lwa%U1%X1 %0,%1
529    extsw %0,%1"
530   [(set_attr "type" "load_ext,exts")])
531
532 (define_insn ""
533   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
534         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
535   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
536   "extsw %0,%1"
537   [(set_attr "type" "exts")])
538
539 (define_insn ""
540   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
541         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
542                     (const_int 0)))
543    (clobber (match_scratch:DI 2 "=r,r"))]
544   "TARGET_64BIT"
545   "@
546    extsw. %2,%1
547    #"
548   [(set_attr "type" "compare")
549    (set_attr "length" "4,8")])
550
551 (define_split
552   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
553         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
554                     (const_int 0)))
555    (clobber (match_scratch:DI 2 ""))]
556   "TARGET_POWERPC64 && reload_completed"
557   [(set (match_dup 2)
558         (sign_extend:DI (match_dup 1)))
559    (set (match_dup 0)
560         (compare:CC (match_dup 2)
561                     (const_int 0)))]
562   "")
563
564 (define_insn ""
565   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
566         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
567                     (const_int 0)))
568    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
569         (sign_extend:DI (match_dup 1)))]
570   "TARGET_64BIT"
571   "@
572    extsw. %0,%1
573    #"
574   [(set_attr "type" "compare")
575    (set_attr "length" "4,8")])
576
577 (define_split
578   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
579         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
580                     (const_int 0)))
581    (set (match_operand:DI 0 "gpc_reg_operand" "")
582         (sign_extend:DI (match_dup 1)))]
583   "TARGET_POWERPC64 && reload_completed"
584   [(set (match_dup 0)
585         (sign_extend:DI (match_dup 1)))
586    (set (match_dup 2)
587         (compare:CC (match_dup 0)
588                     (const_int 0)))]
589   "")
590
591 (define_expand "zero_extendqisi2"
592   [(set (match_operand:SI 0 "gpc_reg_operand" "")
593         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
594   ""
595   "")
596
597 (define_insn ""
598   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
599         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
600   ""
601   "@
602    lbz%U1%X1 %0,%1
603    {rlinm|rlwinm} %0,%1,0,0xff"
604   [(set_attr "type" "load,*")])
605
606 (define_insn ""
607   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
608         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
609                     (const_int 0)))
610    (clobber (match_scratch:SI 2 "=r,r"))]
611   ""
612   "@
613    {andil.|andi.} %2,%1,0xff
614    #"
615   [(set_attr "type" "fast_compare,compare")
616    (set_attr "length" "4,8")])
617
618 (define_split
619   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
620         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
621                     (const_int 0)))
622    (clobber (match_scratch:SI 2 ""))]
623   "reload_completed"
624   [(set (match_dup 2)
625         (zero_extend:SI (match_dup 1)))
626    (set (match_dup 0)
627         (compare:CC (match_dup 2)
628                     (const_int 0)))]
629   "")
630
631 (define_insn ""
632   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
633         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
634                     (const_int 0)))
635    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
636         (zero_extend:SI (match_dup 1)))]
637   ""
638   "@
639    {andil.|andi.} %0,%1,0xff
640    #"
641   [(set_attr "type" "fast_compare,compare")
642    (set_attr "length" "4,8")])
643
644 (define_split
645   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
646         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
647                     (const_int 0)))
648    (set (match_operand:SI 0 "gpc_reg_operand" "")
649         (zero_extend:SI (match_dup 1)))]
650   "reload_completed"
651   [(set (match_dup 0)
652         (zero_extend:SI (match_dup 1)))
653    (set (match_dup 2)
654         (compare:CC (match_dup 0)
655                     (const_int 0)))]
656   "")
657
658 (define_expand "extendqisi2"
659   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
660    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
661   ""
662   "
663 {
664   if (TARGET_POWERPC)
665     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
666   else if (TARGET_POWER)
667     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
668   else
669     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
670   DONE;
671 }")
672
673 (define_insn "extendqisi2_ppc"
674   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
675         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
676   "TARGET_POWERPC"
677   "extsb %0,%1"
678   [(set_attr "type" "exts")])
679
680 (define_insn ""
681   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
682         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
683                     (const_int 0)))
684    (clobber (match_scratch:SI 2 "=r,r"))]
685   "TARGET_POWERPC"
686   "@
687    extsb. %2,%1
688    #"
689   [(set_attr "type" "compare")
690    (set_attr "length" "4,8")])
691
692 (define_split
693   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
694         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
695                     (const_int 0)))
696    (clobber (match_scratch:SI 2 ""))]
697   "TARGET_POWERPC && reload_completed"
698   [(set (match_dup 2)
699         (sign_extend:SI (match_dup 1)))
700    (set (match_dup 0)
701         (compare:CC (match_dup 2)
702                     (const_int 0)))]
703   "")
704
705 (define_insn ""
706   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
707         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
708                     (const_int 0)))
709    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
710         (sign_extend:SI (match_dup 1)))]
711   "TARGET_POWERPC"
712   "@
713    extsb. %0,%1
714    #"
715   [(set_attr "type" "compare")
716    (set_attr "length" "4,8")])
717
718 (define_split
719   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
720         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
721                     (const_int 0)))
722    (set (match_operand:SI 0 "gpc_reg_operand" "")
723         (sign_extend:SI (match_dup 1)))]
724   "TARGET_POWERPC && reload_completed"
725   [(set (match_dup 0)
726         (sign_extend:SI (match_dup 1)))
727    (set (match_dup 2)
728         (compare:CC (match_dup 0)
729                     (const_int 0)))]
730   "")
731
732 (define_expand "extendqisi2_power"
733   [(parallel [(set (match_dup 2)
734                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
735                               (const_int 24)))
736               (clobber (scratch:SI))])
737    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
738                    (ashiftrt:SI (match_dup 2)
739                                 (const_int 24)))
740               (clobber (scratch:SI))])]
741   "TARGET_POWER"
742   "
743 { operands[1] = gen_lowpart (SImode, operands[1]);
744   operands[2] = gen_reg_rtx (SImode); }")
745
746 (define_expand "extendqisi2_no_power"
747   [(set (match_dup 2)
748         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
749                    (const_int 24)))
750    (set (match_operand:SI 0 "gpc_reg_operand" "")
751         (ashiftrt:SI (match_dup 2)
752                      (const_int 24)))]
753   "! TARGET_POWER && ! TARGET_POWERPC"
754   "
755 { operands[1] = gen_lowpart (SImode, operands[1]);
756   operands[2] = gen_reg_rtx (SImode); }")
757
758 (define_expand "zero_extendqihi2"
759   [(set (match_operand:HI 0 "gpc_reg_operand" "")
760         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
761   ""
762   "")
763
764 (define_insn ""
765   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
766         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
767   ""
768   "@
769    lbz%U1%X1 %0,%1
770    {rlinm|rlwinm} %0,%1,0,0xff"
771   [(set_attr "type" "load,*")])
772
773 (define_insn ""
774   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
775         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
776                     (const_int 0)))
777    (clobber (match_scratch:HI 2 "=r,r"))]
778   ""
779   "@
780    {andil.|andi.} %2,%1,0xff
781    #"
782   [(set_attr "type" "fast_compare,compare")
783    (set_attr "length" "4,8")])
784
785 (define_split
786   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
787         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
788                     (const_int 0)))
789    (clobber (match_scratch:HI 2 ""))]
790   "reload_completed"
791   [(set (match_dup 2)
792         (zero_extend:HI (match_dup 1)))
793    (set (match_dup 0)
794         (compare:CC (match_dup 2)
795                     (const_int 0)))]
796   "")
797
798 (define_insn ""
799   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
800         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
801                     (const_int 0)))
802    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
803         (zero_extend:HI (match_dup 1)))]
804   ""
805   "@
806    {andil.|andi.} %0,%1,0xff
807    #"
808   [(set_attr "type" "fast_compare,compare")
809    (set_attr "length" "4,8")])
810
811 (define_split
812   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
813         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
814                     (const_int 0)))
815    (set (match_operand:HI 0 "gpc_reg_operand" "")
816         (zero_extend:HI (match_dup 1)))]
817   "reload_completed"
818   [(set (match_dup 0)
819         (zero_extend:HI (match_dup 1)))
820    (set (match_dup 2)
821         (compare:CC (match_dup 0)
822                     (const_int 0)))]
823   "")
824
825 (define_expand "extendqihi2"
826   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
827    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
828   ""
829   "
830 {
831   if (TARGET_POWERPC)
832     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
833   else if (TARGET_POWER)
834     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
835   else
836     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
837   DONE;
838 }")
839
840 (define_insn "extendqihi2_ppc"
841   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
842         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
843   "TARGET_POWERPC"
844   "extsb %0,%1"
845   [(set_attr "type" "exts")])
846
847 (define_insn ""
848   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
849         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
850                     (const_int 0)))
851    (clobber (match_scratch:HI 2 "=r,r"))]
852   "TARGET_POWERPC"
853   "@
854    extsb. %2,%1
855    #"
856   [(set_attr "type" "compare")
857    (set_attr "length" "4,8")])
858
859 (define_split
860   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
861         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
862                     (const_int 0)))
863    (clobber (match_scratch:HI 2 ""))]
864   "TARGET_POWERPC && reload_completed"
865   [(set (match_dup 2)
866         (sign_extend:HI (match_dup 1)))
867    (set (match_dup 0)
868         (compare:CC (match_dup 2)
869                     (const_int 0)))]
870   "")
871
872 (define_insn ""
873   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
874         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
875                     (const_int 0)))
876    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
877         (sign_extend:HI (match_dup 1)))]
878   "TARGET_POWERPC"
879   "@
880    extsb. %0,%1
881    #"
882   [(set_attr "type" "compare")
883    (set_attr "length" "4,8")])
884
885 (define_split
886   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
887         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
888                     (const_int 0)))
889    (set (match_operand:HI 0 "gpc_reg_operand" "")
890         (sign_extend:HI (match_dup 1)))]
891   "TARGET_POWERPC && reload_completed"
892   [(set (match_dup 0)
893         (sign_extend:HI (match_dup 1)))
894    (set (match_dup 2)
895         (compare:CC (match_dup 0)
896                     (const_int 0)))]
897   "")
898
899 (define_expand "extendqihi2_power"
900   [(parallel [(set (match_dup 2)
901                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
902                               (const_int 24)))
903               (clobber (scratch:SI))])
904    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
905                    (ashiftrt:SI (match_dup 2)
906                                 (const_int 24)))
907               (clobber (scratch:SI))])]
908   "TARGET_POWER"
909   "
910 { operands[0] = gen_lowpart (SImode, operands[0]);
911   operands[1] = gen_lowpart (SImode, operands[1]);
912   operands[2] = gen_reg_rtx (SImode); }")
913
914 (define_expand "extendqihi2_no_power"
915   [(set (match_dup 2)
916         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
917                    (const_int 24)))
918    (set (match_operand:HI 0 "gpc_reg_operand" "")
919         (ashiftrt:SI (match_dup 2)
920                      (const_int 24)))]
921   "! TARGET_POWER && ! TARGET_POWERPC"
922   "
923 { operands[0] = gen_lowpart (SImode, operands[0]);
924   operands[1] = gen_lowpart (SImode, operands[1]);
925   operands[2] = gen_reg_rtx (SImode); }")
926
927 (define_expand "zero_extendhisi2"
928   [(set (match_operand:SI 0 "gpc_reg_operand" "")
929         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
930   ""
931   "")
932
933 (define_insn ""
934   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
935         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
936   ""
937   "@
938    lhz%U1%X1 %0,%1
939    {rlinm|rlwinm} %0,%1,0,0xffff"
940   [(set_attr "type" "load,*")])
941
942 (define_insn ""
943   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
944         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
945                     (const_int 0)))
946    (clobber (match_scratch:SI 2 "=r,r"))]
947   ""
948   "@
949    {andil.|andi.} %2,%1,0xffff
950    #"
951   [(set_attr "type" "fast_compare,compare")
952    (set_attr "length" "4,8")])
953
954 (define_split
955   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
956         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
957                     (const_int 0)))
958    (clobber (match_scratch:SI 2 ""))]
959   "reload_completed"
960   [(set (match_dup 2)
961         (zero_extend:SI (match_dup 1)))
962    (set (match_dup 0)
963         (compare:CC (match_dup 2)
964                     (const_int 0)))]
965   "")
966
967 (define_insn ""
968   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
969         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
970                     (const_int 0)))
971    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
972         (zero_extend:SI (match_dup 1)))]
973   ""
974   "@
975    {andil.|andi.} %0,%1,0xffff
976    #"
977   [(set_attr "type" "fast_compare,compare")
978    (set_attr "length" "4,8")])
979
980 (define_split
981   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
982         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
983                     (const_int 0)))
984    (set (match_operand:SI 0 "gpc_reg_operand" "")
985         (zero_extend:SI (match_dup 1)))]
986   "reload_completed"
987   [(set (match_dup 0)
988         (zero_extend:SI (match_dup 1)))
989    (set (match_dup 2)
990         (compare:CC (match_dup 0)
991                     (const_int 0)))]
992   "")
993
994 (define_expand "extendhisi2"
995   [(set (match_operand:SI 0 "gpc_reg_operand" "")
996         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
997   ""
998   "")
999
1000 (define_insn ""
1001   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1002         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1003   "rs6000_gen_cell_microcode"
1004   "@
1005    lha%U1%X1 %0,%1
1006    {exts|extsh} %0,%1"
1007   [(set_attr "type" "load_ext,exts")])
1008
1009 (define_insn ""
1010   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1011         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
1012   "!rs6000_gen_cell_microcode"
1013   "{exts|extsh} %0,%1"
1014   [(set_attr "type" "exts")])
1015
1016 (define_insn ""
1017   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1018         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1019                     (const_int 0)))
1020    (clobber (match_scratch:SI 2 "=r,r"))]
1021   ""
1022   "@
1023    {exts.|extsh.} %2,%1
1024    #"
1025   [(set_attr "type" "compare")
1026    (set_attr "length" "4,8")])
1027
1028 (define_split
1029   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1030         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1031                     (const_int 0)))
1032    (clobber (match_scratch:SI 2 ""))]
1033   "reload_completed"
1034   [(set (match_dup 2)
1035         (sign_extend:SI (match_dup 1)))
1036    (set (match_dup 0)
1037         (compare:CC (match_dup 2)
1038                     (const_int 0)))]
1039   "")
1040
1041 (define_insn ""
1042   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1043         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1044                     (const_int 0)))
1045    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1046         (sign_extend:SI (match_dup 1)))]
1047   ""
1048   "@
1049    {exts.|extsh.} %0,%1
1050    #"
1051   [(set_attr "type" "compare")
1052    (set_attr "length" "4,8")])
1053 \f
1054 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
1055
1056 (define_insn "*macchwc"
1057   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1058         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1059                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1060                                        (const_int 16))
1061                                       (sign_extend:SI
1062                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1063                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1064                     (const_int 0)))
1065    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1066         (plus:SI (mult:SI (ashiftrt:SI
1067                            (match_dup 2)
1068                            (const_int 16))
1069                           (sign_extend:SI
1070                            (match_dup 1)))
1071                  (match_dup 4)))]
1072   "TARGET_MULHW"
1073   "macchw. %0, %1, %2"
1074   [(set_attr "type" "imul3")])
1075
1076 (define_insn "*macchw"
1077   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1078         (plus:SI (mult:SI (ashiftrt:SI
1079                            (match_operand:SI 2 "gpc_reg_operand" "r")
1080                            (const_int 16))
1081                           (sign_extend:SI
1082                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1083                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1084   "TARGET_MULHW"
1085   "macchw %0, %1, %2"
1086   [(set_attr "type" "imul3")])
1087
1088 (define_insn "*macchwuc"
1089   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1090         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1091                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1092                                        (const_int 16))
1093                                       (zero_extend:SI
1094                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1095                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1096                     (const_int 0)))
1097    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1098         (plus:SI (mult:SI (lshiftrt:SI
1099                            (match_dup 2)
1100                            (const_int 16))
1101                           (zero_extend:SI
1102                            (match_dup 1)))
1103                  (match_dup 4)))]
1104   "TARGET_MULHW"
1105   "macchwu. %0, %1, %2"
1106   [(set_attr "type" "imul3")])
1107
1108 (define_insn "*macchwu"
1109   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1110         (plus:SI (mult:SI (lshiftrt:SI
1111                            (match_operand:SI 2 "gpc_reg_operand" "r")
1112                            (const_int 16))
1113                           (zero_extend:SI
1114                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1115                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1116   "TARGET_MULHW"
1117   "macchwu %0, %1, %2"
1118   [(set_attr "type" "imul3")])
1119
1120 (define_insn "*machhwc"
1121   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1122         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1123                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1124                                        (const_int 16))
1125                                       (ashiftrt:SI
1126                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1127                                        (const_int 16)))
1128                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1129                     (const_int 0)))
1130    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1131         (plus:SI (mult:SI (ashiftrt:SI
1132                            (match_dup 1)
1133                            (const_int 16))
1134                           (ashiftrt:SI
1135                            (match_dup 2)
1136                            (const_int 16)))
1137                  (match_dup 4)))]
1138   "TARGET_MULHW"
1139   "machhw. %0, %1, %2"
1140   [(set_attr "type" "imul3")])
1141
1142 (define_insn "*machhw"
1143   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1144         (plus:SI (mult:SI (ashiftrt:SI
1145                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1146                            (const_int 16))
1147                           (ashiftrt:SI
1148                            (match_operand:SI 2 "gpc_reg_operand" "r")
1149                            (const_int 16)))
1150                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1151   "TARGET_MULHW"
1152   "machhw %0, %1, %2"
1153   [(set_attr "type" "imul3")])
1154
1155 (define_insn "*machhwuc"
1156   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1157         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1158                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1159                                        (const_int 16))
1160                                       (lshiftrt:SI
1161                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1162                                        (const_int 16)))
1163                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1164                     (const_int 0)))
1165    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1166         (plus:SI (mult:SI (lshiftrt:SI
1167                            (match_dup 1)
1168                            (const_int 16))
1169                           (lshiftrt:SI
1170                            (match_dup 2)
1171                            (const_int 16)))
1172                  (match_dup 4)))]
1173   "TARGET_MULHW"
1174   "machhwu. %0, %1, %2"
1175   [(set_attr "type" "imul3")])
1176
1177 (define_insn "*machhwu"
1178   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1179         (plus:SI (mult:SI (lshiftrt:SI
1180                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1181                            (const_int 16))
1182                           (lshiftrt:SI
1183                            (match_operand:SI 2 "gpc_reg_operand" "r")
1184                            (const_int 16)))
1185                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1186   "TARGET_MULHW"
1187   "machhwu %0, %1, %2"
1188   [(set_attr "type" "imul3")])
1189
1190 (define_insn "*maclhwc"
1191   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1192         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1193                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1194                                       (sign_extend:SI
1195                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1196                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1197                     (const_int 0)))
1198    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1199         (plus:SI (mult:SI (sign_extend:SI
1200                            (match_dup 1))
1201                           (sign_extend:SI
1202                            (match_dup 2)))
1203                  (match_dup 4)))]
1204   "TARGET_MULHW"
1205   "maclhw. %0, %1, %2"
1206   [(set_attr "type" "imul3")])
1207
1208 (define_insn "*maclhw"
1209   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1210         (plus:SI (mult:SI (sign_extend:SI
1211                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1212                           (sign_extend:SI
1213                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1214                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1215   "TARGET_MULHW"
1216   "maclhw %0, %1, %2"
1217   [(set_attr "type" "imul3")])
1218
1219 (define_insn "*maclhwuc"
1220   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1221         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1222                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1223                                       (zero_extend:SI
1224                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1225                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1226                     (const_int 0)))
1227    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1228         (plus:SI (mult:SI (zero_extend:SI
1229                            (match_dup 1))
1230                           (zero_extend:SI
1231                            (match_dup 2)))
1232                  (match_dup 4)))]
1233   "TARGET_MULHW"
1234   "maclhwu. %0, %1, %2"
1235   [(set_attr "type" "imul3")])
1236
1237 (define_insn "*maclhwu"
1238   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1239         (plus:SI (mult:SI (zero_extend:SI
1240                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1241                           (zero_extend:SI
1242                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1243                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1244   "TARGET_MULHW"
1245   "maclhwu %0, %1, %2"
1246   [(set_attr "type" "imul3")])
1247
1248 (define_insn "*nmacchwc"
1249   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1250         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1251                               (mult:SI (ashiftrt:SI
1252                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1253                                         (const_int 16))
1254                                        (sign_extend:SI
1255                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1256                     (const_int 0)))
1257    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1258         (minus:SI (match_dup 4)
1259                   (mult:SI (ashiftrt:SI
1260                             (match_dup 2)
1261                             (const_int 16))
1262                            (sign_extend:SI
1263                             (match_dup 1)))))]
1264   "TARGET_MULHW"
1265   "nmacchw. %0, %1, %2"
1266   [(set_attr "type" "imul3")])
1267
1268 (define_insn "*nmacchw"
1269   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1270         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1271                   (mult:SI (ashiftrt:SI
1272                             (match_operand:SI 2 "gpc_reg_operand" "r")
1273                             (const_int 16))
1274                            (sign_extend:SI
1275                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1276   "TARGET_MULHW"
1277   "nmacchw %0, %1, %2"
1278   [(set_attr "type" "imul3")])
1279
1280 (define_insn "*nmachhwc"
1281   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1282         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1283                               (mult:SI (ashiftrt:SI
1284                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1285                                         (const_int 16))
1286                                        (ashiftrt:SI
1287                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1288                                         (const_int 16))))
1289                     (const_int 0)))
1290    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1291         (minus:SI (match_dup 4)
1292                   (mult:SI (ashiftrt:SI
1293                             (match_dup 1)
1294                             (const_int 16))
1295                            (ashiftrt:SI
1296                             (match_dup 2)
1297                             (const_int 16)))))]
1298   "TARGET_MULHW"
1299   "nmachhw. %0, %1, %2"
1300   [(set_attr "type" "imul3")])
1301
1302 (define_insn "*nmachhw"
1303   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1304         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1305                   (mult:SI (ashiftrt:SI
1306                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1307                             (const_int 16))
1308                            (ashiftrt:SI
1309                             (match_operand:SI 2 "gpc_reg_operand" "r")
1310                             (const_int 16)))))]
1311   "TARGET_MULHW"
1312   "nmachhw %0, %1, %2"
1313   [(set_attr "type" "imul3")])
1314
1315 (define_insn "*nmaclhwc"
1316   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1317         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1318                               (mult:SI (sign_extend:SI
1319                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1320                                        (sign_extend:SI
1321                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1322                     (const_int 0)))
1323    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1324         (minus:SI (match_dup 4)
1325                   (mult:SI (sign_extend:SI
1326                             (match_dup 1))
1327                            (sign_extend:SI
1328                             (match_dup 2)))))]
1329   "TARGET_MULHW"
1330   "nmaclhw. %0, %1, %2"
1331   [(set_attr "type" "imul3")])
1332
1333 (define_insn "*nmaclhw"
1334   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1335         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1336                   (mult:SI (sign_extend:SI
1337                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1338                            (sign_extend:SI
1339                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1340   "TARGET_MULHW"
1341   "nmaclhw %0, %1, %2"
1342   [(set_attr "type" "imul3")])
1343
1344 (define_insn "*mulchwc"
1345   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1346         (compare:CC (mult:SI (ashiftrt:SI
1347                               (match_operand:SI 2 "gpc_reg_operand" "r")
1348                               (const_int 16))
1349                              (sign_extend:SI
1350                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1351                     (const_int 0)))
1352    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1353         (mult:SI (ashiftrt:SI
1354                   (match_dup 2)
1355                   (const_int 16))
1356                  (sign_extend:SI
1357                   (match_dup 1))))]
1358   "TARGET_MULHW"
1359   "mulchw. %0, %1, %2"
1360   [(set_attr "type" "imul3")])
1361
1362 (define_insn "*mulchw"
1363   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1364         (mult:SI (ashiftrt:SI
1365                   (match_operand:SI 2 "gpc_reg_operand" "r")
1366                   (const_int 16))
1367                  (sign_extend:SI
1368                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1369   "TARGET_MULHW"
1370   "mulchw %0, %1, %2"
1371   [(set_attr "type" "imul3")])
1372
1373 (define_insn "*mulchwuc"
1374   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1375         (compare:CC (mult:SI (lshiftrt:SI
1376                               (match_operand:SI 2 "gpc_reg_operand" "r")
1377                               (const_int 16))
1378                              (zero_extend:SI
1379                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1380                     (const_int 0)))
1381    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1382         (mult:SI (lshiftrt:SI
1383                   (match_dup 2)
1384                   (const_int 16))
1385                  (zero_extend:SI
1386                   (match_dup 1))))]
1387   "TARGET_MULHW"
1388   "mulchwu. %0, %1, %2"
1389   [(set_attr "type" "imul3")])
1390
1391 (define_insn "*mulchwu"
1392   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1393         (mult:SI (lshiftrt:SI
1394                   (match_operand:SI 2 "gpc_reg_operand" "r")
1395                   (const_int 16))
1396                  (zero_extend:SI
1397                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1398   "TARGET_MULHW"
1399   "mulchwu %0, %1, %2"
1400   [(set_attr "type" "imul3")])
1401
1402 (define_insn "*mulhhwc"
1403   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1404         (compare:CC (mult:SI (ashiftrt:SI
1405                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1406                               (const_int 16))
1407                              (ashiftrt:SI
1408                               (match_operand:SI 2 "gpc_reg_operand" "r")
1409                               (const_int 16)))
1410                     (const_int 0)))
1411    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1412         (mult:SI (ashiftrt:SI
1413                   (match_dup 1)
1414                   (const_int 16))
1415                  (ashiftrt:SI
1416                   (match_dup 2)
1417                   (const_int 16))))]
1418   "TARGET_MULHW"
1419   "mulhhw. %0, %1, %2"
1420   [(set_attr "type" "imul3")])
1421
1422 (define_insn "*mulhhw"
1423   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1424         (mult:SI (ashiftrt:SI
1425                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1426                   (const_int 16))
1427                  (ashiftrt:SI
1428                   (match_operand:SI 2 "gpc_reg_operand" "r")
1429                   (const_int 16))))]
1430   "TARGET_MULHW"
1431   "mulhhw %0, %1, %2"
1432   [(set_attr "type" "imul3")])
1433
1434 (define_insn "*mulhhwuc"
1435   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1436         (compare:CC (mult:SI (lshiftrt:SI
1437                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1438                               (const_int 16))
1439                              (lshiftrt:SI
1440                               (match_operand:SI 2 "gpc_reg_operand" "r")
1441                               (const_int 16)))
1442                     (const_int 0)))
1443    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1444         (mult:SI (lshiftrt:SI
1445                   (match_dup 1)
1446                   (const_int 16))
1447                  (lshiftrt:SI
1448                   (match_dup 2)
1449                   (const_int 16))))]
1450   "TARGET_MULHW"
1451   "mulhhwu. %0, %1, %2"
1452   [(set_attr "type" "imul3")])
1453
1454 (define_insn "*mulhhwu"
1455   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1456         (mult:SI (lshiftrt:SI
1457                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1458                   (const_int 16))
1459                  (lshiftrt:SI
1460                   (match_operand:SI 2 "gpc_reg_operand" "r")
1461                   (const_int 16))))]
1462   "TARGET_MULHW"
1463   "mulhhwu %0, %1, %2"
1464   [(set_attr "type" "imul3")])
1465
1466 (define_insn "*mullhwc"
1467   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1468         (compare:CC (mult:SI (sign_extend:SI
1469                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1470                              (sign_extend:SI
1471                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1472                     (const_int 0)))
1473    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1474         (mult:SI (sign_extend:SI
1475                   (match_dup 1))
1476                  (sign_extend:SI
1477                   (match_dup 2))))]
1478   "TARGET_MULHW"
1479   "mullhw. %0, %1, %2"
1480   [(set_attr "type" "imul3")])
1481
1482 (define_insn "*mullhw"
1483   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1484         (mult:SI (sign_extend:SI
1485                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1486                  (sign_extend:SI
1487                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1488   "TARGET_MULHW"
1489   "mullhw %0, %1, %2"
1490   [(set_attr "type" "imul3")])
1491
1492 (define_insn "*mullhwuc"
1493   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1494         (compare:CC (mult:SI (zero_extend:SI
1495                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1496                              (zero_extend:SI
1497                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1498                     (const_int 0)))
1499    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1500         (mult:SI (zero_extend:SI
1501                   (match_dup 1))
1502                  (zero_extend:SI
1503                   (match_dup 2))))]
1504   "TARGET_MULHW"
1505   "mullhwu. %0, %1, %2"
1506   [(set_attr "type" "imul3")])
1507
1508 (define_insn "*mullhwu"
1509   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1510         (mult:SI (zero_extend:SI
1511                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1512                  (zero_extend:SI
1513                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1514   "TARGET_MULHW"
1515   "mullhwu %0, %1, %2"
1516   [(set_attr "type" "imul3")])
1517 \f
1518 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1519 (define_insn "dlmzb"
1520   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1521         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1522                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1523                    UNSPEC_DLMZB_CR))
1524    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1525         (unspec:SI [(match_dup 1)
1526                     (match_dup 2)]
1527                    UNSPEC_DLMZB))]
1528   "TARGET_DLMZB"
1529   "dlmzb. %0, %1, %2")
1530
1531 (define_expand "strlensi"
1532   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1533         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1534                     (match_operand:QI 2 "const_int_operand" "")
1535                     (match_operand 3 "const_int_operand" "")]
1536                    UNSPEC_DLMZB_STRLEN))
1537    (clobber (match_scratch:CC 4 "=x"))]
1538   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1539 {
1540   rtx result = operands[0];
1541   rtx src = operands[1];
1542   rtx search_char = operands[2];
1543   rtx align = operands[3];
1544   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1545   rtx loop_label, end_label, mem, cr0, cond;
1546   if (search_char != const0_rtx
1547       || GET_CODE (align) != CONST_INT
1548       || INTVAL (align) < 8)
1549         FAIL;
1550   word1 = gen_reg_rtx (SImode);
1551   word2 = gen_reg_rtx (SImode);
1552   scratch_dlmzb = gen_reg_rtx (SImode);
1553   scratch_string = gen_reg_rtx (Pmode);
1554   loop_label = gen_label_rtx ();
1555   end_label = gen_label_rtx ();
1556   addr = force_reg (Pmode, XEXP (src, 0));
1557   emit_move_insn (scratch_string, addr);
1558   emit_label (loop_label);
1559   mem = change_address (src, SImode, scratch_string);
1560   emit_move_insn (word1, mem);
1561   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1562   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1563   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1564   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1565   emit_jump_insn (gen_rtx_SET (VOIDmode,
1566                                pc_rtx,
1567                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1568                                                      cond,
1569                                                      gen_rtx_LABEL_REF
1570                                                        (VOIDmode,
1571                                                         end_label),
1572                                                      pc_rtx)));
1573   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1574   emit_jump_insn (gen_rtx_SET (VOIDmode,
1575                                pc_rtx,
1576                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1577   emit_barrier ();
1578   emit_label (end_label);
1579   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1580   emit_insn (gen_subsi3 (result, scratch_string, addr));
1581   emit_insn (gen_subsi3 (result, result, const1_rtx));
1582   DONE;
1583 })
1584 \f
1585 (define_split
1586   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1587         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1588                     (const_int 0)))
1589    (set (match_operand:SI 0 "gpc_reg_operand" "")
1590         (sign_extend:SI (match_dup 1)))]
1591   "reload_completed"
1592   [(set (match_dup 0)
1593         (sign_extend:SI (match_dup 1)))
1594    (set (match_dup 2)
1595         (compare:CC (match_dup 0)
1596                     (const_int 0)))]
1597   "")
1598
1599 ;; Fixed-point arithmetic insns.
1600
1601 (define_expand "add<mode>3"
1602   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1603         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1604                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1605   ""
1606 {
1607   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1608     {
1609       if (non_short_cint_operand (operands[2], DImode))
1610         FAIL;
1611     }
1612   else if (GET_CODE (operands[2]) == CONST_INT
1613            && ! add_operand (operands[2], <MODE>mode))
1614     {
1615       rtx tmp = ((!can_create_pseudo_p ()
1616                   || rtx_equal_p (operands[0], operands[1]))
1617                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1618
1619       HOST_WIDE_INT val = INTVAL (operands[2]);
1620       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1621       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1622
1623       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1624         FAIL;
1625
1626       /* The ordering here is important for the prolog expander.
1627          When space is allocated from the stack, adding 'low' first may
1628          produce a temporary deallocation (which would be bad).  */
1629       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1630       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1631       DONE;
1632     }
1633 })
1634
1635 ;; Discourage ai/addic because of carry but provide it in an alternative
1636 ;; allowing register zero as source.
1637 (define_insn "*add<mode>3_internal1"
1638   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1639         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1640                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1641   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1642   "@
1643    {cax|add} %0,%1,%2
1644    {cal %0,%2(%1)|addi %0,%1,%2}
1645    {ai|addic} %0,%1,%2
1646    {cau|addis} %0,%1,%v2"
1647   [(set_attr "length" "4,4,4,4")])
1648
1649 (define_insn "addsi3_high"
1650   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1651         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1652                  (high:SI (match_operand 2 "" ""))))]
1653   "TARGET_MACHO && !TARGET_64BIT"
1654   "{cau|addis} %0,%1,ha16(%2)"
1655   [(set_attr "length" "4")])
1656
1657 (define_insn "*add<mode>3_internal2"
1658   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1659         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1660                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1661                     (const_int 0)))
1662    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1663   ""
1664   "@
1665    {cax.|add.} %3,%1,%2
1666    {ai.|addic.} %3,%1,%2
1667    #
1668    #"
1669   [(set_attr "type" "fast_compare,compare,compare,compare")
1670    (set_attr "length" "4,4,8,8")])
1671
1672 (define_split
1673   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1674         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1675                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1676                     (const_int 0)))
1677    (clobber (match_scratch:GPR 3 ""))]
1678   "reload_completed"
1679   [(set (match_dup 3)
1680         (plus:GPR (match_dup 1)
1681                  (match_dup 2)))
1682    (set (match_dup 0)
1683         (compare:CC (match_dup 3)
1684                     (const_int 0)))]
1685   "")
1686
1687 (define_insn "*add<mode>3_internal3"
1688   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1689         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1690                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1691                     (const_int 0)))
1692    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1693         (plus:P (match_dup 1)
1694                 (match_dup 2)))]
1695   ""
1696   "@
1697    {cax.|add.} %0,%1,%2
1698    {ai.|addic.} %0,%1,%2
1699    #
1700    #"
1701   [(set_attr "type" "fast_compare,compare,compare,compare")
1702    (set_attr "length" "4,4,8,8")])
1703
1704 (define_split
1705   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1706         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1707                             (match_operand:P 2 "reg_or_short_operand" ""))
1708                     (const_int 0)))
1709    (set (match_operand:P 0 "gpc_reg_operand" "")
1710         (plus:P (match_dup 1) (match_dup 2)))]
1711   "reload_completed"
1712   [(set (match_dup 0)
1713         (plus:P (match_dup 1)
1714                 (match_dup 2)))
1715    (set (match_dup 3)
1716         (compare:CC (match_dup 0)
1717                     (const_int 0)))]
1718   "")
1719
1720 ;; Split an add that we can't do in one insn into two insns, each of which
1721 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1722 ;; add should be last in case the result gets used in an address.
1723
1724 (define_split
1725   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1726         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1727                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1728   ""
1729   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1730    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1731 {
1732   HOST_WIDE_INT val = INTVAL (operands[2]);
1733   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1734   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1735
1736   operands[4] = GEN_INT (low);
1737   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1738     operands[3] = GEN_INT (rest);
1739   else if (can_create_pseudo_p ())
1740     {
1741       operands[3] = gen_reg_rtx (DImode);
1742       emit_move_insn (operands[3], operands[2]);
1743       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1744       DONE;
1745     }
1746   else
1747     FAIL;
1748 })
1749
1750 (define_insn "one_cmpl<mode>2"
1751   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1752         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1753   ""
1754   "nor %0,%1,%1")
1755
1756 (define_insn ""
1757   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1758         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1759                     (const_int 0)))
1760    (clobber (match_scratch:P 2 "=r,r"))]
1761   ""
1762   "@
1763    nor. %2,%1,%1
1764    #"
1765   [(set_attr "type" "fast_compare,compare")
1766    (set_attr "length" "4,8")])
1767
1768 (define_split
1769   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1770         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1771                     (const_int 0)))
1772    (clobber (match_scratch:P 2 ""))]
1773   "reload_completed"
1774   [(set (match_dup 2)
1775         (not:P (match_dup 1)))
1776    (set (match_dup 0)
1777         (compare:CC (match_dup 2)
1778                     (const_int 0)))]
1779   "")
1780
1781 (define_insn ""
1782   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1783         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1784                     (const_int 0)))
1785    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1786         (not:P (match_dup 1)))]
1787   ""
1788   "@
1789    nor. %0,%1,%1
1790    #"
1791   [(set_attr "type" "fast_compare,compare")
1792    (set_attr "length" "4,8")])
1793
1794 (define_split
1795   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1796         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1797                     (const_int 0)))
1798    (set (match_operand:P 0 "gpc_reg_operand" "")
1799         (not:P (match_dup 1)))]
1800   "reload_completed"
1801   [(set (match_dup 0)
1802         (not:P (match_dup 1)))
1803    (set (match_dup 2)
1804         (compare:CC (match_dup 0)
1805                     (const_int 0)))]
1806   "")
1807
1808 (define_insn ""
1809   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1810         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1811                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1812   "! TARGET_POWERPC"
1813   "{sf%I1|subf%I1c} %0,%2,%1")
1814
1815 (define_insn ""
1816   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1817         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1818                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1819   "TARGET_POWERPC"
1820   "@
1821    subf %0,%2,%1
1822    subfic %0,%2,%1")
1823
1824 (define_insn ""
1825   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1826         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1827                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1828                     (const_int 0)))
1829    (clobber (match_scratch:SI 3 "=r,r"))]
1830   "! TARGET_POWERPC"
1831   "@
1832    {sf.|subfc.} %3,%2,%1
1833    #"
1834   [(set_attr "type" "compare")
1835    (set_attr "length" "4,8")])
1836
1837 (define_insn ""
1838   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1839         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1840                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1841                     (const_int 0)))
1842    (clobber (match_scratch:P 3 "=r,r"))]
1843   "TARGET_POWERPC"
1844   "@
1845    subf. %3,%2,%1
1846    #"
1847   [(set_attr "type" "fast_compare")
1848    (set_attr "length" "4,8")])
1849
1850 (define_split
1851   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1852         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1853                              (match_operand:P 2 "gpc_reg_operand" ""))
1854                     (const_int 0)))
1855    (clobber (match_scratch:P 3 ""))]
1856   "reload_completed"
1857   [(set (match_dup 3)
1858         (minus:P (match_dup 1)
1859                   (match_dup 2)))
1860    (set (match_dup 0)
1861         (compare:CC (match_dup 3)
1862                     (const_int 0)))]
1863   "")
1864
1865 (define_insn ""
1866   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1867         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1868                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1869                     (const_int 0)))
1870    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1871         (minus:SI (match_dup 1) (match_dup 2)))]
1872   "! TARGET_POWERPC"
1873   "@
1874    {sf.|subfc.} %0,%2,%1
1875    #"
1876   [(set_attr "type" "compare")
1877    (set_attr "length" "4,8")])
1878
1879 (define_insn ""
1880   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1881         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1882                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1883                     (const_int 0)))
1884    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1885         (minus:P (match_dup 1)
1886                   (match_dup 2)))]
1887   "TARGET_POWERPC"
1888   "@
1889    subf. %0,%2,%1
1890    #"
1891   [(set_attr "type" "fast_compare")
1892    (set_attr "length" "4,8")])
1893
1894 (define_split
1895   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1896         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1897                              (match_operand:P 2 "gpc_reg_operand" ""))
1898                     (const_int 0)))
1899    (set (match_operand:P 0 "gpc_reg_operand" "")
1900         (minus:P (match_dup 1)
1901                   (match_dup 2)))]
1902   "reload_completed"
1903   [(set (match_dup 0)
1904         (minus:P (match_dup 1)
1905                   (match_dup 2)))
1906    (set (match_dup 3)
1907         (compare:CC (match_dup 0)
1908                     (const_int 0)))]
1909   "")
1910
1911 (define_expand "sub<mode>3"
1912   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1913         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1914                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1915   ""
1916   "
1917 {
1918   if (GET_CODE (operands[2]) == CONST_INT)
1919     {
1920       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1921                                  negate_rtx (<MODE>mode, operands[2])));
1922       DONE;
1923     }
1924 }")
1925
1926 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1927 ;; instruction and some auxiliary computations.  Then we just have a single
1928 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1929 ;; combine.
1930
1931 (define_expand "sminsi3"
1932   [(set (match_dup 3)
1933         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1934                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1935                          (const_int 0)
1936                          (minus:SI (match_dup 2) (match_dup 1))))
1937    (set (match_operand:SI 0 "gpc_reg_operand" "")
1938         (minus:SI (match_dup 2) (match_dup 3)))]
1939   "TARGET_POWER || TARGET_ISEL"
1940   "
1941 {
1942   if (TARGET_ISEL)
1943     {
1944       operands[2] = force_reg (SImode, operands[2]);
1945       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1946       DONE;
1947     }
1948
1949   operands[3] = gen_reg_rtx (SImode);
1950 }")
1951
1952 (define_split
1953   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1954         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1955                  (match_operand:SI 2 "reg_or_short_operand" "")))
1956    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1957   "TARGET_POWER"
1958   [(set (match_dup 3)
1959         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1960                          (const_int 0)
1961                          (minus:SI (match_dup 2) (match_dup 1))))
1962    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1963   "")
1964
1965 (define_expand "smaxsi3"
1966   [(set (match_dup 3)
1967         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1968                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1969                          (const_int 0)
1970                          (minus:SI (match_dup 2) (match_dup 1))))
1971    (set (match_operand:SI 0 "gpc_reg_operand" "")
1972         (plus:SI (match_dup 3) (match_dup 1)))]
1973   "TARGET_POWER || TARGET_ISEL"
1974   "
1975 {
1976   if (TARGET_ISEL)
1977     {
1978       operands[2] = force_reg (SImode, operands[2]);
1979       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1980       DONE;
1981     }
1982   operands[3] = gen_reg_rtx (SImode);
1983 }")
1984
1985 (define_split
1986   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1987         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1988                  (match_operand:SI 2 "reg_or_short_operand" "")))
1989    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1990   "TARGET_POWER"
1991   [(set (match_dup 3)
1992         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1993                          (const_int 0)
1994                          (minus:SI (match_dup 2) (match_dup 1))))
1995    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1996   "")
1997
1998 (define_expand "uminsi3"
1999   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2000                               (match_dup 5)))
2001    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
2002                               (match_dup 5)))
2003    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
2004                                        (const_int 0)
2005                                        (minus:SI (match_dup 4) (match_dup 3))))
2006    (set (match_operand:SI 0 "gpc_reg_operand" "")
2007         (minus:SI (match_dup 2) (match_dup 3)))]
2008   "TARGET_POWER || TARGET_ISEL"
2009   "
2010 {
2011   if (TARGET_ISEL)
2012     {
2013       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
2014       DONE;
2015     }
2016   operands[3] = gen_reg_rtx (SImode);
2017   operands[4] = gen_reg_rtx (SImode);
2018   operands[5] = GEN_INT (-2147483647 - 1);
2019 }")
2020
2021 (define_expand "umaxsi3"
2022   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2023                               (match_dup 5)))
2024    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
2025                               (match_dup 5)))
2026    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
2027                                        (const_int 0)
2028                                        (minus:SI (match_dup 4) (match_dup 3))))
2029    (set (match_operand:SI 0 "gpc_reg_operand" "")
2030         (plus:SI (match_dup 3) (match_dup 1)))]
2031   "TARGET_POWER || TARGET_ISEL"
2032   "
2033 {
2034   if (TARGET_ISEL)
2035     {
2036       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
2037       DONE;
2038     }
2039   operands[3] = gen_reg_rtx (SImode);
2040   operands[4] = gen_reg_rtx (SImode);
2041   operands[5] = GEN_INT (-2147483647 - 1);
2042 }")
2043
2044 (define_insn ""
2045   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2046         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
2047                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
2048                          (const_int 0)
2049                          (minus:SI (match_dup 2) (match_dup 1))))]
2050   "TARGET_POWER"
2051   "doz%I2 %0,%1,%2")
2052
2053 (define_insn ""
2054   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2055         (compare:CC
2056          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2057                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2058                           (const_int 0)
2059                           (minus:SI (match_dup 2) (match_dup 1)))
2060          (const_int 0)))
2061    (clobber (match_scratch:SI 3 "=r,r"))]
2062   "TARGET_POWER"
2063   "@
2064    doz%I2. %3,%1,%2
2065    #"
2066   [(set_attr "type" "delayed_compare")
2067    (set_attr "length" "4,8")])
2068
2069 (define_split
2070   [(set (match_operand:CC 0 "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    (clobber (match_scratch:SI 3 ""))]
2078   "TARGET_POWER && reload_completed"
2079   [(set (match_dup 3)
2080         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2081                           (const_int 0)
2082                           (minus:SI (match_dup 2) (match_dup 1))))
2083    (set (match_dup 0)
2084         (compare:CC (match_dup 3)
2085                     (const_int 0)))]
2086   "")
2087
2088 (define_insn ""
2089   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2090         (compare:CC
2091          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2092                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2093                           (const_int 0)
2094                           (minus:SI (match_dup 2) (match_dup 1)))
2095          (const_int 0)))
2096    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2097         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2098                          (const_int 0)
2099                          (minus:SI (match_dup 2) (match_dup 1))))]
2100   "TARGET_POWER"
2101   "@
2102    doz%I2. %0,%1,%2
2103    #"
2104   [(set_attr "type" "delayed_compare")
2105    (set_attr "length" "4,8")])
2106
2107 (define_split
2108   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2109         (compare:CC
2110          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2111                               (match_operand:SI 2 "reg_or_short_operand" ""))
2112                           (const_int 0)
2113                           (minus:SI (match_dup 2) (match_dup 1)))
2114          (const_int 0)))
2115    (set (match_operand:SI 0 "gpc_reg_operand" "")
2116         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2117                          (const_int 0)
2118                          (minus:SI (match_dup 2) (match_dup 1))))]
2119   "TARGET_POWER && reload_completed"
2120   [(set (match_dup 0)
2121         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2122                          (const_int 0)
2123                          (minus:SI (match_dup 2) (match_dup 1))))
2124    (set (match_dup 3)
2125         (compare:CC (match_dup 0)
2126                     (const_int 0)))]
2127   "")
2128
2129 ;; We don't need abs with condition code because such comparisons should
2130 ;; never be done.
2131 (define_expand "abssi2"
2132   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2133         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2134   ""
2135   "
2136 {
2137   if (TARGET_ISEL)
2138     {
2139       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
2140       DONE;
2141     }
2142   else if (! TARGET_POWER)
2143     {
2144       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
2145       DONE;
2146     }
2147 }")
2148
2149 (define_insn "*abssi2_power"
2150   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2151         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2152   "TARGET_POWER"
2153   "abs %0,%1")
2154
2155 (define_insn_and_split "abs<mode>2_isel"
2156   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2157         (abs:GPR (match_operand:GPR 1 "gpc_reg_operand" "b")))
2158    (clobber (match_scratch:GPR 2 "=&b"))
2159    (clobber (match_scratch:CC 3 "=y"))]
2160   "TARGET_ISEL"
2161   "#"
2162   "&& reload_completed"
2163   [(set (match_dup 2) (neg:GPR (match_dup 1)))
2164    (set (match_dup 3)
2165         (compare:CC (match_dup 1)
2166                     (const_int 0)))
2167    (set (match_dup 0)
2168         (if_then_else:GPR (lt (match_dup 3)
2169                               (const_int 0))
2170                           (match_dup 2)
2171                           (match_dup 1)))]
2172   "")
2173
2174 (define_insn_and_split "nabs<mode>2_isel"
2175   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2176         (neg:GPR (abs:GPR (match_operand:GPR 1 "gpc_reg_operand" "b"))))
2177    (clobber (match_scratch:GPR 2 "=&b"))
2178    (clobber (match_scratch:CC 3 "=y"))]
2179   "TARGET_ISEL"
2180   "#"
2181   "&& reload_completed"
2182   [(set (match_dup 2) (neg:GPR (match_dup 1)))
2183    (set (match_dup 3)
2184         (compare:CC (match_dup 1)
2185                     (const_int 0)))
2186    (set (match_dup 0)
2187         (if_then_else:GPR (lt (match_dup 3)
2188                               (const_int 0))
2189                           (match_dup 1)
2190                           (match_dup 2)))]
2191   "")
2192
2193 (define_insn_and_split "abssi2_nopower"
2194   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2195         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2196    (clobber (match_scratch:SI 2 "=&r,&r"))]
2197   "! TARGET_POWER && ! TARGET_ISEL"
2198   "#"
2199   "&& reload_completed"
2200   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2201    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2202    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2203   "")
2204
2205 (define_insn "*nabs_power"
2206   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2207         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2208   "TARGET_POWER"
2209   "nabs %0,%1")
2210
2211 (define_insn_and_split "*nabs_nopower"
2212   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2213         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2214    (clobber (match_scratch:SI 2 "=&r,&r"))]
2215   "! TARGET_POWER"
2216   "#"
2217   "&& reload_completed"
2218   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2219    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2220    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2221   "")
2222
2223 (define_expand "neg<mode>2"
2224   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2225         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2226   ""
2227   "")
2228
2229 (define_insn "*neg<mode>2_internal"
2230   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2231         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2232   ""
2233   "neg %0,%1")
2234
2235 (define_insn ""
2236   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2237         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2238                     (const_int 0)))
2239    (clobber (match_scratch:P 2 "=r,r"))]
2240   ""
2241   "@
2242    neg. %2,%1
2243    #"
2244   [(set_attr "type" "fast_compare")
2245    (set_attr "length" "4,8")])
2246
2247 (define_split
2248   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2249         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2250                     (const_int 0)))
2251    (clobber (match_scratch:P 2 ""))]
2252   "reload_completed"
2253   [(set (match_dup 2)
2254         (neg:P (match_dup 1)))
2255    (set (match_dup 0)
2256         (compare:CC (match_dup 2)
2257                     (const_int 0)))]
2258   "")
2259
2260 (define_insn ""
2261   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2262         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2263                     (const_int 0)))
2264    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2265         (neg:P (match_dup 1)))]
2266   ""
2267   "@
2268    neg. %0,%1
2269    #"
2270   [(set_attr "type" "fast_compare")
2271    (set_attr "length" "4,8")])
2272
2273 (define_split
2274   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2275         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2276                     (const_int 0)))
2277    (set (match_operand:P 0 "gpc_reg_operand" "")
2278         (neg:P (match_dup 1)))]
2279   "reload_completed"
2280   [(set (match_dup 0)
2281         (neg:P (match_dup 1)))
2282    (set (match_dup 2)
2283         (compare:CC (match_dup 0)
2284                     (const_int 0)))]
2285   "")
2286
2287 (define_insn "clz<mode>2"
2288   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2289         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2290   ""
2291   "{cntlz|cntlz<wd>} %0,%1"
2292   [(set_attr "type" "cntlz")])
2293
2294 (define_expand "ctz<mode>2"
2295   [(set (match_dup 2)
2296         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2297    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2298                                           (match_dup 2)))
2299               (clobber (scratch:CC))])
2300    (set (match_dup 4) (clz:GPR (match_dup 3)))
2301    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2302         (minus:GPR (match_dup 5) (match_dup 4)))]
2303   ""
2304   {
2305      operands[2] = gen_reg_rtx (<MODE>mode);
2306      operands[3] = gen_reg_rtx (<MODE>mode);
2307      operands[4] = gen_reg_rtx (<MODE>mode);
2308      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2309   })
2310
2311 (define_expand "ffs<mode>2"
2312   [(set (match_dup 2)
2313         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2314    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2315                                           (match_dup 2)))
2316               (clobber (scratch:CC))])
2317    (set (match_dup 4) (clz:GPR (match_dup 3)))
2318    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2319         (minus:GPR (match_dup 5) (match_dup 4)))]
2320   ""
2321   {
2322      operands[2] = gen_reg_rtx (<MODE>mode);
2323      operands[3] = gen_reg_rtx (<MODE>mode);
2324      operands[4] = gen_reg_rtx (<MODE>mode);
2325      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2326   })
2327
2328 (define_insn "popcntb<mode>2"
2329   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2330         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2331                      UNSPEC_POPCNTB))]
2332   "TARGET_POPCNTB"
2333   "popcntb %0,%1")
2334
2335 (define_insn "popcntd<mode>2"
2336   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2337         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2338   "TARGET_POPCNTD"
2339   "popcnt<wd> %0,%1")
2340
2341 (define_expand "popcount<mode>2"
2342   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2343         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2344   "TARGET_POPCNTB || TARGET_POPCNTD"
2345   {
2346     rs6000_emit_popcount (operands[0], operands[1]);
2347     DONE;
2348   })
2349
2350 (define_insn "parity<mode>2_cmpb"
2351   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2352         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
2353   "TARGET_CMPB && TARGET_POPCNTB"
2354   "prty<wd> %0,%1")
2355
2356 (define_expand "parity<mode>2"
2357   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2358         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2359   "TARGET_POPCNTB"
2360   {
2361     rs6000_emit_parity (operands[0], operands[1]);
2362     DONE;
2363   })
2364
2365 ;; Since the hardware zeros the upper part of the register, save generating the
2366 ;; AND immediate if we are converting to unsigned
2367 (define_insn "*bswaphi2_extenddi"
2368   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2369         (zero_extend:DI
2370          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2371   "TARGET_POWERPC64"
2372   "lhbrx %0,%y1"
2373   [(set_attr "length" "4")
2374    (set_attr "type" "load")])
2375
2376 (define_insn "*bswaphi2_extendsi"
2377   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2378         (zero_extend:SI
2379          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2380   "TARGET_POWERPC"
2381   "lhbrx %0,%y1"
2382   [(set_attr "length" "4")
2383    (set_attr "type" "load")])
2384
2385 (define_expand "bswaphi2"
2386   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
2387                    (bswap:HI
2388                     (match_operand:HI 1 "reg_or_mem_operand" "")))
2389               (clobber (match_scratch:SI 2 ""))])]
2390   ""
2391 {
2392   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2393     operands[1] = force_reg (HImode, operands[1]);
2394 })
2395
2396 (define_insn "bswaphi2_internal"
2397   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
2398         (bswap:HI
2399          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
2400    (clobber (match_scratch:SI 2 "=X,X,&r"))]
2401   "TARGET_POWERPC"
2402   "@
2403    lhbrx %0,%y1
2404    sthbrx %1,%y0
2405    #"
2406   [(set_attr "length" "4,4,12")
2407    (set_attr "type" "load,store,*")])
2408
2409 (define_split
2410   [(set (match_operand:HI 0 "gpc_reg_operand" "")
2411         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
2412    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2413   "TARGET_POWERPC && reload_completed"
2414   [(set (match_dup 3)
2415         (zero_extract:SI (match_dup 4)
2416                          (const_int 8)
2417                          (const_int 16)))
2418    (set (match_dup 2)
2419         (and:SI (ashift:SI (match_dup 4)
2420                            (const_int 8))
2421                 (const_int 65280)))             ;; 0xff00
2422    (set (match_dup 3)
2423         (ior:SI (match_dup 3)
2424                 (match_dup 2)))]
2425   "
2426 {
2427   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2428   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2429 }")
2430
2431 (define_insn "*bswapsi2_extenddi"
2432   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2433         (zero_extend:DI
2434          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2435   "TARGET_POWERPC64"
2436   "lwbrx %0,%y1"
2437   [(set_attr "length" "4")
2438    (set_attr "type" "load")])
2439
2440 (define_expand "bswapsi2"
2441   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2442         (bswap:SI
2443          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2444   ""
2445 {
2446   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2447     operands[1] = force_reg (SImode, operands[1]);
2448 })
2449
2450 (define_insn "*bswapsi2_internal"
2451   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2452         (bswap:SI
2453          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2454   ""
2455   "@
2456    {lbrx|lwbrx} %0,%y1
2457    {stbrx|stwbrx} %1,%y0
2458    #"
2459   [(set_attr "length" "4,4,12")
2460    (set_attr "type" "load,store,*")])
2461
2462 (define_split
2463   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2464         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2465   "reload_completed"
2466   [(set (match_dup 0)
2467         (rotate:SI (match_dup 1) (const_int 8)))
2468    (set (zero_extract:SI (match_dup 0)
2469                          (const_int 8)
2470                          (const_int 0))
2471         (match_dup 1))
2472    (set (zero_extract:SI (match_dup 0)
2473                          (const_int 8)
2474                          (const_int 16))
2475         (rotate:SI (match_dup 1)
2476                    (const_int 16)))]
2477   "")
2478
2479 (define_expand "bswapdi2"
2480   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2481                    (bswap:DI
2482                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2483               (clobber (match_scratch:DI 2 ""))
2484               (clobber (match_scratch:DI 3 ""))
2485               (clobber (match_scratch:DI 4 ""))])]
2486   ""
2487 {
2488   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2489     operands[1] = force_reg (DImode, operands[1]);
2490
2491   if (!TARGET_POWERPC64)
2492     {
2493       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2494          that uses 64-bit registers needs the same scratch registers as 64-bit
2495          mode.  */
2496       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2497       DONE;
2498     }
2499 })
2500
2501 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2502 (define_insn "*bswapdi2_ldbrx"
2503   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2504         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2505    (clobber (match_scratch:DI 2 "=X,X,&r"))
2506    (clobber (match_scratch:DI 3 "=X,X,&r"))
2507    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2508   "TARGET_POWERPC64 && TARGET_LDBRX
2509    && (REG_P (operands[0]) || REG_P (operands[1]))"
2510   "@
2511    ldbrx %0,%y1
2512    stdbrx %1,%y0
2513    #"
2514   [(set_attr "length" "4,4,36")
2515    (set_attr "type" "load,store,*")])
2516
2517 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2518 (define_insn "*bswapdi2_64bit"
2519   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2520         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2521    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2522    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2523    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2524   "TARGET_POWERPC64 && !TARGET_LDBRX
2525    && (REG_P (operands[0]) || REG_P (operands[1]))"
2526   "#"
2527   [(set_attr "length" "16,12,36")])
2528
2529 (define_split
2530   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2531         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2532    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2533    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2534    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2535   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2536   [(const_int 0)]
2537   "
2538 {
2539   rtx dest   = operands[0];
2540   rtx src    = operands[1];
2541   rtx op2    = operands[2];
2542   rtx op3    = operands[3];
2543   rtx op4    = operands[4];
2544   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode, 4);
2545   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode, 4);
2546   rtx addr1;
2547   rtx addr2;
2548   rtx word_high;
2549   rtx word_low;
2550
2551   addr1 = XEXP (src, 0);
2552   if (GET_CODE (addr1) == PLUS)
2553     {
2554       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2555       if (TARGET_AVOID_XFORM)
2556         {
2557           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2558           addr2 = op2;
2559         }
2560       else
2561         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2562     }
2563   else if (TARGET_AVOID_XFORM)
2564     {
2565       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2566       addr2 = op2;
2567     }
2568   else
2569     {
2570       emit_move_insn (op2, GEN_INT (4));
2571       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2572     }
2573
2574   if (BYTES_BIG_ENDIAN)
2575     {
2576       word_high = change_address (src, SImode, addr1);
2577       word_low  = change_address (src, SImode, addr2);
2578     }
2579   else
2580     {
2581       word_high = change_address (src, SImode, addr2);
2582       word_low  = change_address (src, SImode, addr1);
2583     }
2584
2585   emit_insn (gen_bswapsi2 (op3_32, word_low));
2586   emit_insn (gen_bswapsi2 (op4_32, word_high));
2587   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2588   emit_insn (gen_iordi3 (dest, dest, op4));
2589 }")
2590
2591 (define_split
2592   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2593         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2594    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2595    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2596    (clobber (match_operand:DI 4 "" ""))]
2597   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2598   [(const_int 0)]
2599   "
2600 {
2601   rtx dest   = operands[0];
2602   rtx src    = operands[1];
2603   rtx op2    = operands[2];
2604   rtx op3    = operands[3];
2605   rtx src_si = simplify_gen_subreg (SImode, src, DImode, 4);
2606   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode, 4);
2607   rtx addr1;
2608   rtx addr2;
2609   rtx word_high;
2610   rtx word_low;
2611
2612   addr1 = XEXP (dest, 0);
2613   if (GET_CODE (addr1) == PLUS)
2614     {
2615       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2616       if (TARGET_AVOID_XFORM)
2617         {
2618           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2619           addr2 = op2;
2620         }
2621       else
2622         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2623     }
2624   else if (TARGET_AVOID_XFORM)
2625     {
2626       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2627       addr2 = op2;
2628     }
2629   else
2630     {
2631       emit_move_insn (op2, GEN_INT (4));
2632       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2633     }
2634
2635   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2636   if (BYTES_BIG_ENDIAN)
2637     {
2638       word_high = change_address (dest, SImode, addr1);
2639       word_low  = change_address (dest, SImode, addr2);
2640       emit_insn (gen_bswapsi2 (word_high, src_si));
2641       emit_insn (gen_bswapsi2 (word_low, op3_si));
2642     }
2643   else
2644     {
2645       word_high = change_address (dest, SImode, addr2);
2646       word_low  = change_address (dest, SImode, addr1);
2647       emit_insn (gen_bswapsi2 (word_low, src_si));
2648       emit_insn (gen_bswapsi2 (word_high, op3_si));
2649     }
2650 }")
2651
2652 (define_split
2653   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2654         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2655    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2656    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2657    (clobber (match_operand:DI 4 "" ""))]
2658   "TARGET_POWERPC64 && reload_completed"
2659   [(const_int 0)]
2660   "
2661 {
2662   rtx dest    = operands[0];
2663   rtx src     = operands[1];
2664   rtx op2     = operands[2];
2665   rtx op3     = operands[3];
2666   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, 4);
2667   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, 4);
2668   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, 4);
2669   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, 4);
2670
2671   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2672   emit_insn (gen_bswapsi2 (dest_si, src_si));
2673   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2674   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2675   emit_insn (gen_iordi3 (dest, dest, op3));
2676 }")
2677
2678 (define_insn "bswapdi2_32bit"
2679   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2680         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2681    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2682   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2683   "#"
2684   [(set_attr "length" "16,12,36")])
2685
2686 (define_split
2687   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2688         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2689    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2690   "!TARGET_POWERPC64 && reload_completed"
2691   [(const_int 0)]
2692   "
2693 {
2694   rtx dest   = operands[0];
2695   rtx src    = operands[1];
2696   rtx op2    = operands[2];
2697   rtx dest_hi = simplify_gen_subreg (SImode, dest, DImode, 0);
2698   rtx dest_lo = simplify_gen_subreg (SImode, dest, DImode, 4);
2699   rtx addr1;
2700   rtx addr2;
2701   rtx word_high;
2702   rtx word_low;
2703
2704   addr1 = XEXP (src, 0);
2705   if (GET_CODE (addr1) == PLUS)
2706     {
2707       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2708       if (TARGET_AVOID_XFORM)
2709         {
2710           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2711           addr2 = op2;
2712         }
2713       else
2714         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2715     }
2716   else if (TARGET_AVOID_XFORM)
2717     {
2718       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2719       addr2 = op2;
2720     }
2721   else
2722     {
2723       emit_move_insn (op2, GEN_INT (4));
2724       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2725     }
2726
2727   if (BYTES_BIG_ENDIAN)
2728     {
2729       word_high = change_address (src, SImode, addr1);
2730       word_low  = change_address (src, SImode, addr2);
2731     }
2732   else
2733     {
2734       word_high = change_address (src, SImode, addr2);
2735       word_low  = change_address (src, SImode, addr1);
2736     }
2737
2738   emit_insn (gen_bswapsi2 (dest_hi, word_low));
2739   emit_insn (gen_bswapsi2 (dest_lo, word_high));
2740 }")
2741
2742 (define_split
2743   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2744         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2745    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2746   "!TARGET_POWERPC64 && reload_completed"
2747   [(const_int 0)]
2748   "
2749 {
2750   rtx dest     = operands[0];
2751   rtx src      = operands[1];
2752   rtx op2      = operands[2];
2753   rtx src_high = simplify_gen_subreg (SImode, src, DImode, 0);
2754   rtx src_low  = simplify_gen_subreg (SImode, src, DImode, 4);
2755   rtx addr1;
2756   rtx addr2;
2757   rtx word_high;
2758   rtx word_low;
2759
2760   addr1 = XEXP (dest, 0);
2761   if (GET_CODE (addr1) == PLUS)
2762     {
2763       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2764       if (TARGET_AVOID_XFORM)
2765         {
2766           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2767           addr2 = op2;
2768         }
2769       else
2770         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2771     }
2772   else if (TARGET_AVOID_XFORM)
2773     {
2774       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2775       addr2 = op2;
2776     }
2777   else
2778     {
2779       emit_move_insn (op2, GEN_INT (4));
2780       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2781     }
2782
2783   if (BYTES_BIG_ENDIAN)
2784     {
2785       word_high = change_address (dest, SImode, addr1);
2786       word_low  = change_address (dest, SImode, addr2);
2787     }
2788   else
2789     {
2790       word_high = change_address (dest, SImode, addr2);
2791       word_low  = change_address (dest, SImode, addr1);
2792     }
2793
2794   emit_insn (gen_bswapsi2 (word_high, src_low));
2795   emit_insn (gen_bswapsi2 (word_low, src_high));
2796 }")
2797
2798 (define_split
2799   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2800         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2801    (clobber (match_operand:SI 2 "" ""))]
2802   "!TARGET_POWERPC64 && reload_completed"
2803   [(const_int 0)]
2804   "
2805 {
2806   rtx dest      = operands[0];
2807   rtx src       = operands[1];
2808   rtx src_high  = simplify_gen_subreg (SImode, src, DImode, 0);
2809   rtx src_low   = simplify_gen_subreg (SImode, src, DImode, 4);
2810   rtx dest_high = simplify_gen_subreg (SImode, dest, DImode, 0);
2811   rtx dest_low  = simplify_gen_subreg (SImode, dest, DImode, 4);
2812
2813   emit_insn (gen_bswapsi2 (dest_high, src_low));
2814   emit_insn (gen_bswapsi2 (dest_low, src_high));
2815 }")
2816
2817 (define_expand "mulsi3"
2818   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2819    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2820    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2821   ""
2822   "
2823 {
2824   if (TARGET_POWER)
2825     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2826   else
2827     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2828   DONE;
2829 }")
2830
2831 (define_insn "mulsi3_mq"
2832   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2833         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2834                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2835    (clobber (match_scratch:SI 3 "=q,q"))]
2836   "TARGET_POWER"
2837   "@
2838    {muls|mullw} %0,%1,%2
2839    {muli|mulli} %0,%1,%2"
2840    [(set (attr "type")
2841       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2842                 (const_string "imul3")
2843              (match_operand:SI 2 "short_cint_operand" "")
2844                 (const_string "imul2")]
2845         (const_string "imul")))])
2846
2847 (define_insn "mulsi3_no_mq"
2848   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2849         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2850                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2851   "! TARGET_POWER"
2852   "@
2853    {muls|mullw} %0,%1,%2
2854    {muli|mulli} %0,%1,%2"
2855    [(set (attr "type")
2856       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2857                 (const_string "imul3")
2858              (match_operand:SI 2 "short_cint_operand" "")
2859                 (const_string "imul2")]
2860         (const_string "imul")))])
2861
2862 (define_insn "*mulsi3_mq_internal1"
2863   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2864         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2865                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2866                     (const_int 0)))
2867    (clobber (match_scratch:SI 3 "=r,r"))
2868    (clobber (match_scratch:SI 4 "=q,q"))]
2869   "TARGET_POWER"
2870   "@
2871    {muls.|mullw.} %3,%1,%2
2872    #"
2873   [(set_attr "type" "imul_compare")
2874    (set_attr "length" "4,8")])
2875
2876 (define_split
2877   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2878         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2879                              (match_operand:SI 2 "gpc_reg_operand" ""))
2880                     (const_int 0)))
2881    (clobber (match_scratch:SI 3 ""))
2882    (clobber (match_scratch:SI 4 ""))]
2883   "TARGET_POWER && reload_completed"
2884   [(parallel [(set (match_dup 3)
2885         (mult:SI (match_dup 1) (match_dup 2)))
2886    (clobber (match_dup 4))])
2887    (set (match_dup 0)
2888         (compare:CC (match_dup 3)
2889                     (const_int 0)))]
2890   "")
2891
2892 (define_insn "*mulsi3_no_mq_internal1"
2893   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2894         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2895                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2896                     (const_int 0)))
2897    (clobber (match_scratch:SI 3 "=r,r"))]
2898   "! TARGET_POWER"
2899   "@
2900    {muls.|mullw.} %3,%1,%2
2901    #"
2902   [(set_attr "type" "imul_compare")
2903    (set_attr "length" "4,8")])
2904
2905 (define_split
2906   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2907         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2908                              (match_operand:SI 2 "gpc_reg_operand" ""))
2909                     (const_int 0)))
2910    (clobber (match_scratch:SI 3 ""))]
2911   "! TARGET_POWER && reload_completed"
2912   [(set (match_dup 3)
2913         (mult:SI (match_dup 1) (match_dup 2)))
2914    (set (match_dup 0)
2915         (compare:CC (match_dup 3)
2916                     (const_int 0)))]
2917   "")
2918
2919 (define_insn "*mulsi3_mq_internal2"
2920   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2921         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2922                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2923                     (const_int 0)))
2924    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2925         (mult:SI (match_dup 1) (match_dup 2)))
2926    (clobber (match_scratch:SI 4 "=q,q"))]
2927   "TARGET_POWER"
2928   "@
2929    {muls.|mullw.} %0,%1,%2
2930    #"
2931   [(set_attr "type" "imul_compare")
2932    (set_attr "length" "4,8")])
2933
2934 (define_split
2935   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2936         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2937                              (match_operand:SI 2 "gpc_reg_operand" ""))
2938                     (const_int 0)))
2939    (set (match_operand:SI 0 "gpc_reg_operand" "")
2940         (mult:SI (match_dup 1) (match_dup 2)))
2941    (clobber (match_scratch:SI 4 ""))]
2942   "TARGET_POWER && reload_completed"
2943   [(parallel [(set (match_dup 0)
2944         (mult:SI (match_dup 1) (match_dup 2)))
2945    (clobber (match_dup 4))])
2946    (set (match_dup 3)
2947         (compare:CC (match_dup 0)
2948                     (const_int 0)))]
2949   "")
2950
2951 (define_insn "*mulsi3_no_mq_internal2"
2952   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2953         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2954                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2955                     (const_int 0)))
2956    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2957         (mult:SI (match_dup 1) (match_dup 2)))]
2958   "! TARGET_POWER"
2959   "@
2960    {muls.|mullw.} %0,%1,%2
2961    #"
2962   [(set_attr "type" "imul_compare")
2963    (set_attr "length" "4,8")])
2964
2965 (define_split
2966   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2967         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2968                              (match_operand:SI 2 "gpc_reg_operand" ""))
2969                     (const_int 0)))
2970    (set (match_operand:SI 0 "gpc_reg_operand" "")
2971         (mult:SI (match_dup 1) (match_dup 2)))]
2972   "! TARGET_POWER && reload_completed"
2973   [(set (match_dup 0)
2974         (mult:SI (match_dup 1) (match_dup 2)))
2975    (set (match_dup 3)
2976         (compare:CC (match_dup 0)
2977                     (const_int 0)))]
2978   "")
2979
2980 ;; Operand 1 is divided by operand 2; quotient goes to operand
2981 ;; 0 and remainder to operand 3.
2982 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2983
2984 (define_expand "divmodsi4"
2985   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2986                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2987                            (match_operand:SI 2 "gpc_reg_operand" "")))
2988               (set (match_operand:SI 3 "register_operand" "")
2989                    (mod:SI (match_dup 1) (match_dup 2)))])]
2990   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2991   "
2992 {
2993   if (! TARGET_POWER && ! TARGET_POWERPC)
2994     {
2995       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2996       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2997       emit_insn (gen_divss_call ());
2998       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2999       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
3000       DONE;
3001     }
3002 }")
3003
3004 (define_insn "*divmodsi4_internal"
3005   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3006         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3007                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3008    (set (match_operand:SI 3 "register_operand" "=q")
3009         (mod:SI (match_dup 1) (match_dup 2)))]
3010   "TARGET_POWER"
3011   "divs %0,%1,%2"
3012   [(set_attr "type" "idiv")])
3013
3014 (define_expand "udiv<mode>3"
3015   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
3016         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3017                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
3018   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
3019   "
3020 {
3021   if (! TARGET_POWER && ! TARGET_POWERPC)
3022     {
3023       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
3024       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
3025       emit_insn (gen_quous_call ());
3026       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
3027       DONE;
3028     }
3029   else if (TARGET_POWER)
3030     {
3031       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
3032       DONE;
3033     }
3034 }")
3035
3036 (define_insn "udivsi3_mq"
3037   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3038         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3039                  (match_operand:SI 2 "gpc_reg_operand" "r")))
3040    (clobber (match_scratch:SI 3 "=q"))]
3041   "TARGET_POWERPC && TARGET_POWER"
3042   "divwu %0,%1,%2"
3043   [(set_attr "type" "idiv")])
3044
3045 (define_insn "*udivsi3_no_mq"
3046   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3047         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3048                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
3049   "TARGET_POWERPC && ! TARGET_POWER"
3050   "div<wd>u %0,%1,%2"
3051    [(set (attr "type")
3052       (cond [(match_operand:SI 0 "" "")
3053                 (const_string "idiv")]
3054         (const_string "ldiv")))])
3055
3056
3057 ;; For powers of two we can do srai/aze for divide and then adjust for
3058 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
3059 ;; used; for PowerPC, force operands into register and do a normal divide;
3060 ;; for AIX common-mode, use quoss call on register operands.
3061 (define_expand "div<mode>3"
3062   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
3063         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3064                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
3065   ""
3066   "
3067 {
3068   if (GET_CODE (operands[2]) == CONST_INT
3069       && INTVAL (operands[2]) > 0
3070       && exact_log2 (INTVAL (operands[2])) >= 0)
3071     ;
3072   else if (TARGET_POWERPC)
3073     {
3074       operands[2] = force_reg (<MODE>mode, operands[2]);
3075       if (TARGET_POWER)
3076         {
3077           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
3078           DONE;
3079         }
3080     }
3081   else if (TARGET_POWER)
3082     FAIL;
3083   else
3084     {
3085       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
3086       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
3087       emit_insn (gen_quoss_call ());
3088       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
3089       DONE;
3090     }
3091 }")
3092
3093 (define_insn "divsi3_mq"
3094   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3095         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3096                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3097    (clobber (match_scratch:SI 3 "=q"))]
3098   "TARGET_POWERPC && TARGET_POWER"
3099   "divw %0,%1,%2"
3100   [(set_attr "type" "idiv")])
3101
3102 (define_insn "*div<mode>3_no_mq"
3103   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3104         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3105                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
3106   "TARGET_POWERPC && ! TARGET_POWER"
3107   "div<wd> %0,%1,%2"
3108   [(set (attr "type")
3109      (cond [(match_operand:SI 0 "" "")
3110                 (const_string "idiv")]
3111         (const_string "ldiv")))])
3112
3113 (define_expand "mod<mode>3"
3114   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
3115    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
3116    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
3117   ""
3118   "
3119 {
3120   int i;
3121   rtx temp1;
3122   rtx temp2;
3123
3124   if (GET_CODE (operands[2]) != CONST_INT
3125       || INTVAL (operands[2]) <= 0
3126       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
3127     FAIL;
3128
3129   temp1 = gen_reg_rtx (<MODE>mode);
3130   temp2 = gen_reg_rtx (<MODE>mode);
3131
3132   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
3133   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
3134   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
3135   DONE;
3136 }")
3137
3138 (define_insn ""
3139   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3140         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3141                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
3142   ""
3143   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
3144   [(set_attr "type" "two")
3145    (set_attr "length" "8")])
3146
3147 (define_insn ""
3148   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3149         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
3150                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
3151                     (const_int 0)))
3152    (clobber (match_scratch:P 3 "=r,r"))]
3153   ""
3154   "@
3155    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
3156    #"
3157   [(set_attr "type" "compare")
3158    (set_attr "length" "8,12")
3159    (set_attr "cell_micro" "not")])
3160
3161 (define_split
3162   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3163         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3164                              (match_operand:GPR 2 "exact_log2_cint_operand"
3165                               ""))
3166                     (const_int 0)))
3167    (clobber (match_scratch:GPR 3 ""))]
3168   "reload_completed"
3169   [(set (match_dup 3)
3170         (div:<MODE> (match_dup 1) (match_dup 2)))
3171    (set (match_dup 0)
3172         (compare:CC (match_dup 3)
3173                     (const_int 0)))]
3174   "")
3175
3176 (define_insn ""
3177   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3178         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
3179                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
3180                     (const_int 0)))
3181    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
3182         (div:P (match_dup 1) (match_dup 2)))]
3183   ""
3184   "@
3185    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
3186    #"
3187   [(set_attr "type" "compare")
3188    (set_attr "length" "8,12")
3189    (set_attr "cell_micro" "not")])
3190
3191 (define_split
3192   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3193         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3194                              (match_operand:GPR 2 "exact_log2_cint_operand"
3195                               ""))
3196                     (const_int 0)))
3197    (set (match_operand:GPR 0 "gpc_reg_operand" "")
3198         (div:GPR (match_dup 1) (match_dup 2)))]
3199   "reload_completed"
3200   [(set (match_dup 0)
3201         (div:<MODE> (match_dup 1) (match_dup 2)))
3202    (set (match_dup 3)
3203         (compare:CC (match_dup 0)
3204                     (const_int 0)))]
3205   "")
3206
3207 (define_insn ""
3208   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3209         (udiv:SI
3210          (plus:DI (ashift:DI
3211                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
3212                    (const_int 32))
3213                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
3214          (match_operand:SI 3 "gpc_reg_operand" "r")))
3215    (set (match_operand:SI 2 "register_operand" "=*q")
3216         (umod:SI
3217          (plus:DI (ashift:DI
3218                    (zero_extend:DI (match_dup 1)) (const_int 32))
3219                   (zero_extend:DI (match_dup 4)))
3220          (match_dup 3)))]
3221   "TARGET_POWER"
3222   "div %0,%1,%3"
3223   [(set_attr "type" "idiv")])
3224
3225 ;; To do unsigned divide we handle the cases of the divisor looking like a
3226 ;; negative number.  If it is a constant that is less than 2**31, we don't
3227 ;; have to worry about the branches.  So make a few subroutines here.
3228 ;;
3229 ;; First comes the normal case.
3230 (define_expand "udivmodsi4_normal"
3231   [(set (match_dup 4) (const_int 0))
3232    (parallel [(set (match_operand:SI 0 "" "")
3233                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
3234                                                 (const_int 32))
3235                                      (zero_extend:DI (match_operand:SI 1 "" "")))
3236                             (match_operand:SI 2 "" "")))
3237               (set (match_operand:SI 3 "" "")
3238                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
3239                                                 (const_int 32))
3240                                      (zero_extend:DI (match_dup 1)))
3241                             (match_dup 2)))])]
3242   "TARGET_POWER"
3243   "
3244 { operands[4] = gen_reg_rtx (SImode); }")
3245
3246 ;; This handles the branches.
3247 (define_expand "udivmodsi4_tests"
3248   [(set (match_operand:SI 0 "" "") (const_int 0))
3249    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
3250    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
3251    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
3252                            (label_ref (match_operand:SI 4 "" "")) (pc)))
3253    (set (match_dup 0) (const_int 1))
3254    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
3255    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
3256    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
3257                            (label_ref (match_dup 4)) (pc)))]
3258   "TARGET_POWER"
3259   "
3260 { operands[5] = gen_reg_rtx (CCUNSmode);
3261   operands[6] = gen_reg_rtx (CCmode);
3262 }")
3263
3264 (define_expand "udivmodsi4"
3265   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
3266                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
3267                             (match_operand:SI 2 "reg_or_cint_operand" "")))
3268               (set (match_operand:SI 3 "gpc_reg_operand" "")
3269                    (umod:SI (match_dup 1) (match_dup 2)))])]
3270   ""
3271   "
3272 {
3273   rtx label = 0;
3274
3275   if (! TARGET_POWER)
3276     {
3277       if (! TARGET_POWERPC)
3278         {
3279           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
3280           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
3281           emit_insn (gen_divus_call ());
3282           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
3283           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
3284           DONE;
3285         }
3286       else
3287         FAIL;
3288     }
3289
3290   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
3291     {
3292       operands[2] = force_reg (SImode, operands[2]);
3293       label = gen_label_rtx ();
3294       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
3295                                   operands[3], label));
3296     }
3297   else
3298     operands[2] = force_reg (SImode, operands[2]);
3299
3300   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
3301                                operands[3]));
3302   if (label)
3303     emit_label (label);
3304
3305   DONE;
3306 }")
3307
3308 ;; AIX architecture-independent common-mode multiply (DImode),
3309 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
3310 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
3311 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
3312 ;; assumed unused if generating common-mode, so ignore.
3313 (define_insn "mulh_call"
3314   [(set (reg:SI 3)
3315         (truncate:SI
3316          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
3317                                (sign_extend:DI (reg:SI 4)))
3318                       (const_int 32))))
3319    (clobber (reg:SI LR_REGNO))]
3320   "! TARGET_POWER && ! TARGET_POWERPC"
3321   "bla __mulh"
3322   [(set_attr "type" "imul")])
3323
3324 (define_insn "mull_call"
3325   [(set (reg:DI 3)
3326         (mult:DI (sign_extend:DI (reg:SI 3))
3327                  (sign_extend:DI (reg:SI 4))))
3328    (clobber (reg:SI LR_REGNO))
3329    (clobber (reg:SI 0))]
3330   "! TARGET_POWER && ! TARGET_POWERPC"
3331   "bla __mull"
3332   [(set_attr "type" "imul")])
3333
3334 (define_insn "divss_call"
3335   [(set (reg:SI 3)
3336         (div:SI (reg:SI 3) (reg:SI 4)))
3337    (set (reg:SI 4)
3338         (mod:SI (reg:SI 3) (reg:SI 4)))
3339    (clobber (reg:SI LR_REGNO))
3340    (clobber (reg:SI 0))]
3341   "! TARGET_POWER && ! TARGET_POWERPC"
3342   "bla __divss"
3343   [(set_attr "type" "idiv")])
3344
3345 (define_insn "divus_call"
3346   [(set (reg:SI 3)
3347         (udiv:SI (reg:SI 3) (reg:SI 4)))
3348    (set (reg:SI 4)
3349         (umod:SI (reg:SI 3) (reg:SI 4)))
3350    (clobber (reg:SI LR_REGNO))
3351    (clobber (reg:SI 0))
3352    (clobber (match_scratch:CC 0 "=x"))
3353    (clobber (reg:CC CR1_REGNO))]
3354   "! TARGET_POWER && ! TARGET_POWERPC"
3355   "bla __divus"
3356   [(set_attr "type" "idiv")])
3357
3358 (define_insn "quoss_call"
3359   [(set (reg:SI 3)
3360         (div:SI (reg:SI 3) (reg:SI 4)))
3361    (clobber (reg:SI LR_REGNO))]
3362   "! TARGET_POWER && ! TARGET_POWERPC"
3363   "bla __quoss"
3364   [(set_attr "type" "idiv")])
3365
3366 (define_insn "quous_call"
3367   [(set (reg:SI 3)
3368         (udiv:SI (reg:SI 3) (reg:SI 4)))
3369    (clobber (reg:SI LR_REGNO))
3370    (clobber (reg:SI 0))
3371    (clobber (match_scratch:CC 0 "=x"))
3372    (clobber (reg:CC CR1_REGNO))]
3373   "! TARGET_POWER && ! TARGET_POWERPC"
3374   "bla __quous"
3375   [(set_attr "type" "idiv")])
3376 \f
3377 ;; Logical instructions
3378 ;; The logical instructions are mostly combined by using match_operator,
3379 ;; but the plain AND insns are somewhat different because there is no
3380 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
3381 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
3382
3383 (define_expand "andsi3"
3384   [(parallel
3385     [(set (match_operand:SI 0 "gpc_reg_operand" "")
3386           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3387                   (match_operand:SI 2 "and_operand" "")))
3388      (clobber (match_scratch:CC 3 ""))])]
3389   ""
3390   "")
3391
3392 (define_insn "andsi3_mc"
3393   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3394         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
3395                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
3396    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
3397   "rs6000_gen_cell_microcode"
3398   "@
3399    and %0,%1,%2
3400    {rlinm|rlwinm} %0,%1,0,%m2,%M2
3401    {andil.|andi.} %0,%1,%b2
3402    {andiu.|andis.} %0,%1,%u2"
3403   [(set_attr "type" "*,*,fast_compare,fast_compare")])
3404
3405 (define_insn "andsi3_nomc"
3406   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3407         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
3408                 (match_operand:SI 2 "and_operand" "?r,T")))
3409    (clobber (match_scratch:CC 3 "=X,X"))]
3410   "!rs6000_gen_cell_microcode"
3411   "@
3412    and %0,%1,%2
3413    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
3414
3415 (define_insn "andsi3_internal0_nomc"
3416   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3417         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
3418                 (match_operand:SI 2 "and_operand" "?r,T")))]
3419   "!rs6000_gen_cell_microcode"
3420   "@
3421    and %0,%1,%2
3422    {rlinm|rlwinm} %0,%1,0,%m2,%M2")
3423
3424
3425 ;; Note to set cr's other than cr0 we do the and immediate and then
3426 ;; the test again -- this avoids a mfcr which on the higher end
3427 ;; machines causes an execution serialization
3428
3429 (define_insn "*andsi3_internal2_mc"
3430   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3431         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3432                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3433                     (const_int 0)))
3434    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
3435    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3436   "TARGET_32BIT && rs6000_gen_cell_microcode"
3437   "@
3438    and. %3,%1,%2
3439    {andil.|andi.} %3,%1,%b2
3440    {andiu.|andis.} %3,%1,%u2
3441    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
3442    #
3443    #
3444    #
3445    #"
3446   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
3447                      compare,compare,compare,compare")
3448    (set_attr "length" "4,4,4,4,8,8,8,8")])
3449
3450 (define_insn "*andsi3_internal3_mc"
3451   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3452         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3453                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3454                     (const_int 0)))
3455    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
3456    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3457   "TARGET_64BIT && rs6000_gen_cell_microcode"
3458   "@
3459    #
3460    {andil.|andi.} %3,%1,%b2
3461    {andiu.|andis.} %3,%1,%u2
3462    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
3463    #
3464    #
3465    #
3466    #"
3467   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
3468                      compare,compare,compare")
3469    (set_attr "length" "8,4,4,4,8,8,8,8")])
3470
3471 (define_split
3472   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3473         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3474                              (match_operand:GPR 2 "and_operand" ""))
3475                     (const_int 0)))
3476    (clobber (match_scratch:GPR 3 ""))
3477    (clobber (match_scratch:CC 4 ""))]
3478   "reload_completed"
3479   [(parallel [(set (match_dup 3)
3480                    (and:<MODE> (match_dup 1)
3481                                (match_dup 2)))
3482               (clobber (match_dup 4))])
3483    (set (match_dup 0)
3484         (compare:CC (match_dup 3)
3485                     (const_int 0)))]
3486   "")
3487
3488 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
3489 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
3490
3491 (define_split
3492   [(set (match_operand:CC 0 "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    (clobber (match_scratch:SI 3 ""))
3497    (clobber (match_scratch:CC 4 ""))]
3498   "TARGET_POWERPC64 && reload_completed"
3499   [(parallel [(set (match_dup 3)
3500                    (and:SI (match_dup 1)
3501                            (match_dup 2)))
3502               (clobber (match_dup 4))])
3503    (set (match_dup 0)
3504         (compare:CC (match_dup 3)
3505                     (const_int 0)))]
3506   "")
3507
3508 (define_insn "*andsi3_internal4"
3509   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3510         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3511                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3512                     (const_int 0)))
3513    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3514         (and:SI (match_dup 1)
3515                 (match_dup 2)))
3516    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3517   "TARGET_32BIT && rs6000_gen_cell_microcode"
3518   "@
3519    and. %0,%1,%2
3520    {andil.|andi.} %0,%1,%b2
3521    {andiu.|andis.} %0,%1,%u2
3522    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3523    #
3524    #
3525    #
3526    #"
3527   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
3528                      compare,compare,compare,compare")
3529    (set_attr "length" "4,4,4,4,8,8,8,8")])
3530
3531 (define_insn "*andsi3_internal5_mc"
3532   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3533         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3534                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3535                     (const_int 0)))
3536    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3537         (and:SI (match_dup 1)
3538                 (match_dup 2)))
3539    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3540   "TARGET_64BIT && rs6000_gen_cell_microcode"
3541   "@
3542    #
3543    {andil.|andi.} %0,%1,%b2
3544    {andiu.|andis.} %0,%1,%u2
3545    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3546    #
3547    #
3548    #
3549    #"
3550   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
3551                      compare,compare,compare")
3552    (set_attr "length" "8,4,4,4,8,8,8,8")])
3553
3554 (define_split
3555   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3556         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3557                             (match_operand:SI 2 "and_operand" ""))
3558                     (const_int 0)))
3559    (set (match_operand:SI 0 "gpc_reg_operand" "")
3560         (and:SI (match_dup 1)
3561                 (match_dup 2)))
3562    (clobber (match_scratch:CC 4 ""))]
3563   "reload_completed"
3564   [(parallel [(set (match_dup 0)
3565                    (and:SI (match_dup 1)
3566                            (match_dup 2)))
3567               (clobber (match_dup 4))])
3568    (set (match_dup 3)
3569         (compare:CC (match_dup 0)
3570                     (const_int 0)))]
3571   "")
3572
3573 (define_split
3574   [(set (match_operand:CC 3 "cc_reg_operand" "")
3575         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3576                             (match_operand:SI 2 "gpc_reg_operand" ""))
3577                     (const_int 0)))
3578    (set (match_operand:SI 0 "gpc_reg_operand" "")
3579         (and:SI (match_dup 1)
3580                 (match_dup 2)))
3581    (clobber (match_scratch:CC 4 ""))]
3582   "TARGET_POWERPC64 && reload_completed"
3583   [(parallel [(set (match_dup 0)
3584                    (and:SI (match_dup 1)
3585                            (match_dup 2)))
3586               (clobber (match_dup 4))])
3587    (set (match_dup 3)
3588         (compare:CC (match_dup 0)
3589                     (const_int 0)))]
3590   "")
3591
3592 ;; Handle the PowerPC64 rlwinm corner case
3593
3594 (define_insn_and_split "*andsi3_internal6"
3595   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3596         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3597                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3598   "TARGET_POWERPC64"
3599   "#"
3600   "TARGET_POWERPC64"
3601   [(set (match_dup 0)
3602         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3603                 (match_dup 4)))
3604    (set (match_dup 0)
3605         (rotate:SI (match_dup 0) (match_dup 5)))]
3606   "
3607 {
3608   int mb = extract_MB (operands[2]);
3609   int me = extract_ME (operands[2]);
3610   operands[3] = GEN_INT (me + 1);
3611   operands[5] = GEN_INT (32 - (me + 1));
3612   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3613 }"
3614   [(set_attr "length" "8")])
3615
3616 (define_expand "iorsi3"
3617   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3618         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3619                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3620   ""
3621   "
3622 {
3623   if (GET_CODE (operands[2]) == CONST_INT
3624       && ! logical_operand (operands[2], SImode))
3625     {
3626       HOST_WIDE_INT value = INTVAL (operands[2]);
3627       rtx tmp = ((!can_create_pseudo_p ()
3628                   || rtx_equal_p (operands[0], operands[1]))
3629                  ? operands[0] : gen_reg_rtx (SImode));
3630
3631       emit_insn (gen_iorsi3 (tmp, operands[1],
3632                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3633       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3634       DONE;
3635     }
3636 }")
3637
3638 (define_expand "xorsi3"
3639   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3640         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3641                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3642   ""
3643   "
3644 {
3645   if (GET_CODE (operands[2]) == CONST_INT
3646       && ! logical_operand (operands[2], SImode))
3647     {
3648       HOST_WIDE_INT value = INTVAL (operands[2]);
3649       rtx tmp = ((!can_create_pseudo_p ()
3650                   || rtx_equal_p (operands[0], operands[1]))
3651                  ? operands[0] : gen_reg_rtx (SImode));
3652
3653       emit_insn (gen_xorsi3 (tmp, operands[1],
3654                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3655       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3656       DONE;
3657     }
3658 }")
3659
3660 (define_insn "*boolsi3_internal1"
3661   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3662         (match_operator:SI 3 "boolean_or_operator"
3663          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3664           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3665   ""
3666   "@
3667    %q3 %0,%1,%2
3668    {%q3il|%q3i} %0,%1,%b2
3669    {%q3iu|%q3is} %0,%1,%u2")
3670
3671 (define_insn "*boolsi3_internal2"
3672   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3673         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3674          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3675           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3676          (const_int 0)))
3677    (clobber (match_scratch:SI 3 "=r,r"))]
3678   "TARGET_32BIT"
3679   "@
3680    %q4. %3,%1,%2
3681    #"
3682   [(set_attr "type" "fast_compare,compare")
3683    (set_attr "length" "4,8")])
3684
3685 (define_split
3686   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3687         (compare:CC (match_operator:SI 4 "boolean_operator"
3688          [(match_operand:SI 1 "gpc_reg_operand" "")
3689           (match_operand:SI 2 "gpc_reg_operand" "")])
3690          (const_int 0)))
3691    (clobber (match_scratch:SI 3 ""))]
3692   "TARGET_32BIT && reload_completed"
3693   [(set (match_dup 3) (match_dup 4))
3694    (set (match_dup 0)
3695         (compare:CC (match_dup 3)
3696                     (const_int 0)))]
3697   "")
3698
3699 (define_insn "*boolsi3_internal3"
3700   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3701         (compare:CC (match_operator:SI 4 "boolean_operator"
3702          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3703           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3704          (const_int 0)))
3705    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3706         (match_dup 4))]
3707   "TARGET_32BIT"
3708   "@
3709    %q4. %0,%1,%2
3710    #"
3711   [(set_attr "type" "fast_compare,compare")
3712    (set_attr "length" "4,8")])
3713
3714 (define_split
3715   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3716         (compare:CC (match_operator:SI 4 "boolean_operator"
3717          [(match_operand:SI 1 "gpc_reg_operand" "")
3718           (match_operand:SI 2 "gpc_reg_operand" "")])
3719          (const_int 0)))
3720    (set (match_operand:SI 0 "gpc_reg_operand" "")
3721         (match_dup 4))]
3722   "TARGET_32BIT && reload_completed"
3723   [(set (match_dup 0) (match_dup 4))
3724    (set (match_dup 3)
3725         (compare:CC (match_dup 0)
3726                     (const_int 0)))]
3727   "")
3728
3729 ;; Split a logical operation that we can't do in one insn into two insns,
3730 ;; each of which does one 16-bit part.  This is used by combine.
3731
3732 (define_split
3733   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3734         (match_operator:SI 3 "boolean_or_operator"
3735          [(match_operand:SI 1 "gpc_reg_operand" "")
3736           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3737   ""
3738   [(set (match_dup 0) (match_dup 4))
3739    (set (match_dup 0) (match_dup 5))]
3740 "
3741 {
3742   rtx i;
3743   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3744   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3745                                 operands[1], i);
3746   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3747   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3748                                 operands[0], i);
3749 }")
3750
3751 (define_insn "*boolcsi3_internal1"
3752   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3753         (match_operator:SI 3 "boolean_operator"
3754          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3755           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3756   ""
3757   "%q3 %0,%2,%1")
3758
3759 (define_insn "*boolcsi3_internal2"
3760   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3761         (compare:CC (match_operator:SI 4 "boolean_operator"
3762          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3763           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3764          (const_int 0)))
3765    (clobber (match_scratch:SI 3 "=r,r"))]
3766   "TARGET_32BIT"
3767   "@
3768    %q4. %3,%2,%1
3769    #"
3770   [(set_attr "type" "compare")
3771    (set_attr "length" "4,8")])
3772
3773 (define_split
3774   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3775         (compare:CC (match_operator:SI 4 "boolean_operator"
3776          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3777           (match_operand:SI 2 "gpc_reg_operand" "")])
3778          (const_int 0)))
3779    (clobber (match_scratch:SI 3 ""))]
3780   "TARGET_32BIT && reload_completed"
3781   [(set (match_dup 3) (match_dup 4))
3782    (set (match_dup 0)
3783         (compare:CC (match_dup 3)
3784                     (const_int 0)))]
3785   "")
3786
3787 (define_insn "*boolcsi3_internal3"
3788   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3789         (compare:CC (match_operator:SI 4 "boolean_operator"
3790          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3791           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3792          (const_int 0)))
3793    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3794         (match_dup 4))]
3795   "TARGET_32BIT"
3796   "@
3797    %q4. %0,%2,%1
3798    #"
3799   [(set_attr "type" "compare")
3800    (set_attr "length" "4,8")])
3801
3802 (define_split
3803   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3804         (compare:CC (match_operator:SI 4 "boolean_operator"
3805          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3806           (match_operand:SI 2 "gpc_reg_operand" "")])
3807          (const_int 0)))
3808    (set (match_operand:SI 0 "gpc_reg_operand" "")
3809         (match_dup 4))]
3810   "TARGET_32BIT && reload_completed"
3811   [(set (match_dup 0) (match_dup 4))
3812    (set (match_dup 3)
3813         (compare:CC (match_dup 0)
3814                     (const_int 0)))]
3815   "")
3816
3817 (define_insn "*boolccsi3_internal1"
3818   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3819         (match_operator:SI 3 "boolean_operator"
3820          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3821           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3822   ""
3823   "%q3 %0,%1,%2")
3824
3825 (define_insn "*boolccsi3_internal2"
3826   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3827         (compare:CC (match_operator:SI 4 "boolean_operator"
3828          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3829           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3830          (const_int 0)))
3831    (clobber (match_scratch:SI 3 "=r,r"))]
3832   "TARGET_32BIT"
3833   "@
3834    %q4. %3,%1,%2
3835    #"
3836   [(set_attr "type" "fast_compare,compare")
3837    (set_attr "length" "4,8")])
3838
3839 (define_split
3840   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3841         (compare:CC (match_operator:SI 4 "boolean_operator"
3842          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3843           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3844          (const_int 0)))
3845    (clobber (match_scratch:SI 3 ""))]
3846   "TARGET_32BIT && reload_completed"
3847   [(set (match_dup 3) (match_dup 4))
3848    (set (match_dup 0)
3849         (compare:CC (match_dup 3)
3850                     (const_int 0)))]
3851   "")
3852
3853 (define_insn "*boolccsi3_internal3"
3854   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3855         (compare:CC (match_operator:SI 4 "boolean_operator"
3856          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3857           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3858          (const_int 0)))
3859    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3860         (match_dup 4))]
3861   "TARGET_32BIT"
3862   "@
3863    %q4. %0,%1,%2
3864    #"
3865   [(set_attr "type" "fast_compare,compare")
3866    (set_attr "length" "4,8")])
3867
3868 (define_split
3869   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3870         (compare:CC (match_operator:SI 4 "boolean_operator"
3871          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3872           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3873          (const_int 0)))
3874    (set (match_operand:SI 0 "gpc_reg_operand" "")
3875         (match_dup 4))]
3876   "TARGET_32BIT && reload_completed"
3877   [(set (match_dup 0) (match_dup 4))
3878    (set (match_dup 3)
3879         (compare:CC (match_dup 0)
3880                     (const_int 0)))]
3881   "")
3882
3883 ;; maskir insn.  We need four forms because things might be in arbitrary
3884 ;; orders.  Don't define forms that only set CR fields because these
3885 ;; would modify an input register.
3886
3887 (define_insn "*maskir_internal1"
3888   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3889         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3890                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3891                 (and:SI (match_dup 2)
3892                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3893   "TARGET_POWER"
3894   "maskir %0,%3,%2")
3895
3896 (define_insn "*maskir_internal2"
3897   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3898         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3899                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3900                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3901                         (match_dup 2))))]
3902   "TARGET_POWER"
3903   "maskir %0,%3,%2")
3904
3905 (define_insn "*maskir_internal3"
3906   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3907         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3908                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3909                 (and:SI (not:SI (match_dup 2))
3910                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3911   "TARGET_POWER"
3912   "maskir %0,%3,%2")
3913
3914 (define_insn "*maskir_internal4"
3915   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3916         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3917                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3918                 (and:SI (not:SI (match_dup 2))
3919                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3920   "TARGET_POWER"
3921   "maskir %0,%3,%2")
3922
3923 (define_insn "*maskir_internal5"
3924   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3925         (compare:CC
3926          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3927                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3928                  (and:SI (match_dup 2)
3929                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3930          (const_int 0)))
3931    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3932         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3933                 (and:SI (match_dup 2) (match_dup 3))))]
3934   "TARGET_POWER"
3935   "@
3936    maskir. %0,%3,%2
3937    #"
3938   [(set_attr "type" "compare")
3939    (set_attr "length" "4,8")])
3940
3941 (define_split
3942   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3943         (compare:CC
3944          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3945                          (match_operand:SI 1 "gpc_reg_operand" ""))
3946                  (and:SI (match_dup 2)
3947                          (match_operand:SI 3 "gpc_reg_operand" "")))
3948          (const_int 0)))
3949    (set (match_operand:SI 0 "gpc_reg_operand" "")
3950         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3951                 (and:SI (match_dup 2) (match_dup 3))))]
3952   "TARGET_POWER && reload_completed"
3953   [(set (match_dup 0)
3954         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3955                 (and:SI (match_dup 2) (match_dup 3))))
3956    (set (match_dup 4)
3957         (compare:CC (match_dup 0)
3958                     (const_int 0)))]
3959   "")
3960
3961 (define_insn "*maskir_internal6"
3962   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3963         (compare:CC
3964          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3965                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3966                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3967                          (match_dup 2)))
3968          (const_int 0)))
3969    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3970         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3971                 (and:SI (match_dup 3) (match_dup 2))))]
3972   "TARGET_POWER"
3973   "@
3974    maskir. %0,%3,%2
3975    #"
3976   [(set_attr "type" "compare")
3977    (set_attr "length" "4,8")])
3978
3979 (define_split
3980   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3981         (compare:CC
3982          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3983                          (match_operand:SI 1 "gpc_reg_operand" ""))
3984                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3985                          (match_dup 2)))
3986          (const_int 0)))
3987    (set (match_operand:SI 0 "gpc_reg_operand" "")
3988         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3989                 (and:SI (match_dup 3) (match_dup 2))))]
3990   "TARGET_POWER && reload_completed"
3991   [(set (match_dup 0)
3992         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3993                 (and:SI (match_dup 3) (match_dup 2))))
3994    (set (match_dup 4)
3995         (compare:CC (match_dup 0)
3996                     (const_int 0)))]
3997   "")
3998
3999 (define_insn "*maskir_internal7"
4000   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4001         (compare:CC
4002          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
4003                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
4004                  (and:SI (not:SI (match_dup 2))
4005                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
4006          (const_int 0)))
4007    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4008         (ior:SI (and:SI (match_dup 2) (match_dup 3))
4009                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
4010   "TARGET_POWER"
4011   "@
4012    maskir. %0,%3,%2
4013    #"
4014   [(set_attr "type" "compare")
4015    (set_attr "length" "4,8")])
4016
4017 (define_split
4018   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4019         (compare:CC
4020          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
4021                          (match_operand:SI 3 "gpc_reg_operand" ""))
4022                  (and:SI (not:SI (match_dup 2))
4023                          (match_operand:SI 1 "gpc_reg_operand" "")))
4024          (const_int 0)))
4025    (set (match_operand:SI 0 "gpc_reg_operand" "")
4026         (ior:SI (and:SI (match_dup 2) (match_dup 3))
4027                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
4028   "TARGET_POWER && reload_completed"
4029   [(set (match_dup 0)
4030         (ior:SI (and:SI (match_dup 2) (match_dup 3))
4031                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
4032    (set (match_dup 4)
4033         (compare:CC (match_dup 0)
4034                     (const_int 0)))]
4035   "")
4036
4037 (define_insn "*maskir_internal8"
4038   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4039         (compare:CC
4040          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
4041                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
4042                  (and:SI (not:SI (match_dup 2))
4043                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
4044          (const_int 0)))
4045    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4046         (ior:SI (and:SI (match_dup 3) (match_dup 2))
4047                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
4048   "TARGET_POWER"
4049   "@
4050    maskir. %0,%3,%2
4051    #"
4052   [(set_attr "type" "compare")
4053    (set_attr "length" "4,8")])
4054
4055 (define_split
4056   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4057         (compare:CC
4058          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
4059                          (match_operand:SI 2 "gpc_reg_operand" ""))
4060                  (and:SI (not:SI (match_dup 2))
4061                          (match_operand:SI 1 "gpc_reg_operand" "")))
4062          (const_int 0)))
4063    (set (match_operand:SI 0 "gpc_reg_operand" "")
4064         (ior:SI (and:SI (match_dup 3) (match_dup 2))
4065                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
4066   "TARGET_POWER && reload_completed"
4067   [(set (match_dup 0)
4068         (ior:SI (and:SI (match_dup 3) (match_dup 2))
4069                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
4070    (set (match_dup 4)
4071         (compare:CC (match_dup 0)
4072                     (const_int 0)))]
4073   "")
4074 \f
4075 ;; Rotate and shift insns, in all their variants.  These support shifts,
4076 ;; field inserts and extracts, and various combinations thereof.
4077 (define_expand "insv"
4078   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
4079                        (match_operand:SI 1 "const_int_operand" "")
4080                        (match_operand:SI 2 "const_int_operand" ""))
4081         (match_operand 3 "gpc_reg_operand" ""))]
4082   ""
4083   "
4084 {
4085   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
4086      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
4087      compiler if the address of the structure is taken later.  Likewise, do
4088      not handle invalid E500 subregs.  */
4089   if (GET_CODE (operands[0]) == SUBREG
4090       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
4091           || ((TARGET_E500_DOUBLE || TARGET_SPE)
4092               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
4093     FAIL;
4094
4095   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
4096     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
4097   else
4098     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
4099   DONE;
4100 }")
4101
4102 (define_insn "insvsi"
4103   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4104                          (match_operand:SI 1 "const_int_operand" "i")
4105                          (match_operand:SI 2 "const_int_operand" "i"))
4106         (match_operand:SI 3 "gpc_reg_operand" "r"))]
4107   ""
4108   "*
4109 {
4110   int start = INTVAL (operands[2]) & 31;
4111   int size = INTVAL (operands[1]) & 31;
4112
4113   operands[4] = GEN_INT (32 - start - size);
4114   operands[1] = GEN_INT (start + size - 1);
4115   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4116 }"
4117   [(set_attr "type" "insert_word")])
4118
4119 (define_insn "*insvsi_internal1"
4120   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4121                          (match_operand:SI 1 "const_int_operand" "i")
4122                          (match_operand:SI 2 "const_int_operand" "i"))
4123         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4124                    (match_operand:SI 4 "const_int_operand" "i")))]
4125   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4126   "*
4127 {
4128   int shift = INTVAL (operands[4]) & 31;
4129   int start = INTVAL (operands[2]) & 31;
4130   int size = INTVAL (operands[1]) & 31;
4131
4132   operands[4] = GEN_INT (shift - start - size);
4133   operands[1] = GEN_INT (start + size - 1);
4134   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4135 }"
4136   [(set_attr "type" "insert_word")])
4137
4138 (define_insn "*insvsi_internal2"
4139   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4140                          (match_operand:SI 1 "const_int_operand" "i")
4141                          (match_operand:SI 2 "const_int_operand" "i"))
4142         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4143                      (match_operand:SI 4 "const_int_operand" "i")))]
4144   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4145   "*
4146 {
4147   int shift = INTVAL (operands[4]) & 31;
4148   int start = INTVAL (operands[2]) & 31;
4149   int size = INTVAL (operands[1]) & 31;
4150
4151   operands[4] = GEN_INT (32 - shift - start - size);
4152   operands[1] = GEN_INT (start + size - 1);
4153   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4154 }"
4155   [(set_attr "type" "insert_word")])
4156
4157 (define_insn "*insvsi_internal3"
4158   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4159                          (match_operand:SI 1 "const_int_operand" "i")
4160                          (match_operand:SI 2 "const_int_operand" "i"))
4161         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4162                      (match_operand:SI 4 "const_int_operand" "i")))]
4163   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
4164   "*
4165 {
4166   int shift = INTVAL (operands[4]) & 31;
4167   int start = INTVAL (operands[2]) & 31;
4168   int size = INTVAL (operands[1]) & 31;
4169
4170   operands[4] = GEN_INT (32 - shift - start - size);
4171   operands[1] = GEN_INT (start + size - 1);
4172   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4173 }"
4174   [(set_attr "type" "insert_word")])
4175
4176 (define_insn "*insvsi_internal4"
4177   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4178                          (match_operand:SI 1 "const_int_operand" "i")
4179                          (match_operand:SI 2 "const_int_operand" "i"))
4180         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4181                          (match_operand:SI 4 "const_int_operand" "i")
4182                          (match_operand:SI 5 "const_int_operand" "i")))]
4183   "INTVAL (operands[4]) >= INTVAL (operands[1])"
4184   "*
4185 {
4186   int extract_start = INTVAL (operands[5]) & 31;
4187   int extract_size = INTVAL (operands[4]) & 31;
4188   int insert_start = INTVAL (operands[2]) & 31;
4189   int insert_size = INTVAL (operands[1]) & 31;
4190
4191 /* Align extract field with insert field */
4192   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
4193   operands[1] = GEN_INT (insert_start + insert_size - 1);
4194   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
4195 }"
4196   [(set_attr "type" "insert_word")])
4197
4198 ;; combine patterns for rlwimi
4199 (define_insn "*insvsi_internal5"
4200   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4201         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
4202                         (match_operand:SI 1 "mask_operand" "i"))
4203                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4204                                      (match_operand:SI 2 "const_int_operand" "i"))
4205                         (match_operand:SI 5 "mask_operand" "i"))))]
4206   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
4207   "*
4208 {
4209  int me = extract_ME(operands[5]);
4210  int mb = extract_MB(operands[5]);
4211  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
4212  operands[2] = GEN_INT(mb);
4213  operands[1] = GEN_INT(me);
4214  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4215 }"
4216   [(set_attr "type" "insert_word")])
4217
4218 (define_insn "*insvsi_internal6"
4219   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4220         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
4221                                      (match_operand:SI 2 "const_int_operand" "i"))
4222                         (match_operand:SI 5 "mask_operand" "i"))
4223                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
4224                         (match_operand:SI 1 "mask_operand" "i"))))]
4225   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
4226   "*
4227 {
4228  int me = extract_ME(operands[5]);
4229  int mb = extract_MB(operands[5]);
4230  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
4231  operands[2] = GEN_INT(mb);
4232  operands[1] = GEN_INT(me);
4233  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
4234 }"
4235   [(set_attr "type" "insert_word")])
4236
4237 (define_insn "insvdi"
4238   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4239                          (match_operand:SI 1 "const_int_operand" "i")
4240                          (match_operand:SI 2 "const_int_operand" "i"))
4241         (match_operand:DI 3 "gpc_reg_operand" "r"))]
4242   "TARGET_POWERPC64"
4243   "*
4244 {
4245   int start = INTVAL (operands[2]) & 63;
4246   int size = INTVAL (operands[1]) & 63;
4247
4248   operands[1] = GEN_INT (64 - start - size);
4249   return \"rldimi %0,%3,%H1,%H2\";
4250 }"
4251   [(set_attr "type" "insert_dword")])
4252
4253 (define_insn "*insvdi_internal2"
4254   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4255                          (match_operand:SI 1 "const_int_operand" "i")
4256                          (match_operand:SI 2 "const_int_operand" "i"))
4257         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4258                      (match_operand:SI 4 "const_int_operand" "i")))]
4259   "TARGET_POWERPC64
4260    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
4261   "*
4262 {
4263   int shift = INTVAL (operands[4]) & 63;
4264   int start = (INTVAL (operands[2]) & 63) - 32;
4265   int size = INTVAL (operands[1]) & 63;
4266
4267   operands[4] = GEN_INT (64 - shift - start - size);
4268   operands[2] = GEN_INT (start);
4269   operands[1] = GEN_INT (start + size - 1);
4270   return \"rlwimi %0,%3,%h4,%h2,%h1\";
4271 }")
4272
4273 (define_insn "*insvdi_internal3"
4274   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
4275                          (match_operand:SI 1 "const_int_operand" "i")
4276                          (match_operand:SI 2 "const_int_operand" "i"))
4277         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4278                      (match_operand:SI 4 "const_int_operand" "i")))]
4279   "TARGET_POWERPC64
4280    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
4281   "*
4282 {
4283   int shift = INTVAL (operands[4]) & 63;
4284   int start = (INTVAL (operands[2]) & 63) - 32;
4285   int size = INTVAL (operands[1]) & 63;
4286
4287   operands[4] = GEN_INT (64 - shift - start - size);
4288   operands[2] = GEN_INT (start);
4289   operands[1] = GEN_INT (start + size - 1);
4290   return \"rlwimi %0,%3,%h4,%h2,%h1\";
4291 }")
4292
4293 (define_expand "extzv"
4294   [(set (match_operand 0 "gpc_reg_operand" "")
4295         (zero_extract (match_operand 1 "gpc_reg_operand" "")
4296                        (match_operand:SI 2 "const_int_operand" "")
4297                        (match_operand:SI 3 "const_int_operand" "")))]
4298   ""
4299   "
4300 {
4301   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
4302      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
4303      compiler if the address of the structure is taken later.  */
4304   if (GET_CODE (operands[0]) == SUBREG
4305       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
4306     FAIL;
4307
4308   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
4309     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
4310   else
4311     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
4312   DONE;
4313 }")
4314
4315 (define_insn "extzvsi"
4316   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4317         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4318                          (match_operand:SI 2 "const_int_operand" "i")
4319                          (match_operand:SI 3 "const_int_operand" "i")))]
4320   ""
4321   "*
4322 {
4323   int start = INTVAL (operands[3]) & 31;
4324   int size = INTVAL (operands[2]) & 31;
4325
4326   if (start + size >= 32)
4327     operands[3] = const0_rtx;
4328   else
4329     operands[3] = GEN_INT (start + size);
4330   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
4331 }")
4332
4333 (define_insn "*extzvsi_internal1"
4334   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4335         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4336                          (match_operand:SI 2 "const_int_operand" "i,i")
4337                          (match_operand:SI 3 "const_int_operand" "i,i"))
4338                     (const_int 0)))
4339    (clobber (match_scratch:SI 4 "=r,r"))]
4340   ""
4341   "*
4342 {
4343   int start = INTVAL (operands[3]) & 31;
4344   int size = INTVAL (operands[2]) & 31;
4345
4346   /* Force split for non-cc0 compare.  */
4347   if (which_alternative == 1)
4348      return \"#\";
4349
4350   /* If the bit-field being tested fits in the upper or lower half of a
4351      word, it is possible to use andiu. or andil. to test it.  This is
4352      useful because the condition register set-use delay is smaller for
4353      andi[ul]. than for rlinm.  This doesn't work when the starting bit
4354      position is 0 because the LT and GT bits may be set wrong.  */
4355
4356   if ((start > 0 && start + size <= 16) || start >= 16)
4357     {
4358       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
4359                               - (1 << (16 - (start & 15) - size))));
4360       if (start < 16)
4361         return \"{andiu.|andis.} %4,%1,%3\";
4362       else
4363         return \"{andil.|andi.} %4,%1,%3\";
4364     }
4365
4366   if (start + size >= 32)
4367     operands[3] = const0_rtx;
4368   else
4369     operands[3] = GEN_INT (start + size);
4370   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
4371 }"
4372   [(set_attr "type" "delayed_compare")
4373    (set_attr "length" "4,8")])
4374
4375 (define_split
4376   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4377         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
4378                          (match_operand:SI 2 "const_int_operand" "")
4379                          (match_operand:SI 3 "const_int_operand" ""))
4380                     (const_int 0)))
4381    (clobber (match_scratch:SI 4 ""))]
4382   "reload_completed"
4383   [(set (match_dup 4)
4384         (zero_extract:SI (match_dup 1) (match_dup 2)
4385                          (match_dup 3)))
4386    (set (match_dup 0)
4387         (compare:CC (match_dup 4)
4388                     (const_int 0)))]
4389   "")
4390
4391 (define_insn "*extzvsi_internal2"
4392   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4393         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4394                          (match_operand:SI 2 "const_int_operand" "i,i")
4395                          (match_operand:SI 3 "const_int_operand" "i,i"))
4396                     (const_int 0)))
4397    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4398         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
4399   ""
4400   "*
4401 {
4402   int start = INTVAL (operands[3]) & 31;
4403   int size = INTVAL (operands[2]) & 31;
4404
4405   /* Force split for non-cc0 compare.  */
4406   if (which_alternative == 1)
4407      return \"#\";
4408
4409   /* Since we are using the output value, we can't ignore any need for
4410      a shift.  The bit-field must end at the LSB.  */
4411   if (start >= 16 && start + size == 32)
4412     {
4413       operands[3] = GEN_INT ((1 << size) - 1);
4414       return \"{andil.|andi.} %0,%1,%3\";
4415     }
4416
4417   if (start + size >= 32)
4418     operands[3] = const0_rtx;
4419   else
4420     operands[3] = GEN_INT (start + size);
4421   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
4422 }"
4423   [(set_attr "type" "delayed_compare")
4424    (set_attr "length" "4,8")])
4425
4426 (define_split
4427   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4428         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
4429                          (match_operand:SI 2 "const_int_operand" "")
4430                          (match_operand:SI 3 "const_int_operand" ""))
4431                     (const_int 0)))
4432    (set (match_operand:SI 0 "gpc_reg_operand" "")
4433         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
4434   "reload_completed"
4435   [(set (match_dup 0)
4436         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
4437    (set (match_dup 4)
4438         (compare:CC (match_dup 0)
4439                     (const_int 0)))]
4440   "")
4441
4442 (define_insn "extzvdi"
4443   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4444         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4445                          (match_operand:SI 2 "const_int_operand" "i")
4446                          (match_operand:SI 3 "const_int_operand" "i")))]
4447   "TARGET_POWERPC64"
4448   "*
4449 {
4450   int start = INTVAL (operands[3]) & 63;
4451   int size = INTVAL (operands[2]) & 63;
4452
4453   if (start + size >= 64)
4454     operands[3] = const0_rtx;
4455   else
4456     operands[3] = GEN_INT (start + size);
4457   operands[2] = GEN_INT (64 - size);
4458   return \"rldicl %0,%1,%3,%2\";
4459 }")
4460
4461 (define_insn "*extzvdi_internal1"
4462   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
4463         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4464                          (match_operand:SI 2 "const_int_operand" "i")
4465                          (match_operand:SI 3 "const_int_operand" "i"))
4466                     (const_int 0)))
4467    (clobber (match_scratch:DI 4 "=r"))]
4468   "TARGET_64BIT && rs6000_gen_cell_microcode"
4469   "*
4470 {
4471   int start = INTVAL (operands[3]) & 63;
4472   int size = INTVAL (operands[2]) & 63;
4473
4474   if (start + size >= 64)
4475     operands[3] = const0_rtx;
4476   else
4477     operands[3] = GEN_INT (start + size);
4478   operands[2] = GEN_INT (64 - size);
4479   return \"rldicl. %4,%1,%3,%2\";
4480 }"
4481   [(set_attr "type" "compare")])
4482
4483 (define_insn "*extzvdi_internal2"
4484   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
4485         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4486                          (match_operand:SI 2 "const_int_operand" "i")
4487                          (match_operand:SI 3 "const_int_operand" "i"))
4488                     (const_int 0)))
4489    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4490         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
4491   "TARGET_64BIT && rs6000_gen_cell_microcode"
4492   "*
4493 {
4494   int start = INTVAL (operands[3]) & 63;
4495   int size = INTVAL (operands[2]) & 63;
4496
4497   if (start + size >= 64)
4498     operands[3] = const0_rtx;
4499   else
4500     operands[3] = GEN_INT (start + size);
4501   operands[2] = GEN_INT (64 - size);
4502   return \"rldicl. %0,%1,%3,%2\";
4503 }"
4504   [(set_attr "type" "compare")])
4505
4506 (define_insn "rotlsi3"
4507   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4508         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4509                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4510   ""
4511   "@
4512    {rlnm|rlwnm} %0,%1,%2,0xffffffff
4513    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
4514   [(set_attr "type" "var_shift_rotate,integer")])
4515
4516 (define_insn "*rotlsi3_64"
4517   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4518         (zero_extend:DI
4519             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4520                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4521   "TARGET_64BIT"
4522   "@
4523    {rlnm|rlwnm} %0,%1,%2,0xffffffff
4524    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
4525   [(set_attr "type" "var_shift_rotate,integer")])
4526
4527 (define_insn "*rotlsi3_internal2"
4528   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4529         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4530                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4531                     (const_int 0)))
4532    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4533   ""
4534   "@
4535    {rlnm.|rlwnm.} %3,%1,%2,0xffffffff
4536    {rlinm.|rlwinm.} %3,%1,%h2,0xffffffff
4537    #
4538    #"
4539   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4540    (set_attr "length" "4,4,8,8")])
4541
4542 (define_split
4543   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4544         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4545                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4546                     (const_int 0)))
4547    (clobber (match_scratch:SI 3 ""))]
4548   "reload_completed"
4549   [(set (match_dup 3)
4550         (rotate:SI (match_dup 1) (match_dup 2)))
4551    (set (match_dup 0)
4552         (compare:CC (match_dup 3)
4553                     (const_int 0)))]
4554   "")
4555
4556 (define_insn "*rotlsi3_internal3"
4557   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4558         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4559                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4560                     (const_int 0)))
4561    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4562         (rotate:SI (match_dup 1) (match_dup 2)))]
4563   ""
4564   "@
4565    {rlnm.|rlwnm.} %0,%1,%2,0xffffffff
4566    {rlinm.|rlwinm.} %0,%1,%h2,0xffffffff
4567    #
4568    #"
4569   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4570    (set_attr "length" "4,4,8,8")])
4571
4572 (define_split
4573   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4574         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4575                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4576                     (const_int 0)))
4577    (set (match_operand:SI 0 "gpc_reg_operand" "")
4578         (rotate:SI (match_dup 1) (match_dup 2)))]
4579   "reload_completed"
4580   [(set (match_dup 0)
4581         (rotate:SI (match_dup 1) (match_dup 2)))
4582    (set (match_dup 3)
4583         (compare:CC (match_dup 0)
4584                     (const_int 0)))]
4585   "")
4586
4587 (define_insn "*rotlsi3_internal4"
4588   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4589         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4590                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
4591                 (match_operand:SI 3 "mask_operand" "n,n")))]
4592   ""
4593   "@
4594    {rlnm|rlwnm} %0,%1,%2,%m3,%M3
4595    {rlinm|rlwinm} %0,%1,%h2,%m3,%M3"
4596   [(set_attr "type" "var_shift_rotate,integer")])
4597
4598 (define_insn "*rotlsi3_internal5"
4599   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4600         (compare:CC (and:SI
4601                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4602                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4603                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4604                     (const_int 0)))
4605    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
4606   ""
4607   "@
4608    {rlnm.|rlwnm.} %4,%1,%2,%m3,%M3
4609    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4610    #
4611    #"
4612   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4613    (set_attr "length" "4,4,8,8")])
4614
4615 (define_split
4616   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4617         (compare:CC (and:SI
4618                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4619                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4620                      (match_operand:SI 3 "mask_operand" ""))
4621                     (const_int 0)))
4622    (clobber (match_scratch:SI 4 ""))]
4623   "reload_completed"
4624   [(set (match_dup 4)
4625         (and:SI (rotate:SI (match_dup 1)
4626                                 (match_dup 2))
4627                      (match_dup 3)))
4628    (set (match_dup 0)
4629         (compare:CC (match_dup 4)
4630                     (const_int 0)))]
4631   "")
4632
4633 (define_insn "*rotlsi3_internal6"
4634   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
4635         (compare:CC (and:SI
4636                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4637                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4638                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4639                     (const_int 0)))
4640    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4641         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4642   ""
4643   "@
4644    {rlnm.|rlwnm.} %0,%1,%2,%m3,%M3
4645    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4646    #
4647    #"
4648   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4649    (set_attr "length" "4,4,8,8")])
4650
4651 (define_split
4652   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4653         (compare:CC (and:SI
4654                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4655                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4656                      (match_operand:SI 3 "mask_operand" ""))
4657                     (const_int 0)))
4658    (set (match_operand:SI 0 "gpc_reg_operand" "")
4659         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4660   "reload_completed"
4661   [(set (match_dup 0)
4662         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4663    (set (match_dup 4)
4664         (compare:CC (match_dup 0)
4665                     (const_int 0)))]
4666   "")
4667
4668 (define_insn "*rotlsi3_internal7"
4669   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4670         (zero_extend:SI
4671          (subreg:QI
4672           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4673                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4674   ""
4675   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff"
4676   [(set (attr "cell_micro")
4677      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4678         (const_string "not")
4679         (const_string "always")))])
4680
4681 (define_insn "*rotlsi3_internal8"
4682   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4683         (compare:CC (zero_extend:SI
4684                      (subreg:QI
4685                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4686                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4687                     (const_int 0)))
4688    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4689   ""
4690   "@
4691    {rlnm.|rlwnm.} %3,%1,%2,0xff
4692    {rlinm.|rlwinm.} %3,%1,%h2,0xff
4693    #
4694    #"
4695   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4696    (set_attr "length" "4,4,8,8")])
4697
4698 (define_split
4699   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4700         (compare:CC (zero_extend:SI
4701                      (subreg:QI
4702                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4703                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4704                     (const_int 0)))
4705    (clobber (match_scratch:SI 3 ""))]
4706   "reload_completed"
4707   [(set (match_dup 3)
4708         (zero_extend:SI (subreg:QI
4709                       (rotate:SI (match_dup 1)
4710                                  (match_dup 2)) 0)))
4711    (set (match_dup 0)
4712         (compare:CC (match_dup 3)
4713                     (const_int 0)))]
4714   "")
4715
4716 (define_insn "*rotlsi3_internal9"
4717   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4718         (compare:CC (zero_extend:SI
4719                      (subreg:QI
4720                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4721                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4722                     (const_int 0)))
4723    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4724         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4725   ""
4726   "@
4727    {rlnm.|rlwnm.} %0,%1,%2,0xff
4728    {rlinm.|rlwinm.} %0,%1,%h2,0xff
4729    #
4730    #"
4731   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4732    (set_attr "length" "4,4,8,8")])
4733
4734 (define_split
4735   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4736         (compare:CC (zero_extend:SI
4737                      (subreg:QI
4738                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4739                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4740                     (const_int 0)))
4741    (set (match_operand:SI 0 "gpc_reg_operand" "")
4742         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4743   "reload_completed"
4744   [(set (match_dup 0)
4745         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4746    (set (match_dup 3)
4747         (compare:CC (match_dup 0)
4748                     (const_int 0)))]
4749   "")
4750
4751 (define_insn "*rotlsi3_internal10"
4752   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4753         (zero_extend:SI
4754          (subreg:HI
4755           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4756                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4757   ""
4758   "@
4759    {rlnm|rlwnm} %0,%1,%2,0xffff
4760    {rlinm|rlwinm} %0,%1,%h2,0xffff"
4761   [(set_attr "type" "var_shift_rotate,integer")])
4762
4763
4764 (define_insn "*rotlsi3_internal11"
4765   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4766         (compare:CC (zero_extend:SI
4767                      (subreg:HI
4768                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4769                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4770                     (const_int 0)))
4771    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4772   ""
4773   "@
4774    {rlnm.|rlwnm.} %3,%1,%2,0xffff
4775    {rlinm.|rlwinm.} %3,%1,%h2,0xffff
4776    #
4777    #"
4778   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4779    (set_attr "length" "4,4,8,8")])
4780
4781 (define_split
4782   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4783         (compare:CC (zero_extend:SI
4784                      (subreg:HI
4785                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4786                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4787                     (const_int 0)))
4788    (clobber (match_scratch:SI 3 ""))]
4789   "reload_completed"
4790   [(set (match_dup 3)
4791         (zero_extend:SI (subreg:HI
4792                       (rotate:SI (match_dup 1)
4793                                  (match_dup 2)) 0)))
4794    (set (match_dup 0)
4795         (compare:CC (match_dup 3)
4796                     (const_int 0)))]
4797   "")
4798
4799 (define_insn "*rotlsi3_internal12"
4800   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4801         (compare:CC (zero_extend:SI
4802                      (subreg:HI
4803                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4804                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4805                     (const_int 0)))
4806    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4807         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4808   ""
4809   "@
4810    {rlnm.|rlwnm.} %0,%1,%2,0xffff
4811    {rlinm.|rlwinm.} %0,%1,%h2,0xffff
4812    #
4813    #"
4814   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4815    (set_attr "length" "4,4,8,8")])
4816
4817 (define_split
4818   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4819         (compare:CC (zero_extend:SI
4820                      (subreg:HI
4821                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4822                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4823                     (const_int 0)))
4824    (set (match_operand:SI 0 "gpc_reg_operand" "")
4825         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4826   "reload_completed"
4827   [(set (match_dup 0)
4828         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4829    (set (match_dup 3)
4830         (compare:CC (match_dup 0)
4831                     (const_int 0)))]
4832   "")
4833
4834 ;; Note that we use "sle." instead of "sl." so that we can set
4835 ;; SHIFT_COUNT_TRUNCATED.
4836
4837 (define_expand "ashlsi3"
4838   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4839    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4840    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4841   ""
4842   "
4843 {
4844   if (TARGET_POWER)
4845     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4846   else
4847     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4848   DONE;
4849 }")
4850
4851 (define_insn "ashlsi3_power"
4852   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4853         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4854                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4855    (clobber (match_scratch:SI 3 "=q,X"))]
4856   "TARGET_POWER"
4857   "@
4858    sle %0,%1,%2
4859    {sli|slwi} %0,%1,%h2")
4860
4861 (define_insn "ashlsi3_no_power"
4862   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4863         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4864                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4865   "! TARGET_POWER"
4866   "@
4867    {sl|slw} %0,%1,%2
4868    {sli|slwi} %0,%1,%h2"
4869   [(set_attr "type" "var_shift_rotate,shift")])
4870
4871 (define_insn "*ashlsi3_64"
4872   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4873         (zero_extend:DI
4874             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4875                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4876   "TARGET_POWERPC64"
4877   "@
4878    {sl|slw} %0,%1,%2
4879    {sli|slwi} %0,%1,%h2"
4880   [(set_attr "type" "var_shift_rotate,shift")])
4881
4882 (define_insn ""
4883   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4884         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4885                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4886                     (const_int 0)))
4887    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4888    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4889   "TARGET_POWER"
4890   "@
4891    sle. %3,%1,%2
4892    {sli.|slwi.} %3,%1,%h2
4893    #
4894    #"
4895   [(set_attr "type" "delayed_compare")
4896    (set_attr "length" "4,4,8,8")])
4897
4898 (define_split
4899   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4900         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4901                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4902                     (const_int 0)))
4903    (clobber (match_scratch:SI 3 ""))
4904    (clobber (match_scratch:SI 4 ""))]
4905   "TARGET_POWER && reload_completed"
4906   [(parallel [(set (match_dup 3)
4907         (ashift:SI (match_dup 1) (match_dup 2)))
4908    (clobber (match_dup 4))])
4909    (set (match_dup 0)
4910         (compare:CC (match_dup 3)
4911                     (const_int 0)))]
4912   "")
4913
4914 (define_insn ""
4915   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4916         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4917                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4918                     (const_int 0)))
4919    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4920   "! TARGET_POWER && TARGET_32BIT"
4921   "@
4922    {sl.|slw.} %3,%1,%2
4923    {sli.|slwi.} %3,%1,%h2
4924    #
4925    #"
4926   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4927    (set_attr "length" "4,4,8,8")])
4928
4929 (define_split
4930   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4931         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4932                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4933                     (const_int 0)))
4934    (clobber (match_scratch:SI 3 ""))]
4935   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4936   [(set (match_dup 3)
4937         (ashift:SI (match_dup 1) (match_dup 2)))
4938    (set (match_dup 0)
4939         (compare:CC (match_dup 3)
4940                     (const_int 0)))]
4941   "")
4942
4943 (define_insn ""
4944   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4945         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4946                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4947                     (const_int 0)))
4948    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4949         (ashift:SI (match_dup 1) (match_dup 2)))
4950    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4951   "TARGET_POWER"
4952   "@
4953    sle. %0,%1,%2
4954    {sli.|slwi.} %0,%1,%h2
4955    #
4956    #"
4957   [(set_attr "type" "delayed_compare")
4958    (set_attr "length" "4,4,8,8")])
4959
4960 (define_split
4961   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4962         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4963                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4964                     (const_int 0)))
4965    (set (match_operand:SI 0 "gpc_reg_operand" "")
4966         (ashift:SI (match_dup 1) (match_dup 2)))
4967    (clobber (match_scratch:SI 4 ""))]
4968   "TARGET_POWER && reload_completed"
4969   [(parallel [(set (match_dup 0)
4970         (ashift:SI (match_dup 1) (match_dup 2)))
4971    (clobber (match_dup 4))])
4972    (set (match_dup 3)
4973         (compare:CC (match_dup 0)
4974                     (const_int 0)))]
4975   "")
4976
4977 (define_insn ""
4978   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4979         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4980                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4981                     (const_int 0)))
4982    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4983         (ashift:SI (match_dup 1) (match_dup 2)))]
4984   "! TARGET_POWER && TARGET_32BIT"
4985   "@
4986    {sl.|slw.} %0,%1,%2
4987    {sli.|slwi.} %0,%1,%h2
4988    #
4989    #"
4990   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4991    (set_attr "length" "4,4,8,8")])
4992
4993 (define_split
4994   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4995         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4996                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4997                     (const_int 0)))
4998    (set (match_operand:SI 0 "gpc_reg_operand" "")
4999         (ashift:SI (match_dup 1) (match_dup 2)))]
5000   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5001   [(set (match_dup 0)
5002         (ashift:SI (match_dup 1) (match_dup 2)))
5003    (set (match_dup 3)
5004         (compare:CC (match_dup 0)
5005                     (const_int 0)))]
5006   "")
5007
5008 (define_insn "rlwinm"
5009   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5010         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5011                            (match_operand:SI 2 "const_int_operand" "i"))
5012                 (match_operand:SI 3 "mask_operand" "n")))]
5013   "includes_lshift_p (operands[2], operands[3])"
5014   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
5015
5016 (define_insn ""
5017   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5018         (compare:CC
5019          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5020                             (match_operand:SI 2 "const_int_operand" "i,i"))
5021                  (match_operand:SI 3 "mask_operand" "n,n"))
5022          (const_int 0)))
5023    (clobber (match_scratch:SI 4 "=r,r"))]
5024   "includes_lshift_p (operands[2], operands[3])"
5025   "@
5026    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
5027    #"
5028   [(set_attr "type" "delayed_compare")
5029    (set_attr "length" "4,8")])
5030
5031 (define_split
5032   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5033         (compare:CC
5034          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
5035                             (match_operand:SI 2 "const_int_operand" ""))
5036                  (match_operand:SI 3 "mask_operand" ""))
5037          (const_int 0)))
5038    (clobber (match_scratch:SI 4 ""))]
5039   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
5040   [(set (match_dup 4)
5041         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
5042                  (match_dup 3)))
5043    (set (match_dup 0)
5044         (compare:CC (match_dup 4)
5045                     (const_int 0)))]
5046   "")
5047
5048 (define_insn ""
5049   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
5050         (compare:CC
5051          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5052                             (match_operand:SI 2 "const_int_operand" "i,i"))
5053                  (match_operand:SI 3 "mask_operand" "n,n"))
5054          (const_int 0)))
5055    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5056         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5057   "includes_lshift_p (operands[2], operands[3])"
5058   "@
5059    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
5060    #"
5061   [(set_attr "type" "delayed_compare")
5062    (set_attr "length" "4,8")])
5063
5064 (define_split
5065   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
5066         (compare:CC
5067          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
5068                             (match_operand:SI 2 "const_int_operand" ""))
5069                  (match_operand:SI 3 "mask_operand" ""))
5070          (const_int 0)))
5071    (set (match_operand:SI 0 "gpc_reg_operand" "")
5072         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5073   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
5074   [(set (match_dup 0)
5075         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
5076    (set (match_dup 4)
5077         (compare:CC (match_dup 0)
5078                     (const_int 0)))]
5079   "")
5080
5081 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
5082 ;; "sli x,x,0".
5083 (define_expand "lshrsi3"
5084   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
5085    (use (match_operand:SI 1 "gpc_reg_operand" ""))
5086    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
5087   ""
5088   "
5089 {
5090   if (TARGET_POWER)
5091     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
5092   else
5093     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
5094   DONE;
5095 }")
5096
5097 (define_insn "lshrsi3_power"
5098   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
5099         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
5100                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
5101    (clobber (match_scratch:SI 3 "=q,X,X"))]
5102   "TARGET_POWER"
5103   "@
5104   sre %0,%1,%2
5105   mr %0,%1
5106   {s%A2i|s%A2wi} %0,%1,%h2")
5107
5108 (define_insn "lshrsi3_no_power"
5109   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
5110         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
5111                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
5112   "! TARGET_POWER"
5113   "@
5114   mr %0,%1
5115   {sr|srw} %0,%1,%2
5116   {sri|srwi} %0,%1,%h2"
5117   [(set_attr "type" "integer,var_shift_rotate,shift")])
5118
5119 (define_insn "*lshrsi3_64"
5120   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5121         (zero_extend:DI
5122             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5123                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5124   "TARGET_POWERPC64"
5125   "@
5126   {sr|srw} %0,%1,%2
5127   {sri|srwi} %0,%1,%h2"
5128   [(set_attr "type" "var_shift_rotate,shift")])
5129
5130 (define_insn ""
5131   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5132         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5133                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
5134                     (const_int 0)))
5135    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
5136    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
5137   "TARGET_POWER"
5138   "@
5139   sre. %3,%1,%2
5140   mr. %1,%1
5141   {s%A2i.|s%A2wi.} %3,%1,%h2
5142   #
5143   #
5144   #"
5145   [(set_attr "type" "delayed_compare")
5146    (set_attr "length" "4,4,4,8,8,8")])
5147
5148 (define_split
5149   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5150         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5151                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5152                     (const_int 0)))
5153    (clobber (match_scratch:SI 3 ""))
5154    (clobber (match_scratch:SI 4 ""))]
5155   "TARGET_POWER && reload_completed"
5156   [(parallel [(set (match_dup 3)
5157         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5158    (clobber (match_dup 4))])
5159    (set (match_dup 0)
5160         (compare:CC (match_dup 3)
5161                     (const_int 0)))]
5162   "")
5163
5164 (define_insn ""
5165   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5166         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5167                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
5168                     (const_int 0)))
5169    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
5170   "! TARGET_POWER && TARGET_32BIT"
5171   "@
5172    mr. %1,%1
5173    {sr.|srw.} %3,%1,%2
5174    {sri.|srwi.} %3,%1,%h2
5175    #
5176    #
5177    #"
5178   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5179    (set_attr "length" "4,4,4,8,8,8")])
5180
5181 (define_split
5182   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5183         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5184                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5185                     (const_int 0)))
5186    (clobber (match_scratch:SI 3 ""))]
5187   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5188   [(set (match_dup 3)
5189         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5190    (set (match_dup 0)
5191         (compare:CC (match_dup 3)
5192                     (const_int 0)))]
5193   "")
5194
5195 (define_insn ""
5196   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5197         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5198                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
5199                     (const_int 0)))
5200    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
5201         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5202    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
5203   "TARGET_POWER"
5204   "@
5205   sre. %0,%1,%2
5206   mr. %0,%1
5207   {s%A2i.|s%A2wi.} %0,%1,%h2
5208   #
5209   #
5210   #"
5211   [(set_attr "type" "delayed_compare")
5212    (set_attr "length" "4,4,4,8,8,8")])
5213
5214 (define_split
5215   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5216         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5217                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5218                     (const_int 0)))
5219    (set (match_operand:SI 0 "gpc_reg_operand" "")
5220         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5221    (clobber (match_scratch:SI 4 ""))]
5222   "TARGET_POWER && reload_completed"
5223   [(parallel [(set (match_dup 0)
5224         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5225    (clobber (match_dup 4))])
5226    (set (match_dup 3)
5227         (compare:CC (match_dup 0)
5228                     (const_int 0)))]
5229   "")
5230
5231 (define_insn ""
5232   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
5233         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
5234                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
5235                     (const_int 0)))
5236    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
5237         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
5238   "! TARGET_POWER && TARGET_32BIT"
5239   "@
5240    mr. %0,%1
5241    {sr.|srw.} %0,%1,%2
5242    {sri.|srwi.} %0,%1,%h2
5243    #
5244    #
5245    #"
5246   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5247    (set_attr "length" "4,4,4,8,8,8")])
5248
5249 (define_split
5250   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5251         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5252                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5253                     (const_int 0)))
5254    (set (match_operand:SI 0 "gpc_reg_operand" "")
5255         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
5256   "! TARGET_POWER && TARGET_32BIT && reload_completed"
5257   [(set (match_dup 0)
5258         (lshiftrt:SI (match_dup 1) (match_dup 2)))
5259    (set (match_dup 3)
5260         (compare:CC (match_dup 0)
5261                     (const_int 0)))]
5262   "")
5263
5264 (define_insn ""
5265   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5266         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5267                              (match_operand:SI 2 "const_int_operand" "i"))
5268                 (match_operand:SI 3 "mask_operand" "n")))]
5269   "includes_rshift_p (operands[2], operands[3])"
5270   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
5271
5272 (define_insn ""
5273   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5274         (compare:CC
5275          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5276                               (match_operand:SI 2 "const_int_operand" "i,i"))
5277                  (match_operand:SI 3 "mask_operand" "n,n"))
5278          (const_int 0)))
5279    (clobber (match_scratch:SI 4 "=r,r"))]
5280   "includes_rshift_p (operands[2], operands[3])"
5281   "@
5282    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
5283    #"
5284   [(set_attr "type" "delayed_compare")
5285    (set_attr "length" "4,8")])
5286
5287 (define_split
5288   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5289         (compare:CC
5290          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5291                               (match_operand:SI 2 "const_int_operand" ""))
5292                  (match_operand:SI 3 "mask_operand" ""))
5293          (const_int 0)))
5294    (clobber (match_scratch:SI 4 ""))]
5295   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
5296   [(set (match_dup 4)
5297         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
5298                  (match_dup 3)))
5299    (set (match_dup 0)
5300         (compare:CC (match_dup 4)
5301                     (const_int 0)))]
5302   "")
5303
5304 (define_insn ""
5305   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
5306         (compare:CC
5307          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5308                               (match_operand:SI 2 "const_int_operand" "i,i"))
5309                  (match_operand:SI 3 "mask_operand" "n,n"))
5310          (const_int 0)))
5311    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5312         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5313   "includes_rshift_p (operands[2], operands[3])"
5314   "@
5315    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
5316    #"
5317   [(set_attr "type" "delayed_compare")
5318    (set_attr "length" "4,8")])
5319
5320 (define_split
5321   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
5322         (compare:CC
5323          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5324                               (match_operand:SI 2 "const_int_operand" ""))
5325                  (match_operand:SI 3 "mask_operand" ""))
5326          (const_int 0)))
5327    (set (match_operand:SI 0 "gpc_reg_operand" "")
5328         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
5329   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
5330   [(set (match_dup 0)
5331         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
5332    (set (match_dup 4)
5333         (compare:CC (match_dup 0)
5334                     (const_int 0)))]
5335   "")
5336
5337 (define_insn ""
5338   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5339         (zero_extend:SI
5340          (subreg:QI
5341           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5342                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
5343   "includes_rshift_p (operands[2], GEN_INT (255))"
5344   "{rlinm|rlwinm} %0,%1,%s2,0xff")
5345
5346 (define_insn ""
5347   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5348         (compare:CC
5349          (zero_extend:SI
5350           (subreg:QI
5351            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5352                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5353          (const_int 0)))
5354    (clobber (match_scratch:SI 3 "=r,r"))]
5355   "includes_rshift_p (operands[2], GEN_INT (255))"
5356   "@
5357    {rlinm.|rlwinm.} %3,%1,%s2,0xff
5358    #"
5359   [(set_attr "type" "delayed_compare")
5360    (set_attr "length" "4,8")])
5361
5362 (define_split
5363   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5364         (compare:CC
5365          (zero_extend:SI
5366           (subreg:QI
5367            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5368                         (match_operand:SI 2 "const_int_operand" "")) 0))
5369          (const_int 0)))
5370    (clobber (match_scratch:SI 3 ""))]
5371   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
5372   [(set (match_dup 3)
5373         (zero_extend:SI (subreg:QI
5374            (lshiftrt:SI (match_dup 1)
5375                         (match_dup 2)) 0)))
5376    (set (match_dup 0)
5377         (compare:CC (match_dup 3)
5378                     (const_int 0)))]
5379   "")
5380
5381 (define_insn ""
5382   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5383         (compare:CC
5384          (zero_extend:SI
5385           (subreg:QI
5386            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5387                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5388          (const_int 0)))
5389    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5390         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5391   "includes_rshift_p (operands[2], GEN_INT (255))"
5392   "@
5393    {rlinm.|rlwinm.} %0,%1,%s2,0xff
5394    #"
5395   [(set_attr "type" "delayed_compare")
5396    (set_attr "length" "4,8")])
5397
5398 (define_split
5399   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5400         (compare:CC
5401          (zero_extend:SI
5402           (subreg:QI
5403            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5404                         (match_operand:SI 2 "const_int_operand" "")) 0))
5405          (const_int 0)))
5406    (set (match_operand:SI 0 "gpc_reg_operand" "")
5407         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5408   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
5409   [(set (match_dup 0)
5410         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5411    (set (match_dup 3)
5412         (compare:CC (match_dup 0)
5413                     (const_int 0)))]
5414   "")
5415
5416 (define_insn ""
5417   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5418         (zero_extend:SI
5419          (subreg:HI
5420           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
5421                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
5422   "includes_rshift_p (operands[2], GEN_INT (65535))"
5423   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
5424
5425 (define_insn ""
5426   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5427         (compare:CC
5428          (zero_extend:SI
5429           (subreg:HI
5430            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5431                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5432          (const_int 0)))
5433    (clobber (match_scratch:SI 3 "=r,r"))]
5434   "includes_rshift_p (operands[2], GEN_INT (65535))"
5435   "@
5436    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
5437    #"
5438   [(set_attr "type" "delayed_compare")
5439    (set_attr "length" "4,8")])
5440
5441 (define_split
5442   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5443         (compare:CC
5444          (zero_extend:SI
5445           (subreg:HI
5446            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5447                         (match_operand:SI 2 "const_int_operand" "")) 0))
5448          (const_int 0)))
5449    (clobber (match_scratch:SI 3 ""))]
5450   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5451   [(set (match_dup 3)
5452         (zero_extend:SI (subreg:HI
5453            (lshiftrt:SI (match_dup 1)
5454                         (match_dup 2)) 0)))
5455    (set (match_dup 0)
5456         (compare:CC (match_dup 3)
5457                     (const_int 0)))]
5458   "")
5459
5460 (define_insn ""
5461   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5462         (compare:CC
5463          (zero_extend:SI
5464           (subreg:HI
5465            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5466                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
5467          (const_int 0)))
5468    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5469         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5470   "includes_rshift_p (operands[2], GEN_INT (65535))"
5471   "@
5472    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
5473    #"
5474   [(set_attr "type" "delayed_compare")
5475    (set_attr "length" "4,8")])
5476
5477 (define_split
5478   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5479         (compare:CC
5480          (zero_extend:SI
5481           (subreg:HI
5482            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5483                         (match_operand:SI 2 "const_int_operand" "")) 0))
5484          (const_int 0)))
5485    (set (match_operand:SI 0 "gpc_reg_operand" "")
5486         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5487   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5488   [(set (match_dup 0)
5489         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5490    (set (match_dup 3)
5491         (compare:CC (match_dup 0)
5492                     (const_int 0)))]
5493   "")
5494
5495 (define_insn ""
5496   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5497                          (const_int 1)
5498                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5499         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5500                      (const_int 31)))]
5501   "TARGET_POWER"
5502   "rrib %0,%1,%2")
5503
5504 (define_insn ""
5505   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5506                          (const_int 1)
5507                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5508         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5509                      (const_int 31)))]
5510   "TARGET_POWER"
5511   "rrib %0,%1,%2")
5512
5513 (define_insn ""
5514   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
5515                          (const_int 1)
5516                          (match_operand:SI 1 "gpc_reg_operand" "r"))
5517         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
5518                          (const_int 1)
5519                          (const_int 0)))]
5520   "TARGET_POWER"
5521   "rrib %0,%1,%2")
5522
5523 (define_expand "ashrsi3"
5524   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5525         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5526                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
5527   ""
5528   "
5529 {
5530   if (TARGET_POWER)
5531     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
5532   else
5533     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
5534   DONE;
5535 }")
5536
5537 (define_insn "ashrsi3_power"
5538   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5539         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5540                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
5541    (clobber (match_scratch:SI 3 "=q,X"))]
5542   "TARGET_POWER"
5543   "@
5544    srea %0,%1,%2
5545    {srai|srawi} %0,%1,%h2"
5546   [(set_attr "type" "shift")])
5547
5548 (define_insn "ashrsi3_no_power"
5549   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5550         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5551                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
5552   "! TARGET_POWER"
5553   "@
5554    {sra|sraw} %0,%1,%2
5555    {srai|srawi} %0,%1,%h2"
5556   [(set_attr "type" "var_shift_rotate,shift")])
5557
5558 (define_insn "*ashrsi3_64"
5559   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5560         (sign_extend:DI
5561             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5562                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5563   "TARGET_POWERPC64"
5564   "@
5565    {sra|sraw} %0,%1,%2
5566    {srai|srawi} %0,%1,%h2"
5567   [(set_attr "type" "var_shift_rotate,shift")])
5568
5569 (define_insn ""
5570   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5571         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5572                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5573                     (const_int 0)))
5574    (clobber (match_scratch:SI 3 "=r,r,r,r"))
5575    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5576   "TARGET_POWER"
5577   "@
5578    srea. %3,%1,%2
5579    {srai.|srawi.} %3,%1,%h2
5580    #
5581    #"
5582   [(set_attr "type" "delayed_compare")
5583    (set_attr "length" "4,4,8,8")])
5584
5585 (define_split
5586   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5587         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5588                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5589                     (const_int 0)))
5590    (clobber (match_scratch:SI 3 ""))
5591    (clobber (match_scratch:SI 4 ""))]
5592   "TARGET_POWER && reload_completed"
5593   [(parallel [(set (match_dup 3)
5594         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5595    (clobber (match_dup 4))])
5596    (set (match_dup 0)
5597         (compare:CC (match_dup 3)
5598                     (const_int 0)))]
5599   "")
5600
5601 (define_insn ""
5602   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5603         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5604                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5605                     (const_int 0)))
5606    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
5607   "! TARGET_POWER"
5608   "@
5609    {sra.|sraw.} %3,%1,%2
5610    {srai.|srawi.} %3,%1,%h2
5611    #
5612    #"
5613   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5614    (set_attr "length" "4,4,8,8")])
5615
5616 (define_split
5617   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5618         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5619                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5620                     (const_int 0)))
5621    (clobber (match_scratch:SI 3 ""))]
5622   "! TARGET_POWER && reload_completed"
5623   [(set (match_dup 3)
5624         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5625    (set (match_dup 0)
5626         (compare:CC (match_dup 3)
5627                     (const_int 0)))]
5628   "")
5629
5630 (define_insn ""
5631   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5632         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5633                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5634                     (const_int 0)))
5635    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5636         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5637    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5638   "TARGET_POWER"
5639   "@
5640    srea. %0,%1,%2
5641    {srai.|srawi.} %0,%1,%h2
5642    #
5643    #"
5644   [(set_attr "type" "delayed_compare")
5645    (set_attr "length" "4,4,8,8")])
5646
5647 (define_split
5648   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5649         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5650                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5651                     (const_int 0)))
5652    (set (match_operand:SI 0 "gpc_reg_operand" "")
5653         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5654    (clobber (match_scratch:SI 4 ""))]
5655   "TARGET_POWER && reload_completed"
5656   [(parallel [(set (match_dup 0)
5657         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5658    (clobber (match_dup 4))])
5659    (set (match_dup 3)
5660         (compare:CC (match_dup 0)
5661                     (const_int 0)))]
5662   "")
5663
5664 (define_insn ""
5665   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5666         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5667                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5668                     (const_int 0)))
5669    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5670         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5671   "! TARGET_POWER"
5672   "@
5673    {sra.|sraw.} %0,%1,%2
5674    {srai.|srawi.} %0,%1,%h2
5675    #
5676    #"
5677   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5678    (set_attr "length" "4,4,8,8")])
5679 \f
5680 ;; Builtins to replace a division to generate FRE reciprocal estimate
5681 ;; instructions and the necessary fixup instructions
5682 (define_expand "recip<mode>3"
5683   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5684    (match_operand:RECIPF 1 "gpc_reg_operand" "")
5685    (match_operand:RECIPF 2 "gpc_reg_operand" "")]
5686   "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
5687 {
5688    rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
5689    DONE;
5690 })
5691
5692 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
5693 ;; hardware division.  This is only done before register allocation and with
5694 ;; -ffast-math.  This must appear before the divsf3/divdf3 insns.
5695 (define_split
5696   [(set (match_operand:RECIPF 0 "gpc_reg_operand" "")
5697         (div:RECIPF (match_operand 1 "gpc_reg_operand" "")
5698                     (match_operand 2 "gpc_reg_operand" "")))]
5699   "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
5700    && can_create_pseudo_p () && optimize_insn_for_speed_p ()
5701    && flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math"
5702   [(const_int 0)]
5703 {
5704   rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
5705   DONE;
5706 })
5707
5708 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
5709 ;; appropriate fixup.
5710 (define_expand "rsqrt<mode>2"
5711   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5712    (match_operand:RECIPF 1 "gpc_reg_operand" "")]
5713   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
5714 {
5715   rs6000_emit_swrsqrt (operands[0], operands[1]);
5716   DONE;
5717 })
5718 \f
5719 (define_split
5720   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5721         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5722                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5723                     (const_int 0)))
5724    (set (match_operand:SI 0 "gpc_reg_operand" "")
5725         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5726   "! TARGET_POWER && reload_completed"
5727   [(set (match_dup 0)
5728         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5729    (set (match_dup 3)
5730         (compare:CC (match_dup 0)
5731                     (const_int 0)))]
5732   "")
5733
5734 ;; Floating-point insns, excluding normal data motion.
5735 ;;
5736 ;; PowerPC has a full set of single-precision floating point instructions.
5737 ;;
5738 ;; For the POWER architecture, we pretend that we have both SFmode and
5739 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
5740 ;; The only conversions we will do will be when storing to memory.  In that
5741 ;; case, we will use the "frsp" instruction before storing.
5742 ;;
5743 ;; Note that when we store into a single-precision memory location, we need to
5744 ;; use the frsp insn first.  If the register being stored isn't dead, we
5745 ;; need a scratch register for the frsp.  But this is difficult when the store
5746 ;; is done by reload.  It is not incorrect to do the frsp on the register in
5747 ;; this case, we just lose precision that we would have otherwise gotten but
5748 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
5749
5750 (define_expand "extendsfdf2"
5751   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5752         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5753   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5754   "")
5755
5756 (define_insn_and_split "*extendsfdf2_fpr"
5757   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d")
5758         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
5759   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5760   "@
5761    #
5762    fmr %0,%1
5763    lfs%U1%X1 %0,%1"
5764   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5765   [(const_int 0)]
5766 {
5767   emit_note (NOTE_INSN_DELETED);
5768   DONE;
5769 }
5770   [(set_attr "type" "fp,fp,fpload")])
5771
5772 (define_expand "truncdfsf2"
5773   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5774         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5775   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5776   "")
5777
5778 (define_insn "*truncdfsf2_fpr"
5779   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5780         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5781   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5782   "frsp %0,%1"
5783   [(set_attr "type" "fp")])
5784
5785 (define_insn "aux_truncdfsf2"
5786   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5787         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
5788   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5789   "frsp %0,%1"
5790   [(set_attr "type" "fp")])
5791
5792 (define_expand "negsf2"
5793   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5794         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5795   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5796   "")
5797
5798 (define_insn "*negsf2"
5799   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5800         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5801   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5802   "fneg %0,%1"
5803   [(set_attr "type" "fp")])
5804
5805 (define_expand "abssf2"
5806   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5807         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5808   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5809   "")
5810
5811 (define_insn "*abssf2"
5812   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5813         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5814   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5815   "fabs %0,%1"
5816   [(set_attr "type" "fp")])
5817
5818 (define_insn ""
5819   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5820         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
5821   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5822   "fnabs %0,%1"
5823   [(set_attr "type" "fp")])
5824
5825 (define_expand "addsf3"
5826   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5827         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5828                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5829   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5830   "")
5831
5832 (define_insn ""
5833   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5834         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5835                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5836   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5837   "fadds %0,%1,%2"
5838   [(set_attr "type" "fp")
5839    (set_attr "fp_type" "fp_addsub_s")])
5840
5841 (define_insn ""
5842   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5843         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5844                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5845   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5846   "{fa|fadd} %0,%1,%2"
5847   [(set_attr "type" "fp")])
5848
5849 (define_expand "subsf3"
5850   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5851         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5852                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5853   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5854   "")
5855
5856 (define_insn ""
5857   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5858         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5859                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5860   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5861   "fsubs %0,%1,%2"
5862   [(set_attr "type" "fp")
5863    (set_attr "fp_type" "fp_addsub_s")])
5864
5865 (define_insn ""
5866   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5867         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5868                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5869   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5870   "{fs|fsub} %0,%1,%2"
5871   [(set_attr "type" "fp")])
5872
5873 (define_expand "mulsf3"
5874   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5875         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5876                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5877   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5878   "")
5879
5880 (define_insn ""
5881   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5882         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5883                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5884   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5885   "fmuls %0,%1,%2"
5886   [(set_attr "type" "fp")
5887    (set_attr "fp_type" "fp_mul_s")])
5888
5889 (define_insn ""
5890   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5891         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5892                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5893   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5894   "{fm|fmul} %0,%1,%2"
5895   [(set_attr "type" "dmul")])
5896
5897 (define_expand "divsf3"
5898   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5899         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5900                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5901   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5902   "")
5903
5904 (define_insn ""
5905   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5906         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5907                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5908   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS 
5909    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5910   "fdivs %0,%1,%2"
5911   [(set_attr "type" "sdiv")])
5912
5913 (define_insn ""
5914   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5915         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5916                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5917   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS 
5918    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5919   "{fd|fdiv} %0,%1,%2"
5920   [(set_attr "type" "ddiv")])
5921
5922 (define_insn "fres"
5923   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5924         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5925   "TARGET_FRES"
5926   "fres %0,%1"
5927   [(set_attr "type" "fp")])
5928
5929 ; builtin fmaf support
5930 (define_insn "*fmasf4_fpr"
5931   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5932         (fma: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_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5936 {
5937   return (TARGET_POWERPC
5938           ? "fmadds %0,%1,%2,%3"
5939           : "{fma|fmadd} %0,%1,%2,%3");
5940 }
5941   [(set_attr "type" "fp")
5942    (set_attr "fp_type" "fp_maddsub_s")])
5943
5944 (define_insn "*fmssf4_fpr"
5945   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5946         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5947                 (match_operand:SF 2 "gpc_reg_operand" "f")
5948                 (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5949   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5950 {
5951   return (TARGET_POWERPC
5952           ? "fmsubs %0,%1,%2,%3"
5953           : "{fms|fmsub} %0,%1,%2,%3");
5954 }
5955   [(set_attr "type" "fp")
5956    (set_attr "fp_type" "fp_maddsub_s")])
5957
5958 (define_insn "*nfmasf4_fpr"
5959   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5960         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5961                         (match_operand:SF 2 "gpc_reg_operand" "f")
5962                         (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5963   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5964 {
5965   return (TARGET_POWERPC
5966           ? "fnmadds %0,%1,%2,%3"
5967           : "{fnma|fnmadd} %0,%1,%2,%3");
5968 }
5969   [(set_attr "type" "fp")
5970    (set_attr "fp_type" "fp_maddsub_s")])
5971
5972 (define_insn "*nfmssf4_fpr"
5973   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5974         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5975                         (match_operand:SF 2 "gpc_reg_operand" "f")
5976                         (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f")))))]
5977   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5978 {
5979   return (TARGET_POWERPC
5980           ? "fnmsubs %0,%1,%2,%3"
5981           : "{fnms|fnmsub} %0,%1,%2,%3");
5982 }
5983   [(set_attr "type" "fp")
5984    (set_attr "fp_type" "fp_maddsub_s")])
5985
5986 (define_expand "sqrtsf2"
5987   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5988         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5989   "(TARGET_PPC_GPOPT || TARGET_POWER2 || TARGET_XILINX_FPU)
5990    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5991    && !TARGET_SIMPLE_FPU"
5992   "")
5993
5994 (define_insn ""
5995   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5996         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5997   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU) && TARGET_HARD_FLOAT
5998    && TARGET_FPRS && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5999   "fsqrts %0,%1"
6000   [(set_attr "type" "ssqrt")])
6001
6002 (define_insn ""
6003   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6004         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
6005   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS 
6006    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
6007   "fsqrt %0,%1"
6008   [(set_attr "type" "dsqrt")])
6009
6010 (define_insn "*rsqrtsf_internal1"
6011   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6012         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
6013                    UNSPEC_RSQRT))]
6014   "TARGET_FRSQRTES"
6015   "frsqrtes %0,%1"
6016   [(set_attr "type" "fp")])
6017
6018 (define_expand "copysign<mode>3"
6019   [(set (match_dup 3)
6020         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))
6021    (set (match_dup 4)
6022         (neg:SFDF (abs:SFDF (match_dup 1))))
6023    (set (match_operand:SFDF 0 "gpc_reg_operand" "")
6024         (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand" "")
6025                                (match_dup 5))
6026                          (match_dup 3)
6027                          (match_dup 4)))]
6028   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
6029    && ((TARGET_PPC_GFXOPT
6030         && !HONOR_NANS (<MODE>mode)
6031         && !HONOR_SIGNED_ZEROS (<MODE>mode))
6032        || TARGET_CMPB
6033        || VECTOR_UNIT_VSX_P (<MODE>mode))"
6034 {
6035   if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
6036     {
6037       emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
6038                                              operands[2]));
6039       DONE;
6040     }
6041
6042    operands[3] = gen_reg_rtx (<MODE>mode);
6043    operands[4] = gen_reg_rtx (<MODE>mode);
6044    operands[5] = CONST0_RTX (<MODE>mode);
6045   })
6046
6047 ;; Use an unspec rather providing an if-then-else in RTL, to prevent the
6048 ;; compiler from optimizing -0.0
6049 (define_insn "copysign<mode>3_fcpsgn"
6050   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6051         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")
6052                       (match_operand:SFDF 2 "gpc_reg_operand" "<rreg2>")]
6053                      UNSPEC_COPYSIGN))]
6054   "TARGET_CMPB && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6055   "fcpsgn %0,%2,%1"
6056   [(set_attr "type" "fp")])
6057
6058 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
6059 ;; fsel instruction and some auxiliary computations.  Then we just have a
6060 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
6061 ;; combine.
6062 (define_expand "smaxsf3"
6063   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6064         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
6065                              (match_operand:SF 2 "gpc_reg_operand" ""))
6066                          (match_dup 1)
6067                          (match_dup 2)))]
6068   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6069    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6070   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
6071
6072 (define_expand "sminsf3"
6073   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6074         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
6075                              (match_operand:SF 2 "gpc_reg_operand" ""))
6076                          (match_dup 2)
6077                          (match_dup 1)))]
6078   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6079    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6080   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
6081
6082 (define_split
6083   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6084         (match_operator:SF 3 "min_max_operator"
6085          [(match_operand:SF 1 "gpc_reg_operand" "")
6086           (match_operand:SF 2 "gpc_reg_operand" "")]))]
6087   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
6088    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
6089   [(const_int 0)]
6090   "
6091 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
6092                       operands[1], operands[2]);
6093   DONE;
6094 }")
6095
6096 (define_expand "mov<mode>cc"
6097    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
6098          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
6099                            (match_operand:GPR 2 "gpc_reg_operand" "")
6100                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
6101   "TARGET_ISEL<sel>"
6102   "
6103 {
6104   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6105     DONE;
6106   else
6107     FAIL;
6108 }")
6109
6110 ;; We use the BASE_REGS for the isel input operands because, if rA is
6111 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
6112 ;; because we may switch the operands and rB may end up being rA.
6113 ;;
6114 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
6115 ;; leave out the mode in operand 4 and use one pattern, but reload can
6116 ;; change the mode underneath our feet and then gets confused trying
6117 ;; to reload the value.
6118 (define_insn "isel_signed_<mode>"
6119   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
6120         (if_then_else:GPR
6121          (match_operator 1 "scc_comparison_operator"
6122                          [(match_operand:CC 4 "cc_reg_operand" "y,y")
6123                           (const_int 0)])
6124          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
6125          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
6126   "TARGET_ISEL<sel>"
6127   "*
6128 { return output_isel (operands); }"
6129   [(set_attr "type" "isel")
6130    (set_attr "length" "4")])
6131
6132 (define_insn "isel_unsigned_<mode>"
6133   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
6134         (if_then_else:GPR
6135          (match_operator 1 "scc_comparison_operator"
6136                          [(match_operand:CCUNS 4 "cc_reg_operand" "y,y")
6137                           (const_int 0)])
6138          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
6139          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
6140   "TARGET_ISEL<sel>"
6141   "*
6142 { return output_isel (operands); }"
6143   [(set_attr "type" "isel")
6144    (set_attr "length" "4")])
6145
6146 ;; These patterns can be useful for combine; they let combine know that
6147 ;; isel can handle reversed comparisons so long as the operands are
6148 ;; registers.
6149
6150 (define_insn "*isel_reversed_signed_<mode>"
6151   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
6152         (if_then_else:GPR
6153          (match_operator 1 "scc_rev_comparison_operator"
6154                          [(match_operand:CC 4 "cc_reg_operand" "y")
6155                           (const_int 0)])
6156          (match_operand:GPR 2 "gpc_reg_operand" "b")
6157          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
6158   "TARGET_ISEL<sel>"
6159   "*
6160 { return output_isel (operands); }"
6161   [(set_attr "type" "isel")
6162    (set_attr "length" "4")])
6163
6164 (define_insn "*isel_reversed_unsigned_<mode>"
6165   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
6166         (if_then_else:GPR
6167          (match_operator 1 "scc_rev_comparison_operator"
6168                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
6169                           (const_int 0)])
6170          (match_operand:GPR 2 "gpc_reg_operand" "b")
6171          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
6172   "TARGET_ISEL<sel>"
6173   "*
6174 { return output_isel (operands); }"
6175   [(set_attr "type" "isel")
6176    (set_attr "length" "4")])
6177
6178 (define_expand "movsfcc"
6179    [(set (match_operand:SF 0 "gpc_reg_operand" "")
6180          (if_then_else:SF (match_operand 1 "comparison_operator" "")
6181                           (match_operand:SF 2 "gpc_reg_operand" "")
6182                           (match_operand:SF 3 "gpc_reg_operand" "")))]
6183   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6184   "
6185 {
6186   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6187     DONE;
6188   else
6189     FAIL;
6190 }")
6191
6192 (define_insn "*fselsfsf4"
6193   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6194         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
6195                              (match_operand:SF 4 "zero_fp_constant" "F"))
6196                          (match_operand:SF 2 "gpc_reg_operand" "f")
6197                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
6198   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6199   "fsel %0,%1,%2,%3"
6200   [(set_attr "type" "fp")])
6201
6202 (define_insn "*fseldfsf4"
6203   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6204         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
6205                              (match_operand:DF 4 "zero_fp_constant" "F"))
6206                          (match_operand:SF 2 "gpc_reg_operand" "f")
6207                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
6208   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
6209   "fsel %0,%1,%2,%3"
6210   [(set_attr "type" "fp")])
6211
6212 (define_expand "negdf2"
6213   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6214         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6215   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6216   "")
6217
6218 (define_insn "*negdf2_fpr"
6219   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6220         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6221   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6222    && !VECTOR_UNIT_VSX_P (DFmode)"
6223   "fneg %0,%1"
6224   [(set_attr "type" "fp")])
6225
6226 (define_expand "absdf2"
6227   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6228         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6229   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6230   "")
6231
6232 (define_insn "*absdf2_fpr"
6233   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6234         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6235   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6236    && !VECTOR_UNIT_VSX_P (DFmode)"
6237   "fabs %0,%1"
6238   [(set_attr "type" "fp")])
6239
6240 (define_insn "*nabsdf2_fpr"
6241   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6242         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d"))))]
6243   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6244    && !VECTOR_UNIT_VSX_P (DFmode)"
6245   "fnabs %0,%1"
6246   [(set_attr "type" "fp")])
6247
6248 (define_expand "adddf3"
6249   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6250         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
6251                  (match_operand:DF 2 "gpc_reg_operand" "")))]
6252   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6253   "")
6254
6255 (define_insn "*adddf3_fpr"
6256   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6257         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6258                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
6259   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6260    && !VECTOR_UNIT_VSX_P (DFmode)"
6261   "{fa|fadd} %0,%1,%2"
6262   [(set_attr "type" "fp")
6263    (set_attr "fp_type" "fp_addsub_d")])
6264
6265 (define_expand "subdf3"
6266   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6267         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
6268                   (match_operand:DF 2 "gpc_reg_operand" "")))]
6269   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6270   "")
6271
6272 (define_insn "*subdf3_fpr"
6273   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6274         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "d")
6275                   (match_operand:DF 2 "gpc_reg_operand" "d")))]
6276   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6277    && !VECTOR_UNIT_VSX_P (DFmode)"
6278   "{fs|fsub} %0,%1,%2"
6279   [(set_attr "type" "fp")
6280    (set_attr "fp_type" "fp_addsub_d")])
6281
6282 (define_expand "muldf3"
6283   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6284         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
6285                  (match_operand:DF 2 "gpc_reg_operand" "")))]
6286   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6287   "")
6288
6289 (define_insn "*muldf3_fpr"
6290   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6291         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
6292                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
6293   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6294    && !VECTOR_UNIT_VSX_P (DFmode)"
6295   "{fm|fmul} %0,%1,%2"
6296   [(set_attr "type" "dmul")
6297    (set_attr "fp_type" "fp_mul_d")])
6298
6299 (define_expand "divdf3"
6300   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6301         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
6302                 (match_operand:DF 2 "gpc_reg_operand" "")))]
6303   "TARGET_HARD_FLOAT
6304    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)
6305    && !TARGET_SIMPLE_FPU"
6306   "")
6307
6308 (define_insn "*divdf3_fpr"
6309   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6310         (div:DF (match_operand:DF 1 "gpc_reg_operand" "d")
6311                 (match_operand:DF 2 "gpc_reg_operand" "d")))]
6312   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && !TARGET_SIMPLE_FPU
6313    && !VECTOR_UNIT_VSX_P (DFmode)"
6314   "{fd|fdiv} %0,%1,%2"
6315   [(set_attr "type" "ddiv")])
6316
6317 (define_insn "*fred_fpr"
6318   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6319         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
6320   "TARGET_FRE && !VECTOR_UNIT_VSX_P (DFmode)"
6321   "fre %0,%1"
6322   [(set_attr "type" "fp")])
6323
6324 (define_insn "*rsqrtdf_internal1"
6325   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6326         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")]
6327                    UNSPEC_RSQRT))]
6328   "TARGET_FRSQRTE && !VECTOR_UNIT_VSX_P (DFmode)"
6329   "frsqrte %0,%1"
6330   [(set_attr "type" "fp")])
6331
6332 ; builtin fma support
6333 (define_insn "*fmadf4_fpr"
6334   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6335         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
6336                 (match_operand:DF 2 "gpc_reg_operand" "f")
6337                 (match_operand:DF 3 "gpc_reg_operand" "f")))]
6338   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6339    && VECTOR_UNIT_NONE_P (DFmode)"
6340   "{fma|fmadd} %0,%1,%2,%3"
6341   [(set_attr "type" "fp")
6342    (set_attr "fp_type" "fp_maddsub_d")])
6343
6344 (define_insn "*fmsdf4_fpr"
6345   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6346         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
6347                 (match_operand:DF 2 "gpc_reg_operand" "f")
6348                 (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f"))))]
6349   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6350    && VECTOR_UNIT_NONE_P (DFmode)"
6351   "{fms|fmsub} %0,%1,%2,%3"
6352   [(set_attr "type" "fp")
6353    (set_attr "fp_type" "fp_maddsub_d")])
6354
6355 (define_insn "*nfmadf4_fpr"
6356   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6357         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
6358                         (match_operand:DF 2 "gpc_reg_operand" "f")
6359                         (match_operand:DF 3 "gpc_reg_operand" "f"))))]
6360   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6361    && VECTOR_UNIT_NONE_P (DFmode)"
6362   "{fnma|fnmadd} %0,%1,%2,%3"
6363   [(set_attr "type" "fp")
6364    (set_attr "fp_type" "fp_maddsub_d")])
6365
6366 (define_insn "*nfmsdf4_fpr"
6367   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6368         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
6369                         (match_operand:DF 2 "gpc_reg_operand" "f")
6370                         (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f")))))]
6371   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6372    && VECTOR_UNIT_NONE_P (DFmode)"
6373   "{fnms|fnmsub} %0,%1,%2,%3"
6374   [(set_attr "type" "fp")
6375    (set_attr "fp_type" "fp_maddsub_d")])
6376
6377 (define_expand "sqrtdf2"
6378   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6379         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
6380   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS 
6381    && TARGET_DOUBLE_FLOAT"
6382   "")
6383
6384 (define_insn "*sqrtdf2_fpr"
6385   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6386         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
6387   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS 
6388    && TARGET_DOUBLE_FLOAT
6389    && !VECTOR_UNIT_VSX_P (DFmode)"
6390   "fsqrt %0,%1"
6391   [(set_attr "type" "dsqrt")])
6392
6393 ;; The conditional move instructions allow us to perform max and min
6394 ;; operations even when
6395
6396 (define_expand "smaxdf3"
6397   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6398         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
6399                              (match_operand:DF 2 "gpc_reg_operand" ""))
6400                          (match_dup 1)
6401                          (match_dup 2)))]
6402   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6403    && !flag_trapping_math"
6404   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
6405
6406 (define_expand "smindf3"
6407   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6408         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
6409                              (match_operand:DF 2 "gpc_reg_operand" ""))
6410                          (match_dup 2)
6411                          (match_dup 1)))]
6412   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6413    && !flag_trapping_math"
6414   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
6415
6416 (define_split
6417   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6418         (match_operator:DF 3 "min_max_operator"
6419          [(match_operand:DF 1 "gpc_reg_operand" "")
6420           (match_operand:DF 2 "gpc_reg_operand" "")]))]
6421   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
6422    && !flag_trapping_math"
6423   [(const_int 0)]
6424   "
6425 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
6426                       operands[1], operands[2]);
6427   DONE;
6428 }")
6429
6430 (define_expand "movdfcc"
6431    [(set (match_operand:DF 0 "gpc_reg_operand" "")
6432          (if_then_else:DF (match_operand 1 "comparison_operator" "")
6433                           (match_operand:DF 2 "gpc_reg_operand" "")
6434                           (match_operand:DF 3 "gpc_reg_operand" "")))]
6435   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6436   "
6437 {
6438   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
6439     DONE;
6440   else
6441     FAIL;
6442 }")
6443
6444 (define_insn "*fseldfdf4"
6445   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6446         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
6447                              (match_operand:DF 4 "zero_fp_constant" "F"))
6448                          (match_operand:DF 2 "gpc_reg_operand" "d")
6449                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
6450   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6451   "fsel %0,%1,%2,%3"
6452   [(set_attr "type" "fp")])
6453
6454 (define_insn "*fselsfdf4"
6455   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6456         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
6457                              (match_operand:SF 4 "zero_fp_constant" "F"))
6458                          (match_operand:DF 2 "gpc_reg_operand" "d")
6459                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
6460   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
6461   "fsel %0,%1,%2,%3"
6462   [(set_attr "type" "fp")])
6463 \f
6464 ;; Conversions to and from floating-point.
6465
6466 ; We don't define lfiwax/lfiwzx with the normal definition, because we
6467 ; don't want to support putting SImode in FPR registers.
6468 (define_insn "lfiwax"
6469   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6470         (unspec:DI [(match_operand:SI 1 "indexed_or_indirect_operand" "Z")]
6471                    UNSPEC_LFIWAX))]
6472   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX"
6473   "lfiwax %0,%y1"
6474   [(set_attr "type" "fpload")])
6475
6476 ; This split must be run before register allocation because it allocates the
6477 ; memory slot that is needed to move values to/from the FPR.  We don't allocate
6478 ; it earlier to allow for the combiner to merge insns together where it might
6479 ; not be needed and also in case the insns are deleted as dead code.
6480
6481 (define_insn_and_split "floatsi<mode>2_lfiwax"
6482   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6483         (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
6484    (clobber (match_scratch:DI 2 "=d"))]
6485   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
6486    && <SI_CONVERT_FP> && can_create_pseudo_p ()"
6487   "#"
6488   ""
6489   [(pc)]
6490   "
6491 {
6492   rtx dest = operands[0];
6493   rtx src = operands[1];
6494   rtx tmp;
6495
6496   if (!MEM_P (src) && TARGET_MFPGPR && TARGET_POWERPC64)
6497     tmp = convert_to_mode (DImode, src, false);
6498   else
6499     {
6500       tmp = operands[2];
6501       if (GET_CODE (tmp) == SCRATCH)
6502         tmp = gen_reg_rtx (DImode);
6503       if (MEM_P (src))
6504         {
6505           src = rs6000_address_for_fpconvert (src);
6506           emit_insn (gen_lfiwax (tmp, src));
6507         }
6508       else
6509         {
6510           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6511           emit_move_insn (stack, src);
6512           emit_insn (gen_lfiwax (tmp, stack));
6513         }
6514     }
6515   emit_insn (gen_floatdi<mode>2 (dest, tmp));
6516   DONE;
6517 }"
6518   [(set_attr "length" "12")
6519    (set_attr "type" "fpload")])
6520
6521 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
6522   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
6523         (float:SFDF
6524          (sign_extend:DI
6525           (match_operand:SI 1 "memory_operand" "Z,Z"))))
6526    (clobber (match_scratch:DI 2 "=0,d"))]
6527   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
6528    && <SI_CONVERT_FP>"
6529   "#"
6530   ""
6531   [(pc)]
6532   "
6533 {
6534   operands[1] = rs6000_address_for_fpconvert (operands[1]);
6535   if (GET_CODE (operands[2]) == SCRATCH)
6536     operands[2] = gen_reg_rtx (DImode);
6537   emit_insn (gen_lfiwax (operands[2], operands[1]));
6538   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
6539   DONE;
6540 }"
6541   [(set_attr "length" "8")
6542    (set_attr "type" "fpload")])
6543
6544 (define_insn "lfiwzx"
6545   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6546         (unspec:DI [(match_operand:SI 1 "indexed_or_indirect_operand" "Z")]
6547                    UNSPEC_LFIWZX))]
6548   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX"
6549   "lfiwzx %0,%y1"
6550   [(set_attr "type" "fpload")])
6551
6552 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
6553   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6554         (unsigned_float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
6555    (clobber (match_scratch:DI 2 "=d"))]
6556   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
6557    && <SI_CONVERT_FP>"
6558   "#"
6559   ""
6560   [(pc)]
6561   "
6562 {
6563   rtx dest = operands[0];
6564   rtx src = operands[1];
6565   rtx tmp;
6566
6567   if (!MEM_P (src) && TARGET_MFPGPR && TARGET_POWERPC64)
6568     tmp = convert_to_mode (DImode, src, true);
6569   else
6570     {
6571       tmp = operands[2];
6572       if (GET_CODE (tmp) == SCRATCH)
6573         tmp = gen_reg_rtx (DImode);
6574       if (MEM_P (src))
6575         {
6576           src = rs6000_address_for_fpconvert (src);
6577           emit_insn (gen_lfiwzx (tmp, src));
6578         }
6579       else
6580         {
6581           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6582           emit_move_insn (stack, src);
6583           emit_insn (gen_lfiwzx (tmp, stack));
6584         }
6585     }
6586   emit_insn (gen_floatdi<mode>2 (dest, tmp));
6587   DONE;
6588 }"
6589   [(set_attr "length" "12")
6590    (set_attr "type" "fpload")])
6591
6592 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
6593   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
6594         (unsigned_float:SFDF
6595          (zero_extend:DI
6596           (match_operand:SI 1 "memory_operand" "Z,Z"))))
6597    (clobber (match_scratch:DI 2 "=0,d"))]
6598   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
6599    && <SI_CONVERT_FP>"
6600   "#"
6601   ""
6602   [(pc)]
6603   "
6604 {
6605   operands[1] = rs6000_address_for_fpconvert (operands[1]);
6606   if (GET_CODE (operands[2]) == SCRATCH)
6607     operands[2] = gen_reg_rtx (DImode);
6608   emit_insn (gen_lfiwzx (operands[2], operands[1]));
6609   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
6610   DONE;
6611 }"
6612   [(set_attr "length" "8")
6613    (set_attr "type" "fpload")])
6614
6615 ; For each of these conversions, there is a define_expand, a define_insn
6616 ; with a '#' template, and a define_split (with C code).  The idea is
6617 ; to allow constant folding with the template of the define_insn,
6618 ; then to have the insns split later (between sched1 and final).
6619
6620 (define_expand "floatsidf2"
6621   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
6622                    (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
6623               (use (match_dup 2))
6624               (use (match_dup 3))
6625               (clobber (match_dup 4))
6626               (clobber (match_dup 5))
6627               (clobber (match_dup 6))])]
6628   "TARGET_HARD_FLOAT 
6629    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6630   "
6631 {
6632   if (TARGET_E500_DOUBLE)
6633     {
6634       if (!REG_P (operands[1]))
6635         operands[1] = force_reg (SImode, operands[1]);
6636       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
6637       DONE;
6638     }
6639   else if (TARGET_LFIWAX && TARGET_FCFID)
6640     {
6641       emit_insn (gen_floatsidf2_lfiwax (operands[0], operands[1]));
6642       DONE;
6643     }
6644   else if (TARGET_FCFID)
6645     {
6646       rtx dreg = operands[1];
6647       if (!REG_P (dreg))
6648         dreg = force_reg (SImode, dreg);
6649       dreg = convert_to_mode (DImode, dreg, false);
6650       emit_insn (gen_floatdidf2 (operands[0], dreg));
6651       DONE;
6652     }
6653
6654   if (!REG_P (operands[1]))
6655     operands[1] = force_reg (SImode, operands[1]);
6656   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6657   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
6658   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
6659   operands[5] = gen_reg_rtx (DFmode);
6660   operands[6] = gen_reg_rtx (SImode);
6661 }")
6662
6663 (define_insn_and_split "*floatsidf2_internal"
6664   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6665         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6666    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6667    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6668    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6669    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
6670    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
6671   "! TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6672   "#"
6673   ""
6674   [(pc)]
6675   "
6676 {
6677   rtx lowword, highword;
6678   gcc_assert (MEM_P (operands[4]));
6679   highword = adjust_address (operands[4], SImode, 0);
6680   lowword = adjust_address (operands[4], SImode, 4);
6681   if (! WORDS_BIG_ENDIAN)
6682     {
6683       rtx tmp;
6684       tmp = highword; highword = lowword; lowword = tmp;
6685     }
6686
6687   emit_insn (gen_xorsi3 (operands[6], operands[1],
6688                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
6689   emit_move_insn (lowword, operands[6]);
6690   emit_move_insn (highword, operands[2]);
6691   emit_move_insn (operands[5], operands[4]);
6692   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6693   DONE;
6694 }"
6695   [(set_attr "length" "24")
6696    (set_attr "type" "fp")])
6697
6698 ;; If we don't have a direct conversion to single precision, don't enable this
6699 ;; conversion for 32-bit without fast math, because we don't have the insn to
6700 ;; generate the fixup swizzle to avoid double rounding problems.
6701 (define_expand "floatunssisf2"
6702   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6703         (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
6704   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
6705    && (!TARGET_FPRS
6706        || (TARGET_FPRS
6707            && ((TARGET_FCFIDUS && TARGET_LFIWZX)
6708                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
6709                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
6710   "
6711 {
6712   if (!TARGET_FPRS)
6713     {
6714       if (!REG_P (operands[1]))
6715         operands[1] = force_reg (SImode, operands[1]);
6716     }
6717   else if (TARGET_LFIWZX && TARGET_FCFIDUS)
6718     {
6719       emit_insn (gen_floatunssisf2_lfiwzx (operands[0], operands[1]));
6720       DONE;
6721     }
6722   else
6723     {
6724       rtx dreg = operands[1];
6725       if (!REG_P (dreg))
6726         dreg = force_reg (SImode, dreg);
6727       dreg = convert_to_mode (DImode, dreg, true);
6728       emit_insn (gen_floatdisf2 (operands[0], dreg));
6729       DONE;
6730     }
6731 }")
6732
6733 (define_expand "floatunssidf2"
6734   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
6735                    (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
6736               (use (match_dup 2))
6737               (use (match_dup 3))
6738               (clobber (match_dup 4))
6739               (clobber (match_dup 5))])]
6740   "TARGET_HARD_FLOAT
6741    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
6742   "
6743 {
6744   if (TARGET_E500_DOUBLE)
6745     {
6746       if (!REG_P (operands[1]))
6747         operands[1] = force_reg (SImode, operands[1]);
6748       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
6749       DONE;
6750     }
6751   else if (TARGET_LFIWZX && TARGET_FCFID)
6752     {
6753       emit_insn (gen_floatunssidf2_lfiwzx (operands[0], operands[1]));
6754       DONE;
6755     }
6756   else if (TARGET_FCFID)
6757     {
6758       rtx dreg = operands[1];
6759       if (!REG_P (dreg))
6760         dreg = force_reg (SImode, dreg);
6761       dreg = convert_to_mode (DImode, dreg, true);
6762       emit_insn (gen_floatdidf2 (operands[0], dreg));
6763       DONE;
6764     }
6765
6766   if (!REG_P (operands[1]))
6767     operands[1] = force_reg (SImode, operands[1]);
6768   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6769   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
6770   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
6771   operands[5] = gen_reg_rtx (DFmode);
6772 }")
6773
6774 (define_insn_and_split "*floatunssidf2_internal"
6775   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6776         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6777    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6778    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6779    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6780    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
6781   "! TARGET_FCFIDU && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6782    && !(TARGET_FCFID && TARGET_POWERPC64)"
6783   "#"
6784   ""
6785   [(pc)]
6786   "
6787 {
6788   rtx lowword, highword;
6789   gcc_assert (MEM_P (operands[4]));
6790   highword = adjust_address (operands[4], SImode, 0);
6791   lowword = adjust_address (operands[4], SImode, 4);
6792   if (! WORDS_BIG_ENDIAN)
6793     {
6794       rtx tmp;
6795       tmp = highword; highword = lowword; lowword = tmp;
6796     }
6797
6798   emit_move_insn (lowword, operands[1]);
6799   emit_move_insn (highword, operands[2]);
6800   emit_move_insn (operands[5], operands[4]);
6801   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6802   DONE;
6803 }"
6804   [(set_attr "length" "20")
6805    (set_attr "type" "fp")])
6806
6807 (define_expand "fix_trunc<mode>si2"
6808   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6809         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6810   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT
6811    && ((TARGET_FPRS && <TARGET_FLOAT>) || <E500_CONVERT>)"
6812   "
6813 {
6814   if (!<E500_CONVERT>)
6815     {
6816       rtx tmp, stack;
6817
6818       if (TARGET_STFIWX)
6819         emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6820       else
6821         {
6822           tmp = gen_reg_rtx (DImode);
6823           stack = rs6000_allocate_stack_temp (DImode, true, false);
6824           emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], operands[1],
6825                                                       tmp, stack));
6826         }
6827       DONE;
6828     }
6829 }")
6830
6831 ; Like the convert to float patterns, this insn must be split before
6832 ; register allocation so that it can allocate the memory slot if it
6833 ; needed
6834 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
6835   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6836         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6837    (clobber (match_scratch:DI 2 "=d"))]
6838   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6839    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
6840    && TARGET_STFIWX && can_create_pseudo_p ()"
6841   "#"
6842   ""
6843   [(pc)]
6844 {
6845   rtx dest = operands[0];
6846   rtx src = operands[1];
6847   rtx tmp = operands[2];
6848
6849   if (GET_CODE (tmp) == SCRATCH)
6850     tmp = gen_reg_rtx (DImode);
6851
6852   emit_insn (gen_fctiwz_<mode> (tmp, src));
6853   if (MEM_P (dest))
6854     {
6855       dest = rs6000_address_for_fpconvert (dest);
6856       emit_insn (gen_stfiwx (dest, tmp));
6857       DONE;
6858     }
6859   else if (TARGET_MFPGPR && TARGET_POWERPC64)
6860     {
6861       dest = gen_lowpart (DImode, dest);
6862       emit_move_insn (dest, tmp);
6863       DONE;
6864     }
6865   else
6866     {
6867       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6868       emit_insn (gen_stfiwx (stack, tmp));
6869       emit_move_insn (dest, stack);
6870       DONE;
6871     }
6872 }
6873   [(set_attr "length" "12")
6874    (set_attr "type" "fp")])
6875
6876 (define_insn_and_split "fix_trunc<mode>si2_internal"
6877   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,?r")
6878         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,<rreg>")))
6879    (clobber (match_operand:DI 2 "gpc_reg_operand" "=1,d"))
6880    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o,o"))]
6881   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
6882    && TARGET_DOUBLE_FLOAT"
6883   "#"
6884   ""
6885   [(pc)]
6886   "
6887 {
6888   rtx lowword;
6889   gcc_assert (MEM_P (operands[3]));
6890   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6891
6892   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
6893   emit_move_insn (operands[3], operands[2]);
6894   emit_move_insn (operands[0], lowword);
6895   DONE;
6896 }"
6897   [(set_attr "length" "16")
6898    (set_attr "type" "fp")])
6899
6900 (define_expand "fix_trunc<mode>di2"
6901   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6902         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6903   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6904    && TARGET_FCFID"
6905   "")
6906
6907 (define_insn "*fix_trunc<mode>di2_fctidz"
6908   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6909         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6910   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6911     && TARGET_FCFID && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6912   "fctidz %0,%1"
6913   [(set_attr "type" "fp")])
6914
6915 (define_expand "fixuns_trunc<mode>si2"
6916   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6917         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6918   "TARGET_HARD_FLOAT
6919    && ((TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ && TARGET_STFIWX)
6920        || <E500_CONVERT>)"
6921   "
6922 {
6923   if (!<E500_CONVERT>)
6924     {
6925       emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6926       DONE;
6927     }
6928 }")
6929
6930 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
6931   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6932         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6933    (clobber (match_scratch:DI 2 "=d"))]
6934   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
6935    && TARGET_STFIWX && can_create_pseudo_p ()"
6936   "#"
6937   ""
6938   [(pc)]
6939 {
6940   rtx dest = operands[0];
6941   rtx src = operands[1];
6942   rtx tmp = operands[2];
6943
6944   if (GET_CODE (tmp) == SCRATCH)
6945     tmp = gen_reg_rtx (DImode);
6946
6947   emit_insn (gen_fctiwuz_<mode> (tmp, src));
6948   if (MEM_P (dest))
6949     {
6950       dest = rs6000_address_for_fpconvert (dest);
6951       emit_insn (gen_stfiwx (dest, tmp));
6952       DONE;
6953     }
6954   else if (TARGET_MFPGPR && TARGET_POWERPC64)
6955     {
6956       dest = gen_lowpart (DImode, dest);
6957       emit_move_insn (dest, tmp);
6958       DONE;
6959     }
6960   else
6961     {
6962       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6963       emit_insn (gen_stfiwx (stack, tmp));
6964       emit_move_insn (dest, stack);
6965       DONE;
6966     }
6967 }
6968   [(set_attr "length" "12")
6969    (set_attr "type" "fp")])
6970
6971 (define_expand "fixuns_trunc<mode>di2"
6972   [(set (match_operand:DI 0 "register_operand" "")
6973         (unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
6974   "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
6975   "")
6976
6977 (define_insn "*fixuns_trunc<mode>di2_fctiduz"
6978   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6979         (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6980   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6981     && TARGET_FCTIDUZ && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6982   "fctiduz %0,%1"
6983   [(set_attr "type" "fp")])
6984
6985 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6986 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
6987 ; because the first makes it clear that operand 0 is not live
6988 ; before the instruction.
6989 (define_insn "fctiwz_<mode>"
6990   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6991         (unspec:DI [(fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))]
6992                    UNSPEC_FCTIWZ))]
6993   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS 
6994    && TARGET_DOUBLE_FLOAT"
6995   "{fcirz|fctiwz} %0,%1"
6996   [(set_attr "type" "fp")])
6997
6998 (define_insn "fctiwuz_<mode>"
6999   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
7000         (unspec:DI [(unsigned_fix:SI
7001                      (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>"))]
7002                    UNSPEC_FCTIWUZ))]
7003   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ"
7004   "fctiwuz %0,%1"
7005   [(set_attr "type" "fp")])
7006
7007 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
7008 ;; since the friz instruction does not truncate the value if the floating
7009 ;; point value is < LONG_MIN or > LONG_MAX.
7010 (define_insn "*friz"
7011   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7012         (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d"))))]
7013   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_FPRND
7014    && !VECTOR_UNIT_VSX_P (DFmode) && flag_unsafe_math_optimizations
7015    && !flag_trapping_math && TARGET_FRIZ"
7016   "friz %0,%1"
7017   [(set_attr "type" "fp")])
7018
7019 ;; Since FCTIWZ doesn't sign extend the upper bits, we have to do a store and a
7020 ;; load to properly sign extend the value, but at least doing a store, load
7021 ;; into a GPR to sign extend, a store from the GPR and a load back into the FPR
7022 ;; if we have 32-bit memory ops
7023 (define_insn_and_split "*round32<mode>2_fprs"
7024   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
7025         (float:SFDF
7026          (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
7027    (clobber (match_scratch:DI 2 "=d"))
7028    (clobber (match_scratch:DI 3 "=d"))]
7029   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
7030    && <SI_CONVERT_FP> && TARGET_LFIWAX && TARGET_STFIWX && TARGET_FCFID
7031    && can_create_pseudo_p ()"
7032   "#"
7033   ""
7034   [(pc)]
7035 {
7036   rtx dest = operands[0];
7037   rtx src = operands[1];
7038   rtx tmp1 = operands[2];
7039   rtx tmp2 = operands[3];
7040   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
7041
7042   if (GET_CODE (tmp1) == SCRATCH)
7043     tmp1 = gen_reg_rtx (DImode);
7044   if (GET_CODE (tmp2) == SCRATCH)
7045     tmp2 = gen_reg_rtx (DImode);
7046
7047   emit_insn (gen_fctiwz_<mode> (tmp1, src));
7048   emit_insn (gen_stfiwx (stack, tmp1));
7049   emit_insn (gen_lfiwax (tmp2, stack));
7050   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
7051   DONE;
7052 }
7053   [(set_attr "type" "fpload")
7054    (set_attr "length" "16")])
7055
7056 (define_insn_and_split "*roundu32<mode>2_fprs"
7057   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
7058         (unsigned_float:SFDF
7059          (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
7060    (clobber (match_scratch:DI 2 "=d"))
7061    (clobber (match_scratch:DI 3 "=d"))]
7062   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
7063    && TARGET_LFIWZX && TARGET_STFIWX && TARGET_FCFIDU
7064    && can_create_pseudo_p ()"
7065   "#"
7066   ""
7067   [(pc)]
7068 {
7069   rtx dest = operands[0];
7070   rtx src = operands[1];
7071   rtx tmp1 = operands[2];
7072   rtx tmp2 = operands[3];
7073   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
7074
7075   if (GET_CODE (tmp1) == SCRATCH)
7076     tmp1 = gen_reg_rtx (DImode);
7077   if (GET_CODE (tmp2) == SCRATCH)
7078     tmp2 = gen_reg_rtx (DImode);
7079
7080   emit_insn (gen_fctiwuz_<mode> (tmp1, src));
7081   emit_insn (gen_stfiwx (stack, tmp1));
7082   emit_insn (gen_lfiwzx (tmp2, stack));
7083   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
7084   DONE;
7085 }
7086   [(set_attr "type" "fpload")
7087    (set_attr "length" "16")])
7088
7089 ;; No VSX equivalent to fctid
7090 (define_insn "lrint<mode>di2"
7091   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
7092         (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7093                    UNSPEC_FCTID))]
7094   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7095   "fctid %0,%1"
7096   [(set_attr "type" "fp")])
7097
7098 (define_expand "btrunc<mode>2"
7099   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
7100         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
7101                      UNSPEC_FRIZ))]
7102   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7103   "")
7104
7105 (define_insn "*btrunc<mode>2_fpr"
7106   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
7107         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7108                      UNSPEC_FRIZ))]
7109   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
7110    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
7111   "friz %0,%1"
7112   [(set_attr "type" "fp")])
7113
7114 (define_expand "ceil<mode>2"
7115   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
7116         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
7117                      UNSPEC_FRIP))]
7118   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7119   "")
7120
7121 (define_insn "*ceil<mode>2_fpr"
7122   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
7123         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7124                      UNSPEC_FRIP))]
7125   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
7126    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
7127   "frip %0,%1"
7128   [(set_attr "type" "fp")])
7129
7130 (define_expand "floor<mode>2"
7131   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
7132         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
7133                      UNSPEC_FRIM))]
7134   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7135   "")
7136
7137 (define_insn "*floor<mode>2_fpr"
7138   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
7139         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7140                      UNSPEC_FRIM))]
7141   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
7142    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
7143   "frim %0,%1"
7144   [(set_attr "type" "fp")])
7145
7146 ;; No VSX equivalent to frin
7147 (define_insn "round<mode>2"
7148   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
7149         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
7150                      UNSPEC_FRIN))]
7151   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
7152   "frin %0,%1"
7153   [(set_attr "type" "fp")])
7154
7155 ; An UNSPEC is used so we don't have to support SImode in FP registers.
7156 (define_insn "stfiwx"
7157   [(set (match_operand:SI 0 "memory_operand" "=Z")
7158         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
7159                    UNSPEC_STFIWX))]
7160   "TARGET_PPC_GFXOPT"
7161   "stfiwx %1,%y0"
7162   [(set_attr "type" "fpstore")])
7163
7164 ;; If we don't have a direct conversion to single precision, don't enable this
7165 ;; conversion for 32-bit without fast math, because we don't have the insn to
7166 ;; generate the fixup swizzle to avoid double rounding problems.
7167 (define_expand "floatsisf2"
7168   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7169         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
7170   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
7171    && (!TARGET_FPRS
7172        || (TARGET_FPRS
7173            && ((TARGET_FCFIDS && TARGET_LFIWAX)
7174                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
7175                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
7176   "
7177 {
7178   if (!TARGET_FPRS)
7179     {
7180       if (!REG_P (operands[1]))
7181         operands[1] = force_reg (SImode, operands[1]);
7182     }
7183   else if (TARGET_FCFIDS && TARGET_LFIWAX)
7184     {
7185       emit_insn (gen_floatsisf2_lfiwax (operands[0], operands[1]));
7186       DONE;
7187     }
7188   else if (TARGET_FCFID && TARGET_LFIWAX)
7189     {
7190       rtx dfreg = gen_reg_rtx (DFmode);
7191       emit_insn (gen_floatsidf2_lfiwax (dfreg, operands[1]));
7192       emit_insn (gen_truncdfsf2 (operands[0], dfreg));
7193       DONE;
7194     }
7195   else
7196     {
7197       rtx dreg = operands[1];
7198       if (!REG_P (dreg))
7199         dreg = force_reg (SImode, dreg);
7200       dreg = convert_to_mode (DImode, dreg, false);
7201       emit_insn (gen_floatdisf2 (operands[0], dreg));
7202       DONE;
7203     }
7204 }")
7205
7206 (define_expand "floatdidf2"
7207   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7208         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
7209   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
7210   "")
7211
7212 (define_insn "*floatdidf2_fpr"
7213   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7214         (float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
7215   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
7216    && !VECTOR_UNIT_VSX_P (DFmode)"
7217   "fcfid %0,%1"
7218   [(set_attr "type" "fp")])
7219
7220 ; Allow the combiner to merge source memory operands to the conversion so that
7221 ; the optimizer/register allocator doesn't try to load the value too early in a
7222 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
7223 ; hit.  We will split after reload to avoid the trip through the GPRs
7224
7225 (define_insn_and_split "*floatdidf2_mem"
7226   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7227         (float:DF (match_operand:DI 1 "memory_operand" "m")))
7228    (clobber (match_scratch:DI 2 "=d"))]
7229   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCFID"
7230   "#"
7231   "&& reload_completed"
7232   [(set (match_dup 2) (match_dup 1))
7233    (set (match_dup 0) (float:DF (match_dup 2)))]
7234   ""
7235   [(set_attr "length" "8")
7236    (set_attr "type" "fpload")])
7237
7238 (define_expand "floatunsdidf2"
7239   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7240         (unsigned_float:DF
7241          (match_operand:DI 1 "gpc_reg_operand" "")))]
7242   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
7243   "")
7244
7245 (define_insn "*floatunsdidf2_fcfidu"
7246   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7247         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
7248   "TARGET_HARD_FLOAT && TARGET_FCFIDU && !VECTOR_UNIT_VSX_P (DFmode)"
7249   "fcfidu %0,%1"
7250   [(set_attr "type" "fp")
7251    (set_attr "length" "4")])
7252
7253 (define_insn_and_split "*floatunsdidf2_mem"
7254   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
7255         (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m")))
7256    (clobber (match_scratch:DI 2 "=d"))]
7257   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
7258   "#"
7259   "&& reload_completed"
7260   [(set (match_dup 2) (match_dup 1))
7261    (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
7262   ""
7263   [(set_attr "length" "8")
7264    (set_attr "type" "fpload")])
7265
7266 (define_expand "floatdisf2"
7267   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7268         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
7269   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7270    && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
7271   "
7272 {
7273   if (!TARGET_FCFIDS)
7274     {
7275       rtx val = operands[1];
7276       if (!flag_unsafe_math_optimizations)
7277         {
7278           rtx label = gen_label_rtx ();
7279           val = gen_reg_rtx (DImode);
7280           emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
7281           emit_label (label);
7282         }
7283       emit_insn (gen_floatdisf2_internal1 (operands[0], val));
7284       DONE;
7285     }
7286 }")
7287
7288 (define_insn "floatdisf2_fcfids"
7289   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7290         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
7291   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7292    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
7293   "fcfids %0,%1"
7294   [(set_attr "type" "fp")])
7295
7296 (define_insn_and_split "*floatdisf2_mem"
7297   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7298         (float:SF (match_operand:DI 1 "memory_operand" "m")))
7299    (clobber (match_scratch:DI 2 "=f"))]
7300   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7301    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
7302   "#"
7303   "&& reload_completed"
7304   [(pc)]
7305   "
7306 {
7307   emit_move_insn (operands[2], operands[1]);
7308   emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
7309   DONE;
7310 }"
7311   [(set_attr "length" "8")])
7312
7313 ;; This is not IEEE compliant if rounding mode is "round to nearest".
7314 ;; If the DI->DF conversion is inexact, then it's possible to suffer
7315 ;; from double rounding.
7316 ;; Instead of creating a new cpu type for two FP operations, just use fp
7317 (define_insn_and_split "floatdisf2_internal1"
7318   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7319         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
7320    (clobber (match_scratch:DF 2 "=d"))]
7321   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
7322   "#"
7323   "&& reload_completed"
7324   [(set (match_dup 2)
7325         (float:DF (match_dup 1)))
7326    (set (match_dup 0)
7327         (float_truncate:SF (match_dup 2)))]
7328   ""
7329   [(set_attr "length" "8")
7330    (set_attr "type" "fp")])
7331
7332 ;; Twiddles bits to avoid double rounding.
7333 ;; Bits that might be truncated when converting to DFmode are replaced
7334 ;; by a bit that won't be lost at that stage, but is below the SFmode
7335 ;; rounding position.
7336 (define_expand "floatdisf2_internal2"
7337   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
7338                                    (const_int 53)))
7339    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
7340                                                       (const_int 2047)))
7341               (clobber (scratch:CC))])
7342    (set (match_dup 3) (plus:DI (match_dup 3)
7343                                (const_int 1)))
7344    (set (match_dup 0) (plus:DI (match_dup 0)
7345                                (const_int 2047)))
7346    (set (match_dup 4) (compare:CCUNS (match_dup 3)
7347                                      (const_int 2)))
7348    (set (match_dup 0) (ior:DI (match_dup 0)
7349                               (match_dup 1)))
7350    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
7351                                          (const_int -2048)))
7352               (clobber (scratch:CC))])
7353    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
7354                            (label_ref (match_operand:DI 2 "" ""))
7355                            (pc)))
7356    (set (match_dup 0) (match_dup 1))]
7357   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
7358   "
7359 {
7360   operands[3] = gen_reg_rtx (DImode);
7361   operands[4] = gen_reg_rtx (CCUNSmode);
7362 }")
7363
7364 (define_expand "floatunsdisf2"
7365   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7366         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
7367   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7368    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
7369   "")
7370
7371 (define_insn "floatunsdisf2_fcfidus"
7372   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7373         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
7374   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7375    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
7376   "fcfidus %0,%1"
7377   [(set_attr "type" "fp")])
7378
7379 (define_insn_and_split "*floatunsdisf2_mem"
7380   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7381         (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m")))
7382    (clobber (match_scratch:DI 2 "=f"))]
7383   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
7384    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
7385   "#"
7386   "&& reload_completed"
7387   [(pc)]
7388   "
7389 {
7390   emit_move_insn (operands[2], operands[1]);
7391   emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
7392   DONE;
7393 }"
7394   [(set_attr "length" "8")
7395    (set_attr "type" "fpload")])
7396 \f
7397 ;; Define the DImode operations that can be done in a small number
7398 ;; of instructions.  The & constraints are to prevent the register
7399 ;; allocator from allocating registers that overlap with the inputs
7400 ;; (for example, having an input in 7,8 and an output in 6,7).  We
7401 ;; also allow for the output being the same as one of the inputs.
7402
7403 (define_insn "*adddi3_noppc64"
7404   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
7405         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
7406                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
7407   "! TARGET_POWERPC64"
7408   "*
7409 {
7410   if (WORDS_BIG_ENDIAN)
7411     return (GET_CODE (operands[2])) != CONST_INT
7412             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
7413             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
7414   else
7415     return (GET_CODE (operands[2])) != CONST_INT
7416             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
7417             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
7418 }"
7419   [(set_attr "type" "two")
7420    (set_attr "length" "8")])
7421
7422 (define_insn "*subdi3_noppc64"
7423   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
7424         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
7425                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
7426   "! TARGET_POWERPC64"
7427   "*
7428 {
7429   if (WORDS_BIG_ENDIAN)
7430     return (GET_CODE (operands[1]) != CONST_INT)
7431             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
7432             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
7433   else
7434     return (GET_CODE (operands[1]) != CONST_INT)
7435             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
7436             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
7437 }"
7438   [(set_attr "type" "two")
7439    (set_attr "length" "8")])
7440
7441 (define_insn "*negdi2_noppc64"
7442   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7443         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
7444   "! TARGET_POWERPC64"
7445   "*
7446 {
7447   return (WORDS_BIG_ENDIAN)
7448     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
7449     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
7450 }"
7451   [(set_attr "type" "two")
7452    (set_attr "length" "8")])
7453
7454 (define_expand "mulsidi3"
7455   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7456         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7457                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7458   "! TARGET_POWERPC64"
7459   "
7460 {
7461   if (! TARGET_POWER && ! TARGET_POWERPC)
7462     {
7463       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
7464       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
7465       emit_insn (gen_mull_call ());
7466       if (WORDS_BIG_ENDIAN)
7467         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
7468       else
7469         {
7470           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
7471                           gen_rtx_REG (SImode, 3));
7472           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
7473                           gen_rtx_REG (SImode, 4));
7474         }
7475       DONE;
7476     }
7477   else if (TARGET_POWER)
7478     {
7479       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
7480       DONE;
7481     }
7482 }")
7483
7484 (define_insn "mulsidi3_mq"
7485   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7486         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7487                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
7488    (clobber (match_scratch:SI 3 "=q"))]
7489   "TARGET_POWER"
7490   "mul %0,%1,%2\;mfmq %L0"
7491   [(set_attr "type" "imul")
7492    (set_attr "length" "8")])
7493
7494 (define_insn "*mulsidi3_no_mq"
7495   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7496         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7497                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
7498   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
7499   "*
7500 {
7501   return (WORDS_BIG_ENDIAN)
7502     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
7503     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
7504 }"
7505   [(set_attr "type" "imul")
7506    (set_attr "length" "8")])
7507
7508 (define_split
7509   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7510         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7511                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7512   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
7513   [(set (match_dup 3)
7514         (truncate:SI
7515          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
7516                                (sign_extend:DI (match_dup 2)))
7517                       (const_int 32))))
7518    (set (match_dup 4)
7519         (mult:SI (match_dup 1)
7520                  (match_dup 2)))]
7521   "
7522 {
7523   int endian = (WORDS_BIG_ENDIAN == 0);
7524   operands[3] = operand_subword (operands[0], endian, 0, DImode);
7525   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
7526 }")
7527
7528 (define_expand "umulsidi3"
7529   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7530         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7531                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7532   "TARGET_POWERPC && ! TARGET_POWERPC64"
7533   "
7534 {
7535   if (TARGET_POWER)
7536     {
7537       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
7538       DONE;
7539     }
7540 }")
7541
7542 (define_insn "umulsidi3_mq"
7543   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7544         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7545                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
7546    (clobber (match_scratch:SI 3 "=q"))]
7547   "TARGET_POWERPC && TARGET_POWER"
7548   "*
7549 {
7550   return (WORDS_BIG_ENDIAN)
7551     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
7552     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
7553 }"
7554   [(set_attr "type" "imul")
7555    (set_attr "length" "8")])
7556
7557 (define_insn "*umulsidi3_no_mq"
7558   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
7559         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
7560                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
7561   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
7562   "*
7563 {
7564   return (WORDS_BIG_ENDIAN)
7565     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
7566     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
7567 }"
7568   [(set_attr "type" "imul")
7569    (set_attr "length" "8")])
7570
7571 (define_split
7572   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7573         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
7574                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
7575   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
7576   [(set (match_dup 3)
7577         (truncate:SI
7578          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
7579                                (zero_extend:DI (match_dup 2)))
7580                       (const_int 32))))
7581    (set (match_dup 4)
7582         (mult:SI (match_dup 1)
7583                  (match_dup 2)))]
7584   "
7585 {
7586   int endian = (WORDS_BIG_ENDIAN == 0);
7587   operands[3] = operand_subword (operands[0], endian, 0, DImode);
7588   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
7589 }")
7590
7591 (define_expand "smulsi3_highpart"
7592   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7593         (truncate:SI
7594          (lshiftrt:DI (mult:DI (sign_extend:DI
7595                                 (match_operand:SI 1 "gpc_reg_operand" ""))
7596                                (sign_extend:DI
7597                                 (match_operand:SI 2 "gpc_reg_operand" "")))
7598                       (const_int 32))))]
7599   ""
7600   "
7601 {
7602   if (! TARGET_POWER && ! TARGET_POWERPC)
7603     {
7604       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
7605       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
7606       emit_insn (gen_mulh_call ());
7607       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
7608       DONE;
7609     }
7610   else if (TARGET_POWER)
7611     {
7612       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
7613       DONE;
7614     }
7615 }")
7616
7617 (define_insn "smulsi3_highpart_mq"
7618   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7619         (truncate:SI
7620          (lshiftrt:DI (mult:DI (sign_extend:DI
7621                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7622                                (sign_extend:DI
7623                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7624                       (const_int 32))))
7625    (clobber (match_scratch:SI 3 "=q"))]
7626   "TARGET_POWER"
7627   "mul %0,%1,%2"
7628   [(set_attr "type" "imul")])
7629
7630 (define_insn "*smulsi3_highpart_no_mq"
7631   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7632         (truncate:SI
7633          (lshiftrt:DI (mult:DI (sign_extend:DI
7634                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7635                                (sign_extend:DI
7636                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7637                       (const_int 32))))]
7638   "TARGET_POWERPC && ! TARGET_POWER"
7639   "mulhw %0,%1,%2"
7640   [(set_attr "type" "imul")])
7641
7642 (define_expand "umulsi3_highpart"
7643   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7644         (truncate:SI
7645          (lshiftrt:DI (mult:DI (zero_extend:DI
7646                                 (match_operand:SI 1 "gpc_reg_operand" ""))
7647                                (zero_extend:DI
7648                                 (match_operand:SI 2 "gpc_reg_operand" "")))
7649                       (const_int 32))))]
7650   "TARGET_POWERPC"
7651   "
7652 {
7653   if (TARGET_POWER)
7654     {
7655       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
7656       DONE;
7657     }
7658 }")
7659
7660 (define_insn "umulsi3_highpart_mq"
7661   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7662         (truncate:SI
7663          (lshiftrt:DI (mult:DI (zero_extend:DI
7664                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7665                                (zero_extend:DI
7666                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7667                       (const_int 32))))
7668    (clobber (match_scratch:SI 3 "=q"))]
7669   "TARGET_POWERPC && TARGET_POWER"
7670   "mulhwu %0,%1,%2"
7671   [(set_attr "type" "imul")])
7672
7673 (define_insn "*umulsi3_highpart_no_mq"
7674   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7675         (truncate:SI
7676          (lshiftrt:DI (mult:DI (zero_extend:DI
7677                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
7678                                (zero_extend:DI
7679                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
7680                       (const_int 32))))]
7681   "TARGET_POWERPC && ! TARGET_POWER"
7682   "mulhwu %0,%1,%2"
7683   [(set_attr "type" "imul")])
7684
7685 ;; If operands 0 and 2 are in the same register, we have a problem.  But
7686 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
7687 ;; why we have the strange constraints below.
7688 (define_insn "ashldi3_power"
7689   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
7690         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
7691                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
7692    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
7693   "TARGET_POWER"
7694   "@
7695    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
7696    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
7697    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
7698    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
7699   [(set_attr "length" "8")])
7700
7701 (define_insn "lshrdi3_power"
7702   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
7703         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
7704                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
7705    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
7706   "TARGET_POWER"
7707   "@
7708    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
7709    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
7710    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
7711    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
7712   [(set_attr "length" "8")])
7713
7714 ;; Shift by a variable amount is too complex to be worth open-coding.  We
7715 ;; just handle shifts by constants.
7716 (define_insn "ashrdi3_power"
7717   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7718         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7719                      (match_operand:SI 2 "const_int_operand" "M,i")))
7720    (clobber (match_scratch:SI 3 "=X,q"))]
7721   "TARGET_POWER"
7722   "@
7723    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
7724    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
7725   [(set_attr "type" "shift")
7726    (set_attr "length" "8")])
7727
7728 (define_insn "ashrdi3_no_power"
7729   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
7730         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7731                      (match_operand:SI 2 "const_int_operand" "M,i")))]
7732   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
7733   "@
7734    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
7735    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
7736   [(set_attr "type" "two,three")
7737    (set_attr "length" "8,12")])
7738
7739 (define_insn "*ashrdisi3_noppc64"
7740   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7741         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7742                                 (const_int 32)) 4))]
7743   "TARGET_32BIT && !TARGET_POWERPC64"
7744   "*
7745 {
7746   if (REGNO (operands[0]) == REGNO (operands[1]))
7747     return \"\";
7748   else
7749     return \"mr %0,%1\";
7750 }"
7751    [(set_attr "length" "4")])
7752
7753 \f
7754 ;; PowerPC64 DImode operations.
7755
7756 (define_expand "absdi2"
7757   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7758         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
7759   "TARGET_POWERPC64"
7760   "
7761 {
7762   if (TARGET_ISEL)
7763     emit_insn (gen_absdi2_isel (operands[0], operands[1]));
7764   else
7765     emit_insn (gen_absdi2_internal (operands[0], operands[1]));
7766   DONE;
7767 }")
7768
7769 (define_insn_and_split "absdi2_internal"
7770   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7771         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
7772    (clobber (match_scratch:DI 2 "=&r,&r"))]
7773   "TARGET_POWERPC64 && !TARGET_ISEL"
7774   "#"
7775   "&& reload_completed"
7776   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
7777    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
7778    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
7779   "")
7780
7781 (define_insn_and_split "*nabsdi2"
7782   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
7783         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
7784    (clobber (match_scratch:DI 2 "=&r,&r"))]
7785   "TARGET_POWERPC64 && !TARGET_ISEL"
7786   "#"
7787   "&& reload_completed"
7788   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
7789    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
7790    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
7791   "")
7792
7793 (define_insn "muldi3"
7794   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7795         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7796                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
7797   "TARGET_POWERPC64"
7798   "@
7799    mulld %0,%1,%2
7800    mulli %0,%1,%2"
7801    [(set (attr "type")
7802       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
7803                 (const_string "imul3")
7804              (match_operand:SI 2 "short_cint_operand" "")
7805                 (const_string "imul2")]
7806         (const_string "lmul")))])
7807
7808 (define_insn "*muldi3_internal1"
7809   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7810         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7811                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
7812                     (const_int 0)))
7813    (clobber (match_scratch:DI 3 "=r,r"))]
7814   "TARGET_POWERPC64"
7815   "@
7816    mulld. %3,%1,%2
7817    #"
7818   [(set_attr "type" "lmul_compare")
7819    (set_attr "length" "4,8")])
7820
7821 (define_split
7822   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7823         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
7824                              (match_operand:DI 2 "gpc_reg_operand" ""))
7825                     (const_int 0)))
7826    (clobber (match_scratch:DI 3 ""))]
7827   "TARGET_POWERPC64 && reload_completed"
7828   [(set (match_dup 3)
7829         (mult:DI (match_dup 1) (match_dup 2)))
7830    (set (match_dup 0)
7831         (compare:CC (match_dup 3)
7832                     (const_int 0)))]
7833   "")
7834
7835 (define_insn "*muldi3_internal2"
7836   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7837         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
7838                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
7839                     (const_int 0)))
7840    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7841         (mult:DI (match_dup 1) (match_dup 2)))]
7842   "TARGET_POWERPC64"
7843   "@
7844    mulld. %0,%1,%2
7845    #"
7846   [(set_attr "type" "lmul_compare")
7847    (set_attr "length" "4,8")])
7848
7849 (define_split
7850   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7851         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
7852                              (match_operand:DI 2 "gpc_reg_operand" ""))
7853                     (const_int 0)))
7854    (set (match_operand:DI 0 "gpc_reg_operand" "")
7855         (mult:DI (match_dup 1) (match_dup 2)))]
7856   "TARGET_POWERPC64 && reload_completed"
7857   [(set (match_dup 0)
7858         (mult:DI (match_dup 1) (match_dup 2)))
7859    (set (match_dup 3)
7860         (compare:CC (match_dup 0)
7861                     (const_int 0)))]
7862   "")
7863
7864 (define_insn "smuldi3_highpart"
7865   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7866         (truncate:DI
7867          (lshiftrt:TI (mult:TI (sign_extend:TI
7868                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
7869                                (sign_extend:TI
7870                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
7871                       (const_int 64))))]
7872   "TARGET_POWERPC64"
7873   "mulhd %0,%1,%2"
7874   [(set_attr "type" "lmul")])
7875
7876 (define_insn "umuldi3_highpart"
7877   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7878         (truncate:DI
7879          (lshiftrt:TI (mult:TI (zero_extend:TI
7880                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
7881                                (zero_extend:TI
7882                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
7883                       (const_int 64))))]
7884   "TARGET_POWERPC64"
7885   "mulhdu %0,%1,%2"
7886   [(set_attr "type" "lmul")])
7887
7888 (define_insn "rotldi3"
7889   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7890         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7891                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
7892   "TARGET_POWERPC64"
7893   "@
7894    rldcl %0,%1,%2,0
7895    rldicl %0,%1,%H2,0"
7896   [(set_attr "type" "var_shift_rotate,integer")])
7897
7898 (define_insn "*rotldi3_internal2"
7899   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7900         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7901                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7902                     (const_int 0)))
7903    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7904   "TARGET_64BIT"
7905   "@
7906    rldcl. %3,%1,%2,0
7907    rldicl. %3,%1,%H2,0
7908    #
7909    #"
7910   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7911    (set_attr "length" "4,4,8,8")])
7912
7913 (define_split
7914   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7915         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7916                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7917                     (const_int 0)))
7918    (clobber (match_scratch:DI 3 ""))]
7919   "TARGET_POWERPC64 && reload_completed"
7920   [(set (match_dup 3)
7921         (rotate:DI (match_dup 1) (match_dup 2)))
7922    (set (match_dup 0)
7923         (compare:CC (match_dup 3)
7924                     (const_int 0)))]
7925   "")
7926
7927 (define_insn "*rotldi3_internal3"
7928   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7929         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7930                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7931                     (const_int 0)))
7932    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7933         (rotate:DI (match_dup 1) (match_dup 2)))]
7934   "TARGET_64BIT"
7935   "@
7936    rldcl. %0,%1,%2,0
7937    rldicl. %0,%1,%H2,0
7938    #
7939    #"
7940   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7941    (set_attr "length" "4,4,8,8")])
7942
7943 (define_split
7944   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7945         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7946                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7947                     (const_int 0)))
7948    (set (match_operand:DI 0 "gpc_reg_operand" "")
7949         (rotate:DI (match_dup 1) (match_dup 2)))]
7950   "TARGET_POWERPC64 && reload_completed"
7951   [(set (match_dup 0)
7952         (rotate:DI (match_dup 1) (match_dup 2)))
7953    (set (match_dup 3)
7954         (compare:CC (match_dup 0)
7955                     (const_int 0)))]
7956   "")
7957
7958 (define_insn "*rotldi3_internal4"
7959   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7960         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7961                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
7962                 (match_operand:DI 3 "mask64_operand" "n,n")))]
7963   "TARGET_POWERPC64"
7964   "@
7965    rldc%B3 %0,%1,%2,%S3
7966    rldic%B3 %0,%1,%H2,%S3"
7967   [(set_attr "type" "var_shift_rotate,integer")])
7968
7969 (define_insn "*rotldi3_internal5"
7970   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7971         (compare:CC (and:DI
7972                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7973                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7974                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7975                     (const_int 0)))
7976    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
7977   "TARGET_64BIT"
7978   "@
7979    rldc%B3. %4,%1,%2,%S3
7980    rldic%B3. %4,%1,%H2,%S3
7981    #
7982    #"
7983   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7984    (set_attr "length" "4,4,8,8")])
7985
7986 (define_split
7987   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7988         (compare:CC (and:DI
7989                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7990                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7991                      (match_operand:DI 3 "mask64_operand" ""))
7992                     (const_int 0)))
7993    (clobber (match_scratch:DI 4 ""))]
7994   "TARGET_POWERPC64 && reload_completed"
7995   [(set (match_dup 4)
7996         (and:DI (rotate:DI (match_dup 1)
7997                                 (match_dup 2))
7998                      (match_dup 3)))
7999    (set (match_dup 0)
8000         (compare:CC (match_dup 4)
8001                     (const_int 0)))]
8002   "")
8003
8004 (define_insn "*rotldi3_internal6"
8005   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
8006         (compare:CC (and:DI
8007                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8008                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
8009                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
8010                     (const_int 0)))
8011    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8012         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8013   "TARGET_64BIT"
8014   "@
8015    rldc%B3. %0,%1,%2,%S3
8016    rldic%B3. %0,%1,%H2,%S3
8017    #
8018    #"
8019   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8020    (set_attr "length" "4,4,8,8")])
8021
8022 (define_split
8023   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
8024         (compare:CC (and:DI
8025                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8026                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
8027                      (match_operand:DI 3 "mask64_operand" ""))
8028                     (const_int 0)))
8029    (set (match_operand:DI 0 "gpc_reg_operand" "")
8030         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8031   "TARGET_POWERPC64 && reload_completed"
8032   [(set (match_dup 0)
8033         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
8034    (set (match_dup 4)
8035         (compare:CC (match_dup 0)
8036                     (const_int 0)))]
8037   "")
8038
8039 (define_insn "*rotldi3_internal7"
8040   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8041         (zero_extend:DI
8042          (subreg:QI
8043           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8044                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
8045   "TARGET_POWERPC64"
8046   "@
8047    rldcl %0,%1,%2,56
8048    rldicl %0,%1,%H2,56"
8049   [(set_attr "type" "var_shift_rotate,integer")])
8050
8051 (define_insn "*rotldi3_internal8"
8052   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8053         (compare:CC (zero_extend:DI
8054                      (subreg:QI
8055                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8056                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8057                     (const_int 0)))
8058    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8059   "TARGET_64BIT"
8060   "@
8061    rldcl. %3,%1,%2,56
8062    rldicl. %3,%1,%H2,56
8063    #
8064    #"
8065   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8066    (set_attr "length" "4,4,8,8")])
8067
8068 (define_split
8069   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8070         (compare:CC (zero_extend:DI
8071                      (subreg:QI
8072                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8073                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8074                     (const_int 0)))
8075    (clobber (match_scratch:DI 3 ""))]
8076   "TARGET_POWERPC64 && reload_completed"
8077   [(set (match_dup 3)
8078         (zero_extend:DI (subreg:QI
8079                       (rotate:DI (match_dup 1)
8080                                  (match_dup 2)) 0)))
8081    (set (match_dup 0)
8082         (compare:CC (match_dup 3)
8083                     (const_int 0)))]
8084   "")
8085
8086 (define_insn "*rotldi3_internal9"
8087   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8088         (compare:CC (zero_extend:DI
8089                      (subreg:QI
8090                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8091                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8092                     (const_int 0)))
8093    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8094         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8095   "TARGET_64BIT"
8096   "@
8097    rldcl. %0,%1,%2,56
8098    rldicl. %0,%1,%H2,56
8099    #
8100    #"
8101   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8102    (set_attr "length" "4,4,8,8")])
8103
8104 (define_split
8105   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8106         (compare:CC (zero_extend:DI
8107                      (subreg:QI
8108                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8109                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8110                     (const_int 0)))
8111    (set (match_operand:DI 0 "gpc_reg_operand" "")
8112         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8113   "TARGET_POWERPC64 && reload_completed"
8114   [(set (match_dup 0)
8115         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
8116    (set (match_dup 3)
8117         (compare:CC (match_dup 0)
8118                     (const_int 0)))]
8119   "")
8120
8121 (define_insn "*rotldi3_internal10"
8122   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8123         (zero_extend:DI
8124          (subreg:HI
8125           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8126                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
8127   "TARGET_POWERPC64"
8128   "@
8129    rldcl %0,%1,%2,48
8130    rldicl %0,%1,%H2,48"
8131   [(set_attr "type" "var_shift_rotate,integer")])
8132
8133 (define_insn "*rotldi3_internal11"
8134   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8135         (compare:CC (zero_extend:DI
8136                      (subreg:HI
8137                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8138                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8139                     (const_int 0)))
8140    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8141   "TARGET_64BIT"
8142   "@
8143    rldcl. %3,%1,%2,48
8144    rldicl. %3,%1,%H2,48
8145    #
8146    #"
8147   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8148    (set_attr "length" "4,4,8,8")])
8149
8150 (define_split
8151   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8152         (compare:CC (zero_extend:DI
8153                      (subreg:HI
8154                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8155                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8156                     (const_int 0)))
8157    (clobber (match_scratch:DI 3 ""))]
8158   "TARGET_POWERPC64 && reload_completed"
8159   [(set (match_dup 3)
8160         (zero_extend:DI (subreg:HI
8161                       (rotate:DI (match_dup 1)
8162                                  (match_dup 2)) 0)))
8163    (set (match_dup 0)
8164         (compare:CC (match_dup 3)
8165                     (const_int 0)))]
8166   "")
8167
8168 (define_insn "*rotldi3_internal12"
8169   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8170         (compare:CC (zero_extend:DI
8171                      (subreg:HI
8172                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8173                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8174                     (const_int 0)))
8175    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8176         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8177   "TARGET_64BIT"
8178   "@
8179    rldcl. %0,%1,%2,48
8180    rldicl. %0,%1,%H2,48
8181    #
8182    #"
8183   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8184    (set_attr "length" "4,4,8,8")])
8185
8186 (define_split
8187   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8188         (compare:CC (zero_extend:DI
8189                      (subreg:HI
8190                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8191                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8192                     (const_int 0)))
8193    (set (match_operand:DI 0 "gpc_reg_operand" "")
8194         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8195   "TARGET_POWERPC64 && reload_completed"
8196   [(set (match_dup 0)
8197         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
8198    (set (match_dup 3)
8199         (compare:CC (match_dup 0)
8200                     (const_int 0)))]
8201   "")
8202
8203 (define_insn "*rotldi3_internal13"
8204   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8205         (zero_extend:DI
8206          (subreg:SI
8207           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8208                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
8209   "TARGET_POWERPC64"
8210   "@
8211    rldcl %0,%1,%2,32
8212    rldicl %0,%1,%H2,32"
8213   [(set_attr "type" "var_shift_rotate,integer")])
8214
8215 (define_insn "*rotldi3_internal14"
8216   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8217         (compare:CC (zero_extend:DI
8218                      (subreg:SI
8219                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8220                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8221                     (const_int 0)))
8222    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8223   "TARGET_64BIT"
8224   "@
8225    rldcl. %3,%1,%2,32
8226    rldicl. %3,%1,%H2,32
8227    #
8228    #"
8229   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8230    (set_attr "length" "4,4,8,8")])
8231
8232 (define_split
8233   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8234         (compare:CC (zero_extend:DI
8235                      (subreg:SI
8236                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8237                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8238                     (const_int 0)))
8239    (clobber (match_scratch:DI 3 ""))]
8240   "TARGET_POWERPC64 && reload_completed"
8241   [(set (match_dup 3)
8242         (zero_extend:DI (subreg:SI
8243                       (rotate:DI (match_dup 1)
8244                                  (match_dup 2)) 0)))
8245    (set (match_dup 0)
8246         (compare:CC (match_dup 3)
8247                     (const_int 0)))]
8248   "")
8249
8250 (define_insn "*rotldi3_internal15"
8251   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8252         (compare:CC (zero_extend:DI
8253                      (subreg:SI
8254                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8255                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
8256                     (const_int 0)))
8257    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8258         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8259   "TARGET_64BIT"
8260   "@
8261    rldcl. %0,%1,%2,32
8262    rldicl. %0,%1,%H2,32
8263    #
8264    #"
8265   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8266    (set_attr "length" "4,4,8,8")])
8267
8268 (define_split
8269   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8270         (compare:CC (zero_extend:DI
8271                      (subreg:SI
8272                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
8273                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
8274                     (const_int 0)))
8275    (set (match_operand:DI 0 "gpc_reg_operand" "")
8276         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
8277   "TARGET_POWERPC64 && reload_completed"
8278   [(set (match_dup 0)
8279         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
8280    (set (match_dup 3)
8281         (compare:CC (match_dup 0)
8282                     (const_int 0)))]
8283   "")
8284
8285 (define_expand "ashldi3"
8286   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8287         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8288                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
8289   "TARGET_POWERPC64 || TARGET_POWER"
8290   "
8291 {
8292   if (TARGET_POWERPC64)
8293     ;
8294   else if (TARGET_POWER)
8295     {
8296       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
8297       DONE;
8298     }
8299   else
8300     FAIL;
8301 }")
8302
8303 (define_insn "*ashldi3_internal1"
8304   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8305         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8306                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8307   "TARGET_POWERPC64"
8308   "@
8309    sld %0,%1,%2
8310    sldi %0,%1,%H2"
8311   [(set_attr "type" "var_shift_rotate,shift")])
8312
8313 (define_insn "*ashldi3_internal2"
8314   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8315         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8316                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8317                     (const_int 0)))
8318    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8319   "TARGET_64BIT"
8320   "@
8321    sld. %3,%1,%2
8322    sldi. %3,%1,%H2
8323    #
8324    #"
8325   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8326    (set_attr "length" "4,4,8,8")])
8327
8328 (define_split
8329   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
8330         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8331                                (match_operand:SI 2 "reg_or_cint_operand" ""))
8332                     (const_int 0)))
8333    (clobber (match_scratch:DI 3 ""))]
8334   "TARGET_POWERPC64 && reload_completed"
8335   [(set (match_dup 3)
8336         (ashift:DI (match_dup 1) (match_dup 2)))
8337    (set (match_dup 0)
8338         (compare:CC (match_dup 3)
8339                     (const_int 0)))]
8340   "")
8341
8342 (define_insn "*ashldi3_internal3"
8343   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8344         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8345                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8346                     (const_int 0)))
8347    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8348         (ashift:DI (match_dup 1) (match_dup 2)))]
8349   "TARGET_64BIT"
8350   "@
8351    sld. %0,%1,%2
8352    sldi. %0,%1,%H2
8353    #
8354    #"
8355   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8356    (set_attr "length" "4,4,8,8")])
8357
8358 (define_split
8359   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
8360         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8361                                (match_operand:SI 2 "reg_or_cint_operand" ""))
8362                     (const_int 0)))
8363    (set (match_operand:DI 0 "gpc_reg_operand" "")
8364         (ashift:DI (match_dup 1) (match_dup 2)))]
8365   "TARGET_POWERPC64 && reload_completed"
8366   [(set (match_dup 0)
8367         (ashift:DI (match_dup 1) (match_dup 2)))
8368    (set (match_dup 3)
8369         (compare:CC (match_dup 0)
8370                     (const_int 0)))]
8371   "")
8372
8373 (define_insn "*ashldi3_internal4"
8374   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8375         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
8376                            (match_operand:SI 2 "const_int_operand" "i"))
8377                 (match_operand:DI 3 "const_int_operand" "n")))]
8378   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
8379   "rldic %0,%1,%H2,%W3")
8380
8381 (define_insn "ashldi3_internal5"
8382   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8383         (compare:CC
8384          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8385                             (match_operand:SI 2 "const_int_operand" "i,i"))
8386                  (match_operand:DI 3 "const_int_operand" "n,n"))
8387          (const_int 0)))
8388    (clobber (match_scratch:DI 4 "=r,r"))]
8389   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
8390   "@
8391    rldic. %4,%1,%H2,%W3
8392    #"
8393   [(set_attr "type" "compare")
8394    (set_attr "length" "4,8")])
8395
8396 (define_split
8397   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8398         (compare:CC
8399          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8400                             (match_operand:SI 2 "const_int_operand" ""))
8401                  (match_operand:DI 3 "const_int_operand" ""))
8402          (const_int 0)))
8403    (clobber (match_scratch:DI 4 ""))]
8404   "TARGET_POWERPC64 && reload_completed
8405    && includes_rldic_lshift_p (operands[2], operands[3])"
8406   [(set (match_dup 4)
8407         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8408                 (match_dup 3)))
8409    (set (match_dup 0)
8410         (compare:CC (match_dup 4)
8411                     (const_int 0)))]
8412   "")
8413
8414 (define_insn "*ashldi3_internal6"
8415   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
8416         (compare:CC
8417          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8418                             (match_operand:SI 2 "const_int_operand" "i,i"))
8419                     (match_operand:DI 3 "const_int_operand" "n,n"))
8420          (const_int 0)))
8421    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8422         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8423   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
8424   "@
8425    rldic. %0,%1,%H2,%W3
8426    #"
8427   [(set_attr "type" "compare")
8428    (set_attr "length" "4,8")])
8429
8430 (define_split
8431   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
8432         (compare:CC
8433          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8434                             (match_operand:SI 2 "const_int_operand" ""))
8435                  (match_operand:DI 3 "const_int_operand" ""))
8436          (const_int 0)))
8437    (set (match_operand:DI 0 "gpc_reg_operand" "")
8438         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8439   "TARGET_POWERPC64 && reload_completed
8440    && includes_rldic_lshift_p (operands[2], operands[3])"
8441   [(set (match_dup 0)
8442         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8443                 (match_dup 3)))
8444    (set (match_dup 4)
8445         (compare:CC (match_dup 0)
8446                     (const_int 0)))]
8447   "")
8448
8449 (define_insn "*ashldi3_internal7"
8450   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8451         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
8452                            (match_operand:SI 2 "const_int_operand" "i"))
8453                 (match_operand:DI 3 "mask64_operand" "n")))]
8454   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
8455   "rldicr %0,%1,%H2,%S3")
8456
8457 (define_insn "ashldi3_internal8"
8458   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8459         (compare:CC
8460          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8461                             (match_operand:SI 2 "const_int_operand" "i,i"))
8462                  (match_operand:DI 3 "mask64_operand" "n,n"))
8463          (const_int 0)))
8464    (clobber (match_scratch:DI 4 "=r,r"))]
8465   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
8466   "@
8467    rldicr. %4,%1,%H2,%S3
8468    #"
8469   [(set_attr "type" "compare")
8470    (set_attr "length" "4,8")])
8471
8472 (define_split
8473   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8474         (compare:CC
8475          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8476                             (match_operand:SI 2 "const_int_operand" ""))
8477                  (match_operand:DI 3 "mask64_operand" ""))
8478          (const_int 0)))
8479    (clobber (match_scratch:DI 4 ""))]
8480   "TARGET_POWERPC64 && reload_completed
8481    && includes_rldicr_lshift_p (operands[2], operands[3])"
8482   [(set (match_dup 4)
8483         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8484                 (match_dup 3)))
8485    (set (match_dup 0)
8486         (compare:CC (match_dup 4)
8487                     (const_int 0)))]
8488   "")
8489
8490 (define_insn "*ashldi3_internal9"
8491   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
8492         (compare:CC
8493          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8494                             (match_operand:SI 2 "const_int_operand" "i,i"))
8495                     (match_operand:DI 3 "mask64_operand" "n,n"))
8496          (const_int 0)))
8497    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8498         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8499   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
8500   "@
8501    rldicr. %0,%1,%H2,%S3
8502    #"
8503   [(set_attr "type" "compare")
8504    (set_attr "length" "4,8")])
8505
8506 (define_split
8507   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
8508         (compare:CC
8509          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
8510                             (match_operand:SI 2 "const_int_operand" ""))
8511                  (match_operand:DI 3 "mask64_operand" ""))
8512          (const_int 0)))
8513    (set (match_operand:DI 0 "gpc_reg_operand" "")
8514         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
8515   "TARGET_POWERPC64 && reload_completed
8516    && includes_rldicr_lshift_p (operands[2], operands[3])"
8517   [(set (match_dup 0)
8518         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
8519                 (match_dup 3)))
8520    (set (match_dup 4)
8521         (compare:CC (match_dup 0)
8522                     (const_int 0)))]
8523   "")
8524
8525 (define_expand "lshrdi3"
8526   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8527         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8528                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
8529   "TARGET_POWERPC64 || TARGET_POWER"
8530   "
8531 {
8532   if (TARGET_POWERPC64)
8533     ;
8534   else if (TARGET_POWER)
8535     {
8536       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
8537       DONE;
8538     }
8539   else
8540     FAIL;
8541 }")
8542
8543 (define_insn "*lshrdi3_internal1"
8544   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8545         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8546                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8547   "TARGET_POWERPC64"
8548   "@
8549    srd %0,%1,%2
8550    srdi %0,%1,%H2"
8551   [(set_attr "type" "var_shift_rotate,shift")])
8552
8553 (define_insn "*lshrdi3_internal2"
8554   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8555         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8556                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8557                     (const_int 0)))
8558    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8559   "TARGET_64BIT "
8560   "@
8561    srd. %3,%1,%2
8562    srdi. %3,%1,%H2
8563    #
8564    #"
8565   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8566    (set_attr "length" "4,4,8,8")])
8567
8568 (define_split
8569   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8570         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8571                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8572                     (const_int 0)))
8573    (clobber (match_scratch:DI 3 ""))]
8574   "TARGET_POWERPC64 && reload_completed"
8575   [(set (match_dup 3)
8576         (lshiftrt:DI (match_dup 1) (match_dup 2)))
8577    (set (match_dup 0)
8578         (compare:CC (match_dup 3)
8579                     (const_int 0)))]
8580   "")
8581
8582 (define_insn "*lshrdi3_internal3"
8583   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8584         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8585                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8586                     (const_int 0)))
8587    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8588         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
8589   "TARGET_64BIT"
8590   "@
8591    srd. %0,%1,%2
8592    srdi. %0,%1,%H2
8593    #
8594    #"
8595   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8596    (set_attr "length" "4,4,8,8")])
8597
8598 (define_split
8599   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8600         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8601                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8602                     (const_int 0)))
8603    (set (match_operand:DI 0 "gpc_reg_operand" "")
8604         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
8605   "TARGET_POWERPC64 && reload_completed"
8606   [(set (match_dup 0)
8607         (lshiftrt:DI (match_dup 1) (match_dup 2)))
8608    (set (match_dup 3)
8609         (compare:CC (match_dup 0)
8610                     (const_int 0)))]
8611   "")
8612
8613 (define_expand "ashrdi3"
8614   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8615         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8616                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
8617   "WORDS_BIG_ENDIAN"
8618   "
8619 {
8620   if (TARGET_POWERPC64)
8621     ;
8622   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
8623     {
8624       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
8625       DONE;
8626     }
8627   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
8628            && WORDS_BIG_ENDIAN)
8629     {
8630       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
8631       DONE;
8632     }
8633   else
8634     FAIL;
8635 }")
8636
8637 (define_insn "*ashrdi3_internal1"
8638   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8639         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8640                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8641   "TARGET_POWERPC64"
8642   "@
8643    srad %0,%1,%2
8644    sradi %0,%1,%H2"
8645   [(set_attr "type" "var_shift_rotate,shift")])
8646
8647 (define_insn "*ashrdi3_internal2"
8648   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8649         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8650                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8651                     (const_int 0)))
8652    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8653   "TARGET_64BIT"
8654   "@
8655    srad. %3,%1,%2
8656    sradi. %3,%1,%H2
8657    #
8658    #"
8659   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8660    (set_attr "length" "4,4,8,8")])
8661
8662 (define_split
8663   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
8664         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8665                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8666                     (const_int 0)))
8667    (clobber (match_scratch:DI 3 ""))]
8668   "TARGET_POWERPC64 && reload_completed"
8669   [(set (match_dup 3)
8670         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8671    (set (match_dup 0)
8672         (compare:CC (match_dup 3)
8673                     (const_int 0)))]
8674   "")
8675
8676 (define_insn "*ashrdi3_internal3"
8677   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8678         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8679                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8680                     (const_int 0)))
8681    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8682         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8683   "TARGET_64BIT"
8684   "@
8685    srad. %0,%1,%2
8686    sradi. %0,%1,%H2
8687    #
8688    #"
8689   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
8690    (set_attr "length" "4,4,8,8")])
8691
8692 (define_split
8693   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
8694         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8695                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8696                     (const_int 0)))
8697    (set (match_operand:DI 0 "gpc_reg_operand" "")
8698         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8699   "TARGET_POWERPC64 && reload_completed"
8700   [(set (match_dup 0)
8701         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8702    (set (match_dup 3)
8703         (compare:CC (match_dup 0)
8704                     (const_int 0)))]
8705   "")
8706
8707 (define_expand "anddi3"
8708   [(parallel
8709     [(set (match_operand:DI 0 "gpc_reg_operand" "")
8710           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8711                   (match_operand:DI 2 "and64_2_operand" "")))
8712      (clobber (match_scratch:CC 3 ""))])]
8713   "TARGET_POWERPC64"
8714   "")
8715
8716 (define_insn "anddi3_mc"
8717   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
8718         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
8719                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
8720    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
8721   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
8722   "@
8723    and %0,%1,%2
8724    rldic%B2 %0,%1,0,%S2
8725    rlwinm %0,%1,0,%m2,%M2
8726    andi. %0,%1,%b2
8727    andis. %0,%1,%u2
8728    #"
8729   [(set_attr "type" "*,*,*,fast_compare,fast_compare,*")
8730    (set_attr "length" "4,4,4,4,4,8")])
8731
8732 (define_insn "anddi3_nomc"
8733   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8734         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
8735                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
8736    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
8737   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
8738   "@
8739    and %0,%1,%2
8740    rldic%B2 %0,%1,0,%S2
8741    rlwinm %0,%1,0,%m2,%M2
8742    #"
8743   [(set_attr "length" "4,4,4,8")])
8744
8745 (define_split
8746   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8747         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8748                 (match_operand:DI 2 "mask64_2_operand" "")))
8749    (clobber (match_scratch:CC 3 ""))]
8750   "TARGET_POWERPC64
8751     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8752     && !mask_operand (operands[2], DImode)
8753     && !mask64_operand (operands[2], DImode)"
8754   [(set (match_dup 0)
8755         (and:DI (rotate:DI (match_dup 1)
8756                            (match_dup 4))
8757                 (match_dup 5)))
8758    (set (match_dup 0)
8759         (and:DI (rotate:DI (match_dup 0)
8760                            (match_dup 6))
8761                 (match_dup 7)))]
8762 {
8763   build_mask64_2_operands (operands[2], &operands[4]);
8764 })
8765
8766 (define_insn "*anddi3_internal2_mc"
8767   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8768         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8769                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8770                     (const_int 0)))
8771    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
8772    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8773   "TARGET_64BIT && rs6000_gen_cell_microcode"
8774   "@
8775    and. %3,%1,%2
8776    rldic%B2. %3,%1,0,%S2
8777    rlwinm. %3,%1,0,%m2,%M2
8778    andi. %3,%1,%b2
8779    andis. %3,%1,%u2
8780    #
8781    #
8782    #
8783    #
8784    #
8785    #
8786    #"
8787   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8788                      fast_compare,compare,compare,compare,compare,compare,\
8789                      compare,compare")
8790    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8791
8792 (define_split
8793   [(set (match_operand:CC 0 "cc_reg_operand" "")
8794         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8795                             (match_operand:DI 2 "mask64_2_operand" ""))
8796                     (const_int 0)))
8797    (clobber (match_scratch:DI 3 ""))
8798    (clobber (match_scratch:CC 4 ""))]
8799   "TARGET_64BIT && reload_completed
8800     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8801     && !mask_operand (operands[2], DImode)
8802     && !mask64_operand (operands[2], DImode)"
8803   [(set (match_dup 3)
8804         (and:DI (rotate:DI (match_dup 1)
8805                            (match_dup 5))
8806                 (match_dup 6)))
8807    (parallel [(set (match_dup 0)
8808                    (compare:CC (and:DI (rotate:DI (match_dup 3)
8809                                                   (match_dup 7))
8810                                        (match_dup 8))
8811                                (const_int 0)))
8812               (clobber (match_dup 3))])]
8813   "
8814 {
8815   build_mask64_2_operands (operands[2], &operands[5]);
8816 }")
8817
8818 (define_insn "*anddi3_internal3_mc"
8819   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8820         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8821                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8822                     (const_int 0)))
8823    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
8824         (and:DI (match_dup 1) (match_dup 2)))
8825    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8826   "TARGET_64BIT && rs6000_gen_cell_microcode"
8827   "@
8828    and. %0,%1,%2
8829    rldic%B2. %0,%1,0,%S2
8830    rlwinm. %0,%1,0,%m2,%M2
8831    andi. %0,%1,%b2
8832    andis. %0,%1,%u2
8833    #
8834    #
8835    #
8836    #
8837    #
8838    #
8839    #"
8840   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8841                      fast_compare,compare,compare,compare,compare,compare,\
8842                      compare,compare")
8843    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8844
8845 (define_split
8846   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8847         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8848                             (match_operand:DI 2 "and64_2_operand" ""))
8849                     (const_int 0)))
8850    (set (match_operand:DI 0 "gpc_reg_operand" "")
8851         (and:DI (match_dup 1) (match_dup 2)))
8852    (clobber (match_scratch:CC 4 ""))]
8853   "TARGET_64BIT && reload_completed"
8854   [(parallel [(set (match_dup 0)
8855                     (and:DI (match_dup 1) (match_dup 2)))
8856                (clobber (match_dup 4))])
8857    (set (match_dup 3)
8858         (compare:CC (match_dup 0)
8859                     (const_int 0)))]
8860   "")
8861
8862 (define_split
8863   [(set (match_operand:CC 3 "cc_reg_operand" "")
8864         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8865                             (match_operand:DI 2 "mask64_2_operand" ""))
8866                     (const_int 0)))
8867    (set (match_operand:DI 0 "gpc_reg_operand" "")
8868         (and:DI (match_dup 1) (match_dup 2)))
8869    (clobber (match_scratch:CC 4 ""))]
8870   "TARGET_64BIT && reload_completed
8871     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8872     && !mask_operand (operands[2], DImode)
8873     && !mask64_operand (operands[2], DImode)"
8874   [(set (match_dup 0)
8875         (and:DI (rotate:DI (match_dup 1)
8876                            (match_dup 5))
8877                 (match_dup 6)))
8878    (parallel [(set (match_dup 3)
8879                    (compare:CC (and:DI (rotate:DI (match_dup 0)
8880                                                   (match_dup 7))
8881                                        (match_dup 8))
8882                                (const_int 0)))
8883               (set (match_dup 0)
8884                    (and:DI (rotate:DI (match_dup 0)
8885                                       (match_dup 7))
8886                            (match_dup 8)))])]
8887   "
8888 {
8889   build_mask64_2_operands (operands[2], &operands[5]);
8890 }")
8891
8892 (define_expand "iordi3"
8893   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8894         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
8895                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8896   "TARGET_POWERPC64"
8897   "
8898 {
8899   if (non_logical_cint_operand (operands[2], DImode))
8900     {
8901       HOST_WIDE_INT value;
8902       rtx tmp = ((!can_create_pseudo_p ()
8903                   || rtx_equal_p (operands[0], operands[1]))
8904                  ? operands[0] : gen_reg_rtx (DImode));
8905
8906       if (GET_CODE (operands[2]) == CONST_INT)
8907         {
8908           value = INTVAL (operands[2]);
8909           emit_insn (gen_iordi3 (tmp, operands[1],
8910                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8911         }
8912       else
8913         {
8914           value = CONST_DOUBLE_LOW (operands[2]);
8915           emit_insn (gen_iordi3 (tmp, operands[1],
8916                                  immed_double_const (value
8917                                                      & (~ (HOST_WIDE_INT) 0xffff),
8918                                                      0, DImode)));
8919         }
8920
8921       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8922       DONE;
8923     }
8924 }")
8925
8926 (define_expand "xordi3"
8927   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8928         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
8929                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8930   "TARGET_POWERPC64"
8931   "
8932 {
8933   if (non_logical_cint_operand (operands[2], DImode))
8934     {
8935       HOST_WIDE_INT value;
8936       rtx tmp = ((!can_create_pseudo_p ()
8937                   || rtx_equal_p (operands[0], operands[1]))
8938                  ? operands[0] : gen_reg_rtx (DImode));
8939
8940       if (GET_CODE (operands[2]) == CONST_INT)
8941         {
8942           value = INTVAL (operands[2]);
8943           emit_insn (gen_xordi3 (tmp, operands[1],
8944                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8945         }
8946       else
8947         {
8948           value = CONST_DOUBLE_LOW (operands[2]);
8949           emit_insn (gen_xordi3 (tmp, operands[1],
8950                                  immed_double_const (value
8951                                                      & (~ (HOST_WIDE_INT) 0xffff),
8952                                                      0, DImode)));
8953         }
8954
8955       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8956       DONE;
8957     }
8958 }")
8959
8960 (define_insn "*booldi3_internal1"
8961   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
8962         (match_operator:DI 3 "boolean_or_operator"
8963          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
8964           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
8965   "TARGET_POWERPC64"
8966   "@
8967    %q3 %0,%1,%2
8968    %q3i %0,%1,%b2
8969    %q3is %0,%1,%u2")
8970
8971 (define_insn "*booldi3_internal2"
8972   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8973         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8974          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8975           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8976          (const_int 0)))
8977    (clobber (match_scratch:DI 3 "=r,r"))]
8978   "TARGET_64BIT"
8979   "@
8980    %q4. %3,%1,%2
8981    #"
8982   [(set_attr "type" "fast_compare,compare")
8983    (set_attr "length" "4,8")])
8984
8985 (define_split
8986   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8987         (compare:CC (match_operator:DI 4 "boolean_operator"
8988          [(match_operand:DI 1 "gpc_reg_operand" "")
8989           (match_operand:DI 2 "gpc_reg_operand" "")])
8990          (const_int 0)))
8991    (clobber (match_scratch:DI 3 ""))]
8992   "TARGET_POWERPC64 && reload_completed"
8993   [(set (match_dup 3) (match_dup 4))
8994    (set (match_dup 0)
8995         (compare:CC (match_dup 3)
8996                     (const_int 0)))]
8997   "")
8998
8999 (define_insn "*booldi3_internal3"
9000   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
9001         (compare:CC (match_operator:DI 4 "boolean_or_operator"
9002          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
9003           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
9004          (const_int 0)))
9005    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
9006         (match_dup 4))]
9007   "TARGET_64BIT"
9008   "@
9009    %q4. %0,%1,%2
9010    #"
9011   [(set_attr "type" "fast_compare,compare")
9012    (set_attr "length" "4,8")])
9013
9014 (define_split
9015   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
9016         (compare:CC (match_operator:DI 4 "boolean_operator"
9017          [(match_operand:DI 1 "gpc_reg_operand" "")
9018           (match_operand:DI 2 "gpc_reg_operand" "")])
9019          (const_int 0)))
9020    (set (match_operand:DI 0 "gpc_reg_operand" "")
9021         (match_dup 4))]
9022   "TARGET_POWERPC64 && reload_completed"
9023   [(set (match_dup 0) (match_dup 4))
9024    (set (match_dup 3)
9025         (compare:CC (match_dup 0)
9026                     (const_int 0)))]
9027   "")
9028
9029 ;; Split a logical operation that we can't do in one insn into two insns,
9030 ;; each of which does one 16-bit part.  This is used by combine.
9031
9032 (define_split
9033   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9034         (match_operator:DI 3 "boolean_or_operator"
9035          [(match_operand:DI 1 "gpc_reg_operand" "")
9036           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
9037   "TARGET_POWERPC64"
9038   [(set (match_dup 0) (match_dup 4))
9039    (set (match_dup 0) (match_dup 5))]
9040 "
9041 {
9042   rtx i3,i4;
9043
9044   if (GET_CODE (operands[2]) == CONST_DOUBLE)
9045     {
9046       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
9047       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
9048                                         0, DImode);
9049       i4 = GEN_INT (value & 0xffff);
9050     }
9051   else
9052     {
9053       i3 = GEN_INT (INTVAL (operands[2])
9054                              & (~ (HOST_WIDE_INT) 0xffff));
9055       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
9056     }
9057   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
9058                                 operands[1], i3);
9059   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
9060                                 operands[0], i4);
9061 }")
9062
9063 (define_insn "*boolcdi3_internal1"
9064   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9065         (match_operator:DI 3 "boolean_operator"
9066          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
9067           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
9068   "TARGET_POWERPC64"
9069   "%q3 %0,%2,%1")
9070
9071 (define_insn "*boolcdi3_internal2"
9072   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
9073         (compare:CC (match_operator:DI 4 "boolean_operator"
9074          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
9075           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
9076          (const_int 0)))
9077    (clobber (match_scratch:DI 3 "=r,r"))]
9078   "TARGET_64BIT"
9079   "@
9080    %q4. %3,%2,%1
9081    #"
9082   [(set_attr "type" "fast_compare,compare")
9083    (set_attr "length" "4,8")])
9084
9085 (define_split
9086   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
9087         (compare:CC (match_operator:DI 4 "boolean_operator"
9088          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
9089           (match_operand:DI 2 "gpc_reg_operand" "")])
9090          (const_int 0)))
9091    (clobber (match_scratch:DI 3 ""))]
9092   "TARGET_POWERPC64 && reload_completed"
9093   [(set (match_dup 3) (match_dup 4))
9094    (set (match_dup 0)
9095         (compare:CC (match_dup 3)
9096                     (const_int 0)))]
9097   "")
9098
9099 (define_insn "*boolcdi3_internal3"
9100   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
9101         (compare:CC (match_operator:DI 4 "boolean_operator"
9102          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
9103           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
9104          (const_int 0)))
9105    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
9106         (match_dup 4))]
9107   "TARGET_64BIT"
9108   "@
9109    %q4. %0,%2,%1
9110    #"
9111   [(set_attr "type" "fast_compare,compare")
9112    (set_attr "length" "4,8")])
9113
9114 (define_split
9115   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
9116         (compare:CC (match_operator:DI 4 "boolean_operator"
9117          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
9118           (match_operand:DI 2 "gpc_reg_operand" "")])
9119          (const_int 0)))
9120    (set (match_operand:DI 0 "gpc_reg_operand" "")
9121         (match_dup 4))]
9122   "TARGET_POWERPC64 && reload_completed"
9123   [(set (match_dup 0) (match_dup 4))
9124    (set (match_dup 3)
9125         (compare:CC (match_dup 0)
9126                     (const_int 0)))]
9127   "")
9128
9129 (define_insn "*boolccdi3_internal1"
9130   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9131         (match_operator:DI 3 "boolean_operator"
9132          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
9133           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
9134   "TARGET_POWERPC64"
9135   "%q3 %0,%1,%2")
9136
9137 (define_insn "*boolccdi3_internal2"
9138   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
9139         (compare:CC (match_operator:DI 4 "boolean_operator"
9140          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
9141           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
9142          (const_int 0)))
9143    (clobber (match_scratch:DI 3 "=r,r"))]
9144   "TARGET_64BIT"
9145   "@
9146    %q4. %3,%1,%2
9147    #"
9148   [(set_attr "type" "fast_compare,compare")
9149    (set_attr "length" "4,8")])
9150
9151 (define_split
9152   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
9153         (compare:CC (match_operator:DI 4 "boolean_operator"
9154          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
9155           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
9156          (const_int 0)))
9157    (clobber (match_scratch:DI 3 ""))]
9158   "TARGET_POWERPC64 && reload_completed"
9159   [(set (match_dup 3) (match_dup 4))
9160    (set (match_dup 0)
9161         (compare:CC (match_dup 3)
9162                     (const_int 0)))]
9163   "")
9164
9165 (define_insn "*boolccdi3_internal3"
9166   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
9167         (compare:CC (match_operator:DI 4 "boolean_operator"
9168          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
9169           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
9170          (const_int 0)))
9171    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
9172         (match_dup 4))]
9173   "TARGET_64BIT"
9174   "@
9175    %q4. %0,%1,%2
9176    #"
9177   [(set_attr "type" "fast_compare,compare")
9178    (set_attr "length" "4,8")])
9179
9180 (define_split
9181   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
9182         (compare:CC (match_operator:DI 4 "boolean_operator"
9183          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
9184           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
9185          (const_int 0)))
9186    (set (match_operand:DI 0 "gpc_reg_operand" "")
9187         (match_dup 4))]
9188   "TARGET_POWERPC64 && reload_completed"
9189   [(set (match_dup 0) (match_dup 4))
9190    (set (match_dup 3)
9191         (compare:CC (match_dup 0)
9192                     (const_int 0)))]
9193   "")
9194
9195 (define_expand "smindi3"
9196   [(match_operand:DI 0 "gpc_reg_operand" "")
9197    (match_operand:DI 1 "gpc_reg_operand" "")
9198    (match_operand:DI 2 "gpc_reg_operand" "")]
9199   "TARGET_ISEL64"
9200   "
9201 {
9202   rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
9203   DONE;
9204 }")
9205
9206 (define_expand "smaxdi3"
9207   [(match_operand:DI 0 "gpc_reg_operand" "")
9208    (match_operand:DI 1 "gpc_reg_operand" "")
9209    (match_operand:DI 2 "gpc_reg_operand" "")]
9210   "TARGET_ISEL64"
9211   "
9212 {
9213   rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
9214   DONE;
9215 }")
9216
9217 (define_expand "umindi3"
9218   [(match_operand:DI 0 "gpc_reg_operand" "")
9219    (match_operand:DI 1 "gpc_reg_operand" "")
9220    (match_operand:DI 2 "gpc_reg_operand" "")]
9221   "TARGET_ISEL64"
9222   "
9223 {
9224   rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
9225   DONE;
9226 }")
9227
9228 (define_expand "umaxdi3"
9229   [(match_operand:DI 0 "gpc_reg_operand" "")
9230    (match_operand:DI 1 "gpc_reg_operand" "")
9231    (match_operand:DI 2 "gpc_reg_operand" "")]
9232   "TARGET_ISEL64"
9233   "
9234 {
9235   rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
9236   DONE;
9237 }")
9238
9239 \f
9240 ;; Now define ways of moving data around.
9241
9242 ;; Set up a register with a value from the GOT table
9243
9244 (define_expand "movsi_got"
9245   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9246         (unspec:SI [(match_operand:SI 1 "got_operand" "")
9247                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
9248   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
9249   "
9250 {
9251   if (GET_CODE (operands[1]) == CONST)
9252     {
9253       rtx offset = const0_rtx;
9254       HOST_WIDE_INT value;
9255
9256       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
9257       value = INTVAL (offset);
9258       if (value != 0)
9259         {
9260           rtx tmp = (!can_create_pseudo_p ()
9261                      ? operands[0]
9262                      : gen_reg_rtx (Pmode));
9263           emit_insn (gen_movsi_got (tmp, operands[1]));
9264           emit_insn (gen_addsi3 (operands[0], tmp, offset));
9265           DONE;
9266         }
9267     }
9268
9269   operands[2] = rs6000_got_register (operands[1]);
9270 }")
9271
9272 (define_insn "*movsi_got_internal"
9273   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9274         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
9275                     (match_operand:SI 2 "gpc_reg_operand" "b")]
9276                    UNSPEC_MOVSI_GOT))]
9277   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
9278   "{l|lwz} %0,%a1@got(%2)"
9279   [(set_attr "type" "load")])
9280
9281 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
9282 ;; didn't get allocated to a hard register.
9283 (define_split
9284   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9285         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
9286                     (match_operand:SI 2 "memory_operand" "")]
9287                    UNSPEC_MOVSI_GOT))]
9288   "DEFAULT_ABI == ABI_V4
9289     && flag_pic == 1
9290     && (reload_in_progress || reload_completed)"
9291   [(set (match_dup 0) (match_dup 2))
9292    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
9293                                  UNSPEC_MOVSI_GOT))]
9294   "")
9295
9296 ;; For SI, we special-case integers that can't be loaded in one insn.  We
9297 ;; do the load 16-bits at a time.  We could do this by loading from memory,
9298 ;; and this is even supposed to be faster, but it is simpler not to get
9299 ;; integers in the TOC.
9300 (define_insn "movsi_low"
9301   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9302         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
9303                            (match_operand 2 "" ""))))]
9304   "TARGET_MACHO && ! TARGET_64BIT"
9305   "{l|lwz} %0,lo16(%2)(%1)"
9306   [(set_attr "type" "load")
9307    (set_attr "length" "4")])
9308
9309 (define_insn "*movsi_internal1"
9310   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
9311         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
9312   "!TARGET_SINGLE_FPU &&
9313    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
9314   "@
9315    mr %0,%1
9316    {cal|la} %0,%a1
9317    {l%U1%X1|lwz%U1%X1} %0,%1
9318    {st%U0%X0|stw%U0%X0} %1,%0
9319    {lil|li} %0,%1
9320    {liu|lis} %0,%v1
9321    #
9322    {cal|la} %0,%a1
9323    mf%1 %0
9324    mt%0 %1
9325    mt%0 %1
9326    mt%0 %1
9327    {cror 0,0,0|nop}"
9328   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
9329    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
9330
9331 (define_insn "*movsi_internal1_single"
9332   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h,m,*f")
9333         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0,f,m"))]
9334   "TARGET_SINGLE_FPU &&
9335    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
9336   "@
9337    mr %0,%1
9338    {cal|la} %0,%a1
9339    {l%U1%X1|lwz%U1%X1} %0,%1
9340    {st%U0%X0|stw%U0%X0} %1,%0
9341    {lil|li} %0,%1
9342    {liu|lis} %0,%v1
9343    #
9344    {cal|la} %0,%a1
9345    mf%1 %0
9346    mt%0 %1
9347    mt%0 %1
9348    mt%0 %1
9349    {cror 0,0,0|nop}
9350    stfs%U0%X0 %1, %0
9351    lfs%U1%X1 %0, %1"
9352   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*,*,*")
9353    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4,4,4")])
9354
9355 ;; Split a load of a large constant into the appropriate two-insn
9356 ;; sequence.
9357
9358 (define_split
9359   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9360         (match_operand:SI 1 "const_int_operand" ""))]
9361   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
9362    && (INTVAL (operands[1]) & 0xffff) != 0"
9363   [(set (match_dup 0)
9364         (match_dup 2))
9365    (set (match_dup 0)
9366         (ior:SI (match_dup 0)
9367                 (match_dup 3)))]
9368   "
9369 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
9370
9371   if (tem == operands[0])
9372     DONE;
9373   else
9374     FAIL;
9375 }")
9376
9377 (define_insn "*mov<mode>_internal2"
9378   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
9379         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
9380                     (const_int 0)))
9381    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
9382   ""
9383   "@
9384    {cmpi|cmp<wd>i} %2,%0,0
9385    mr. %0,%1
9386    #"
9387   [(set_attr "type" "cmp,compare,cmp")
9388    (set_attr "length" "4,4,8")])
9389
9390 (define_split
9391   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
9392         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
9393                     (const_int 0)))
9394    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
9395   "reload_completed"
9396   [(set (match_dup 0) (match_dup 1))
9397    (set (match_dup 2)
9398         (compare:CC (match_dup 0)
9399                     (const_int 0)))]
9400   "")
9401 \f
9402 (define_insn "*movhi_internal"
9403   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
9404         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
9405   "gpc_reg_operand (operands[0], HImode)
9406    || gpc_reg_operand (operands[1], HImode)"
9407   "@
9408    mr %0,%1
9409    lhz%U1%X1 %0,%1
9410    sth%U0%X0 %1,%0
9411    {lil|li} %0,%w1
9412    mf%1 %0
9413    mt%0 %1
9414    mt%0 %1
9415    {cror 0,0,0|nop}"
9416   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
9417
9418 (define_expand "mov<mode>"
9419   [(set (match_operand:INT 0 "general_operand" "")
9420         (match_operand:INT 1 "any_operand" ""))]
9421   ""
9422   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9423
9424 (define_insn "*movqi_internal"
9425   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
9426         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
9427   "gpc_reg_operand (operands[0], QImode)
9428    || gpc_reg_operand (operands[1], QImode)"
9429   "@
9430    mr %0,%1
9431    lbz%U1%X1 %0,%1
9432    stb%U0%X0 %1,%0
9433    {lil|li} %0,%1
9434    mf%1 %0
9435    mt%0 %1
9436    mt%0 %1
9437    {cror 0,0,0|nop}"
9438   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
9439 \f
9440 ;; Here is how to move condition codes around.  When we store CC data in
9441 ;; an integer register or memory, we store just the high-order 4 bits.
9442 ;; This lets us not shift in the most common case of CR0.
9443 (define_expand "movcc"
9444   [(set (match_operand:CC 0 "nonimmediate_operand" "")
9445         (match_operand:CC 1 "nonimmediate_operand" ""))]
9446   ""
9447   "")
9448
9449 (define_insn "*movcc_internal1"
9450   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,q,cl,r,m")
9451         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,r,m,r"))]
9452   "register_operand (operands[0], CCmode)
9453    || register_operand (operands[1], CCmode)"
9454   "@
9455    mcrf %0,%1
9456    mtcrf 128,%1
9457    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
9458    crxor %0,%0,%0
9459    mfcr %0%Q1
9460    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
9461    mr %0,%1
9462    {lil|li} %0,%1
9463    mf%1 %0
9464    mt%0 %1
9465    mt%0 %1
9466    {l%U1%X1|lwz%U1%X1} %0,%1
9467    {st%U0%U1|stw%U0%U1} %1,%0"
9468   [(set (attr "type")
9469      (cond [(eq_attr "alternative" "0,3")
9470                 (const_string "cr_logical")
9471             (eq_attr "alternative" "1,2")
9472                 (const_string "mtcr")
9473             (eq_attr "alternative" "6,7,9")
9474                 (const_string "integer")
9475             (eq_attr "alternative" "8")
9476                 (const_string "mfjmpr")
9477             (eq_attr "alternative" "10")
9478                 (const_string "mtjmpr")
9479             (eq_attr "alternative" "11")
9480                 (const_string "load")
9481             (eq_attr "alternative" "12")
9482                 (const_string "store")
9483             (match_test "TARGET_MFCRF")
9484                 (const_string "mfcrf")
9485            ]
9486         (const_string "mfcr")))
9487    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4,4")])
9488 \f
9489 ;; For floating-point, we normally deal with the floating-point registers
9490 ;; unless -msoft-float is used.  The sole exception is that parameter passing
9491 ;; can produce floating-point values in fixed-point registers.  Unless the
9492 ;; value is a simple constant or already in memory, we deal with this by
9493 ;; allocating memory and copying the value explicitly via that memory location.
9494 (define_expand "movsf"
9495   [(set (match_operand:SF 0 "nonimmediate_operand" "")
9496         (match_operand:SF 1 "any_operand" ""))]
9497   ""
9498   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
9499
9500 (define_split
9501   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9502         (match_operand:SF 1 "const_double_operand" ""))]
9503   "reload_completed
9504    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9505        || (GET_CODE (operands[0]) == SUBREG
9506            && GET_CODE (SUBREG_REG (operands[0])) == REG
9507            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9508   [(set (match_dup 2) (match_dup 3))]
9509   "
9510 {
9511   long l;
9512   REAL_VALUE_TYPE rv;
9513
9514   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9515   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9516
9517   if (! TARGET_POWERPC64)
9518     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
9519   else
9520     operands[2] = gen_lowpart (SImode, operands[0]);
9521
9522   operands[3] = gen_int_mode (l, SImode);
9523 }")
9524
9525 (define_insn "*movsf_hardfloat"
9526   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
9527         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
9528   "(gpc_reg_operand (operands[0], SFmode)
9529    || gpc_reg_operand (operands[1], SFmode))
9530    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
9531   "@
9532    mr %0,%1
9533    {l%U1%X1|lwz%U1%X1} %0,%1
9534    {st%U0%X0|stw%U0%X0} %1,%0
9535    fmr %0,%1
9536    lfs%U1%X1 %0,%1
9537    stfs%U0%X0 %1,%0
9538    mt%0 %1
9539    mt%0 %1
9540    mf%1 %0
9541    {cror 0,0,0|nop}
9542    #
9543    #"
9544   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
9545    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
9546
9547 (define_insn "*movsf_softfloat"
9548   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
9549         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
9550   "(gpc_reg_operand (operands[0], SFmode)
9551    || gpc_reg_operand (operands[1], SFmode))
9552    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
9553   "@
9554    mr %0,%1
9555    mt%0 %1
9556    mt%0 %1
9557    mf%1 %0
9558    {l%U1%X1|lwz%U1%X1} %0,%1
9559    {st%U0%X0|stw%U0%X0} %1,%0
9560    {lil|li} %0,%1
9561    {liu|lis} %0,%v1
9562    {cal|la} %0,%a1
9563    #
9564    #
9565    {cror 0,0,0|nop}"
9566   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
9567    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
9568
9569 \f
9570 (define_expand "movdf"
9571   [(set (match_operand:DF 0 "nonimmediate_operand" "")
9572         (match_operand:DF 1 "any_operand" ""))]
9573   ""
9574   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
9575
9576 (define_split
9577   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9578         (match_operand:DF 1 "const_int_operand" ""))]
9579   "! TARGET_POWERPC64 && reload_completed
9580    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9581        || (GET_CODE (operands[0]) == SUBREG
9582            && GET_CODE (SUBREG_REG (operands[0])) == REG
9583            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9584   [(set (match_dup 2) (match_dup 4))
9585    (set (match_dup 3) (match_dup 1))]
9586   "
9587 {
9588   int endian = (WORDS_BIG_ENDIAN == 0);
9589   HOST_WIDE_INT value = INTVAL (operands[1]);
9590
9591   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
9592   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
9593 #if HOST_BITS_PER_WIDE_INT == 32
9594   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
9595 #else
9596   operands[4] = GEN_INT (value >> 32);
9597   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9598 #endif
9599 }")
9600
9601 (define_split
9602   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9603         (match_operand:DF 1 "const_double_operand" ""))]
9604   "! TARGET_POWERPC64 && reload_completed
9605    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9606        || (GET_CODE (operands[0]) == SUBREG
9607            && GET_CODE (SUBREG_REG (operands[0])) == REG
9608            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9609   [(set (match_dup 2) (match_dup 4))
9610    (set (match_dup 3) (match_dup 5))]
9611   "
9612 {
9613   int endian = (WORDS_BIG_ENDIAN == 0);
9614   long l[2];
9615   REAL_VALUE_TYPE rv;
9616
9617   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9618   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
9619
9620   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
9621   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
9622   operands[4] = gen_int_mode (l[endian], SImode);
9623   operands[5] = gen_int_mode (l[1 - endian], SImode);
9624 }")
9625
9626 (define_split
9627   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9628         (match_operand:DF 1 "const_double_operand" ""))]
9629   "TARGET_POWERPC64 && reload_completed
9630    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9631        || (GET_CODE (operands[0]) == SUBREG
9632            && GET_CODE (SUBREG_REG (operands[0])) == REG
9633            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9634   [(set (match_dup 2) (match_dup 3))]
9635   "
9636 {
9637   int endian = (WORDS_BIG_ENDIAN == 0);
9638   long l[2];
9639   REAL_VALUE_TYPE rv;
9640 #if HOST_BITS_PER_WIDE_INT >= 64
9641   HOST_WIDE_INT val;
9642 #endif
9643
9644   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9645   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
9646
9647   operands[2] = gen_lowpart (DImode, operands[0]);
9648   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
9649 #if HOST_BITS_PER_WIDE_INT >= 64
9650   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
9651          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
9652
9653   operands[3] = gen_int_mode (val, DImode);
9654 #else
9655   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
9656 #endif
9657 }")
9658
9659 ;; Don't have reload use general registers to load a constant.  First,
9660 ;; it might not work if the output operand is the equivalent of
9661 ;; a non-offsettable memref, but also it is less efficient than loading
9662 ;; the constant into an FP register, since it will probably be used there.
9663 ;; The "??" is a kludge until we can figure out a more reasonable way
9664 ;; of handling these non-offsettable values.
9665 (define_insn "*movdf_hardfloat32"
9666   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,ws,?wa,ws,?wa,Z,?Z,d,d,m,wa,!r,!r,!r")
9667         (match_operand:DF 1 "input_operand" "r,m,r,ws,wa,Z,Z,ws,wa,d,m,d,j,G,H,F"))]
9668   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9669    && (gpc_reg_operand (operands[0], DFmode)
9670        || gpc_reg_operand (operands[1], DFmode))"
9671   "*
9672 {
9673   switch (which_alternative)
9674     {
9675     default:
9676       gcc_unreachable ();
9677     case 0:
9678     case 1:
9679     case 2:
9680       return \"#\";
9681     case 3:
9682     case 4:
9683       return \"xxlor %x0,%x1,%x1\";
9684     case 5:
9685     case 6:
9686       return \"lxsd%U1x %x0,%y1\";
9687     case 7:
9688     case 8:
9689       return \"stxsd%U0x %x1,%y0\";
9690     case 9:
9691       return \"fmr %0,%1\";
9692     case 10:
9693       return \"lfd%U1%X1 %0,%1\";
9694     case 11:
9695       return \"stfd%U0%X0 %1,%0\";
9696     case 12:
9697       return \"xxlxor %x0,%x0,%x0\";
9698     case 13:
9699     case 14:
9700     case 15:
9701       return \"#\";
9702     }
9703 }"
9704   [(set_attr "type" "two,load,store,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,*,*,*")
9705    (set_attr "length" "8,16,16,4,4,4,4,4,4,4,4,4,4,8,12,16")])
9706
9707 (define_insn "*movdf_softfloat32"
9708   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
9709         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
9710   "! TARGET_POWERPC64 
9711    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
9712        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
9713    && (gpc_reg_operand (operands[0], DFmode)
9714        || gpc_reg_operand (operands[1], DFmode))"
9715   "#"
9716   [(set_attr "type" "two,load,store,*,*,*")
9717    (set_attr "length" "8,8,8,8,12,16")])
9718
9719 ;; Reload patterns to support gpr load/store with misaligned mem.
9720 (define_expand "reload_di_store"
9721   [(parallel [(match_operand 0 "memory_operand" "=m")
9722               (match_operand 1 "gpc_reg_operand" "r")
9723               (match_operand:DI 2 "register_operand" "=&b")])]
9724   "TARGET_POWERPC64"
9725 {
9726   rs6000_secondary_reload_ppc64 (operands[1], operands[0], operands[2], true);
9727   DONE;
9728 })
9729
9730 (define_expand "reload_di_load"
9731   [(parallel [(match_operand 0 "gpc_reg_operand" "=r")
9732               (match_operand 1 "memory_operand" "m")
9733               (match_operand:DI 2 "register_operand" "=b")])]
9734   "TARGET_POWERPC64"
9735 {
9736   rs6000_secondary_reload_ppc64 (operands[0], operands[1], operands[2], false);
9737   DONE;
9738 })
9739
9740 ; ld/std require word-aligned displacements -> 'Y' constraint.
9741 ; List Y->r and r->Y before r->r for reload.
9742 (define_insn "*movdf_hardfloat64_mfpgpr"
9743   [(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")
9744         (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"))]
9745   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
9746    && TARGET_DOUBLE_FLOAT
9747    && (gpc_reg_operand (operands[0], DFmode)
9748        || gpc_reg_operand (operands[1], DFmode))"
9749   "@
9750    std%U0%X0 %1,%0
9751    ld%U1%X1 %0,%1
9752    mr %0,%1
9753    xxlor %x0,%x1,%x1
9754    xxlor %x0,%x1,%x1
9755    lxsd%U1x %x0,%y1
9756    lxsd%U1x %x0,%y1
9757    stxsd%U0x %x1,%y0
9758    stxsd%U0x %x1,%y0
9759    fmr %0,%1
9760    lfd%U1%X1 %0,%1
9761    stfd%U0%X0 %1,%0
9762    xxlxor %x0,%x0,%x0
9763    mt%0 %1
9764    mf%1 %0
9765    {cror 0,0,0|nop}
9766    #
9767    #
9768    #
9769    mftgpr %0,%1
9770    mffgpr %0,%1"
9771   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
9772    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
9773
9774 ; ld/std require word-aligned displacements -> 'Y' constraint.
9775 ; List Y->r and r->Y before r->r for reload.
9776 (define_insn "*movdf_hardfloat64"
9777   [(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")
9778         (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"))]
9779   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
9780    && TARGET_DOUBLE_FLOAT
9781    && (gpc_reg_operand (operands[0], DFmode)
9782        || gpc_reg_operand (operands[1], DFmode))"
9783   "@
9784    std%U0%X0 %1,%0
9785    ld%U1%X1 %0,%1
9786    mr %0,%1
9787    xxlor %x0,%x1,%x1
9788    xxlor %x0,%x1,%x1
9789    lxsd%U1x %x0,%y1
9790    lxsd%U1x %x0,%y1
9791    stxsd%U0x %x1,%y0
9792    stxsd%U0x %x1,%y0
9793    fmr %0,%1
9794    lfd%U1%X1 %0,%1
9795    stfd%U0%X0 %1,%0
9796    xxlxor %x0,%x0,%x0
9797    mt%0 %1
9798    mf%1 %0
9799    {cror 0,0,0|nop}
9800    #
9801    #
9802    #"
9803   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fp,fpload,fpstore,vecsimple,mtjmpr,mfjmpr,*,*,*,*")
9804    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16")])
9805
9806 (define_insn "*movdf_softfloat64"
9807   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
9808         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
9809   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
9810    && (gpc_reg_operand (operands[0], DFmode)
9811        || gpc_reg_operand (operands[1], DFmode))"
9812   "@
9813    ld%U1%X1 %0,%1
9814    std%U0%X0 %1,%0
9815    mr %0,%1
9816    mt%0 %1
9817    mf%1 %0
9818    #
9819    #
9820    #
9821    {cror 0,0,0|nop}"
9822   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
9823    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
9824 \f
9825 (define_expand "movtf"
9826   [(set (match_operand:TF 0 "general_operand" "")
9827         (match_operand:TF 1 "any_operand" ""))]
9828   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
9829   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
9830
9831 ; It's important to list the o->f and f->o moves before f->f because
9832 ; otherwise reload, given m->f, will try to pick f->f and reload it,
9833 ; which doesn't make progress.  Likewise r->Y must be before r->r.
9834 (define_insn_and_split "*movtf_internal"
9835   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,d,d,r,Y,r")
9836         (match_operand:TF 1 "input_operand"         "d,o,d,YGHF,r,r"))]
9837   "!TARGET_IEEEQUAD
9838    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
9839    && (gpc_reg_operand (operands[0], TFmode)
9840        || gpc_reg_operand (operands[1], TFmode))"
9841   "#"
9842   "&& reload_completed"
9843   [(pc)]
9844 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9845   [(set_attr "length" "8,8,8,20,20,16")])
9846
9847 (define_insn_and_split "*movtf_softfloat"
9848   [(set (match_operand:TF 0 "rs6000_nonimmediate_operand" "=r,Y,r")
9849         (match_operand:TF 1 "input_operand"         "YGHF,r,r"))]
9850   "!TARGET_IEEEQUAD
9851    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
9852    && (gpc_reg_operand (operands[0], TFmode)
9853        || gpc_reg_operand (operands[1], TFmode))"
9854   "#"
9855   "&& reload_completed"
9856   [(pc)]
9857 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9858   [(set_attr "length" "20,20,16")])
9859
9860 (define_expand "extenddftf2"
9861   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9862         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
9863   "!TARGET_IEEEQUAD
9864    && TARGET_HARD_FLOAT
9865    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9866    && TARGET_LONG_DOUBLE_128"
9867 {
9868   if (TARGET_E500_DOUBLE)
9869     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
9870   else
9871     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
9872   DONE;
9873 })
9874
9875 (define_expand "extenddftf2_fprs"
9876   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9877                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
9878               (use (match_dup 2))])]
9879   "!TARGET_IEEEQUAD
9880    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9881    && TARGET_LONG_DOUBLE_128"
9882 {
9883   operands[2] = CONST0_RTX (DFmode);
9884   /* Generate GOT reference early for SVR4 PIC.  */
9885   if (DEFAULT_ABI == ABI_V4 && flag_pic)
9886     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
9887 })
9888
9889 (define_insn_and_split "*extenddftf2_internal"
9890   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,d,&d,r")
9891        (float_extend:TF (match_operand:DF 1 "input_operand" "dr,md,md,rmGHF")))
9892    (use (match_operand:DF 2 "zero_reg_mem_operand" "rd,m,d,n"))]
9893   "!TARGET_IEEEQUAD
9894    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9895    && TARGET_LONG_DOUBLE_128"
9896   "#"
9897   "&& reload_completed"
9898   [(pc)]
9899 {
9900   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
9901   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
9902   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
9903                   operands[1]);
9904   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
9905                   operands[2]);
9906   DONE;
9907 })
9908
9909 (define_expand "extendsftf2"
9910   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9911         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
9912   "!TARGET_IEEEQUAD
9913    && TARGET_HARD_FLOAT
9914    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9915    && TARGET_LONG_DOUBLE_128"
9916 {
9917   rtx tmp = gen_reg_rtx (DFmode);
9918   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
9919   emit_insn (gen_extenddftf2 (operands[0], tmp));
9920   DONE;
9921 })
9922
9923 (define_expand "trunctfdf2"
9924   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9925         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
9926   "!TARGET_IEEEQUAD
9927    && TARGET_HARD_FLOAT
9928    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9929    && TARGET_LONG_DOUBLE_128"
9930   "")
9931
9932 (define_insn_and_split "trunctfdf2_internal1"
9933   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
9934         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
9935   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
9936    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9937   "@
9938    #
9939    fmr %0,%1"
9940   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
9941   [(const_int 0)]
9942 {
9943   emit_note (NOTE_INSN_DELETED);
9944   DONE;
9945 }
9946   [(set_attr "type" "fp")])
9947
9948 (define_insn "trunctfdf2_internal2"
9949   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9950         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9951   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
9952    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9953    && TARGET_LONG_DOUBLE_128"
9954   "fadd %0,%1,%L1"
9955   [(set_attr "type" "fp")
9956    (set_attr "fp_type" "fp_addsub_d")])
9957
9958 (define_expand "trunctfsf2"
9959   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9960         (float_truncate:SF (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   if (TARGET_E500_DOUBLE)
9967     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
9968   else
9969     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
9970   DONE;
9971 })
9972
9973 (define_insn_and_split "trunctfsf2_fprs"
9974   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
9975         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
9976    (clobber (match_scratch:DF 2 "=d"))]
9977   "!TARGET_IEEEQUAD
9978    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
9979    && TARGET_LONG_DOUBLE_128"
9980   "#"
9981   "&& reload_completed"
9982   [(set (match_dup 2)
9983         (float_truncate:DF (match_dup 1)))
9984    (set (match_dup 0)
9985         (float_truncate:SF (match_dup 2)))]
9986   "")
9987
9988 (define_expand "floatsitf2"
9989   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9990         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
9991   "!TARGET_IEEEQUAD
9992    && TARGET_HARD_FLOAT
9993    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9994    && TARGET_LONG_DOUBLE_128"
9995 {
9996   rtx tmp = gen_reg_rtx (DFmode);
9997   expand_float (tmp, operands[1], false);
9998   emit_insn (gen_extenddftf2 (operands[0], tmp));
9999   DONE;
10000 })
10001
10002 ; fadd, but rounding towards zero.
10003 ; This is probably not the optimal code sequence.
10004 (define_insn "fix_trunc_helper"
10005   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
10006         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
10007                    UNSPEC_FIX_TRUNC_TF))
10008    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
10009   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
10010   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
10011   [(set_attr "type" "fp")
10012    (set_attr "length" "20")])
10013
10014 (define_expand "fix_trunctfsi2"
10015   [(set (match_operand:SI 0 "gpc_reg_operand" "")
10016         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
10017   "!TARGET_IEEEQUAD
10018    && (TARGET_POWER2 || TARGET_POWERPC)
10019    && TARGET_HARD_FLOAT
10020    && (TARGET_FPRS || TARGET_E500_DOUBLE)
10021    && TARGET_LONG_DOUBLE_128"
10022 {
10023   if (TARGET_E500_DOUBLE)
10024     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
10025   else
10026     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
10027   DONE;
10028 })
10029
10030 (define_expand "fix_trunctfsi2_fprs"
10031   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
10032                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
10033               (clobber (match_dup 2))
10034               (clobber (match_dup 3))
10035               (clobber (match_dup 4))
10036               (clobber (match_dup 5))])]
10037   "!TARGET_IEEEQUAD
10038    && (TARGET_POWER2 || TARGET_POWERPC)
10039    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10040 {
10041   operands[2] = gen_reg_rtx (DFmode);
10042   operands[3] = gen_reg_rtx (DFmode);
10043   operands[4] = gen_reg_rtx (DImode);
10044   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
10045 })
10046
10047 (define_insn_and_split "*fix_trunctfsi2_internal"
10048   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10049         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
10050    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
10051    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
10052    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
10053    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
10054   "!TARGET_IEEEQUAD
10055    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10056   "#"
10057   ""
10058   [(pc)]
10059 {
10060   rtx lowword;
10061   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
10062
10063   gcc_assert (MEM_P (operands[5]));
10064   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
10065
10066   emit_insn (gen_fctiwz_df (operands[4], operands[2]));
10067   emit_move_insn (operands[5], operands[4]);
10068   emit_move_insn (operands[0], lowword);
10069   DONE;
10070 })
10071
10072 (define_expand "negtf2"
10073   [(set (match_operand:TF 0 "gpc_reg_operand" "")
10074         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
10075   "!TARGET_IEEEQUAD
10076    && TARGET_HARD_FLOAT
10077    && (TARGET_FPRS || TARGET_E500_DOUBLE)
10078    && TARGET_LONG_DOUBLE_128"
10079   "")
10080
10081 (define_insn "negtf2_internal"
10082   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
10083         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
10084   "!TARGET_IEEEQUAD
10085    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10086   "*
10087 {
10088   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
10089     return \"fneg %L0,%L1\;fneg %0,%1\";
10090   else
10091     return \"fneg %0,%1\;fneg %L0,%L1\";
10092 }"
10093   [(set_attr "type" "fp")
10094    (set_attr "length" "8")])
10095
10096 (define_expand "abstf2"
10097   [(set (match_operand:TF 0 "gpc_reg_operand" "")
10098         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
10099   "!TARGET_IEEEQUAD
10100    && TARGET_HARD_FLOAT
10101    && (TARGET_FPRS || TARGET_E500_DOUBLE)
10102    && TARGET_LONG_DOUBLE_128"
10103   "
10104 {
10105   rtx label = gen_label_rtx ();
10106   if (TARGET_E500_DOUBLE)
10107     {
10108       if (flag_finite_math_only && !flag_trapping_math)
10109         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
10110       else
10111         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
10112     }
10113   else
10114     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
10115   emit_label (label);
10116   DONE;
10117 }")
10118
10119 (define_expand "abstf2_internal"
10120   [(set (match_operand:TF 0 "gpc_reg_operand" "")
10121         (match_operand:TF 1 "gpc_reg_operand" ""))
10122    (set (match_dup 3) (match_dup 5))
10123    (set (match_dup 5) (abs:DF (match_dup 5)))
10124    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
10125    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
10126                            (label_ref (match_operand 2 "" ""))
10127                            (pc)))
10128    (set (match_dup 6) (neg:DF (match_dup 6)))]
10129   "!TARGET_IEEEQUAD
10130    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
10131    && TARGET_LONG_DOUBLE_128"
10132   "
10133 {
10134   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
10135   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
10136   operands[3] = gen_reg_rtx (DFmode);
10137   operands[4] = gen_reg_rtx (CCFPmode);
10138   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
10139   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
10140 }")
10141 \f
10142 ;; Next come the multi-word integer load and store and the load and store
10143 ;; multiple insns.
10144
10145 ; List r->r after r->"o<>", otherwise reload will try to reload a
10146 ; non-offsettable address by using r->r which won't make progress.
10147 (define_insn "*movdi_internal32"
10148   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=o<>,r,r,*d,*d,m,r,?wa")
10149         (match_operand:DI 1 "input_operand" "r,r,m,d,m,d,IJKnGHF,O"))]
10150   "! TARGET_POWERPC64
10151    && (gpc_reg_operand (operands[0], DImode)
10152        || gpc_reg_operand (operands[1], DImode))"
10153   "@
10154    #
10155    #
10156    #
10157    fmr %0,%1
10158    lfd%U1%X1 %0,%1
10159    stfd%U0%X0 %1,%0
10160    #
10161    xxlxor %x0,%x0,%x0"
10162   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*,vecsimple")])
10163
10164 (define_split
10165   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10166         (match_operand:DI 1 "const_int_operand" ""))]
10167   "! TARGET_POWERPC64 && reload_completed
10168    && gpr_or_gpr_p (operands[0], operands[1])"
10169   [(set (match_dup 2) (match_dup 4))
10170    (set (match_dup 3) (match_dup 1))]
10171   "
10172 {
10173   HOST_WIDE_INT value = INTVAL (operands[1]);
10174   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10175                                        DImode);
10176   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10177                                        DImode);
10178 #if HOST_BITS_PER_WIDE_INT == 32
10179   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
10180 #else
10181   operands[4] = GEN_INT (value >> 32);
10182   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
10183 #endif
10184 }")
10185
10186 (define_split
10187   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
10188         (match_operand:DIFD 1 "input_operand" ""))]
10189   "reload_completed && !TARGET_POWERPC64
10190    && gpr_or_gpr_p (operands[0], operands[1])"
10191   [(pc)]
10192 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10193
10194 (define_insn "*movdi_mfpgpr"
10195   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*d,*d,m,r,*h,*h,r,*d")
10196         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,d,m,d,*h,r,0,*d,r"))]
10197   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
10198    && (gpc_reg_operand (operands[0], DImode)
10199        || gpc_reg_operand (operands[1], DImode))"
10200   "@
10201    mr %0,%1
10202    ld%U1%X1 %0,%1
10203    std%U0%X0 %1,%0
10204    li %0,%1
10205    lis %0,%v1
10206    #
10207    la %0,%a1
10208    fmr %0,%1
10209    lfd%U1%X1 %0,%1
10210    stfd%U0%X0 %1,%0
10211    mf%1 %0
10212    mt%0 %1
10213    {cror 0,0,0|nop}
10214    mftgpr %0,%1
10215    mffgpr %0,%1"
10216   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*,mftgpr,mffgpr")
10217    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4")])
10218
10219 (define_insn "*movdi_internal64"
10220   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*d,*d,m,r,*h,*h,?wa")
10221         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,d,m,d,*h,r,0,O"))]
10222   "TARGET_POWERPC64 && (!TARGET_MFPGPR || !TARGET_HARD_FLOAT || !TARGET_FPRS)
10223    && (gpc_reg_operand (operands[0], DImode)
10224        || gpc_reg_operand (operands[1], DImode))"
10225   "@
10226    mr %0,%1
10227    ld%U1%X1 %0,%1
10228    std%U0%X0 %1,%0
10229    li %0,%1
10230    lis %0,%v1
10231    #
10232    la %0,%a1
10233    fmr %0,%1
10234    lfd%U1%X1 %0,%1
10235    stfd%U0%X0 %1,%0
10236    mf%1 %0
10237    mt%0 %1
10238    {cror 0,0,0|nop}
10239    xxlxor %x0,%x0,%x0"
10240   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*,vecsimple")
10241    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4")])
10242
10243 ;; immediate value valid for a single instruction hiding in a const_double
10244 (define_insn ""
10245   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10246         (match_operand:DI 1 "const_double_operand" "F"))]
10247   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
10248    && GET_CODE (operands[1]) == CONST_DOUBLE
10249    && num_insns_constant (operands[1], DImode) == 1"
10250   "*
10251 {
10252   return ((unsigned HOST_WIDE_INT)
10253           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
10254          ? \"li %0,%1\" : \"lis %0,%v1\";
10255 }")
10256
10257 ;; Generate all one-bits and clear left or right.
10258 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
10259 (define_split
10260   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10261         (match_operand:DI 1 "mask64_operand" ""))]
10262   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10263   [(set (match_dup 0) (const_int -1))
10264    (set (match_dup 0)
10265         (and:DI (rotate:DI (match_dup 0)
10266                            (const_int 0))
10267                 (match_dup 1)))]
10268   "")
10269
10270 ;; Split a load of a large constant into the appropriate five-instruction
10271 ;; sequence.  Handle anything in a constant number of insns.
10272 ;; When non-easy constants can go in the TOC, this should use
10273 ;; easy_fp_constant predicate.
10274 (define_split
10275   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10276         (match_operand:DI 1 "const_int_operand" ""))]
10277   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10278   [(set (match_dup 0) (match_dup 2))
10279    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
10280   "
10281 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
10282
10283   if (tem == operands[0])
10284     DONE;
10285   else
10286     FAIL;
10287 }")
10288
10289 (define_split
10290   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10291         (match_operand:DI 1 "const_double_operand" ""))]
10292   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10293   [(set (match_dup 0) (match_dup 2))
10294    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
10295   "
10296 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
10297
10298   if (tem == operands[0])
10299     DONE;
10300   else
10301     FAIL;
10302 }")
10303 \f
10304 ;; TImode is similar, except that we usually want to compute the address into
10305 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
10306 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
10307
10308 ;; We say that MQ is clobbered in the last alternative because the first
10309 ;; alternative would never get used otherwise since it would need a reload
10310 ;; while the 2nd alternative would not.  We put memory cases first so they
10311 ;; are preferred.  Otherwise, we'd try to reload the output instead of
10312 ;; giving the SCRATCH mq.
10313
10314 (define_insn "*movti_power"
10315   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
10316         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
10317    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
10318   "TARGET_POWER && ! TARGET_POWERPC64
10319    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
10320   "*
10321 {
10322   switch (which_alternative)
10323     {
10324     default:
10325       gcc_unreachable ();
10326
10327     case 0:
10328       if (TARGET_STRING)
10329         return \"{stsi|stswi} %1,%P0,16\";
10330     case 1:
10331     case 2:
10332       return \"#\";
10333     case 3:
10334       /* If the address is not used in the output, we can use lsi.  Otherwise,
10335          fall through to generating four loads.  */
10336       if (TARGET_STRING
10337           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
10338         return \"{lsi|lswi} %0,%P1,16\";
10339       /* ... fall through ...  */
10340     case 4:
10341     case 5:
10342       return \"#\";
10343     }
10344 }"
10345   [(set_attr "type" "store,store,*,load,load,*")])
10346
10347 (define_insn "*movti_string"
10348   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
10349         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
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     case 0:
10359       if (TARGET_STRING)
10360         return \"{stsi|stswi} %1,%P0,16\";
10361     case 1:
10362     case 2:
10363       return \"#\";
10364     case 3:
10365       /* If the address is not used in the output, we can use lsi.  Otherwise,
10366          fall through to generating four loads.  */
10367       if (TARGET_STRING
10368           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
10369         return \"{lsi|lswi} %0,%P1,16\";
10370       /* ... fall through ...  */
10371     case 4:
10372     case 5:
10373       return \"#\";
10374     }
10375 }"
10376   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")
10377    (set (attr "cell_micro") (if_then_else (match_test "TARGET_STRING")
10378                                           (const_string "always")
10379                                           (const_string "conditional")))])
10380
10381 (define_insn "*movti_ppc64"
10382   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
10383         (match_operand:TI 1 "input_operand" "r,r,m"))]
10384   "(TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
10385     || gpc_reg_operand (operands[1], TImode)))
10386    && VECTOR_MEM_NONE_P (TImode)"
10387   "#"
10388   [(set_attr "type" "*,store,load")])
10389
10390 (define_split
10391   [(set (match_operand:TI 0 "gpc_reg_operand" "")
10392         (match_operand:TI 1 "const_double_operand" ""))]
10393   "TARGET_POWERPC64 && VECTOR_MEM_NONE_P (TImode)"
10394   [(set (match_dup 2) (match_dup 4))
10395    (set (match_dup 3) (match_dup 5))]
10396   "
10397 {
10398   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10399                                        TImode);
10400   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10401                                        TImode);
10402   if (GET_CODE (operands[1]) == CONST_DOUBLE)
10403     {
10404       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
10405       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
10406     }
10407   else if (GET_CODE (operands[1]) == CONST_INT)
10408     {
10409       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
10410       operands[5] = operands[1];
10411     }
10412   else
10413     FAIL;
10414 }")
10415
10416 (define_split
10417   [(set (match_operand:TI 0 "nonimmediate_operand" "")
10418         (match_operand:TI 1 "input_operand" ""))]
10419   "reload_completed && VECTOR_MEM_NONE_P (TImode)
10420    && gpr_or_gpr_p (operands[0], operands[1])"
10421   [(pc)]
10422 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10423 \f
10424 (define_expand "load_multiple"
10425   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10426                           (match_operand:SI 1 "" ""))
10427                      (use (match_operand:SI 2 "" ""))])]
10428   "TARGET_STRING && !TARGET_POWERPC64"
10429   "
10430 {
10431   int regno;
10432   int count;
10433   rtx op1;
10434   int i;
10435
10436   /* Support only loading a constant number of fixed-point registers from
10437      memory and only bother with this if more than two; the machine
10438      doesn't support more than eight.  */
10439   if (GET_CODE (operands[2]) != CONST_INT
10440       || INTVAL (operands[2]) <= 2
10441       || INTVAL (operands[2]) > 8
10442       || GET_CODE (operands[1]) != MEM
10443       || GET_CODE (operands[0]) != REG
10444       || REGNO (operands[0]) >= 32)
10445     FAIL;
10446
10447   count = INTVAL (operands[2]);
10448   regno = REGNO (operands[0]);
10449
10450   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
10451   op1 = replace_equiv_address (operands[1],
10452                                force_reg (SImode, XEXP (operands[1], 0)));
10453
10454   for (i = 0; i < count; i++)
10455     XVECEXP (operands[3], 0, i)
10456       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
10457                      adjust_address_nv (op1, SImode, i * 4));
10458 }")
10459
10460 (define_insn "*ldmsi8"
10461   [(match_parallel 0 "load_multiple_operation"
10462     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10463           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10464      (set (match_operand:SI 3 "gpc_reg_operand" "")
10465           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10466      (set (match_operand:SI 4 "gpc_reg_operand" "")
10467           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10468      (set (match_operand:SI 5 "gpc_reg_operand" "")
10469           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10470      (set (match_operand:SI 6 "gpc_reg_operand" "")
10471           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10472      (set (match_operand:SI 7 "gpc_reg_operand" "")
10473           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10474      (set (match_operand:SI 8 "gpc_reg_operand" "")
10475           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
10476      (set (match_operand:SI 9 "gpc_reg_operand" "")
10477           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
10478   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10479   "*
10480 { return rs6000_output_load_multiple (operands); }"
10481   [(set_attr "type" "load_ux")
10482    (set_attr "length" "32")])
10483
10484 (define_insn "*ldmsi7"
10485   [(match_parallel 0 "load_multiple_operation"
10486     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10487           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10488      (set (match_operand:SI 3 "gpc_reg_operand" "")
10489           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10490      (set (match_operand:SI 4 "gpc_reg_operand" "")
10491           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10492      (set (match_operand:SI 5 "gpc_reg_operand" "")
10493           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10494      (set (match_operand:SI 6 "gpc_reg_operand" "")
10495           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10496      (set (match_operand:SI 7 "gpc_reg_operand" "")
10497           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10498      (set (match_operand:SI 8 "gpc_reg_operand" "")
10499           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
10500   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10501   "*
10502 { return rs6000_output_load_multiple (operands); }"
10503   [(set_attr "type" "load_ux")
10504    (set_attr "length" "32")])
10505
10506 (define_insn "*ldmsi6"
10507   [(match_parallel 0 "load_multiple_operation"
10508     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10509           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10510      (set (match_operand:SI 3 "gpc_reg_operand" "")
10511           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10512      (set (match_operand:SI 4 "gpc_reg_operand" "")
10513           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10514      (set (match_operand:SI 5 "gpc_reg_operand" "")
10515           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10516      (set (match_operand:SI 6 "gpc_reg_operand" "")
10517           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10518      (set (match_operand:SI 7 "gpc_reg_operand" "")
10519           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
10520   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10521   "*
10522 { return rs6000_output_load_multiple (operands); }"
10523   [(set_attr "type" "load_ux")
10524    (set_attr "length" "32")])
10525
10526 (define_insn "*ldmsi5"
10527   [(match_parallel 0 "load_multiple_operation"
10528     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10529           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10530      (set (match_operand:SI 3 "gpc_reg_operand" "")
10531           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10532      (set (match_operand:SI 4 "gpc_reg_operand" "")
10533           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10534      (set (match_operand:SI 5 "gpc_reg_operand" "")
10535           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10536      (set (match_operand:SI 6 "gpc_reg_operand" "")
10537           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
10538   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10539   "*
10540 { return rs6000_output_load_multiple (operands); }"
10541   [(set_attr "type" "load_ux")
10542    (set_attr "length" "32")])
10543
10544 (define_insn "*ldmsi4"
10545   [(match_parallel 0 "load_multiple_operation"
10546     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10547           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10548      (set (match_operand:SI 3 "gpc_reg_operand" "")
10549           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10550      (set (match_operand:SI 4 "gpc_reg_operand" "")
10551           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10552      (set (match_operand:SI 5 "gpc_reg_operand" "")
10553           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
10554   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10555   "*
10556 { return rs6000_output_load_multiple (operands); }"
10557   [(set_attr "type" "load_ux")
10558    (set_attr "length" "32")])
10559
10560 (define_insn "*ldmsi3"
10561   [(match_parallel 0 "load_multiple_operation"
10562     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10563           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10564      (set (match_operand:SI 3 "gpc_reg_operand" "")
10565           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10566      (set (match_operand:SI 4 "gpc_reg_operand" "")
10567           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
10568   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
10569   "*
10570 { return rs6000_output_load_multiple (operands); }"
10571   [(set_attr "type" "load_ux")
10572    (set_attr "length" "32")])
10573
10574 (define_expand "store_multiple"
10575   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10576                           (match_operand:SI 1 "" ""))
10577                      (clobber (scratch:SI))
10578                      (use (match_operand:SI 2 "" ""))])]
10579   "TARGET_STRING && !TARGET_POWERPC64"
10580   "
10581 {
10582   int regno;
10583   int count;
10584   rtx to;
10585   rtx op0;
10586   int i;
10587
10588   /* Support only storing a constant number of fixed-point registers to
10589      memory and only bother with this if more than two; the machine
10590      doesn't support more than eight.  */
10591   if (GET_CODE (operands[2]) != CONST_INT
10592       || INTVAL (operands[2]) <= 2
10593       || INTVAL (operands[2]) > 8
10594       || GET_CODE (operands[0]) != MEM
10595       || GET_CODE (operands[1]) != REG
10596       || REGNO (operands[1]) >= 32)
10597     FAIL;
10598
10599   count = INTVAL (operands[2]);
10600   regno = REGNO (operands[1]);
10601
10602   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
10603   to = force_reg (SImode, XEXP (operands[0], 0));
10604   op0 = replace_equiv_address (operands[0], to);
10605
10606   XVECEXP (operands[3], 0, 0)
10607     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
10608   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
10609                                                  gen_rtx_SCRATCH (SImode));
10610
10611   for (i = 1; i < count; i++)
10612     XVECEXP (operands[3], 0, i + 1)
10613       = gen_rtx_SET (VOIDmode,
10614                      adjust_address_nv (op0, SImode, i * 4),
10615                      gen_rtx_REG (SImode, regno + i));
10616 }")
10617
10618 (define_insn "*stmsi8"
10619   [(match_parallel 0 "store_multiple_operation"
10620     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10621           (match_operand:SI 2 "gpc_reg_operand" "r"))
10622      (clobber (match_scratch:SI 3 "=X"))
10623      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10624           (match_operand:SI 4 "gpc_reg_operand" "r"))
10625      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10626           (match_operand:SI 5 "gpc_reg_operand" "r"))
10627      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10628           (match_operand:SI 6 "gpc_reg_operand" "r"))
10629      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10630           (match_operand:SI 7 "gpc_reg_operand" "r"))
10631      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10632           (match_operand:SI 8 "gpc_reg_operand" "r"))
10633      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10634           (match_operand:SI 9 "gpc_reg_operand" "r"))
10635      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10636           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10637   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
10638   "{stsi|stswi} %2,%1,%O0"
10639   [(set_attr "type" "store_ux")
10640    (set_attr "cell_micro" "always")])
10641
10642 (define_insn "*stmsi7"
10643   [(match_parallel 0 "store_multiple_operation"
10644     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10645           (match_operand:SI 2 "gpc_reg_operand" "r"))
10646      (clobber (match_scratch:SI 3 "=X"))
10647      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10648           (match_operand:SI 4 "gpc_reg_operand" "r"))
10649      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10650           (match_operand:SI 5 "gpc_reg_operand" "r"))
10651      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10652           (match_operand:SI 6 "gpc_reg_operand" "r"))
10653      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10654           (match_operand:SI 7 "gpc_reg_operand" "r"))
10655      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10656           (match_operand:SI 8 "gpc_reg_operand" "r"))
10657      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10658           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10659   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
10660   "{stsi|stswi} %2,%1,%O0"
10661   [(set_attr "type" "store_ux")
10662    (set_attr "cell_micro" "always")])
10663
10664 (define_insn "*stmsi6"
10665   [(match_parallel 0 "store_multiple_operation"
10666     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10667           (match_operand:SI 2 "gpc_reg_operand" "r"))
10668      (clobber (match_scratch:SI 3 "=X"))
10669      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10670           (match_operand:SI 4 "gpc_reg_operand" "r"))
10671      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10672           (match_operand:SI 5 "gpc_reg_operand" "r"))
10673      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10674           (match_operand:SI 6 "gpc_reg_operand" "r"))
10675      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10676           (match_operand:SI 7 "gpc_reg_operand" "r"))
10677      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10678           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10679   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
10680   "{stsi|stswi} %2,%1,%O0"
10681   [(set_attr "type" "store_ux")
10682    (set_attr "cell_micro" "always")])
10683
10684 (define_insn "*stmsi5"
10685   [(match_parallel 0 "store_multiple_operation"
10686     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10687           (match_operand:SI 2 "gpc_reg_operand" "r"))
10688      (clobber (match_scratch:SI 3 "=X"))
10689      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10690           (match_operand:SI 4 "gpc_reg_operand" "r"))
10691      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10692           (match_operand:SI 5 "gpc_reg_operand" "r"))
10693      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10694           (match_operand:SI 6 "gpc_reg_operand" "r"))
10695      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10696           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10697   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
10698   "{stsi|stswi} %2,%1,%O0"
10699   [(set_attr "type" "store_ux")
10700    (set_attr "cell_micro" "always")])
10701
10702 (define_insn "*stmsi4"
10703   [(match_parallel 0 "store_multiple_operation"
10704     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10705           (match_operand:SI 2 "gpc_reg_operand" "r"))
10706      (clobber (match_scratch:SI 3 "=X"))
10707      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10708           (match_operand:SI 4 "gpc_reg_operand" "r"))
10709      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10710           (match_operand:SI 5 "gpc_reg_operand" "r"))
10711      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10712           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10713   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
10714   "{stsi|stswi} %2,%1,%O0"
10715   [(set_attr "type" "store_ux")
10716    (set_attr "cell_micro" "always")])
10717
10718 (define_insn "*stmsi3"
10719   [(match_parallel 0 "store_multiple_operation"
10720     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10721           (match_operand:SI 2 "gpc_reg_operand" "r"))
10722      (clobber (match_scratch:SI 3 "=X"))
10723      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10724           (match_operand:SI 4 "gpc_reg_operand" "r"))
10725      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10726           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10727   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
10728   "{stsi|stswi} %2,%1,%O0"
10729   [(set_attr "type" "store_ux")
10730    (set_attr "cell_micro" "always")])
10731
10732 (define_insn "*stmsi8_power"
10733   [(match_parallel 0 "store_multiple_operation"
10734     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10735           (match_operand:SI 2 "gpc_reg_operand" "r"))
10736      (clobber (match_scratch:SI 3 "=q"))
10737      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10738           (match_operand:SI 4 "gpc_reg_operand" "r"))
10739      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10740           (match_operand:SI 5 "gpc_reg_operand" "r"))
10741      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10742           (match_operand:SI 6 "gpc_reg_operand" "r"))
10743      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10744           (match_operand:SI 7 "gpc_reg_operand" "r"))
10745      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10746           (match_operand:SI 8 "gpc_reg_operand" "r"))
10747      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10748           (match_operand:SI 9 "gpc_reg_operand" "r"))
10749      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10750           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10751   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 9"
10752   "{stsi|stswi} %2,%1,%O0"
10753   [(set_attr "type" "store_ux")
10754    (set_attr "cell_micro" "always")])
10755
10756 (define_insn "*stmsi7_power"
10757   [(match_parallel 0 "store_multiple_operation"
10758     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10759           (match_operand:SI 2 "gpc_reg_operand" "r"))
10760      (clobber (match_scratch:SI 3 "=q"))
10761      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10762           (match_operand:SI 4 "gpc_reg_operand" "r"))
10763      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10764           (match_operand:SI 5 "gpc_reg_operand" "r"))
10765      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10766           (match_operand:SI 6 "gpc_reg_operand" "r"))
10767      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10768           (match_operand:SI 7 "gpc_reg_operand" "r"))
10769      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10770           (match_operand:SI 8 "gpc_reg_operand" "r"))
10771      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10772           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10773   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 8"
10774   "{stsi|stswi} %2,%1,%O0"
10775   [(set_attr "type" "store_ux")
10776    (set_attr "cell_micro" "always")])
10777
10778 (define_insn "*stmsi6_power"
10779   [(match_parallel 0 "store_multiple_operation"
10780     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10781           (match_operand:SI 2 "gpc_reg_operand" "r"))
10782      (clobber (match_scratch:SI 3 "=q"))
10783      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10784           (match_operand:SI 4 "gpc_reg_operand" "r"))
10785      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10786           (match_operand:SI 5 "gpc_reg_operand" "r"))
10787      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10788           (match_operand:SI 6 "gpc_reg_operand" "r"))
10789      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10790           (match_operand:SI 7 "gpc_reg_operand" "r"))
10791      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10792           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10793   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 7"
10794   "{stsi|stswi} %2,%1,%O0"
10795   [(set_attr "type" "store_ux")
10796    (set_attr "cell_micro" "always")])
10797
10798 (define_insn "*stmsi5_power"
10799   [(match_parallel 0 "store_multiple_operation"
10800     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10801           (match_operand:SI 2 "gpc_reg_operand" "r"))
10802      (clobber (match_scratch:SI 3 "=q"))
10803      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10804           (match_operand:SI 4 "gpc_reg_operand" "r"))
10805      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10806           (match_operand:SI 5 "gpc_reg_operand" "r"))
10807      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10808           (match_operand:SI 6 "gpc_reg_operand" "r"))
10809      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10810           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10811   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 6"
10812   "{stsi|stswi} %2,%1,%O0"
10813   [(set_attr "type" "store_ux")
10814    (set_attr "cell_micro" "always")])
10815
10816 (define_insn "*stmsi4_power"
10817   [(match_parallel 0 "store_multiple_operation"
10818     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10819           (match_operand:SI 2 "gpc_reg_operand" "r"))
10820      (clobber (match_scratch:SI 3 "=q"))
10821      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10822           (match_operand:SI 4 "gpc_reg_operand" "r"))
10823      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10824           (match_operand:SI 5 "gpc_reg_operand" "r"))
10825      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10826           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10827   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 5"
10828   "{stsi|stswi} %2,%1,%O0"
10829   [(set_attr "type" "store_ux")
10830    (set_attr "cell_micro" "always")])
10831
10832 (define_insn "*stmsi3_power"
10833   [(match_parallel 0 "store_multiple_operation"
10834     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10835           (match_operand:SI 2 "gpc_reg_operand" "r"))
10836      (clobber (match_scratch:SI 3 "=q"))
10837      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10838           (match_operand:SI 4 "gpc_reg_operand" "r"))
10839      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10840           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10841   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 4"
10842   "{stsi|stswi} %2,%1,%O0"
10843   [(set_attr "type" "store_ux")
10844    (set_attr "cell_micro" "always")])
10845 \f
10846 (define_expand "setmemsi"
10847   [(parallel [(set (match_operand:BLK 0 "" "")
10848                    (match_operand 2 "const_int_operand" ""))
10849               (use (match_operand:SI 1 "" ""))
10850               (use (match_operand:SI 3 "" ""))])]
10851   ""
10852   "
10853 {
10854   /* If value to set is not zero, use the library routine.  */
10855   if (operands[2] != const0_rtx)
10856     FAIL;
10857
10858   if (expand_block_clear (operands))
10859     DONE;
10860   else
10861     FAIL;
10862 }")
10863
10864 ;; String/block move insn.
10865 ;; Argument 0 is the destination
10866 ;; Argument 1 is the source
10867 ;; Argument 2 is the length
10868 ;; Argument 3 is the alignment
10869
10870 (define_expand "movmemsi"
10871   [(parallel [(set (match_operand:BLK 0 "" "")
10872                    (match_operand:BLK 1 "" ""))
10873               (use (match_operand:SI 2 "" ""))
10874               (use (match_operand:SI 3 "" ""))])]
10875   ""
10876   "
10877 {
10878   if (expand_block_move (operands))
10879     DONE;
10880   else
10881     FAIL;
10882 }")
10883
10884 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
10885 ;; register allocator doesn't have a clue about allocating 8 word registers.
10886 ;; rD/rS = r5 is preferred, efficient form.
10887 (define_expand "movmemsi_8reg"
10888   [(parallel [(set (match_operand 0 "" "")
10889                    (match_operand 1 "" ""))
10890               (use (match_operand 2 "" ""))
10891               (use (match_operand 3 "" ""))
10892               (clobber (reg:SI  5))
10893               (clobber (reg:SI  6))
10894               (clobber (reg:SI  7))
10895               (clobber (reg:SI  8))
10896               (clobber (reg:SI  9))
10897               (clobber (reg:SI 10))
10898               (clobber (reg:SI 11))
10899               (clobber (reg:SI 12))
10900               (clobber (match_scratch:SI 4 ""))])]
10901   "TARGET_STRING"
10902   "")
10903
10904 (define_insn ""
10905   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10906         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10907    (use (match_operand:SI 2 "immediate_operand" "i"))
10908    (use (match_operand:SI 3 "immediate_operand" "i"))
10909    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10910    (clobber (reg:SI  6))
10911    (clobber (reg:SI  7))
10912    (clobber (reg:SI  8))
10913    (clobber (reg:SI  9))
10914    (clobber (reg:SI 10))
10915    (clobber (reg:SI 11))
10916    (clobber (reg:SI 12))
10917    (clobber (match_scratch:SI 5 "=q"))]
10918   "TARGET_STRING && TARGET_POWER
10919    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10920        || INTVAL (operands[2]) == 0)
10921    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10922    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10923    && REGNO (operands[4]) == 5"
10924   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10925   [(set_attr "type" "store_ux")
10926    (set_attr "cell_micro" "always")
10927    (set_attr "length" "8")])
10928
10929 (define_insn ""
10930   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10931         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10932    (use (match_operand:SI 2 "immediate_operand" "i"))
10933    (use (match_operand:SI 3 "immediate_operand" "i"))
10934    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10935    (clobber (reg:SI  6))
10936    (clobber (reg:SI  7))
10937    (clobber (reg:SI  8))
10938    (clobber (reg:SI  9))
10939    (clobber (reg:SI 10))
10940    (clobber (reg:SI 11))
10941    (clobber (reg:SI 12))
10942    (clobber (match_scratch:SI 5 "=X"))]
10943   "TARGET_STRING && ! TARGET_POWER
10944    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10945        || INTVAL (operands[2]) == 0)
10946    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10947    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10948    && REGNO (operands[4]) == 5"
10949   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10950   [(set_attr "type" "store_ux")
10951    (set_attr "cell_micro" "always")
10952    (set_attr "length" "8")])
10953
10954 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
10955 ;; register allocator doesn't have a clue about allocating 6 word registers.
10956 ;; rD/rS = r5 is preferred, efficient form.
10957 (define_expand "movmemsi_6reg"
10958   [(parallel [(set (match_operand 0 "" "")
10959                    (match_operand 1 "" ""))
10960               (use (match_operand 2 "" ""))
10961               (use (match_operand 3 "" ""))
10962               (clobber (reg:SI  5))
10963               (clobber (reg:SI  6))
10964               (clobber (reg:SI  7))
10965               (clobber (reg:SI  8))
10966               (clobber (reg:SI  9))
10967               (clobber (reg:SI 10))
10968               (clobber (match_scratch:SI 4 ""))])]
10969   "TARGET_STRING"
10970   "")
10971
10972 (define_insn ""
10973   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10974         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10975    (use (match_operand:SI 2 "immediate_operand" "i"))
10976    (use (match_operand:SI 3 "immediate_operand" "i"))
10977    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10978    (clobber (reg:SI  6))
10979    (clobber (reg:SI  7))
10980    (clobber (reg:SI  8))
10981    (clobber (reg:SI  9))
10982    (clobber (reg:SI 10))
10983    (clobber (match_scratch:SI 5 "=q"))]
10984   "TARGET_STRING && TARGET_POWER
10985    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
10986    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10987    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10988    && REGNO (operands[4]) == 5"
10989   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
10990   [(set_attr "type" "store_ux")
10991    (set_attr "cell_micro" "always")
10992    (set_attr "length" "8")])
10993
10994 (define_insn ""
10995   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10996         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10997    (use (match_operand:SI 2 "immediate_operand" "i"))
10998    (use (match_operand:SI 3 "immediate_operand" "i"))
10999    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
11000    (clobber (reg:SI  6))
11001    (clobber (reg:SI  7))
11002    (clobber (reg:SI  8))
11003    (clobber (reg:SI  9))
11004    (clobber (reg:SI 10))
11005    (clobber (match_scratch:SI 5 "=X"))]
11006   "TARGET_STRING && ! TARGET_POWER
11007    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
11008    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
11009    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
11010    && REGNO (operands[4]) == 5"
11011   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11012   [(set_attr "type" "store_ux")
11013    (set_attr "cell_micro" "always")
11014    (set_attr "length" "8")])
11015
11016 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
11017 ;; problems with TImode.
11018 ;; rD/rS = r5 is preferred, efficient form.
11019 (define_expand "movmemsi_4reg"
11020   [(parallel [(set (match_operand 0 "" "")
11021                    (match_operand 1 "" ""))
11022               (use (match_operand 2 "" ""))
11023               (use (match_operand 3 "" ""))
11024               (clobber (reg:SI 5))
11025               (clobber (reg:SI 6))
11026               (clobber (reg:SI 7))
11027               (clobber (reg:SI 8))
11028               (clobber (match_scratch:SI 4 ""))])]
11029   "TARGET_STRING"
11030   "")
11031
11032 (define_insn ""
11033   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11034         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11035    (use (match_operand:SI 2 "immediate_operand" "i"))
11036    (use (match_operand:SI 3 "immediate_operand" "i"))
11037    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
11038    (clobber (reg:SI 6))
11039    (clobber (reg:SI 7))
11040    (clobber (reg:SI 8))
11041    (clobber (match_scratch:SI 5 "=q"))]
11042   "TARGET_STRING && TARGET_POWER
11043    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
11044    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
11045    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
11046    && REGNO (operands[4]) == 5"
11047   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11048   [(set_attr "type" "store_ux")
11049    (set_attr "cell_micro" "always")
11050    (set_attr "length" "8")])
11051
11052 (define_insn ""
11053   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
11054         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
11055    (use (match_operand:SI 2 "immediate_operand" "i"))
11056    (use (match_operand:SI 3 "immediate_operand" "i"))
11057    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
11058    (clobber (reg:SI 6))
11059    (clobber (reg:SI 7))
11060    (clobber (reg:SI 8))
11061    (clobber (match_scratch:SI 5 "=X"))]
11062   "TARGET_STRING && ! TARGET_POWER
11063    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
11064    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
11065    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
11066    && REGNO (operands[4]) == 5"
11067   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11068   [(set_attr "type" "store_ux")
11069    (set_attr "cell_micro" "always")
11070    (set_attr "length" "8")])
11071
11072 ;; Move up to 8 bytes at a time.
11073 (define_expand "movmemsi_2reg"
11074   [(parallel [(set (match_operand 0 "" "")
11075                    (match_operand 1 "" ""))
11076               (use (match_operand 2 "" ""))
11077               (use (match_operand 3 "" ""))
11078               (clobber (match_scratch:DI 4 ""))
11079               (clobber (match_scratch:SI 5 ""))])]
11080   "TARGET_STRING && ! TARGET_POWERPC64"
11081   "")
11082
11083 (define_insn ""
11084   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11085         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11086    (use (match_operand:SI 2 "immediate_operand" "i"))
11087    (use (match_operand:SI 3 "immediate_operand" "i"))
11088    (clobber (match_scratch:DI 4 "=&r"))
11089    (clobber (match_scratch:SI 5 "=q"))]
11090   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
11091    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
11092   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11093   [(set_attr "type" "store_ux")
11094    (set_attr "cell_micro" "always")
11095    (set_attr "length" "8")])
11096
11097 (define_insn ""
11098   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11099         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11100    (use (match_operand:SI 2 "immediate_operand" "i"))
11101    (use (match_operand:SI 3 "immediate_operand" "i"))
11102    (clobber (match_scratch:DI 4 "=&r"))
11103    (clobber (match_scratch:SI 5 "=X"))]
11104   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
11105    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
11106   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11107   [(set_attr "type" "store_ux")
11108    (set_attr "cell_micro" "always")
11109    (set_attr "length" "8")])
11110
11111 ;; Move up to 4 bytes at a time.
11112 (define_expand "movmemsi_1reg"
11113   [(parallel [(set (match_operand 0 "" "")
11114                    (match_operand 1 "" ""))
11115               (use (match_operand 2 "" ""))
11116               (use (match_operand 3 "" ""))
11117               (clobber (match_scratch:SI 4 ""))
11118               (clobber (match_scratch:SI 5 ""))])]
11119   "TARGET_STRING"
11120   "")
11121
11122 (define_insn ""
11123   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
11124         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
11125    (use (match_operand:SI 2 "immediate_operand" "i"))
11126    (use (match_operand:SI 3 "immediate_operand" "i"))
11127    (clobber (match_scratch:SI 4 "=&r"))
11128    (clobber (match_scratch:SI 5 "=q"))]
11129   "TARGET_STRING && TARGET_POWER
11130    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
11131   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11132   [(set_attr "type" "store_ux")
11133    (set_attr "cell_micro" "always")
11134    (set_attr "length" "8")])
11135
11136 (define_insn ""
11137   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
11138         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
11139    (use (match_operand:SI 2 "immediate_operand" "i"))
11140    (use (match_operand:SI 3 "immediate_operand" "i"))
11141    (clobber (match_scratch:SI 4 "=&r"))
11142    (clobber (match_scratch:SI 5 "=X"))]
11143   "TARGET_STRING && ! TARGET_POWER
11144    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
11145   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
11146   [(set_attr "type" "store_ux")
11147    (set_attr "cell_micro" "always")
11148    (set_attr "length" "8")])
11149 \f
11150 ;; Define insns that do load or store with update.  Some of these we can
11151 ;; get by using pre-decrement or pre-increment, but the hardware can also
11152 ;; do cases where the increment is not the size of the object.
11153 ;;
11154 ;; In all these cases, we use operands 0 and 1 for the register being
11155 ;; incremented because those are the operands that local-alloc will
11156 ;; tie and these are the pair most likely to be tieable (and the ones
11157 ;; that will benefit the most).
11158
11159 (define_insn "*movdi_update1"
11160   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
11161         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
11162                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
11163    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
11164         (plus:DI (match_dup 1) (match_dup 2)))]
11165   "TARGET_POWERPC64 && TARGET_UPDATE
11166    && (!avoiding_indexed_address_p (DImode)
11167        || !gpc_reg_operand (operands[2], DImode))"
11168   "@
11169    ldux %3,%0,%2
11170    ldu %3,%2(%0)"
11171   [(set_attr "type" "load_ux,load_u")])
11172
11173 (define_insn "movdi_<mode>_update"
11174   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
11175                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
11176         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
11177    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
11178         (plus:P (match_dup 1) (match_dup 2)))]
11179   "TARGET_POWERPC64 && TARGET_UPDATE
11180    && (!avoiding_indexed_address_p (Pmode)
11181        || !gpc_reg_operand (operands[2], Pmode)
11182        || (REG_P (operands[0])
11183            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
11184   "@
11185    stdux %3,%0,%2
11186    stdu %3,%2(%0)"
11187   [(set_attr "type" "store_ux,store_u")])
11188
11189 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
11190 ;; needed for stack allocation, even if the user passes -mno-update.
11191 (define_insn "movdi_<mode>_update_stack"
11192   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
11193                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
11194         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
11195    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
11196         (plus:P (match_dup 1) (match_dup 2)))]
11197   "TARGET_POWERPC64"
11198   "@
11199    stdux %3,%0,%2
11200    stdu %3,%2(%0)"
11201   [(set_attr "type" "store_ux,store_u")])
11202
11203 (define_insn "*movsi_update1"
11204   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11205         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11206                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11207    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11208         (plus:SI (match_dup 1) (match_dup 2)))]
11209   "TARGET_UPDATE
11210    && (!avoiding_indexed_address_p (SImode)
11211        || !gpc_reg_operand (operands[2], SImode))"
11212   "@
11213    {lux|lwzux} %3,%0,%2
11214    {lu|lwzu} %3,%2(%0)"
11215   [(set_attr "type" "load_ux,load_u")])
11216
11217 (define_insn "*movsi_update2"
11218   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
11219         (sign_extend:DI
11220          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
11221                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
11222    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
11223         (plus:DI (match_dup 1) (match_dup 2)))]
11224   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
11225    && !avoiding_indexed_address_p (DImode)"
11226   "lwaux %3,%0,%2"
11227   [(set_attr "type" "load_ext_ux")])
11228
11229 (define_insn "movsi_update"
11230   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11231                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11232         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
11233    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11234         (plus:SI (match_dup 1) (match_dup 2)))]
11235   "TARGET_UPDATE
11236    && (!avoiding_indexed_address_p (SImode)
11237        || !gpc_reg_operand (operands[2], SImode)
11238        || (REG_P (operands[0])
11239            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
11240   "@
11241    {stux|stwux} %3,%0,%2
11242    {stu|stwu} %3,%2(%0)"
11243   [(set_attr "type" "store_ux,store_u")])
11244
11245 ;; This is an unconditional pattern; needed for stack allocation, even
11246 ;; if the user passes -mno-update.
11247 (define_insn "movsi_update_stack"
11248   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11249                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11250         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
11251    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11252         (plus:SI (match_dup 1) (match_dup 2)))]
11253   ""
11254   "@
11255    {stux|stwux} %3,%0,%2
11256    {stu|stwu} %3,%2(%0)"
11257   [(set_attr "type" "store_ux,store_u")])
11258
11259 (define_insn "*movhi_update1"
11260   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
11261         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11262                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11263    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11264         (plus:SI (match_dup 1) (match_dup 2)))]
11265   "TARGET_UPDATE
11266    && (!avoiding_indexed_address_p (SImode)
11267        || !gpc_reg_operand (operands[2], SImode))"
11268   "@
11269    lhzux %3,%0,%2
11270    lhzu %3,%2(%0)"
11271   [(set_attr "type" "load_ux,load_u")])
11272
11273 (define_insn "*movhi_update2"
11274   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11275         (zero_extend:SI
11276          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11277                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
11278    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11279         (plus:SI (match_dup 1) (match_dup 2)))]
11280   "TARGET_UPDATE
11281    && (!avoiding_indexed_address_p (SImode)
11282        || !gpc_reg_operand (operands[2], SImode))"
11283   "@
11284    lhzux %3,%0,%2
11285    lhzu %3,%2(%0)"
11286   [(set_attr "type" "load_ux,load_u")])
11287
11288 (define_insn "*movhi_update3"
11289   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11290         (sign_extend:SI
11291          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11292                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
11293    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11294         (plus:SI (match_dup 1) (match_dup 2)))]
11295   "TARGET_UPDATE && rs6000_gen_cell_microcode
11296    && (!avoiding_indexed_address_p (SImode)
11297        || !gpc_reg_operand (operands[2], SImode))"
11298   "@
11299    lhaux %3,%0,%2
11300    lhau %3,%2(%0)"
11301   [(set_attr "type" "load_ext_ux,load_ext_u")])
11302
11303 (define_insn "*movhi_update4"
11304   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11305                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11306         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
11307    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11308         (plus:SI (match_dup 1) (match_dup 2)))]
11309   "TARGET_UPDATE
11310    && (!avoiding_indexed_address_p (SImode)
11311        || !gpc_reg_operand (operands[2], SImode))"
11312   "@
11313    sthux %3,%0,%2
11314    sthu %3,%2(%0)"
11315   [(set_attr "type" "store_ux,store_u")])
11316
11317 (define_insn "*movqi_update1"
11318   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
11319         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11320                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11321    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11322         (plus:SI (match_dup 1) (match_dup 2)))]
11323   "TARGET_UPDATE
11324    && (!avoiding_indexed_address_p (SImode)
11325        || !gpc_reg_operand (operands[2], SImode))"
11326   "@
11327    lbzux %3,%0,%2
11328    lbzu %3,%2(%0)"
11329   [(set_attr "type" "load_ux,load_u")])
11330
11331 (define_insn "*movqi_update2"
11332   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11333         (zero_extend:SI
11334          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11335                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
11336    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11337         (plus:SI (match_dup 1) (match_dup 2)))]
11338   "TARGET_UPDATE
11339    && (!avoiding_indexed_address_p (SImode)
11340        || !gpc_reg_operand (operands[2], SImode))"
11341   "@
11342    lbzux %3,%0,%2
11343    lbzu %3,%2(%0)"
11344   [(set_attr "type" "load_ux,load_u")])
11345
11346 (define_insn "*movqi_update3"
11347   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11348                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11349         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
11350    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11351         (plus:SI (match_dup 1) (match_dup 2)))]
11352   "TARGET_UPDATE
11353    && (!avoiding_indexed_address_p (SImode)
11354        || !gpc_reg_operand (operands[2], SImode))"
11355   "@
11356    stbux %3,%0,%2
11357    stbu %3,%2(%0)"
11358   [(set_attr "type" "store_ux,store_u")])
11359
11360 (define_insn "*movsf_update1"
11361   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
11362         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11363                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11364    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11365         (plus:SI (match_dup 1) (match_dup 2)))]
11366   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
11367    && (!avoiding_indexed_address_p (SImode)
11368        || !gpc_reg_operand (operands[2], SImode))"
11369   "@
11370    lfsux %3,%0,%2
11371    lfsu %3,%2(%0)"
11372   [(set_attr "type" "fpload_ux,fpload_u")])
11373
11374 (define_insn "*movsf_update2"
11375   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11376                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11377         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
11378    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11379         (plus:SI (match_dup 1) (match_dup 2)))]
11380   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
11381    && (!avoiding_indexed_address_p (SImode)
11382        || !gpc_reg_operand (operands[2], SImode))"
11383   "@
11384    stfsux %3,%0,%2
11385    stfsu %3,%2(%0)"
11386   [(set_attr "type" "fpstore_ux,fpstore_u")])
11387
11388 (define_insn "*movsf_update3"
11389   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
11390         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11391                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11392    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11393         (plus:SI (match_dup 1) (match_dup 2)))]
11394   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
11395    && (!avoiding_indexed_address_p (SImode)
11396        || !gpc_reg_operand (operands[2], SImode))"
11397   "@
11398    {lux|lwzux} %3,%0,%2
11399    {lu|lwzu} %3,%2(%0)"
11400   [(set_attr "type" "load_ux,load_u")])
11401
11402 (define_insn "*movsf_update4"
11403   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11404                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11405         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
11406    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11407         (plus:SI (match_dup 1) (match_dup 2)))]
11408   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
11409    && (!avoiding_indexed_address_p (SImode)
11410        || !gpc_reg_operand (operands[2], SImode))"
11411   "@
11412    {stux|stwux} %3,%0,%2
11413    {stu|stwu} %3,%2(%0)"
11414   [(set_attr "type" "store_ux,store_u")])
11415
11416 (define_insn "*movdf_update1"
11417   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
11418         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11419                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11420    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11421         (plus:SI (match_dup 1) (match_dup 2)))]
11422   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
11423    && (!avoiding_indexed_address_p (SImode)
11424        || !gpc_reg_operand (operands[2], SImode))"
11425   "@
11426    lfdux %3,%0,%2
11427    lfdu %3,%2(%0)"
11428   [(set_attr "type" "fpload_ux,fpload_u")])
11429
11430 (define_insn "*movdf_update2"
11431   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11432                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11433         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
11434    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11435         (plus:SI (match_dup 1) (match_dup 2)))]
11436   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
11437    && (!avoiding_indexed_address_p (SImode)
11438        || !gpc_reg_operand (operands[2], SImode))"
11439   "@
11440    stfdux %3,%0,%2
11441    stfdu %3,%2(%0)"
11442   [(set_attr "type" "fpstore_ux,fpstore_u")])
11443
11444 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
11445
11446 (define_insn "*lfq_power2"
11447   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
11448         (match_operand:V2DF 1 "memory_operand" ""))]
11449   "TARGET_POWER2
11450    && TARGET_HARD_FLOAT && TARGET_FPRS"
11451   "lfq%U1%X1 %0,%1")
11452
11453 (define_peephole2
11454   [(set (match_operand:DF 0 "gpc_reg_operand" "")
11455         (match_operand:DF 1 "memory_operand" ""))
11456    (set (match_operand:DF 2 "gpc_reg_operand" "")
11457         (match_operand:DF 3 "memory_operand" ""))]
11458   "TARGET_POWER2
11459    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
11460    && registers_ok_for_quad_peep (operands[0], operands[2])
11461    && mems_ok_for_quad_peep (operands[1], operands[3])"
11462   [(set (match_dup 0)
11463         (match_dup 1))]
11464   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
11465    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
11466
11467 (define_insn "*stfq_power2"
11468   [(set (match_operand:V2DF 0 "memory_operand" "")
11469         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
11470   "TARGET_POWER2
11471    && TARGET_HARD_FLOAT && TARGET_FPRS"
11472   "stfq%U0%X0 %1,%0")
11473
11474
11475 (define_peephole2
11476   [(set (match_operand:DF 0 "memory_operand" "")
11477         (match_operand:DF 1 "gpc_reg_operand" ""))
11478    (set (match_operand:DF 2 "memory_operand" "")
11479         (match_operand:DF 3 "gpc_reg_operand" ""))]
11480   "TARGET_POWER2
11481    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
11482    && registers_ok_for_quad_peep (operands[1], operands[3])
11483    && mems_ok_for_quad_peep (operands[0], operands[2])"
11484   [(set (match_dup 0)
11485         (match_dup 1))]
11486   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
11487    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
11488
11489 ;; After inserting conditional returns we can sometimes have
11490 ;; unnecessary register moves.  Unfortunately we cannot have a
11491 ;; modeless peephole here, because some single SImode sets have early
11492 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
11493 ;; sequences, using get_attr_length here will smash the operands
11494 ;; array.  Neither is there an early_cobbler_p predicate.
11495 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
11496 (define_peephole2
11497   [(set (match_operand:DF 0 "gpc_reg_operand" "")
11498         (match_operand:DF 1 "any_operand" ""))
11499    (set (match_operand:DF 2 "gpc_reg_operand" "")
11500         (match_dup 0))]
11501   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
11502    && peep2_reg_dead_p (2, operands[0])"
11503   [(set (match_dup 2) (match_dup 1))])
11504
11505 (define_peephole2
11506   [(set (match_operand:SF 0 "gpc_reg_operand" "")
11507         (match_operand:SF 1 "any_operand" ""))
11508    (set (match_operand:SF 2 "gpc_reg_operand" "")
11509         (match_dup 0))]
11510   "peep2_reg_dead_p (2, operands[0])"
11511   [(set (match_dup 2) (match_dup 1))])
11512
11513 \f
11514 ;; TLS support.
11515
11516 ;; Mode attributes for different ABIs.
11517 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
11518 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
11519 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
11520 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
11521
11522 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
11523   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11524         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11525               (match_operand 4 "" "g")))
11526    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11527                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11528                    UNSPEC_TLSGD)
11529    (clobber (reg:SI LR_REGNO))]
11530   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11531 {
11532   if (TARGET_CMODEL != CMODEL_SMALL)
11533     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;bl %z3\;%.";
11534   else
11535     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;%.";
11536 }
11537   "&& TARGET_TLS_MARKERS"
11538   [(set (match_dup 0)
11539         (unspec:TLSmode [(match_dup 1)
11540                          (match_dup 2)]
11541                         UNSPEC_TLSGD))
11542    (parallel [(set (match_dup 0)
11543                    (call (mem:TLSmode (match_dup 3))
11544                          (match_dup 4)))
11545               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11546               (clobber (reg:SI LR_REGNO))])]
11547   ""
11548   [(set_attr "type" "two")
11549    (set (attr "length")
11550      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11551                    (const_int 16)
11552                    (const_int 12)))])
11553
11554 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_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_V4"
11563 {
11564   if (flag_pic)
11565     {
11566       if (TARGET_SECURE_PLT && flag_pic == 2)
11567         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
11568       else
11569         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
11570     }
11571   else
11572     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
11573 }
11574   "&& TARGET_TLS_MARKERS"
11575   [(set (match_dup 0)
11576         (unspec:TLSmode [(match_dup 1)
11577                          (match_dup 2)]
11578                         UNSPEC_TLSGD))
11579    (parallel [(set (match_dup 0)
11580                    (call (mem:TLSmode (match_dup 3))
11581                          (match_dup 4)))
11582               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11583               (clobber (reg:SI LR_REGNO))])]
11584   ""
11585   [(set_attr "type" "two")
11586    (set_attr "length" "8")])
11587
11588 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
11589   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11590         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11591                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11592                         UNSPEC_TLSGD))]
11593   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11594   "addi %0,%1,%2@got@tlsgd"
11595   "&& TARGET_CMODEL != CMODEL_SMALL"
11596   [(set (match_dup 3)
11597         (const:TLSmode
11598           (plus:TLSmode (match_dup 1)
11599             (high:TLSmode
11600               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)))))
11601    (set (match_dup 0)
11602         (lo_sum:TLSmode (match_dup 3)
11603             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)))]
11604   "
11605 {
11606   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11607 }"
11608   [(set (attr "length")
11609      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11610                    (const_int 8)
11611                    (const_int 4)))])
11612
11613 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
11614   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11615      (const:TLSmode
11616        (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11617          (high:TLSmode
11618            (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11619                            UNSPEC_TLSGD)))))]
11620   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11621   "addis %0,%1,%2@got@tlsgd@ha"
11622   [(set_attr "length" "4")])
11623
11624 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
11625   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11626      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11627        (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11628                        UNSPEC_TLSGD)))]
11629   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11630   "addi %0,%1,%2@got@tlsgd@l"
11631   [(set_attr "length" "4")])
11632
11633 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
11634   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11635         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11636               (match_operand 2 "" "g")))
11637    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11638                    UNSPEC_TLSGD)
11639    (clobber (reg:SI LR_REGNO))]
11640   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11641   "bl %z1(%3@tlsgd)\;%."
11642   [(set_attr "type" "branch")
11643    (set_attr "length" "8")])
11644
11645 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
11646   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11647         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11648               (match_operand 2 "" "g")))
11649    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11650                    UNSPEC_TLSGD)
11651    (clobber (reg:SI LR_REGNO))]
11652   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11653 {
11654   if (flag_pic)
11655     {
11656       if (TARGET_SECURE_PLT && flag_pic == 2)
11657         return "bl %z1+32768(%3@tlsgd)@plt";
11658       return "bl %z1(%3@tlsgd)@plt";
11659     }
11660   return "bl %z1(%3@tlsgd)";
11661 }
11662   [(set_attr "type" "branch")
11663    (set_attr "length" "4")])
11664
11665 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
11666   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11667         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11668               (match_operand 3 "" "g")))
11669    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11670                    UNSPEC_TLSLD)
11671    (clobber (reg:SI LR_REGNO))]
11672   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11673 {
11674   if (TARGET_CMODEL != CMODEL_SMALL)
11675     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;bl %z2\;%.";
11676   else
11677     return "addi %0,%1,%&@got@tlsld\;bl %z2\;%.";
11678 }
11679   "&& TARGET_TLS_MARKERS"
11680   [(set (match_dup 0)
11681         (unspec:TLSmode [(match_dup 1)]
11682                         UNSPEC_TLSLD))
11683    (parallel [(set (match_dup 0)
11684                    (call (mem:TLSmode (match_dup 2))
11685                          (match_dup 3)))
11686               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11687               (clobber (reg:SI LR_REGNO))])]
11688   ""
11689   [(set_attr "type" "two")
11690    (set (attr "length")
11691      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11692                    (const_int 16)
11693                    (const_int 12)))])
11694
11695 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_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_V4"
11703 {
11704   if (flag_pic)
11705     {
11706       if (TARGET_SECURE_PLT && flag_pic == 2)
11707         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11708       else
11709         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11710     }
11711   else
11712     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11713 }
11714   "&& TARGET_TLS_MARKERS"
11715   [(set (match_dup 0)
11716         (unspec:TLSmode [(match_dup 1)]
11717                         UNSPEC_TLSLD))
11718    (parallel [(set (match_dup 0)
11719                    (call (mem:TLSmode (match_dup 2))
11720                          (match_dup 3)))
11721               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11722               (clobber (reg:SI LR_REGNO))])]
11723   ""
11724   [(set_attr "length" "8")])
11725
11726 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
11727   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11728         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11729                         UNSPEC_TLSLD))]
11730   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11731   "addi %0,%1,%&@got@tlsld"
11732   "&& TARGET_CMODEL != CMODEL_SMALL"
11733   [(set (match_dup 2)
11734         (const:TLSmode
11735           (plus:TLSmode (match_dup 1)
11736             (high:TLSmode
11737               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))))
11738    (set (match_dup 0)
11739         (lo_sum:TLSmode (match_dup 2)
11740             (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
11741   "
11742 {
11743   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11744 }"
11745   [(set (attr "length")
11746      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11747                    (const_int 8)
11748                    (const_int 4)))])
11749
11750 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
11751   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11752      (const:TLSmode
11753        (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11754          (high:TLSmode
11755            (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))))]
11756   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11757   "addis %0,%1,%&@got@tlsld@ha"
11758   [(set_attr "length" "4")])
11759
11760 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
11761   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11762      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11763        (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
11764   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11765   "addi %0,%1,%&@got@tlsld@l"
11766   [(set_attr "length" "4")])
11767
11768 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11769   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11770         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11771               (match_operand 2 "" "g")))
11772    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11773    (clobber (reg:SI LR_REGNO))]
11774   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11775   "bl %z1(%&@tlsld)\;%."
11776   [(set_attr "type" "branch")
11777    (set_attr "length" "8")])
11778
11779 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11780   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11781         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11782               (match_operand 2 "" "g")))
11783    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11784    (clobber (reg:SI LR_REGNO))]
11785   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11786 {
11787   if (flag_pic)
11788     {
11789       if (TARGET_SECURE_PLT && flag_pic == 2)
11790         return "bl %z1+32768(%&@tlsld)@plt";
11791       return "bl %z1(%&@tlsld)@plt";
11792     }
11793   return "bl %z1(%&@tlsld)";
11794 }
11795   [(set_attr "type" "branch")
11796    (set_attr "length" "4")])
11797
11798 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11799   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11800         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11801                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11802                         UNSPEC_TLSDTPREL))]
11803   "HAVE_AS_TLS"
11804   "addi %0,%1,%2@dtprel")
11805
11806 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11807   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11808         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11809                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11810                         UNSPEC_TLSDTPRELHA))]
11811   "HAVE_AS_TLS"
11812   "addis %0,%1,%2@dtprel@ha")
11813
11814 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11815   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11816         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11817                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11818                         UNSPEC_TLSDTPRELLO))]
11819   "HAVE_AS_TLS"
11820   "addi %0,%1,%2@dtprel@l")
11821
11822 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11823   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11824         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11825                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11826                         UNSPEC_TLSGOTDTPREL))]
11827   "HAVE_AS_TLS"
11828   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
11829   "&& TARGET_CMODEL != CMODEL_SMALL"
11830   [(set (match_dup 3)
11831         (const:TLSmode
11832           (plus:TLSmode (match_dup 1)
11833             (high:TLSmode
11834               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL)))))
11835    (set (match_dup 0)
11836         (lo_sum:TLSmode (match_dup 3)
11837             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
11838   "
11839 {
11840   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11841 }"
11842   [(set (attr "length")
11843      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11844                    (const_int 8)
11845                    (const_int 4)))])
11846
11847 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
11848   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11849      (const:TLSmode
11850        (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11851          (high:TLSmode
11852            (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11853                            UNSPEC_TLSGOTDTPREL)))))]
11854   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11855   "addis %0,%1,%2@got@dtprel@ha"
11856   [(set_attr "length" "4")])
11857
11858 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
11859   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11860      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11861          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11862                          UNSPEC_TLSGOTDTPREL)))]
11863   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11864   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
11865   [(set_attr "length" "4")])
11866
11867 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11868   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11869         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11870                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11871                         UNSPEC_TLSTPREL))]
11872   "HAVE_AS_TLS"
11873   "addi %0,%1,%2@tprel")
11874
11875 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11876   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11877         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11878                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11879                         UNSPEC_TLSTPRELHA))]
11880   "HAVE_AS_TLS"
11881   "addis %0,%1,%2@tprel@ha")
11882
11883 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11884   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11885         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11886                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11887                         UNSPEC_TLSTPRELLO))]
11888   "HAVE_AS_TLS"
11889   "addi %0,%1,%2@tprel@l")
11890
11891 ;; "b" output constraint here and on tls_tls input to support linker tls
11892 ;; optimization.  The linker may edit the instructions emitted by a
11893 ;; tls_got_tprel/tls_tls pair to addis,addi.
11894 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11895   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11896         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11897                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11898                         UNSPEC_TLSGOTTPREL))]
11899   "HAVE_AS_TLS"
11900   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
11901   "&& TARGET_CMODEL != CMODEL_SMALL"
11902   [(set (match_dup 3)
11903         (const:TLSmode
11904           (plus:TLSmode (match_dup 1)
11905             (high:TLSmode
11906               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL)))))
11907    (set (match_dup 0)
11908         (lo_sum:TLSmode (match_dup 3)
11909             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL)))]
11910   "
11911 {
11912   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11913 }"
11914   [(set (attr "length")
11915      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11916                    (const_int 8)
11917                    (const_int 4)))])
11918
11919 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
11920   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11921      (const:TLSmode
11922        (plus:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11923          (high:TLSmode
11924            (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11925                            UNSPEC_TLSGOTTPREL)))))]
11926   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11927   "addis %0,%1,%2@got@tprel@ha"
11928   [(set_attr "length" "4")])
11929
11930 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
11931   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11932      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11933          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11934                          UNSPEC_TLSGOTTPREL)))]
11935   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11936   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
11937   [(set_attr "length" "4")])
11938
11939 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11940   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11941         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11942                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11943                         UNSPEC_TLSTLS))]
11944   "HAVE_AS_TLS"
11945   "add %0,%1,%2@tls")
11946 \f
11947 ;; Next come insns related to the calling sequence.
11948 ;;
11949 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11950 ;; We move the back-chain and decrement the stack pointer.
11951
11952 (define_expand "allocate_stack"
11953   [(set (match_operand 0 "gpc_reg_operand" "")
11954         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11955    (set (reg 1)
11956         (minus (reg 1) (match_dup 1)))]
11957   ""
11958   "
11959 { rtx chain = gen_reg_rtx (Pmode);
11960   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11961   rtx neg_op0;
11962   rtx insn, par, set, mem;
11963
11964   emit_move_insn (chain, stack_bot);
11965
11966   /* Check stack bounds if necessary.  */
11967   if (crtl->limit_stack)
11968     {
11969       rtx available;
11970       available = expand_binop (Pmode, sub_optab,
11971                                 stack_pointer_rtx, stack_limit_rtx,
11972                                 NULL_RTX, 1, OPTAB_WIDEN);
11973       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11974     }
11975
11976   if (GET_CODE (operands[1]) != CONST_INT
11977       || INTVAL (operands[1]) < -32767
11978       || INTVAL (operands[1]) > 32768)
11979     {
11980       neg_op0 = gen_reg_rtx (Pmode);
11981       if (TARGET_32BIT)
11982         emit_insn (gen_negsi2 (neg_op0, operands[1]));
11983       else
11984         emit_insn (gen_negdi2 (neg_op0, operands[1]));
11985     }
11986   else
11987     neg_op0 = GEN_INT (- INTVAL (operands[1]));
11988
11989   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
11990                                        : gen_movdi_di_update_stack))
11991                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
11992                          chain));
11993   /* Since we didn't use gen_frame_mem to generate the MEM, grab
11994      it now and set the alias set/attributes. The above gen_*_update
11995      calls will generate a PARALLEL with the MEM set being the first
11996      operation. */
11997   par = PATTERN (insn);
11998   gcc_assert (GET_CODE (par) == PARALLEL);
11999   set = XVECEXP (par, 0, 0);
12000   gcc_assert (GET_CODE (set) == SET);
12001   mem = SET_DEST (set);
12002   gcc_assert (MEM_P (mem));
12003   MEM_NOTRAP_P (mem) = 1;
12004   set_mem_alias_set (mem, get_frame_alias_set ());
12005
12006   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
12007   DONE;
12008 }")
12009
12010 ;; These patterns say how to save and restore the stack pointer.  We need not
12011 ;; save the stack pointer at function level since we are careful to
12012 ;; preserve the backchain.  At block level, we have to restore the backchain
12013 ;; when we restore the stack pointer.
12014 ;;
12015 ;; For nonlocal gotos, we must save both the stack pointer and its
12016 ;; backchain and restore both.  Note that in the nonlocal case, the
12017 ;; save area is a memory location.
12018
12019 (define_expand "save_stack_function"
12020   [(match_operand 0 "any_operand" "")
12021    (match_operand 1 "any_operand" "")]
12022   ""
12023   "DONE;")
12024
12025 (define_expand "restore_stack_function"
12026   [(match_operand 0 "any_operand" "")
12027    (match_operand 1 "any_operand" "")]
12028   ""
12029   "DONE;")
12030
12031 ;; Adjust stack pointer (op0) to a new value (op1).
12032 ;; First copy old stack backchain to new location, and ensure that the
12033 ;; scheduler won't reorder the sp assignment before the backchain write.
12034 (define_expand "restore_stack_block"
12035   [(set (match_dup 2) (match_dup 3))
12036    (set (match_dup 4) (match_dup 2))
12037    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
12038    (set (match_operand 0 "register_operand" "")
12039         (match_operand 1 "register_operand" ""))]
12040   ""
12041   "
12042 {
12043   operands[1] = force_reg (Pmode, operands[1]);
12044   operands[2] = gen_reg_rtx (Pmode);
12045   operands[3] = gen_frame_mem (Pmode, operands[0]);
12046   operands[4] = gen_frame_mem (Pmode, operands[1]);
12047   operands[5] = gen_frame_mem (BLKmode, operands[0]);
12048 }")
12049
12050 (define_expand "save_stack_nonlocal"
12051   [(set (match_dup 3) (match_dup 4))
12052    (set (match_operand 0 "memory_operand" "") (match_dup 3))
12053    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
12054   ""
12055   "
12056 {
12057   int units_per_word = (TARGET_32BIT) ? 4 : 8;
12058
12059   /* Copy the backchain to the first word, sp to the second.  */
12060   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
12061   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
12062   operands[3] = gen_reg_rtx (Pmode);
12063   operands[4] = gen_frame_mem (Pmode, operands[1]);
12064 }")
12065
12066 (define_expand "restore_stack_nonlocal"
12067   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
12068    (set (match_dup 3) (match_dup 4))
12069    (set (match_dup 5) (match_dup 2))
12070    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
12071    (set (match_operand 0 "register_operand" "") (match_dup 3))]
12072   ""
12073   "
12074 {
12075   int units_per_word = (TARGET_32BIT) ? 4 : 8;
12076
12077   /* Restore the backchain from the first word, sp from the second.  */
12078   operands[2] = gen_reg_rtx (Pmode);
12079   operands[3] = gen_reg_rtx (Pmode);
12080   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
12081   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
12082   operands[5] = gen_frame_mem (Pmode, operands[3]);
12083   operands[6] = gen_frame_mem (BLKmode, operands[0]);
12084 }")
12085 \f
12086 ;; TOC register handling.
12087
12088 ;; Code to initialize the TOC register...
12089
12090 (define_insn "load_toc_aix_si"
12091   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12092                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
12093               (use (reg:SI 2))])]
12094   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
12095   "*
12096 {
12097   char buf[30];
12098   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
12099   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12100   operands[2] = gen_rtx_REG (Pmode, 2);
12101   return \"{l|lwz} %0,%1(%2)\";
12102 }"
12103   [(set_attr "type" "load")])
12104
12105 (define_insn "load_toc_aix_di"
12106   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12107                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
12108               (use (reg:DI 2))])]
12109   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
12110   "*
12111 {
12112   char buf[30];
12113 #ifdef TARGET_RELOCATABLE
12114   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
12115                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
12116 #else
12117   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
12118 #endif
12119   if (TARGET_ELF)
12120     strcat (buf, \"@toc\");
12121   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12122   operands[2] = gen_rtx_REG (Pmode, 2);
12123   return \"ld %0,%1(%2)\";
12124 }"
12125   [(set_attr "type" "load")])
12126
12127 (define_insn "load_toc_v4_pic_si"
12128   [(set (reg:SI LR_REGNO)
12129         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
12130   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
12131   "bl _GLOBAL_OFFSET_TABLE_@local-4"
12132   [(set_attr "type" "branch")
12133    (set_attr "length" "4")])
12134
12135 (define_expand "load_toc_v4_PIC_1"
12136   [(parallel [(set (reg:SI LR_REGNO)
12137                    (match_operand:SI 0 "immediate_operand" "s"))
12138               (use (unspec [(match_dup 0)] UNSPEC_TOC))])]
12139   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
12140    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
12141   "")
12142
12143 (define_insn "load_toc_v4_PIC_1_normal"
12144   [(set (reg:SI LR_REGNO)
12145         (match_operand:SI 0 "immediate_operand" "s"))
12146    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
12147   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX
12148    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
12149   "bcl 20,31,%0\\n%0:"
12150   [(set_attr "type" "branch")
12151    (set_attr "length" "4")])
12152
12153 (define_insn "load_toc_v4_PIC_1_476"
12154   [(set (reg:SI LR_REGNO)
12155         (match_operand:SI 0 "immediate_operand" "s"))
12156    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
12157   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX
12158    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
12159   "*
12160 {
12161   char name[32];
12162   static char templ[32];
12163
12164   get_ppc476_thunk_name (name);
12165   sprintf (templ, \"bl %s\\n%%0:\", name);
12166   return templ;
12167 }"
12168   [(set_attr "type" "branch")
12169    (set_attr "length" "4")])
12170
12171 (define_expand "load_toc_v4_PIC_1b"
12172   [(parallel [(set (reg:SI LR_REGNO)
12173                    (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
12174                                (label_ref (match_operand 1 "" ""))]
12175                            UNSPEC_TOCPTR))
12176               (match_dup 1)])]
12177   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
12178   "")
12179
12180 (define_insn "load_toc_v4_PIC_1b_normal"
12181   [(set (reg:SI LR_REGNO)
12182         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
12183                     (label_ref (match_operand 1 "" ""))]
12184                 UNSPEC_TOCPTR))
12185    (match_dup 1)]
12186   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
12187   "bcl 20,31,$+8\;.long %0-$"
12188   [(set_attr "type" "branch")
12189    (set_attr "length" "8")])
12190
12191 (define_insn "load_toc_v4_PIC_1b_476"
12192   [(set (reg:SI LR_REGNO)
12193         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
12194                     (label_ref (match_operand 1 "" ""))]
12195                 UNSPEC_TOCPTR))
12196    (match_dup 1)]
12197   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
12198   "*
12199 {
12200   char name[32];
12201   static char templ[32];
12202
12203   get_ppc476_thunk_name (name);
12204   sprintf (templ, \"bl %s\\n\\tb $+8\\n\\t.long %%0-$\", name);
12205   return templ;
12206 }"
12207   [(set_attr "type" "branch")
12208    (set_attr "length" "16")])
12209
12210 (define_insn "load_toc_v4_PIC_2"
12211   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12212         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
12213                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
12214                              (match_operand:SI 3 "immediate_operand" "s")))))]
12215   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
12216   "{l|lwz} %0,%2-%3(%1)"
12217   [(set_attr "type" "load")])
12218
12219 (define_insn "load_toc_v4_PIC_3b"
12220   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12221         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
12222                  (high:SI
12223                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
12224                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
12225   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
12226   "{cau|addis} %0,%1,%2-%3@ha")
12227
12228 (define_insn "load_toc_v4_PIC_3c"
12229   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12230         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
12231                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
12232                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
12233   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
12234   "{cal %0,%2-%3@l(%1)|addi %0,%1,%2-%3@l}")
12235
12236 ;; If the TOC is shared over a translation unit, as happens with all
12237 ;; the kinds of PIC that we support, we need to restore the TOC
12238 ;; pointer only when jumping over units of translation.
12239 ;; On Darwin, we need to reload the picbase.
12240
12241 (define_expand "builtin_setjmp_receiver"
12242   [(use (label_ref (match_operand 0 "" "")))]
12243   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
12244    || (TARGET_TOC && TARGET_MINIMAL_TOC)
12245    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
12246   "
12247 {
12248 #if TARGET_MACHO
12249   if (DEFAULT_ABI == ABI_DARWIN)
12250     {
12251       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
12252       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
12253       rtx tmplabrtx;
12254       char tmplab[20];
12255
12256       crtl->uses_pic_offset_table = 1;
12257       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
12258                                   CODE_LABEL_NUMBER (operands[0]));
12259       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
12260
12261       emit_insn (gen_load_macho_picbase (tmplabrtx));
12262       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
12263       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
12264     }
12265   else
12266 #endif
12267     rs6000_emit_load_toc_table (FALSE);
12268   DONE;
12269 }")
12270
12271 ;; Elf specific ways of loading addresses for non-PIC code.
12272 ;; The output of this could be r0, but we make a very strong
12273 ;; preference for a base register because it will usually
12274 ;; be needed there.
12275 (define_insn "elf_high"
12276   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
12277         (high:SI (match_operand 1 "" "")))]
12278   "TARGET_ELF && ! TARGET_64BIT"
12279   "{liu|lis} %0,%1@ha")
12280
12281 (define_insn "elf_low"
12282   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12283         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
12284                    (match_operand 2 "" "")))]
12285    "TARGET_ELF && ! TARGET_64BIT"
12286    "@
12287     {cal|la} %0,%2@l(%1)
12288     {ai|addic} %0,%1,%K2")
12289
12290 ;; Largetoc support
12291 (define_insn "largetoc_high"
12292   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
12293         (const:DI
12294           (plus:DI (match_operand:DI 1 "gpc_reg_operand" "b")
12295                    (high:DI (match_operand:DI 2 "" "")))))]
12296    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
12297    "{cau|addis} %0,%1,%2@ha")
12298
12299 (define_insn "largetoc_low"
12300   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12301         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b")
12302                    (match_operand:DI 2 "" "")))]
12303    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
12304    "{cal %0,%2@l(%1)|addi %0,%1,%2@l}")
12305 \f
12306 ;; A function pointer under AIX is a pointer to a data area whose first word
12307 ;; contains the actual address of the function, whose second word contains a
12308 ;; pointer to its TOC, and whose third word contains a value to place in the
12309 ;; static chain register (r11).  Note that if we load the static chain, our
12310 ;; "trampoline" need not have any executable code.
12311
12312 (define_expand "call_indirect_aix32"
12313   [(set (match_dup 2)
12314         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
12315    (set (match_dup 3)
12316         (reg:SI 2))
12317    (set (reg:SI 11)
12318         (mem:SI (plus:SI (match_dup 0)
12319                          (const_int 8))))
12320    (parallel [(call (mem:SI (match_dup 2))
12321                     (match_operand 1 "" ""))
12322               (use (match_dup 4))
12323               (set (reg:SI 2) (match_dup 3))
12324               (use (reg:SI 11))
12325               (clobber (reg:SI LR_REGNO))])]
12326   "TARGET_32BIT"
12327   "
12328 {
12329   operands[2] = gen_reg_rtx (SImode);
12330   operands[3] = gen_rtx_MEM (SImode,
12331                              gen_rtx_PLUS (SImode, stack_pointer_rtx,
12332                                            GEN_INT (20)));
12333
12334   operands[4] = gen_rtx_MEM (SImode,
12335                              gen_rtx_PLUS (SImode, operands[0],
12336                                            GEN_INT (4)));
12337
12338   /* Make sure the compiler does not optimize away the store of the TOC.  */
12339   MEM_VOLATILE_P (operands[3]) = 1;
12340 }")
12341
12342 (define_expand "call_indirect_aix64"
12343   [(set (match_dup 2)
12344         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
12345    (set (match_dup 3)
12346         (reg:DI 2))
12347    (set (reg:DI 11)
12348         (mem:DI (plus:DI (match_dup 0)
12349                          (const_int 16))))
12350    (parallel [(call (mem:SI (match_dup 2))
12351                     (match_operand 1 "" ""))
12352               (use (match_dup 4))
12353               (set (reg:DI 2) (match_dup 3))
12354               (use (reg:DI 11))
12355               (clobber (reg:DI LR_REGNO))])]
12356   "TARGET_64BIT"
12357   "
12358 {
12359   operands[2] = gen_reg_rtx (DImode);
12360   operands[3] = gen_rtx_MEM (DImode,
12361                              gen_rtx_PLUS (DImode, stack_pointer_rtx,
12362                                            GEN_INT (40)));
12363
12364   operands[4] = gen_rtx_MEM (DImode,
12365                              gen_rtx_PLUS (DImode, operands[0],
12366                                            GEN_INT (8)));
12367
12368   /* Make sure the compiler does not optimize away the store of the TOC.  */
12369   MEM_VOLATILE_P (operands[3]) = 1;
12370 }")
12371
12372 (define_expand "call_value_indirect_aix32"
12373   [(set (match_dup 3)
12374         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12375    (set (match_dup 4)
12376         (reg:SI 2))
12377    (set (reg:SI 11)
12378         (mem:SI (plus:SI (match_dup 1)
12379                          (const_int 8))))
12380    (parallel [(set (match_operand 0 "" "")
12381                    (call (mem:SI (match_dup 3))
12382                          (match_operand 2 "" "")))
12383               (use (match_dup 5))
12384               (set (reg:SI 2) (match_dup 4))
12385               (use (reg:SI 11))
12386               (clobber (reg:SI LR_REGNO))])]
12387   "TARGET_32BIT"
12388   "
12389 {
12390   operands[3] = gen_reg_rtx (SImode);
12391   operands[4] = gen_rtx_MEM (SImode,
12392                              gen_rtx_PLUS (SImode, stack_pointer_rtx,
12393                                            GEN_INT (20)));
12394
12395   operands[5] = gen_rtx_MEM (SImode,
12396                              gen_rtx_PLUS (SImode, operands[1],
12397                                            GEN_INT (4)));
12398
12399   /* Make sure the compiler does not optimize away the store of the TOC.  */
12400   MEM_VOLATILE_P (operands[4]) = 1;
12401 }")
12402
12403 (define_expand "call_value_indirect_aix64"
12404   [(set (match_dup 3)
12405         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12406    (set (match_dup 4)
12407         (reg:DI 2))
12408    (set (reg:DI 11)
12409         (mem:DI (plus:DI (match_dup 1)
12410                          (const_int 16))))
12411    (parallel [(set (match_operand 0 "" "")
12412                    (call (mem:SI (match_dup 3))
12413                          (match_operand 2 "" "")))
12414               (use (match_dup 5))
12415               (set (reg:DI 2) (match_dup 4))
12416               (use (reg:DI 11))
12417               (clobber (reg:DI LR_REGNO))])]
12418   "TARGET_64BIT"
12419   "
12420 {
12421   operands[3] = gen_reg_rtx (DImode);
12422   operands[4] = gen_rtx_MEM (DImode,
12423                              gen_rtx_PLUS (DImode, stack_pointer_rtx,
12424                                            GEN_INT (40)));
12425
12426   operands[5] = gen_rtx_MEM (DImode,
12427                              gen_rtx_PLUS (DImode, operands[1],
12428                                            GEN_INT (8)));
12429
12430   /* Make sure the compiler does not optimize away the store of the TOC.  */
12431   MEM_VOLATILE_P (operands[4]) = 1;
12432 }")
12433
12434 ;; Now the definitions for the call and call_value insns
12435 (define_expand "call"
12436   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12437                     (match_operand 1 "" ""))
12438               (use (match_operand 2 "" ""))
12439               (clobber (reg:SI LR_REGNO))])]
12440   ""
12441   "
12442 {
12443 #if TARGET_MACHO
12444   if (MACHOPIC_INDIRECT)
12445     operands[0] = machopic_indirect_call_target (operands[0]);
12446 #endif
12447
12448   gcc_assert (GET_CODE (operands[0]) == MEM);
12449   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12450
12451   operands[0] = XEXP (operands[0], 0);
12452
12453   if (GET_CODE (operands[0]) != SYMBOL_REF
12454       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
12455       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
12456     {
12457       if (INTVAL (operands[2]) & CALL_LONG)
12458         operands[0] = rs6000_longcall_ref (operands[0]);
12459
12460       switch (DEFAULT_ABI)
12461         {
12462         case ABI_V4:
12463         case ABI_DARWIN:
12464           operands[0] = force_reg (Pmode, operands[0]);
12465           break;
12466
12467         case ABI_AIX:
12468           /* AIX function pointers are really pointers to a three word
12469              area.  */
12470           rs6000_call_indirect_aix (NULL_RTX, operands[0], operands[1]);
12471           DONE;
12472
12473         default:
12474           gcc_unreachable ();
12475         }
12476     }
12477 }")
12478
12479 (define_expand "call_value"
12480   [(parallel [(set (match_operand 0 "" "")
12481                    (call (mem:SI (match_operand 1 "address_operand" ""))
12482                          (match_operand 2 "" "")))
12483               (use (match_operand 3 "" ""))
12484               (clobber (reg:SI LR_REGNO))])]
12485   ""
12486   "
12487 {
12488 #if TARGET_MACHO
12489   if (MACHOPIC_INDIRECT)
12490     operands[1] = machopic_indirect_call_target (operands[1]);
12491 #endif
12492
12493   gcc_assert (GET_CODE (operands[1]) == MEM);
12494   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12495
12496   operands[1] = XEXP (operands[1], 0);
12497
12498   if (GET_CODE (operands[1]) != SYMBOL_REF
12499       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
12500       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
12501     {
12502       if (INTVAL (operands[3]) & CALL_LONG)
12503         operands[1] = rs6000_longcall_ref (operands[1]);
12504
12505       switch (DEFAULT_ABI)
12506         {
12507         case ABI_V4:
12508         case ABI_DARWIN:
12509           operands[1] = force_reg (Pmode, operands[1]);
12510           break;
12511
12512         case ABI_AIX:
12513           /* AIX function pointers are really pointers to a three word
12514              area.  */
12515           rs6000_call_indirect_aix (operands[0], operands[1], operands[2]);
12516           DONE;
12517
12518         default:
12519           gcc_unreachable ();
12520         }
12521     }
12522 }")
12523
12524 ;; Call to function in current module.  No TOC pointer reload needed.
12525 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12526 ;; either the function was not prototyped, or it was prototyped as a
12527 ;; variable argument function.  It is > 0 if FP registers were passed
12528 ;; and < 0 if they were not.
12529
12530 (define_insn "*call_local32"
12531   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12532          (match_operand 1 "" "g,g"))
12533    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12534    (clobber (reg:SI LR_REGNO))]
12535   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12536   "*
12537 {
12538   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12539     output_asm_insn (\"crxor 6,6,6\", operands);
12540
12541   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12542     output_asm_insn (\"creqv 6,6,6\", operands);
12543
12544   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12545 }"
12546   [(set_attr "type" "branch")
12547    (set_attr "length" "4,8")])
12548
12549 (define_insn "*call_local64"
12550   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12551          (match_operand 1 "" "g,g"))
12552    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12553    (clobber (reg:SI LR_REGNO))]
12554   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12555   "*
12556 {
12557   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12558     output_asm_insn (\"crxor 6,6,6\", operands);
12559
12560   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12561     output_asm_insn (\"creqv 6,6,6\", operands);
12562
12563   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12564 }"
12565   [(set_attr "type" "branch")
12566    (set_attr "length" "4,8")])
12567
12568 (define_insn "*call_value_local32"
12569   [(set (match_operand 0 "" "")
12570         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12571               (match_operand 2 "" "g,g")))
12572    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12573    (clobber (reg:SI LR_REGNO))]
12574   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12575   "*
12576 {
12577   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12578     output_asm_insn (\"crxor 6,6,6\", operands);
12579
12580   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12581     output_asm_insn (\"creqv 6,6,6\", operands);
12582
12583   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12584 }"
12585   [(set_attr "type" "branch")
12586    (set_attr "length" "4,8")])
12587
12588
12589 (define_insn "*call_value_local64"
12590   [(set (match_operand 0 "" "")
12591         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12592               (match_operand 2 "" "g,g")))
12593    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12594    (clobber (reg:SI LR_REGNO))]
12595   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12596   "*
12597 {
12598   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12599     output_asm_insn (\"crxor 6,6,6\", operands);
12600
12601   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12602     output_asm_insn (\"creqv 6,6,6\", operands);
12603
12604   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12605 }"
12606   [(set_attr "type" "branch")
12607    (set_attr "length" "4,8")])
12608
12609 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
12610 ;; Operand0 is the addresss of the function to call
12611 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
12612 ;; Operand2 is the location in the function descriptor to load r2 from
12613 ;; Operand3 is the stack location to hold the current TOC pointer
12614
12615 (define_insn "call_indirect_aix<ptrsize>"
12616   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12617          (match_operand 1 "" "g,g"))
12618    (use (match_operand:P 2 "memory_operand" "m,m"))
12619    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "m,m"))
12620    (use (reg:P STATIC_CHAIN_REGNUM))
12621    (clobber (reg:P LR_REGNO))]
12622   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12623   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
12624   [(set_attr "type" "jmpreg")
12625    (set_attr "length" "12")])
12626
12627 ;; Like call_indirect_aix<ptrsize>, but no use of the static chain
12628 ;; Operand0 is the addresss of the function to call
12629 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
12630 ;; Operand2 is the location in the function descriptor to load r2 from
12631 ;; Operand3 is the stack location to hold the current TOC pointer
12632
12633 (define_insn "call_indirect_aix<ptrsize>_nor11"
12634   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12635          (match_operand 1 "" "g,g"))
12636    (use (match_operand:P 2 "memory_operand" "m,m"))
12637    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "m,m"))
12638    (clobber (reg:P LR_REGNO))]
12639   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12640   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
12641   [(set_attr "type" "jmpreg")
12642    (set_attr "length" "12")])
12643
12644 ;; Operand0 is the return result of the function
12645 ;; Operand1 is the addresss of the function to call
12646 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
12647 ;; Operand3 is the location in the function descriptor to load r2 from
12648 ;; Operand4 is the stack location to hold the current TOC pointer
12649
12650 (define_insn "call_value_indirect_aix<ptrsize>"
12651   [(set (match_operand 0 "" "")
12652         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12653               (match_operand 2 "" "g,g")))
12654    (use (match_operand:P 3 "memory_operand" "m,m"))
12655    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "m,m"))
12656    (use (reg:P STATIC_CHAIN_REGNUM))
12657    (clobber (reg:P LR_REGNO))]
12658   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12659   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12660   [(set_attr "type" "jmpreg")
12661    (set_attr "length" "12")])
12662
12663 ;; Like call_value_indirect_aix<ptrsize>, but no use of the static chain
12664 ;; Operand0 is the return result of the function
12665 ;; Operand1 is the addresss of the function to call
12666 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
12667 ;; Operand3 is the location in the function descriptor to load r2 from
12668 ;; Operand4 is the stack location to hold the current TOC pointer
12669
12670 (define_insn "call_value_indirect_aix<ptrsize>_nor11"
12671   [(set (match_operand 0 "" "")
12672         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12673               (match_operand 2 "" "g,g")))
12674    (use (match_operand:P 3 "memory_operand" "m,m"))
12675    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "m,m"))
12676    (clobber (reg:P LR_REGNO))]
12677   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12678   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12679   [(set_attr "type" "jmpreg")
12680    (set_attr "length" "12")])
12681
12682 ;; Call to function which may be in another module.  Restore the TOC
12683 ;; pointer (r2) after the call unless this is System V.
12684 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12685 ;; either the function was not prototyped, or it was prototyped as a
12686 ;; variable argument function.  It is > 0 if FP registers were passed
12687 ;; and < 0 if they were not.
12688
12689 (define_insn "*call_nonlocal_aix32"
12690   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
12691          (match_operand 1 "" "g"))
12692    (use (match_operand:SI 2 "immediate_operand" "O"))
12693    (clobber (reg:SI LR_REGNO))]
12694   "TARGET_32BIT
12695    && DEFAULT_ABI == ABI_AIX
12696    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12697   "bl %z0\;%."
12698   [(set_attr "type" "branch")
12699    (set_attr "length" "8")])
12700    
12701 (define_insn "*call_nonlocal_aix64"
12702   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
12703          (match_operand 1 "" "g"))
12704    (use (match_operand:SI 2 "immediate_operand" "O"))
12705    (clobber (reg:SI LR_REGNO))]
12706   "TARGET_64BIT
12707    && DEFAULT_ABI == ABI_AIX
12708    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12709   "bl %z0\;%."
12710   [(set_attr "type" "branch")
12711    (set_attr "length" "8")])
12712
12713 (define_insn "*call_value_nonlocal_aix32"
12714   [(set (match_operand 0 "" "")
12715         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12716               (match_operand 2 "" "g")))
12717    (use (match_operand:SI 3 "immediate_operand" "O"))
12718    (clobber (reg:SI LR_REGNO))]
12719   "TARGET_32BIT
12720    && DEFAULT_ABI == ABI_AIX
12721    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12722   "bl %z1\;%."
12723   [(set_attr "type" "branch")
12724    (set_attr "length" "8")])
12725
12726 (define_insn "*call_value_nonlocal_aix64"
12727   [(set (match_operand 0 "" "")
12728         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12729               (match_operand 2 "" "g")))
12730    (use (match_operand:SI 3 "immediate_operand" "O"))
12731    (clobber (reg:SI LR_REGNO))]
12732   "TARGET_64BIT
12733    && DEFAULT_ABI == ABI_AIX
12734    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12735   "bl %z1\;%."
12736   [(set_attr "type" "branch")
12737    (set_attr "length" "8")])
12738
12739 ;; A function pointer under System V is just a normal pointer
12740 ;; operands[0] is the function pointer
12741 ;; operands[1] is the stack size to clean up
12742 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12743 ;; which indicates how to set cr1
12744
12745 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12746   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12747          (match_operand 1 "" "g,g,g,g"))
12748    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12749    (clobber (reg:SI LR_REGNO))]
12750   "DEFAULT_ABI == ABI_V4
12751    || DEFAULT_ABI == ABI_DARWIN"
12752 {
12753   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12754     output_asm_insn ("crxor 6,6,6", operands);
12755
12756   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12757     output_asm_insn ("creqv 6,6,6", operands);
12758
12759   return "b%T0l";
12760 }
12761   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12762    (set_attr "length" "4,4,8,8")])
12763
12764 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12765   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12766          (match_operand 1 "" "g,g"))
12767    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12768    (clobber (reg:SI LR_REGNO))]
12769   "(DEFAULT_ABI == ABI_DARWIN
12770    || (DEFAULT_ABI == ABI_V4
12771        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12772 {
12773   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12774     output_asm_insn ("crxor 6,6,6", operands);
12775
12776   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12777     output_asm_insn ("creqv 6,6,6", operands);
12778
12779 #if TARGET_MACHO
12780   return output_call(insn, operands, 0, 2);
12781 #else
12782   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12783     {
12784       gcc_assert (!TARGET_SECURE_PLT);
12785       return "bl %z0@plt";
12786     }
12787   else
12788     return "bl %z0";
12789 #endif
12790 }
12791   "DEFAULT_ABI == ABI_V4
12792    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12793    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12794   [(parallel [(call (mem:SI (match_dup 0))
12795                     (match_dup 1))
12796               (use (match_dup 2))
12797               (use (match_dup 3))
12798               (clobber (reg:SI LR_REGNO))])]
12799 {
12800   operands[3] = pic_offset_table_rtx;
12801 }
12802   [(set_attr "type" "branch,branch")
12803    (set_attr "length" "4,8")])
12804
12805 (define_insn "*call_nonlocal_sysv_secure<mode>"
12806   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12807          (match_operand 1 "" "g,g"))
12808    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12809    (use (match_operand:SI 3 "register_operand" "r,r"))
12810    (clobber (reg:SI LR_REGNO))]
12811   "(DEFAULT_ABI == ABI_V4
12812     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12813     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
12814 {
12815   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12816     output_asm_insn ("crxor 6,6,6", operands);
12817
12818   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12819     output_asm_insn ("creqv 6,6,6", operands);
12820
12821   if (flag_pic == 2)
12822     /* The magic 32768 offset here and in the other sysv call insns
12823        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12824        See sysv4.h:toc_section.  */
12825     return "bl %z0+32768@plt";
12826   else
12827     return "bl %z0@plt";
12828 }
12829   [(set_attr "type" "branch,branch")
12830    (set_attr "length" "4,8")])
12831
12832 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12833   [(set (match_operand 0 "" "")
12834         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12835               (match_operand 2 "" "g,g,g,g")))
12836    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12837    (clobber (reg:SI LR_REGNO))]
12838   "DEFAULT_ABI == ABI_V4
12839    || DEFAULT_ABI == ABI_DARWIN"
12840 {
12841   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12842     output_asm_insn ("crxor 6,6,6", operands);
12843
12844   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12845     output_asm_insn ("creqv 6,6,6", operands);
12846
12847   return "b%T1l";
12848 }
12849   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12850    (set_attr "length" "4,4,8,8")])
12851
12852 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12853   [(set (match_operand 0 "" "")
12854         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12855               (match_operand 2 "" "g,g")))
12856    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12857    (clobber (reg:SI LR_REGNO))]
12858   "(DEFAULT_ABI == ABI_DARWIN
12859    || (DEFAULT_ABI == ABI_V4
12860        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12861 {
12862   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12863     output_asm_insn ("crxor 6,6,6", operands);
12864
12865   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12866     output_asm_insn ("creqv 6,6,6", operands);
12867
12868 #if TARGET_MACHO
12869   return output_call(insn, operands, 1, 3);
12870 #else
12871   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12872     {
12873       gcc_assert (!TARGET_SECURE_PLT);
12874       return "bl %z1@plt";
12875     }
12876   else
12877     return "bl %z1";
12878 #endif
12879 }
12880   "DEFAULT_ABI == ABI_V4
12881    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12882    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12883   [(parallel [(set (match_dup 0)
12884                    (call (mem:SI (match_dup 1))
12885                          (match_dup 2)))
12886               (use (match_dup 3))
12887               (use (match_dup 4))
12888               (clobber (reg:SI LR_REGNO))])]
12889 {
12890   operands[4] = pic_offset_table_rtx;
12891 }
12892   [(set_attr "type" "branch,branch")
12893    (set_attr "length" "4,8")])
12894
12895 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12896   [(set (match_operand 0 "" "")
12897         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12898               (match_operand 2 "" "g,g")))
12899    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12900    (use (match_operand:SI 4 "register_operand" "r,r"))
12901    (clobber (reg:SI LR_REGNO))]
12902   "(DEFAULT_ABI == ABI_V4
12903     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12904     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12905 {
12906   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12907     output_asm_insn ("crxor 6,6,6", operands);
12908
12909   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12910     output_asm_insn ("creqv 6,6,6", operands);
12911
12912   if (flag_pic == 2)
12913     return "bl %z1+32768@plt";
12914   else
12915     return "bl %z1@plt";
12916 }
12917   [(set_attr "type" "branch,branch")
12918    (set_attr "length" "4,8")])
12919
12920 ;; Call subroutine returning any type.
12921 (define_expand "untyped_call"
12922   [(parallel [(call (match_operand 0 "" "")
12923                     (const_int 0))
12924               (match_operand 1 "" "")
12925               (match_operand 2 "" "")])]
12926   ""
12927   "
12928 {
12929   int i;
12930
12931   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12932
12933   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12934     {
12935       rtx set = XVECEXP (operands[2], 0, i);
12936       emit_move_insn (SET_DEST (set), SET_SRC (set));
12937     }
12938
12939   /* The optimizer does not know that the call sets the function value
12940      registers we stored in the result block.  We avoid problems by
12941      claiming that all hard registers are used and clobbered at this
12942      point.  */
12943   emit_insn (gen_blockage ());
12944
12945   DONE;
12946 }")
12947
12948 ;; sibling call patterns
12949 (define_expand "sibcall"
12950   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12951                     (match_operand 1 "" ""))
12952               (use (match_operand 2 "" ""))
12953               (use (reg:SI LR_REGNO))
12954               (simple_return)])]
12955   ""
12956   "
12957 {
12958 #if TARGET_MACHO
12959   if (MACHOPIC_INDIRECT)
12960     operands[0] = machopic_indirect_call_target (operands[0]);
12961 #endif
12962
12963   gcc_assert (GET_CODE (operands[0]) == MEM);
12964   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12965
12966   operands[0] = XEXP (operands[0], 0);
12967 }")
12968
12969 ;; this and similar patterns must be marked as using LR, otherwise
12970 ;; dataflow will try to delete the store into it.  This is true
12971 ;; even when the actual reg to jump to is in CTR, when LR was
12972 ;; saved and restored around the PIC-setting BCL.
12973 (define_insn "*sibcall_local32"
12974   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12975          (match_operand 1 "" "g,g"))
12976    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12977    (use (reg:SI LR_REGNO))
12978    (simple_return)]
12979   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12980   "*
12981 {
12982   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12983     output_asm_insn (\"crxor 6,6,6\", operands);
12984
12985   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12986     output_asm_insn (\"creqv 6,6,6\", operands);
12987
12988   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12989 }"
12990   [(set_attr "type" "branch")
12991    (set_attr "length" "4,8")])
12992
12993 (define_insn "*sibcall_local64"
12994   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12995          (match_operand 1 "" "g,g"))
12996    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12997    (use (reg:SI LR_REGNO))
12998    (simple_return)]
12999   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
13000   "*
13001 {
13002   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
13003     output_asm_insn (\"crxor 6,6,6\", operands);
13004
13005   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
13006     output_asm_insn (\"creqv 6,6,6\", operands);
13007
13008   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
13009 }"
13010   [(set_attr "type" "branch")
13011    (set_attr "length" "4,8")])
13012
13013 (define_insn "*sibcall_value_local32"
13014   [(set (match_operand 0 "" "")
13015         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
13016               (match_operand 2 "" "g,g")))
13017    (use (match_operand:SI 3 "immediate_operand" "O,n"))
13018    (use (reg:SI LR_REGNO))
13019    (simple_return)]
13020   "(INTVAL (operands[3]) & CALL_LONG) == 0"
13021   "*
13022 {
13023   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
13024     output_asm_insn (\"crxor 6,6,6\", operands);
13025
13026   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
13027     output_asm_insn (\"creqv 6,6,6\", operands);
13028
13029   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
13030 }"
13031   [(set_attr "type" "branch")
13032    (set_attr "length" "4,8")])
13033
13034
13035 (define_insn "*sibcall_value_local64"
13036   [(set (match_operand 0 "" "")
13037         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
13038               (match_operand 2 "" "g,g")))
13039    (use (match_operand:SI 3 "immediate_operand" "O,n"))
13040    (use (reg:SI LR_REGNO))
13041    (simple_return)]
13042   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
13043   "*
13044 {
13045   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
13046     output_asm_insn (\"crxor 6,6,6\", operands);
13047
13048   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
13049     output_asm_insn (\"creqv 6,6,6\", operands);
13050
13051   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
13052 }"
13053   [(set_attr "type" "branch")
13054    (set_attr "length" "4,8")])
13055
13056 (define_insn "*sibcall_nonlocal_aix<mode>"
13057   [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
13058          (match_operand 1 "" "g,g"))
13059    (use (match_operand:SI 2 "immediate_operand" "O,O"))
13060    (use (reg:SI LR_REGNO))
13061    (simple_return)]
13062   "DEFAULT_ABI == ABI_AIX
13063    && (INTVAL (operands[2]) & CALL_LONG) == 0"
13064   "@
13065    b %z0
13066    b%T0"
13067   [(set_attr "type" "branch")
13068    (set_attr "length" "4")])
13069
13070 (define_insn "*sibcall_value_nonlocal_aix<mode>"
13071   [(set (match_operand 0 "" "")
13072         (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
13073               (match_operand 2 "" "g,g")))
13074    (use (match_operand:SI 3 "immediate_operand" "O,O"))
13075    (use (reg:SI LR_REGNO))
13076    (simple_return)]
13077   "DEFAULT_ABI == ABI_AIX
13078    && (INTVAL (operands[3]) & CALL_LONG) == 0"
13079   "@
13080    b %z1
13081    b%T1"
13082   [(set_attr "type" "branch")
13083    (set_attr "length" "4")])
13084
13085 (define_insn "*sibcall_nonlocal_sysv<mode>"
13086   [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c"))
13087          (match_operand 1 "" ""))
13088    (use (match_operand 2 "immediate_operand" "O,n,O,n"))
13089    (use (reg:SI LR_REGNO))
13090    (simple_return)]
13091   "(DEFAULT_ABI == ABI_DARWIN
13092     || DEFAULT_ABI == ABI_V4)
13093    && (INTVAL (operands[2]) & CALL_LONG) == 0"
13094   "*
13095 {
13096   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
13097     output_asm_insn (\"crxor 6,6,6\", operands);
13098
13099   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
13100     output_asm_insn (\"creqv 6,6,6\", operands);
13101
13102   if (which_alternative >= 2)
13103     return \"b%T0\";
13104   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
13105     {
13106       gcc_assert (!TARGET_SECURE_PLT);
13107       return \"b %z0@plt\";
13108     }
13109   else
13110     return \"b %z0\";
13111 }"
13112   [(set_attr "type" "branch")
13113    (set_attr "length" "4,8,4,8")])
13114
13115 (define_expand "sibcall_value"
13116   [(parallel [(set (match_operand 0 "register_operand" "")
13117                 (call (mem:SI (match_operand 1 "address_operand" ""))
13118                       (match_operand 2 "" "")))
13119               (use (match_operand 3 "" ""))
13120               (use (reg:SI LR_REGNO))
13121               (simple_return)])]
13122   ""
13123   "
13124 {
13125 #if TARGET_MACHO
13126   if (MACHOPIC_INDIRECT)
13127     operands[1] = machopic_indirect_call_target (operands[1]);
13128 #endif
13129
13130   gcc_assert (GET_CODE (operands[1]) == MEM);
13131   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
13132
13133   operands[1] = XEXP (operands[1], 0);
13134 }")
13135
13136 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
13137   [(set (match_operand 0 "" "")
13138         (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c"))
13139               (match_operand 2 "" "")))
13140    (use (match_operand:SI 3 "immediate_operand" "O,n,O,n"))
13141    (use (reg:SI LR_REGNO))
13142    (simple_return)]
13143   "(DEFAULT_ABI == ABI_DARWIN
13144     || DEFAULT_ABI == ABI_V4)
13145    && (INTVAL (operands[3]) & CALL_LONG) == 0"
13146   "*
13147 {
13148   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
13149     output_asm_insn (\"crxor 6,6,6\", operands);
13150
13151   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
13152     output_asm_insn (\"creqv 6,6,6\", operands);
13153
13154   if (which_alternative >= 2)
13155     return \"b%T1\";
13156   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
13157     {
13158       gcc_assert (!TARGET_SECURE_PLT);
13159       return \"b %z1@plt\";
13160     }
13161   else
13162     return \"b %z1\";
13163 }"
13164   [(set_attr "type" "branch")
13165    (set_attr "length" "4,8,4,8")])
13166
13167 (define_expand "sibcall_epilogue"
13168   [(use (const_int 0))]
13169   ""
13170 {
13171   if (!TARGET_SCHED_PROLOG)
13172     emit_insn (gen_blockage ());
13173   rs6000_emit_epilogue (TRUE);
13174   DONE;
13175 })
13176
13177 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
13178 ;; all of memory.  This blocks insns from being moved across this point.
13179
13180 (define_insn "blockage"
13181   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
13182   ""
13183   "")
13184
13185 (define_insn "probe_stack"
13186   [(set (match_operand 0 "memory_operand" "=m")
13187         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
13188   ""
13189   "*
13190 {
13191   operands[1] = gen_rtx_REG (Pmode, 0);
13192   return \"{st%U0%X0|stw%U0%X0} %1,%0\";
13193 }"
13194   [(set_attr "type" "store")
13195    (set_attr "length" "4")])
13196
13197 (define_insn "probe_stack_range<P:mode>"
13198   [(set (match_operand:P 0 "register_operand" "=r")
13199         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
13200                             (match_operand:P 2 "register_operand" "r")]
13201                            UNSPECV_PROBE_STACK_RANGE))]
13202   ""
13203   "* return output_probe_stack_range (operands[0], operands[2]);"
13204   [(set_attr "type" "three")])
13205 \f
13206 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
13207 ;; signed & unsigned, and one type of branch.
13208 ;;
13209 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
13210 ;; insns, and branches.
13211
13212 (define_expand "cbranch<mode>4"
13213   [(use (match_operator 0 "rs6000_cbranch_operator"
13214          [(match_operand:GPR 1 "gpc_reg_operand" "")
13215           (match_operand:GPR 2 "reg_or_short_operand" "")]))
13216    (use (match_operand 3 ""))]
13217   ""
13218   "
13219 {
13220   /* Take care of the possibility that operands[2] might be negative but
13221      this might be a logical operation.  That insn doesn't exist.  */
13222   if (GET_CODE (operands[2]) == CONST_INT
13223       && INTVAL (operands[2]) < 0)
13224     {
13225       operands[2] = force_reg (<MODE>mode, operands[2]);
13226       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
13227                                     GET_MODE (operands[0]),
13228                                     operands[1], operands[2]);
13229    }
13230
13231   rs6000_emit_cbranch (<MODE>mode, operands);
13232   DONE;
13233 }")
13234
13235 (define_expand "cbranch<mode>4"
13236   [(use (match_operator 0 "rs6000_cbranch_operator"
13237          [(match_operand:FP 1 "gpc_reg_operand" "")
13238           (match_operand:FP 2 "gpc_reg_operand" "")]))
13239    (use (match_operand 3 ""))]
13240   ""
13241   "
13242 {
13243   rs6000_emit_cbranch (<MODE>mode, operands);
13244   DONE;
13245 }")
13246
13247 (define_expand "cstore<mode>4"
13248   [(use (match_operator 1 "rs6000_cbranch_operator"
13249          [(match_operand:GPR 2 "gpc_reg_operand" "")
13250           (match_operand:GPR 3 "reg_or_short_operand" "")]))
13251    (clobber (match_operand:SI 0 "register_operand"))]
13252   ""
13253   "
13254 {
13255   /* Take care of the possibility that operands[3] might be negative but
13256      this might be a logical operation.  That insn doesn't exist.  */
13257   if (GET_CODE (operands[3]) == CONST_INT
13258       && INTVAL (operands[3]) < 0)
13259     {
13260       operands[3] = force_reg (<MODE>mode, operands[3]);
13261       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
13262                                     GET_MODE (operands[1]),
13263                                     operands[2], operands[3]);
13264     }
13265
13266   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
13267      For SEQ, likewise, except that comparisons with zero should be done
13268      with an scc insns.  However, due to the order that combine see the
13269      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
13270      the cases we don't want to handle or are best handled by portable
13271      code.  */
13272   if (GET_CODE (operands[1]) == NE)
13273     FAIL;
13274   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
13275        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
13276       && operands[3] == const0_rtx)
13277     FAIL;
13278   rs6000_emit_sCOND (<MODE>mode, operands);
13279   DONE;
13280 }")
13281
13282 (define_expand "cstore<mode>4"
13283   [(use (match_operator 1 "rs6000_cbranch_operator"
13284          [(match_operand:FP 2 "gpc_reg_operand" "")
13285           (match_operand:FP 3 "gpc_reg_operand" "")]))
13286    (clobber (match_operand:SI 0 "register_operand"))]
13287   ""
13288   "
13289 {
13290   rs6000_emit_sCOND (<MODE>mode, operands);
13291   DONE;
13292 }")
13293
13294
13295 (define_expand "stack_protect_set"
13296   [(match_operand 0 "memory_operand" "")
13297    (match_operand 1 "memory_operand" "")]
13298   ""
13299 {
13300 #ifdef TARGET_THREAD_SSP_OFFSET
13301   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
13302   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
13303   operands[1] = gen_rtx_MEM (Pmode, addr);
13304 #endif
13305   if (TARGET_64BIT)
13306     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
13307   else
13308     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
13309   DONE;
13310 })
13311
13312 (define_insn "stack_protect_setsi"
13313   [(set (match_operand:SI 0 "memory_operand" "=m")
13314         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
13315    (set (match_scratch:SI 2 "=&r") (const_int 0))]
13316   "TARGET_32BIT"
13317   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
13318   [(set_attr "type" "three")
13319    (set_attr "length" "12")])
13320
13321 (define_insn "stack_protect_setdi"
13322   [(set (match_operand:DI 0 "memory_operand" "=m")
13323         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
13324    (set (match_scratch:DI 2 "=&r") (const_int 0))]
13325   "TARGET_64BIT"
13326   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
13327   [(set_attr "type" "three")
13328    (set_attr "length" "12")])
13329
13330 (define_expand "stack_protect_test"
13331   [(match_operand 0 "memory_operand" "")
13332    (match_operand 1 "memory_operand" "")
13333    (match_operand 2 "" "")]
13334   ""
13335 {
13336   rtx test, op0, op1;
13337 #ifdef TARGET_THREAD_SSP_OFFSET
13338   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
13339   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
13340   operands[1] = gen_rtx_MEM (Pmode, addr);
13341 #endif
13342   op0 = operands[0];
13343   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
13344   test = gen_rtx_EQ (VOIDmode, op0, op1);
13345   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
13346   DONE;
13347 })
13348
13349 (define_insn "stack_protect_testsi"
13350   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13351         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
13352                       (match_operand:SI 2 "memory_operand" "m,m")]
13353                      UNSPEC_SP_TEST))
13354    (set (match_scratch:SI 4 "=r,r") (const_int 0))
13355    (clobber (match_scratch:SI 3 "=&r,&r"))]
13356   "TARGET_32BIT"
13357   "@
13358    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
13359    {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"
13360   [(set_attr "length" "16,20")])
13361
13362 (define_insn "stack_protect_testdi"
13363   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13364         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
13365                       (match_operand:DI 2 "memory_operand" "m,m")]
13366                      UNSPEC_SP_TEST))
13367    (set (match_scratch:DI 4 "=r,r") (const_int 0))
13368    (clobber (match_scratch:DI 3 "=&r,&r"))]
13369   "TARGET_64BIT"
13370   "@
13371    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
13372    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
13373   [(set_attr "length" "16,20")])
13374
13375 \f
13376 ;; Here are the actual compare insns.
13377 (define_insn "*cmp<mode>_internal1"
13378   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
13379         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
13380                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
13381   ""
13382   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
13383   [(set_attr "type" "cmp")])
13384
13385 ;; If we are comparing a register for equality with a large constant,
13386 ;; we can do this with an XOR followed by a compare.  But this is profitable
13387 ;; only if the large constant is only used for the comparison (and in this
13388 ;; case we already have a register to reuse as scratch).
13389 ;;
13390 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
13391 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
13392
13393 (define_peephole2
13394   [(set (match_operand:SI 0 "register_operand")
13395         (match_operand:SI 1 "logical_const_operand" ""))
13396    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
13397                        [(match_dup 0)
13398                         (match_operand:SI 2 "logical_const_operand" "")]))
13399    (set (match_operand:CC 4 "cc_reg_operand" "")
13400         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
13401                     (match_dup 0)))
13402    (set (pc)
13403         (if_then_else (match_operator 6 "equality_operator"
13404                        [(match_dup 4) (const_int 0)])
13405                       (match_operand 7 "" "")
13406                       (match_operand 8 "" "")))]
13407   "peep2_reg_dead_p (3, operands[0])
13408    && peep2_reg_dead_p (4, operands[4])"
13409  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
13410   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
13411   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
13412  
13413 {
13414   /* Get the constant we are comparing against, and see what it looks like
13415      when sign-extended from 16 to 32 bits.  Then see what constant we could
13416      XOR with SEXTC to get the sign-extended value.  */
13417   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
13418                                               SImode,
13419                                               operands[1], operands[2]);
13420   HOST_WIDE_INT c = INTVAL (cnst);
13421   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
13422   HOST_WIDE_INT xorv = c ^ sextc;
13423
13424   operands[9] = GEN_INT (xorv);
13425   operands[10] = GEN_INT (sextc);
13426 })
13427
13428 (define_insn "*cmpsi_internal2"
13429   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13430         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13431                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
13432   ""
13433   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
13434   [(set_attr "type" "cmp")])
13435
13436 (define_insn "*cmpdi_internal2"
13437   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13438         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
13439                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
13440   ""
13441   "cmpld%I2 %0,%1,%b2"
13442   [(set_attr "type" "cmp")])
13443
13444 ;; The following two insns don't exist as single insns, but if we provide
13445 ;; them, we can swap an add and compare, which will enable us to overlap more
13446 ;; of the required delay between a compare and branch.  We generate code for
13447 ;; them by splitting.
13448
13449 (define_insn ""
13450   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13451         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
13452                     (match_operand:SI 2 "short_cint_operand" "i")))
13453    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13454         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13455   ""
13456   "#"
13457   [(set_attr "length" "8")])
13458
13459 (define_insn ""
13460   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
13461         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13462                        (match_operand:SI 2 "u_short_cint_operand" "i")))
13463    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13464         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13465   ""
13466   "#"
13467   [(set_attr "length" "8")])
13468
13469 (define_split
13470   [(set (match_operand:CC 3 "cc_reg_operand" "")
13471         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
13472                     (match_operand:SI 2 "short_cint_operand" "")))
13473    (set (match_operand:SI 0 "gpc_reg_operand" "")
13474         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13475   ""
13476   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
13477    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13478
13479 (define_split
13480   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
13481         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
13482                        (match_operand:SI 2 "u_short_cint_operand" "")))
13483    (set (match_operand:SI 0 "gpc_reg_operand" "")
13484         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13485   ""
13486   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
13487    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13488
13489 (define_insn "*cmpsf_internal1"
13490   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13491         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
13492                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
13493   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
13494   "fcmpu %0,%1,%2"
13495   [(set_attr "type" "fpcompare")])
13496
13497 (define_insn "*cmpdf_internal1"
13498   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13499         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
13500                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
13501   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
13502    && !VECTOR_UNIT_VSX_P (DFmode)"
13503   "fcmpu %0,%1,%2"
13504   [(set_attr "type" "fpcompare")])
13505
13506 ;; Only need to compare second words if first words equal
13507 (define_insn "*cmptf_internal1"
13508   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13509         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13510                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
13511   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
13512    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13513   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
13514   [(set_attr "type" "fpcompare")
13515    (set_attr "length" "12")])
13516
13517 (define_insn_and_split "*cmptf_internal2"
13518   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13519         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13520                       (match_operand:TF 2 "gpc_reg_operand" "d")))
13521     (clobber (match_scratch:DF 3 "=d"))
13522     (clobber (match_scratch:DF 4 "=d"))
13523     (clobber (match_scratch:DF 5 "=d"))
13524     (clobber (match_scratch:DF 6 "=d"))
13525     (clobber (match_scratch:DF 7 "=d"))
13526     (clobber (match_scratch:DF 8 "=d"))
13527     (clobber (match_scratch:DF 9 "=d"))
13528     (clobber (match_scratch:DF 10 "=d"))
13529     (clobber (match_scratch:GPR 11 "=b"))]
13530   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
13531    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13532   "#"
13533   "&& reload_completed"
13534   [(set (match_dup 3) (match_dup 14))
13535    (set (match_dup 4) (match_dup 15))
13536    (set (match_dup 9) (abs:DF (match_dup 5)))
13537    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
13538    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
13539                            (label_ref (match_dup 12))
13540                            (pc)))
13541    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
13542    (set (pc) (label_ref (match_dup 13)))
13543    (match_dup 12)
13544    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
13545    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
13546    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
13547    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
13548    (match_dup 13)]
13549 {
13550   REAL_VALUE_TYPE rv;
13551   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
13552   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
13553
13554   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
13555   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
13556   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
13557   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
13558   operands[12] = gen_label_rtx ();
13559   operands[13] = gen_label_rtx ();
13560   real_inf (&rv);
13561   operands[14] = force_const_mem (DFmode,
13562                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
13563   operands[15] = force_const_mem (DFmode,
13564                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
13565                                                                 DFmode));
13566   if (TARGET_TOC)
13567     {
13568       rtx tocref;
13569       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
13570       operands[14] = gen_const_mem (DFmode, tocref);
13571       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
13572       operands[15] = gen_const_mem (DFmode, tocref);
13573       set_mem_alias_set (operands[14], get_TOC_alias_set ());
13574       set_mem_alias_set (operands[15], get_TOC_alias_set ());
13575     }
13576 })
13577 \f
13578 ;; Now we have the scc insns.  We can do some combinations because of the
13579 ;; way the machine works.
13580 ;;
13581 ;; Note that this is probably faster if we can put an insn between the
13582 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
13583 ;; cases the insns below which don't use an intermediate CR field will
13584 ;; be used instead.
13585 (define_insn ""
13586   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13587         (match_operator:SI 1 "scc_comparison_operator"
13588                            [(match_operand 2 "cc_reg_operand" "y")
13589                             (const_int 0)]))]
13590   ""
13591   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
13592   [(set (attr "type")
13593      (cond [(match_test "TARGET_MFCRF")
13594                 (const_string "mfcrf")
13595            ]
13596         (const_string "mfcr")))
13597    (set_attr "length" "8")])
13598
13599 ;; Same as above, but get the GT bit.
13600 (define_insn "move_from_CR_gt_bit"
13601   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13602         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
13603   "TARGET_HARD_FLOAT && !TARGET_FPRS"
13604   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
13605   [(set_attr "type" "mfcr")
13606    (set_attr "length" "8")])
13607
13608 ;; Same as above, but get the OV/ORDERED bit.
13609 (define_insn "move_from_CR_ov_bit"
13610   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13611         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
13612   "TARGET_ISEL"
13613   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
13614   [(set_attr "type" "mfcr")
13615    (set_attr "length" "8")])
13616
13617 (define_insn ""
13618   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13619         (match_operator:DI 1 "scc_comparison_operator"
13620                            [(match_operand 2 "cc_reg_operand" "y")
13621                             (const_int 0)]))]
13622   "TARGET_POWERPC64"
13623   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
13624   [(set (attr "type")
13625      (cond [(match_test "TARGET_MFCRF")
13626                 (const_string "mfcrf")
13627            ]
13628         (const_string "mfcr")))
13629    (set_attr "length" "8")])
13630
13631 (define_insn ""
13632   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13633         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13634                                        [(match_operand 2 "cc_reg_operand" "y,y")
13635                                         (const_int 0)])
13636                     (const_int 0)))
13637    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
13638         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13639   "TARGET_32BIT"
13640   "@
13641    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
13642    #"
13643   [(set_attr "type" "delayed_compare")
13644    (set_attr "length" "8,16")])
13645
13646 (define_split
13647   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13648         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13649                                        [(match_operand 2 "cc_reg_operand" "")
13650                                         (const_int 0)])
13651                     (const_int 0)))
13652    (set (match_operand:SI 3 "gpc_reg_operand" "")
13653         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13654   "TARGET_32BIT && reload_completed"
13655   [(set (match_dup 3)
13656         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
13657    (set (match_dup 0)
13658         (compare:CC (match_dup 3)
13659                     (const_int 0)))]
13660   "")
13661
13662 (define_insn ""
13663   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13664         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13665                                       [(match_operand 2 "cc_reg_operand" "y")
13666                                        (const_int 0)])
13667                    (match_operand:SI 3 "const_int_operand" "n")))]
13668   ""
13669   "*
13670 {
13671   int is_bit = ccr_bit (operands[1], 1);
13672   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13673   int count;
13674
13675   if (is_bit >= put_bit)
13676     count = is_bit - put_bit;
13677   else
13678     count = 32 - (put_bit - is_bit);
13679
13680   operands[4] = GEN_INT (count);
13681   operands[5] = GEN_INT (put_bit);
13682
13683   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
13684 }"
13685   [(set (attr "type")
13686      (cond [(match_test "TARGET_MFCRF")
13687                 (const_string "mfcrf")
13688            ]
13689         (const_string "mfcr")))
13690    (set_attr "length" "8")])
13691
13692 (define_insn ""
13693   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13694         (compare:CC
13695          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13696                                        [(match_operand 2 "cc_reg_operand" "y,y")
13697                                         (const_int 0)])
13698                     (match_operand:SI 3 "const_int_operand" "n,n"))
13699          (const_int 0)))
13700    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
13701         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13702                    (match_dup 3)))]
13703   ""
13704   "*
13705 {
13706   int is_bit = ccr_bit (operands[1], 1);
13707   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13708   int count;
13709
13710   /* Force split for non-cc0 compare.  */
13711   if (which_alternative == 1)
13712      return \"#\";
13713
13714   if (is_bit >= put_bit)
13715     count = is_bit - put_bit;
13716   else
13717     count = 32 - (put_bit - is_bit);
13718
13719   operands[5] = GEN_INT (count);
13720   operands[6] = GEN_INT (put_bit);
13721
13722   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
13723 }"
13724   [(set_attr "type" "delayed_compare")
13725    (set_attr "length" "8,16")])
13726
13727 (define_split
13728   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13729         (compare:CC
13730          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13731                                        [(match_operand 2 "cc_reg_operand" "")
13732                                         (const_int 0)])
13733                     (match_operand:SI 3 "const_int_operand" ""))
13734          (const_int 0)))
13735    (set (match_operand:SI 4 "gpc_reg_operand" "")
13736         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13737                    (match_dup 3)))]
13738   "reload_completed"
13739   [(set (match_dup 4)
13740         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13741                    (match_dup 3)))
13742    (set (match_dup 0)
13743         (compare:CC (match_dup 4)
13744                     (const_int 0)))]
13745   "")
13746
13747 ;; There is a 3 cycle delay between consecutive mfcr instructions
13748 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13749
13750 (define_peephole
13751   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13752         (match_operator:SI 1 "scc_comparison_operator"
13753                            [(match_operand 2 "cc_reg_operand" "y")
13754                             (const_int 0)]))
13755    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13756         (match_operator:SI 4 "scc_comparison_operator"
13757                            [(match_operand 5 "cc_reg_operand" "y")
13758                             (const_int 0)]))]
13759   "REGNO (operands[2]) != REGNO (operands[5])"
13760   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13761   [(set_attr "type" "mfcr")
13762    (set_attr "length" "12")])
13763
13764 (define_peephole
13765   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13766         (match_operator:DI 1 "scc_comparison_operator"
13767                            [(match_operand 2 "cc_reg_operand" "y")
13768                             (const_int 0)]))
13769    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13770         (match_operator:DI 4 "scc_comparison_operator"
13771                            [(match_operand 5 "cc_reg_operand" "y")
13772                             (const_int 0)]))]
13773   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13774   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13775   [(set_attr "type" "mfcr")
13776    (set_attr "length" "12")])
13777
13778 ;; There are some scc insns that can be done directly, without a compare.
13779 ;; These are faster because they don't involve the communications between
13780 ;; the FXU and branch units.   In fact, we will be replacing all of the
13781 ;; integer scc insns here or in the portable methods in emit_store_flag.
13782 ;;
13783 ;; Also support (neg (scc ..)) since that construct is used to replace
13784 ;; branches, (plus (scc ..) ..) since that construct is common and
13785 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13786 ;; cases where it is no more expensive than (neg (scc ..)).
13787
13788 ;; Have reload force a constant into a register for the simple insns that
13789 ;; otherwise won't accept constants.  We do this because it is faster than
13790 ;; the cmp/mfcr sequence we would otherwise generate.
13791
13792 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13793                               (DI "rKJI")])
13794
13795 (define_insn_and_split "*eq<mode>"
13796   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13797         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13798                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13799   "!TARGET_POWER"
13800   "#"
13801   "!TARGET_POWER"
13802   [(set (match_dup 0)
13803         (clz:GPR (match_dup 3)))
13804    (set (match_dup 0)
13805         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13806   {
13807     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13808       {
13809         /* Use output operand as intermediate.  */
13810         operands[3] = operands[0];
13811
13812         if (logical_operand (operands[2], <MODE>mode))
13813           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13814                                   gen_rtx_XOR (<MODE>mode,
13815                                                operands[1], operands[2])));
13816         else
13817           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13818                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13819                                                 negate_rtx (<MODE>mode,
13820                                                             operands[2]))));
13821       }
13822     else
13823       operands[3] = operands[1];
13824
13825     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13826   })
13827
13828 (define_insn_and_split "*eq<mode>_compare"
13829   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13830         (compare:CC
13831          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13832                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13833          (const_int 0)))
13834    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13835         (eq:P (match_dup 1) (match_dup 2)))]
13836   "!TARGET_POWER && optimize_size"
13837   "#"
13838   "!TARGET_POWER && optimize_size"
13839   [(set (match_dup 0)
13840         (clz:P (match_dup 4)))
13841    (parallel [(set (match_dup 3)
13842                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13843                                (const_int 0)))
13844               (set (match_dup 0)
13845                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13846   {
13847     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13848       {
13849         /* Use output operand as intermediate.  */
13850         operands[4] = operands[0];
13851
13852         if (logical_operand (operands[2], <MODE>mode))
13853           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13854                                   gen_rtx_XOR (<MODE>mode,
13855                                                operands[1], operands[2])));
13856         else
13857           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13858                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13859                                                 negate_rtx (<MODE>mode,
13860                                                             operands[2]))));
13861       }
13862     else
13863       operands[4] = operands[1];
13864
13865     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13866   })
13867
13868 (define_insn "*eqsi_power"
13869   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
13870         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13871                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
13872    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
13873   "TARGET_POWER"
13874   "@
13875    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13876    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
13877    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13878    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13879    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
13880   [(set_attr "type" "three,two,three,three,three")
13881    (set_attr "length" "12,8,12,12,12")])
13882
13883 ;; We have insns of the form shown by the first define_insn below.  If
13884 ;; there is something inside the comparison operation, we must split it.
13885 (define_split
13886   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13887         (plus:SI (match_operator 1 "comparison_operator"
13888                                  [(match_operand:SI 2 "" "")
13889                                   (match_operand:SI 3
13890                                                     "reg_or_cint_operand" "")])
13891                  (match_operand:SI 4 "gpc_reg_operand" "")))
13892    (clobber (match_operand:SI 5 "register_operand" ""))]
13893   "! gpc_reg_operand (operands[2], SImode)"
13894   [(set (match_dup 5) (match_dup 2))
13895    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
13896                                (match_dup 4)))])
13897
13898 (define_insn "*plus_eqsi"
13899   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13900         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13901                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13902                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13903   "TARGET_32BIT"
13904   "@
13905    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13906    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
13907    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13908    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13909    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
13910   [(set_attr "type" "three,two,three,three,three")
13911    (set_attr "length" "12,8,12,12,12")])
13912
13913 (define_insn "*compare_plus_eqsi"
13914   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13915         (compare:CC
13916          (plus:SI
13917           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13918                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13919           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13920          (const_int 0)))
13921    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13922   "TARGET_32BIT && optimize_size"
13923   "@
13924    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13925    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
13926    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13927    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13928    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13929    #
13930    #
13931    #
13932    #
13933    #"
13934   [(set_attr "type" "compare")
13935    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13936
13937 (define_split
13938   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13939         (compare:CC
13940          (plus:SI
13941           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13942                  (match_operand:SI 2 "scc_eq_operand" ""))
13943           (match_operand:SI 3 "gpc_reg_operand" ""))
13944          (const_int 0)))
13945    (clobber (match_scratch:SI 4 ""))]
13946   "TARGET_32BIT && optimize_size && reload_completed"
13947   [(set (match_dup 4)
13948         (plus:SI (eq:SI (match_dup 1)
13949                  (match_dup 2))
13950           (match_dup 3)))
13951    (set (match_dup 0)
13952         (compare:CC (match_dup 4)
13953                     (const_int 0)))]
13954   "")
13955
13956 (define_insn "*plus_eqsi_compare"
13957   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13958         (compare:CC
13959          (plus:SI
13960           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13961                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13962           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13963          (const_int 0)))
13964    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13965         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13966   "TARGET_32BIT && optimize_size"
13967   "@
13968    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13969    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
13970    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13971    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13972    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13973    #
13974    #
13975    #
13976    #
13977    #"
13978   [(set_attr "type" "compare")
13979    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13980
13981 (define_split
13982   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13983         (compare:CC
13984          (plus:SI
13985           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13986                  (match_operand:SI 2 "scc_eq_operand" ""))
13987           (match_operand:SI 3 "gpc_reg_operand" ""))
13988          (const_int 0)))
13989    (set (match_operand:SI 0 "gpc_reg_operand" "")
13990         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13991   "TARGET_32BIT && optimize_size && reload_completed"
13992   [(set (match_dup 0)
13993         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13994    (set (match_dup 4)
13995         (compare:CC (match_dup 0)
13996                     (const_int 0)))]
13997   "")
13998
13999 (define_insn "*neg_eq0<mode>"
14000   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14001         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
14002                      (const_int 0))))]
14003   ""
14004   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
14005   [(set_attr "type" "two")
14006    (set_attr "length" "8")])
14007
14008 (define_insn_and_split "*neg_eq<mode>"
14009   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14010         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
14011                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
14012   ""
14013   "#"
14014   ""
14015   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
14016   {
14017     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
14018       {
14019         /* Use output operand as intermediate.  */
14020         operands[3] = operands[0];
14021
14022         if (logical_operand (operands[2], <MODE>mode))
14023           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
14024                                   gen_rtx_XOR (<MODE>mode,
14025                                                operands[1], operands[2])));
14026         else
14027           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
14028                                   gen_rtx_PLUS (<MODE>mode, operands[1],
14029                                                 negate_rtx (<MODE>mode,
14030                                                             operands[2]))));
14031       }
14032     else
14033       operands[3] = operands[1];
14034   })
14035
14036 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
14037 ;; since it nabs/sr is just as fast.
14038 (define_insn "*ne0si"
14039   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14040         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
14041                      (const_int 31)))
14042    (clobber (match_scratch:SI 2 "=&r"))]
14043   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
14044   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
14045   [(set_attr "type" "two")
14046    (set_attr "length" "8")])
14047
14048 (define_insn "*ne0di"
14049   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
14050         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
14051                      (const_int 63)))
14052    (clobber (match_scratch:DI 2 "=&r"))]
14053   "TARGET_64BIT"
14054   "addic %2,%1,-1\;subfe %0,%2,%1"
14055   [(set_attr "type" "two")
14056    (set_attr "length" "8")])
14057
14058 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
14059 (define_insn "*plus_ne0si"
14060   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14061         (plus:SI (lshiftrt:SI
14062                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
14063                   (const_int 31))
14064                  (match_operand:SI 2 "gpc_reg_operand" "r")))
14065    (clobber (match_scratch:SI 3 "=&r"))]
14066   "TARGET_32BIT"
14067   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
14068   [(set_attr "type" "two")
14069    (set_attr "length" "8")])
14070
14071 (define_insn "*plus_ne0di"
14072   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
14073         (plus:DI (lshiftrt:DI
14074                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
14075                   (const_int 63))
14076                  (match_operand:DI 2 "gpc_reg_operand" "r")))
14077    (clobber (match_scratch:DI 3 "=&r"))]
14078   "TARGET_64BIT"
14079   "addic %3,%1,-1\;addze %0,%2"
14080   [(set_attr "type" "two")
14081    (set_attr "length" "8")])
14082
14083 (define_insn "*compare_plus_ne0si"
14084   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14085         (compare:CC
14086          (plus:SI (lshiftrt:SI
14087                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
14088                    (const_int 31))
14089                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14090          (const_int 0)))
14091    (clobber (match_scratch:SI 3 "=&r,&r"))
14092    (clobber (match_scratch:SI 4 "=X,&r"))]
14093   "TARGET_32BIT"
14094   "@
14095    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
14096    #"
14097   [(set_attr "type" "compare")
14098    (set_attr "length" "8,12")])
14099
14100 (define_split
14101   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14102         (compare:CC
14103          (plus:SI (lshiftrt:SI
14104                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
14105                    (const_int 31))
14106                   (match_operand:SI 2 "gpc_reg_operand" ""))
14107          (const_int 0)))
14108    (clobber (match_scratch:SI 3 ""))
14109    (clobber (match_scratch:SI 4 ""))]
14110   "TARGET_32BIT && reload_completed"
14111   [(parallel [(set (match_dup 3)
14112                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
14113                                          (const_int 31))
14114                             (match_dup 2)))
14115               (clobber (match_dup 4))])
14116    (set (match_dup 0)
14117         (compare:CC (match_dup 3)
14118                     (const_int 0)))]
14119   "")
14120
14121 (define_insn "*compare_plus_ne0di"
14122   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14123         (compare:CC
14124          (plus:DI (lshiftrt:DI
14125                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
14126                    (const_int 63))
14127                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14128          (const_int 0)))
14129    (clobber (match_scratch:DI 3 "=&r,&r"))]
14130   "TARGET_64BIT"
14131   "@
14132    addic %3,%1,-1\;addze. %3,%2
14133    #"
14134   [(set_attr "type" "compare")
14135    (set_attr "length" "8,12")])
14136
14137 (define_split
14138   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14139         (compare:CC
14140          (plus:DI (lshiftrt:DI
14141                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
14142                    (const_int 63))
14143                   (match_operand:DI 2 "gpc_reg_operand" ""))
14144          (const_int 0)))
14145    (clobber (match_scratch:DI 3 ""))]
14146   "TARGET_64BIT && reload_completed"
14147   [(set (match_dup 3)
14148         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
14149                    (const_int 63))
14150                   (match_dup 2)))
14151    (set (match_dup 0)
14152         (compare:CC (match_dup 3)
14153                     (const_int 0)))]
14154   "")
14155
14156 (define_insn "*plus_ne0si_compare"
14157   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14158         (compare:CC
14159          (plus:SI (lshiftrt:SI
14160                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
14161                    (const_int 31))
14162                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14163          (const_int 0)))
14164    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14165         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14166                  (match_dup 2)))
14167    (clobber (match_scratch:SI 3 "=&r,&r"))]
14168   "TARGET_32BIT"
14169   "@
14170    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
14171    #"
14172   [(set_attr "type" "compare")
14173    (set_attr "length" "8,12")])
14174
14175 (define_split
14176   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14177         (compare:CC
14178          (plus:SI (lshiftrt:SI
14179                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
14180                    (const_int 31))
14181                   (match_operand:SI 2 "gpc_reg_operand" ""))
14182          (const_int 0)))
14183    (set (match_operand:SI 0 "gpc_reg_operand" "")
14184         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14185                  (match_dup 2)))
14186    (clobber (match_scratch:SI 3 ""))]
14187   "TARGET_32BIT && reload_completed"
14188   [(parallel [(set (match_dup 0)
14189         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14190                  (match_dup 2)))
14191    (clobber (match_dup 3))])
14192    (set (match_dup 4)
14193         (compare:CC (match_dup 0)
14194                     (const_int 0)))]
14195   "")
14196
14197 (define_insn "*plus_ne0di_compare"
14198   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14199         (compare:CC
14200          (plus:DI (lshiftrt:DI
14201                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
14202                    (const_int 63))
14203                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14204          (const_int 0)))
14205    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
14206         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14207                  (match_dup 2)))
14208    (clobber (match_scratch:DI 3 "=&r,&r"))]
14209   "TARGET_64BIT"
14210   "@
14211    addic %3,%1,-1\;addze. %0,%2
14212    #"
14213   [(set_attr "type" "compare")
14214    (set_attr "length" "8,12")])
14215
14216 (define_split
14217   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
14218         (compare:CC
14219          (plus:DI (lshiftrt:DI
14220                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
14221                    (const_int 63))
14222                   (match_operand:DI 2 "gpc_reg_operand" ""))
14223          (const_int 0)))
14224    (set (match_operand:DI 0 "gpc_reg_operand" "")
14225         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14226                  (match_dup 2)))
14227    (clobber (match_scratch:DI 3 ""))]
14228   "TARGET_64BIT && reload_completed"
14229   [(parallel [(set (match_dup 0)
14230         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14231                  (match_dup 2)))
14232    (clobber (match_dup 3))])
14233    (set (match_dup 4)
14234         (compare:CC (match_dup 0)
14235                     (const_int 0)))]
14236   "")
14237
14238 (define_insn ""
14239   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14240         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14241                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
14242    (clobber (match_scratch:SI 3 "=r,X"))]
14243   "TARGET_POWER"
14244   "@
14245    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
14246    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
14247   [(set_attr "length" "12")])
14248
14249 (define_insn ""
14250   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14251         (compare:CC
14252          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14253                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14254          (const_int 0)))
14255    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
14256         (le:SI (match_dup 1) (match_dup 2)))
14257    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
14258   "TARGET_POWER"
14259   "@
14260    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14261    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
14262    #
14263    #"
14264   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
14265    (set_attr "length" "12,12,16,16")])
14266
14267 (define_split
14268   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14269         (compare:CC
14270          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14271                 (match_operand:SI 2 "reg_or_short_operand" ""))
14272          (const_int 0)))
14273    (set (match_operand:SI 0 "gpc_reg_operand" "")
14274         (le:SI (match_dup 1) (match_dup 2)))
14275    (clobber (match_scratch:SI 3 ""))]
14276   "TARGET_POWER && reload_completed"
14277   [(parallel [(set (match_dup 0)
14278         (le:SI (match_dup 1) (match_dup 2)))
14279    (clobber (match_dup 3))])
14280    (set (match_dup 4)
14281         (compare:CC (match_dup 0)
14282                     (const_int 0)))]
14283   "")
14284
14285 (define_insn ""
14286   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14287         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14288                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
14289                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
14290   "TARGET_POWER"
14291   "@
14292    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
14293    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
14294   [(set_attr "length" "12")])
14295
14296 (define_insn ""
14297   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14298         (compare:CC
14299          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14300                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14301                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14302          (const_int 0)))
14303    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14304   "TARGET_POWER"
14305   "@
14306    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14307    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
14308    #
14309    #"
14310   [(set_attr "type" "compare")
14311    (set_attr "length" "12,12,16,16")])
14312
14313 (define_split
14314   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14315         (compare:CC
14316          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14317                          (match_operand:SI 2 "reg_or_short_operand" ""))
14318                   (match_operand:SI 3 "gpc_reg_operand" ""))
14319          (const_int 0)))
14320    (clobber (match_scratch:SI 4 ""))]
14321   "TARGET_POWER && reload_completed"
14322   [(set (match_dup 4)
14323         (plus:SI (le:SI (match_dup 1) (match_dup 2))
14324                  (match_dup 3)))
14325    (set (match_dup 0)
14326         (compare:CC (match_dup 4)
14327                     (const_int 0)))]
14328   "")
14329
14330 (define_insn ""
14331   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14332         (compare:CC
14333          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14334                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14335                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14336          (const_int 0)))
14337    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14338         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14339   "TARGET_POWER"
14340   "@
14341    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14342    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
14343    #
14344    #"
14345   [(set_attr "type" "compare")
14346    (set_attr "length" "12,12,16,16")])
14347
14348 (define_split
14349   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14350         (compare:CC
14351          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14352                          (match_operand:SI 2 "reg_or_short_operand" ""))
14353                   (match_operand:SI 3 "gpc_reg_operand" ""))
14354          (const_int 0)))
14355    (set (match_operand:SI 0 "gpc_reg_operand" "")
14356         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14357   "TARGET_POWER && reload_completed"
14358   [(set (match_dup 0)
14359         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14360    (set (match_dup 4)
14361         (compare:CC (match_dup 0)
14362                     (const_int 0)))]
14363   "")
14364
14365 (define_insn ""
14366   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14367         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14368                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
14369   "TARGET_POWER"
14370   "@
14371    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
14372    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
14373   [(set_attr "length" "12")])
14374
14375 (define_insn "*leu<mode>"
14376   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14377         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14378                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14379   ""
14380   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14381   [(set_attr "type" "three")
14382    (set_attr "length" "12")])
14383
14384 (define_insn "*leu<mode>_compare"
14385   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14386         (compare:CC
14387          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14388                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14389          (const_int 0)))
14390    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14391         (leu:P (match_dup 1) (match_dup 2)))]
14392   ""
14393   "@
14394    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14395    #"
14396   [(set_attr "type" "compare")
14397    (set_attr "length" "12,16")])
14398
14399 (define_split
14400   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14401         (compare:CC
14402          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
14403                 (match_operand:P 2 "reg_or_short_operand" ""))
14404          (const_int 0)))
14405    (set (match_operand:P 0 "gpc_reg_operand" "")
14406         (leu:P (match_dup 1) (match_dup 2)))]
14407   "reload_completed"
14408   [(set (match_dup 0)
14409         (leu:P (match_dup 1) (match_dup 2)))
14410    (set (match_dup 3)
14411         (compare:CC (match_dup 0)
14412                     (const_int 0)))]
14413   "")
14414
14415 (define_insn "*plus_leu<mode>"
14416   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14417         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14418                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14419                 (match_operand:P 3 "gpc_reg_operand" "r")))]
14420   ""
14421   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
14422   [(set_attr "type" "two")
14423    (set_attr "length" "8")])
14424
14425 (define_insn ""
14426   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14427         (compare:CC
14428          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14429                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14430                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14431          (const_int 0)))
14432    (clobber (match_scratch:SI 4 "=&r,&r"))]
14433   "TARGET_32BIT"
14434   "@
14435    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
14436    #"
14437   [(set_attr "type" "compare")
14438    (set_attr "length" "8,12")])
14439
14440 (define_split
14441   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14442         (compare:CC
14443          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14444                           (match_operand:SI 2 "reg_or_short_operand" ""))
14445                   (match_operand:SI 3 "gpc_reg_operand" ""))
14446          (const_int 0)))
14447    (clobber (match_scratch:SI 4 ""))]
14448   "TARGET_32BIT && reload_completed"
14449   [(set (match_dup 4)
14450         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
14451                   (match_dup 3)))
14452    (set (match_dup 0)
14453         (compare:CC (match_dup 4)
14454                     (const_int 0)))]
14455   "")
14456
14457 (define_insn ""
14458   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14459         (compare:CC
14460          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14461                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14462                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14463          (const_int 0)))
14464    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14465         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14466   "TARGET_32BIT"
14467   "@
14468    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
14469    #"
14470   [(set_attr "type" "compare")
14471    (set_attr "length" "8,12")])
14472
14473 (define_split
14474   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14475         (compare:CC
14476          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14477                           (match_operand:SI 2 "reg_or_short_operand" ""))
14478                   (match_operand:SI 3 "gpc_reg_operand" ""))
14479          (const_int 0)))
14480    (set (match_operand:SI 0 "gpc_reg_operand" "")
14481         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14482   "TARGET_32BIT && reload_completed"
14483   [(set (match_dup 0)
14484         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14485    (set (match_dup 4)
14486         (compare:CC (match_dup 0)
14487                     (const_int 0)))]
14488   "")
14489
14490 (define_insn "*neg_leu<mode>"
14491   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14492         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14493                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14494   ""
14495   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
14496    [(set_attr "type" "three")
14497     (set_attr "length" "12")])
14498
14499 (define_insn "*and_neg_leu<mode>"
14500   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14501         (and:P (neg:P
14502                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14503                         (match_operand:P 2 "reg_or_short_operand" "rI")))
14504                 (match_operand:P 3 "gpc_reg_operand" "r")))]
14505   ""
14506   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
14507   [(set_attr "type" "three")
14508    (set_attr "length" "12")])
14509
14510 (define_insn ""
14511   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14512         (compare:CC
14513          (and:SI (neg:SI
14514                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14515                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
14516                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14517          (const_int 0)))
14518    (clobber (match_scratch:SI 4 "=&r,&r"))]
14519   "TARGET_32BIT"
14520   "@
14521    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14522    #"
14523   [(set_attr "type" "compare")
14524    (set_attr "length" "12,16")])
14525
14526 (define_split
14527   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14528         (compare:CC
14529          (and:SI (neg:SI
14530                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14531                           (match_operand:SI 2 "reg_or_short_operand" "")))
14532                  (match_operand:SI 3 "gpc_reg_operand" ""))
14533          (const_int 0)))
14534    (clobber (match_scratch:SI 4 ""))]
14535   "TARGET_32BIT && reload_completed"
14536   [(set (match_dup 4)
14537         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
14538                 (match_dup 3)))
14539    (set (match_dup 0)
14540         (compare:CC (match_dup 4)
14541                     (const_int 0)))]
14542   "")
14543
14544 (define_insn ""
14545   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14546         (compare:CC
14547          (and:SI (neg:SI
14548                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14549                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
14550                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14551          (const_int 0)))
14552    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14553         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14554   "TARGET_32BIT"
14555   "@
14556    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14557    #"
14558   [(set_attr "type" "compare")
14559    (set_attr "length" "12,16")])
14560
14561 (define_split
14562   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14563         (compare:CC
14564          (and:SI (neg:SI
14565                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14566                           (match_operand:SI 2 "reg_or_short_operand" "")))
14567                  (match_operand:SI 3 "gpc_reg_operand" ""))
14568          (const_int 0)))
14569    (set (match_operand:SI 0 "gpc_reg_operand" "")
14570         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14571   "TARGET_32BIT && reload_completed"
14572   [(set (match_dup 0)
14573         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
14574                 (match_dup 3)))
14575    (set (match_dup 4)
14576         (compare:CC (match_dup 0)
14577                     (const_int 0)))]
14578   "")
14579
14580 (define_insn ""
14581   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14582         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14583                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
14584   "TARGET_POWER"
14585   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
14586    [(set_attr "length" "12")])
14587
14588 (define_insn ""
14589   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14590         (compare:CC
14591          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14592                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14593          (const_int 0)))
14594    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14595         (lt:SI (match_dup 1) (match_dup 2)))]
14596   "TARGET_POWER"
14597   "@
14598    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
14599    #"
14600   [(set_attr "type" "delayed_compare")
14601    (set_attr "length" "12,16")])
14602
14603 (define_split
14604   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14605         (compare:CC
14606          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14607                 (match_operand:SI 2 "reg_or_short_operand" ""))
14608          (const_int 0)))
14609    (set (match_operand:SI 0 "gpc_reg_operand" "")
14610         (lt:SI (match_dup 1) (match_dup 2)))]
14611   "TARGET_POWER && reload_completed"
14612   [(set (match_dup 0)
14613         (lt:SI (match_dup 1) (match_dup 2)))
14614    (set (match_dup 3)
14615         (compare:CC (match_dup 0)
14616                     (const_int 0)))]
14617   "")
14618
14619 (define_insn ""
14620   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14621         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14622                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14623                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14624   "TARGET_POWER"
14625   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
14626   [(set_attr "length" "12")])
14627
14628 (define_insn ""
14629   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14630         (compare:CC
14631          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14632                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14633                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14634          (const_int 0)))
14635    (clobber (match_scratch:SI 4 "=&r,&r"))]
14636   "TARGET_POWER"
14637   "@
14638    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
14639    #"
14640   [(set_attr "type" "compare")
14641    (set_attr "length" "12,16")])
14642
14643 (define_split
14644   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14645         (compare:CC
14646          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14647                          (match_operand:SI 2 "reg_or_short_operand" ""))
14648                   (match_operand:SI 3 "gpc_reg_operand" ""))
14649          (const_int 0)))
14650    (clobber (match_scratch:SI 4 ""))]
14651   "TARGET_POWER && reload_completed"
14652   [(set (match_dup 4)
14653         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
14654                  (match_dup 3)))
14655    (set (match_dup 0)
14656         (compare:CC (match_dup 4)
14657                     (const_int 0)))]
14658   "")
14659
14660 (define_insn ""
14661   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14662         (compare:CC
14663          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14664                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14665                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14666          (const_int 0)))
14667    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14668         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14669   "TARGET_POWER"
14670   "@
14671    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
14672    #"
14673   [(set_attr "type" "compare")
14674    (set_attr "length" "12,16")])
14675
14676 (define_split
14677   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14678         (compare:CC
14679          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14680                          (match_operand:SI 2 "reg_or_short_operand" ""))
14681                   (match_operand:SI 3 "gpc_reg_operand" ""))
14682          (const_int 0)))
14683    (set (match_operand:SI 0 "gpc_reg_operand" "")
14684         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14685   "TARGET_POWER && reload_completed"
14686   [(set (match_dup 0)
14687         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14688    (set (match_dup 4)
14689         (compare:CC (match_dup 0)
14690                     (const_int 0)))]
14691   "")
14692
14693 (define_insn ""
14694   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14695         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14696                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14697   "TARGET_POWER"
14698   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
14699   [(set_attr "length" "12")])
14700
14701 (define_insn_and_split "*ltu<mode>"
14702   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14703         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14704                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14705   ""
14706   "#"
14707   ""
14708   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14709    (set (match_dup 0) (neg:P (match_dup 0)))]
14710   "")
14711
14712 (define_insn_and_split "*ltu<mode>_compare"
14713   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14714         (compare:CC
14715          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14716                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14717          (const_int 0)))
14718    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14719         (ltu:P (match_dup 1) (match_dup 2)))]
14720   ""
14721   "#"
14722   ""
14723   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14724    (parallel [(set (match_dup 3)
14725                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14726               (set (match_dup 0) (neg:P (match_dup 0)))])]
14727   "")
14728
14729 (define_insn_and_split "*plus_ltu<mode>"
14730   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
14731         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14732                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14733                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
14734   ""
14735   "#"
14736   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14737   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14738    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14739   "")
14740
14741 (define_insn_and_split "*plus_ltu<mode>_compare"
14742   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14743         (compare:CC
14744          (plus:P (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                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14747          (const_int 0)))
14748    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14749         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14750   ""
14751   "#"
14752   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14753   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14754    (parallel [(set (match_dup 4)
14755                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14756                                (const_int 0)))
14757               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14758   "")
14759
14760 (define_insn "*neg_ltu<mode>"
14761   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14762         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14763                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
14764   ""
14765   "@
14766    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
14767    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
14768   [(set_attr "type" "two")
14769    (set_attr "length" "8")])
14770
14771 (define_insn ""
14772   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14773         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14774                (match_operand:SI 2 "reg_or_short_operand" "rI")))
14775    (clobber (match_scratch:SI 3 "=r"))]
14776   "TARGET_POWER"
14777   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
14778    [(set_attr "length" "12")])
14779
14780 (define_insn ""
14781   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14782         (compare:CC
14783          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14784                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14785          (const_int 0)))
14786    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14787         (ge:SI (match_dup 1) (match_dup 2)))
14788    (clobber (match_scratch:SI 3 "=r,r"))]
14789   "TARGET_POWER"
14790   "@
14791    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14792    #"
14793   [(set_attr "type" "compare")
14794    (set_attr "length" "12,16")])
14795
14796 (define_split
14797   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14798         (compare:CC
14799          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14800                 (match_operand:SI 2 "reg_or_short_operand" ""))
14801          (const_int 0)))
14802    (set (match_operand:SI 0 "gpc_reg_operand" "")
14803         (ge:SI (match_dup 1) (match_dup 2)))
14804    (clobber (match_scratch:SI 3 ""))]
14805   "TARGET_POWER && reload_completed"
14806   [(parallel [(set (match_dup 0)
14807                    (ge:SI (match_dup 1) (match_dup 2)))
14808               (clobber (match_dup 3))])
14809    (set (match_dup 4)
14810         (compare:CC (match_dup 0)
14811                     (const_int 0)))]
14812   "")
14813
14814 (define_insn ""
14815   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14816         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14817                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14818                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14819   "TARGET_POWER"
14820   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
14821   [(set_attr "length" "12")])
14822
14823 (define_insn ""
14824   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14825         (compare:CC
14826          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14827                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14828                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14829          (const_int 0)))
14830    (clobber (match_scratch:SI 4 "=&r,&r"))]
14831   "TARGET_POWER"
14832   "@
14833    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14834    #"
14835   [(set_attr "type" "compare")
14836    (set_attr "length" "12,16")])
14837
14838 (define_split
14839   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14840         (compare:CC
14841          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14842                          (match_operand:SI 2 "reg_or_short_operand" ""))
14843                   (match_operand:SI 3 "gpc_reg_operand" ""))
14844          (const_int 0)))
14845    (clobber (match_scratch:SI 4 ""))]
14846   "TARGET_POWER && reload_completed"
14847   [(set (match_dup 4)
14848         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
14849                  (match_dup 3)))
14850    (set (match_dup 0)
14851         (compare:CC (match_dup 4)
14852                     (const_int 0)))]
14853   "")
14854
14855 (define_insn ""
14856   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14857         (compare:CC
14858          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14859                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14860                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14861          (const_int 0)))
14862    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14863         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14864   "TARGET_POWER"
14865   "@
14866    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14867    #"
14868   [(set_attr "type" "compare")
14869    (set_attr "length" "12,16")])
14870
14871 (define_split
14872   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14873         (compare:CC
14874          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14875                          (match_operand:SI 2 "reg_or_short_operand" ""))
14876                   (match_operand:SI 3 "gpc_reg_operand" ""))
14877          (const_int 0)))
14878    (set (match_operand:SI 0 "gpc_reg_operand" "")
14879         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14880   "TARGET_POWER && reload_completed"
14881   [(set (match_dup 0)
14882         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14883    (set (match_dup 4)
14884         (compare:CC (match_dup 0)
14885                     (const_int 0)))]
14886   "")
14887
14888 (define_insn ""
14889   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14890         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14891                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14892   "TARGET_POWER"
14893   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
14894   [(set_attr "length" "12")])
14895
14896 (define_insn "*geu<mode>"
14897   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14898         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14899                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14900   ""
14901   "@
14902    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
14903    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14904   [(set_attr "type" "three")
14905    (set_attr "length" "12")])
14906
14907 (define_insn "*geu<mode>_compare"
14908   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14909         (compare:CC
14910          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14911                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14912          (const_int 0)))
14913    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14914         (geu:P (match_dup 1) (match_dup 2)))]
14915   ""
14916   "@
14917    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14918    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14919    #
14920    #"
14921   [(set_attr "type" "compare")
14922    (set_attr "length" "12,12,16,16")])
14923
14924 (define_split
14925   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14926         (compare:CC
14927          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
14928                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
14929          (const_int 0)))
14930    (set (match_operand:P 0 "gpc_reg_operand" "")
14931         (geu:P (match_dup 1) (match_dup 2)))]
14932   "reload_completed"
14933   [(set (match_dup 0)
14934         (geu:P (match_dup 1) (match_dup 2)))
14935    (set (match_dup 3)
14936         (compare:CC (match_dup 0)
14937                     (const_int 0)))]
14938   "")
14939
14940 (define_insn "*plus_geu<mode>"
14941   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14942         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14943                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14944                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14945   ""
14946   "@
14947    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
14948    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
14949   [(set_attr "type" "two")
14950    (set_attr "length" "8")])
14951
14952 (define_insn ""
14953   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14954         (compare:CC
14955          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14956                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14957                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14958          (const_int 0)))
14959    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14960   "TARGET_32BIT"
14961   "@
14962    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
14963    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
14964    #
14965    #"
14966   [(set_attr "type" "compare")
14967    (set_attr "length" "8,8,12,12")])
14968
14969 (define_split
14970   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14971         (compare:CC
14972          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14973                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14974                   (match_operand:SI 3 "gpc_reg_operand" ""))
14975          (const_int 0)))
14976    (clobber (match_scratch:SI 4 ""))]
14977   "TARGET_32BIT && reload_completed"
14978   [(set (match_dup 4)
14979         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
14980                   (match_dup 3)))
14981    (set (match_dup 0)
14982         (compare:CC (match_dup 4)
14983                     (const_int 0)))]
14984   "")
14985
14986 (define_insn ""
14987   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14988         (compare:CC
14989          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14990                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14991                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14992          (const_int 0)))
14993    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14994         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14995   "TARGET_32BIT"
14996   "@
14997    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
14998    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
14999    #
15000    #"
15001   [(set_attr "type" "compare")
15002    (set_attr "length" "8,8,12,12")])
15003
15004 (define_split
15005   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
15006         (compare:CC
15007          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
15008                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
15009                   (match_operand:SI 3 "gpc_reg_operand" ""))
15010          (const_int 0)))
15011    (set (match_operand:SI 0 "gpc_reg_operand" "")
15012         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15013   "TARGET_32BIT && reload_completed"
15014   [(set (match_dup 0)
15015         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
15016    (set (match_dup 4)
15017         (compare:CC (match_dup 0)
15018                     (const_int 0)))]
15019   "")
15020
15021 (define_insn "*neg_geu<mode>"
15022   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
15023         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
15024                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
15025   ""
15026   "@
15027    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
15028    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
15029   [(set_attr "type" "three")
15030    (set_attr "length" "12")])
15031
15032 (define_insn "*and_neg_geu<mode>"
15033   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
15034         (and:P (neg:P
15035                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
15036                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
15037                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
15038   ""
15039   "@
15040    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
15041    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
15042   [(set_attr "type" "three")
15043    (set_attr "length" "12")])
15044
15045 (define_insn ""
15046   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
15047         (compare:CC
15048          (and:SI (neg:SI
15049                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
15050                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
15051                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
15052          (const_int 0)))
15053    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
15054   "TARGET_32BIT"
15055   "@
15056    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
15057    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
15058    #
15059    #"
15060   [(set_attr "type" "compare")
15061    (set_attr "length" "12,12,16,16")])
15062
15063 (define_split
15064   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15065         (compare:CC
15066          (and:SI (neg:SI
15067                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
15068                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
15069                  (match_operand:SI 3 "gpc_reg_operand" ""))
15070          (const_int 0)))
15071    (clobber (match_scratch:SI 4 ""))]
15072   "TARGET_32BIT && reload_completed"
15073   [(set (match_dup 4)
15074         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
15075                 (match_dup 3)))
15076    (set (match_dup 0)
15077         (compare:CC (match_dup 4)
15078                     (const_int 0)))]
15079   "")
15080
15081 (define_insn ""
15082   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
15083         (compare:CC
15084          (and:SI (neg:SI
15085                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
15086                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
15087                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
15088          (const_int 0)))
15089    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
15090         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
15091   "TARGET_32BIT"
15092   "@
15093    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
15094    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
15095    #
15096    #"
15097   [(set_attr "type" "compare")
15098    (set_attr "length" "12,12,16,16")])
15099
15100 (define_split
15101   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
15102         (compare:CC
15103          (and:SI (neg:SI
15104                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
15105                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
15106                  (match_operand:SI 3 "gpc_reg_operand" ""))
15107          (const_int 0)))
15108    (set (match_operand:SI 0 "gpc_reg_operand" "")
15109         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
15110   "TARGET_32BIT && reload_completed"
15111   [(set (match_dup 0)
15112         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
15113    (set (match_dup 4)
15114         (compare:CC (match_dup 0)
15115                     (const_int 0)))]
15116   "")
15117
15118 (define_insn ""
15119   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15120         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
15121                (match_operand:SI 2 "reg_or_short_operand" "r")))]
15122   "TARGET_POWER"
15123   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
15124   [(set_attr "length" "12")])
15125
15126 (define_insn ""
15127   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15128         (compare:CC
15129          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15130                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15131          (const_int 0)))
15132    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
15133         (gt:SI (match_dup 1) (match_dup 2)))]
15134   "TARGET_POWER"
15135   "@
15136    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
15137    #"
15138   [(set_attr "type" "delayed_compare")
15139    (set_attr "length" "12,16")])
15140
15141 (define_split
15142   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
15143         (compare:CC
15144          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15145                 (match_operand:SI 2 "reg_or_short_operand" ""))
15146          (const_int 0)))
15147    (set (match_operand:SI 0 "gpc_reg_operand" "")
15148         (gt:SI (match_dup 1) (match_dup 2)))]
15149   "TARGET_POWER && reload_completed"
15150   [(set (match_dup 0)
15151         (gt:SI (match_dup 1) (match_dup 2)))
15152    (set (match_dup 3)
15153         (compare:CC (match_dup 0)
15154                     (const_int 0)))]
15155   "")
15156
15157 (define_insn "*plus_gt0<mode>"
15158   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
15159         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
15160                       (const_int 0))
15161                  (match_operand:P 2 "gpc_reg_operand" "r")))]
15162   ""
15163   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
15164   [(set_attr "type" "three")
15165    (set_attr "length" "12")])
15166
15167 (define_insn ""
15168   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15169         (compare:CC
15170          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15171                          (const_int 0))
15172                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
15173          (const_int 0)))
15174    (clobber (match_scratch:SI 3 "=&r,&r"))]
15175   "TARGET_32BIT"
15176   "@
15177    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
15178    #"
15179   [(set_attr "type" "compare")
15180    (set_attr "length" "12,16")])
15181
15182 (define_split
15183   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15184         (compare:CC
15185          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15186                          (const_int 0))
15187                   (match_operand:SI 2 "gpc_reg_operand" ""))
15188          (const_int 0)))
15189    (clobber (match_scratch:SI 3 ""))]
15190   "TARGET_32BIT && reload_completed"
15191   [(set (match_dup 3)
15192         (plus:SI (gt:SI (match_dup 1) (const_int 0))
15193                   (match_dup 2)))
15194    (set (match_dup 0)
15195         (compare:CC (match_dup 3)
15196                     (const_int 0)))]
15197   "")
15198
15199 (define_insn ""
15200   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15201         (compare:CC
15202          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
15203                          (const_int 0))
15204                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
15205          (const_int 0)))
15206    (clobber (match_scratch:DI 3 "=&r,&r"))]
15207   "TARGET_64BIT"
15208   "@
15209    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
15210    #"
15211   [(set_attr "type" "compare")
15212    (set_attr "length" "12,16")])
15213
15214 (define_split
15215   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
15216         (compare:CC
15217          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
15218                          (const_int 0))
15219                   (match_operand:DI 2 "gpc_reg_operand" ""))
15220          (const_int 0)))
15221    (clobber (match_scratch:DI 3 ""))]
15222   "TARGET_64BIT && reload_completed"
15223   [(set (match_dup 3)
15224         (plus:DI (gt:DI (match_dup 1) (const_int 0))
15225                  (match_dup 2)))
15226    (set (match_dup 0)
15227         (compare:CC (match_dup 3)
15228                     (const_int 0)))]
15229   "")
15230
15231 (define_insn ""
15232   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15233         (compare:CC
15234          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15235                          (const_int 0))
15236                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
15237          (const_int 0)))
15238    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
15239         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
15240   "TARGET_32BIT"
15241   "@
15242    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
15243    #"
15244   [(set_attr "type" "compare")
15245    (set_attr "length" "12,16")])
15246
15247 (define_split
15248   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
15249         (compare:CC
15250          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15251                          (const_int 0))
15252                   (match_operand:SI 2 "gpc_reg_operand" ""))
15253          (const_int 0)))
15254    (set (match_operand:SI 0 "gpc_reg_operand" "")
15255         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
15256   "TARGET_32BIT && reload_completed"
15257   [(set (match_dup 0)
15258         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
15259    (set (match_dup 3)
15260         (compare:CC (match_dup 0)
15261                     (const_int 0)))]
15262   "")
15263
15264 (define_insn ""
15265   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15266         (compare:CC
15267          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
15268                          (const_int 0))
15269                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
15270          (const_int 0)))
15271    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
15272         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
15273   "TARGET_64BIT"
15274   "@
15275    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
15276    #"
15277   [(set_attr "type" "compare")
15278    (set_attr "length" "12,16")])
15279
15280 (define_split
15281   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
15282         (compare:CC
15283          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
15284                          (const_int 0))
15285                   (match_operand:DI 2 "gpc_reg_operand" ""))
15286          (const_int 0)))
15287    (set (match_operand:DI 0 "gpc_reg_operand" "")
15288         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
15289   "TARGET_64BIT && reload_completed"
15290   [(set (match_dup 0)
15291         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
15292    (set (match_dup 3)
15293         (compare:CC (match_dup 0)
15294                     (const_int 0)))]
15295   "")
15296
15297 (define_insn ""
15298   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
15299         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
15300                         (match_operand:SI 2 "reg_or_short_operand" "r"))
15301                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
15302   "TARGET_POWER"
15303   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
15304   [(set_attr "length" "12")])
15305
15306 (define_insn ""
15307   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15308         (compare:CC
15309          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15310                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15311                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
15312          (const_int 0)))
15313    (clobber (match_scratch:SI 4 "=&r,&r"))]
15314   "TARGET_POWER"
15315   "@
15316    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
15317    #"
15318   [(set_attr "type" "compare")
15319    (set_attr "length" "12,16")])
15320
15321 (define_split
15322   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15323         (compare:CC
15324          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15325                          (match_operand:SI 2 "reg_or_short_operand" ""))
15326                   (match_operand:SI 3 "gpc_reg_operand" ""))
15327          (const_int 0)))
15328    (clobber (match_scratch:SI 4 ""))]
15329   "TARGET_POWER && reload_completed"
15330   [(set (match_dup 4)
15331         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
15332    (set (match_dup 0)
15333         (compare:CC (match_dup 4)
15334                     (const_int 0)))]
15335   "")
15336
15337 (define_insn ""
15338   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
15339         (compare:CC
15340          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15341                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15342                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
15343          (const_int 0)))
15344    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
15345         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15346   "TARGET_POWER"
15347   "@
15348    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
15349    #"
15350   [(set_attr "type" "compare")
15351    (set_attr "length" "12,16")])
15352
15353 (define_split
15354   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
15355         (compare:CC
15356          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15357                          (match_operand:SI 2 "reg_or_short_operand" ""))
15358                   (match_operand:SI 3 "gpc_reg_operand" ""))
15359          (const_int 0)))
15360    (set (match_operand:SI 0 "gpc_reg_operand" "")
15361         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15362   "TARGET_POWER && reload_completed"
15363   [(set (match_dup 0)
15364         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
15365    (set (match_dup 4)
15366         (compare:CC (match_dup 0)
15367                     (const_int 0)))]
15368   "")
15369
15370 (define_insn ""
15371   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15372         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
15373                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
15374   "TARGET_POWER"
15375   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
15376   [(set_attr "length" "12")])
15377
15378 (define_insn_and_split "*gtu<mode>"
15379   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15380         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15381                (match_operand:P 2 "reg_or_short_operand" "rI")))]
15382   ""
15383   "#"
15384   ""
15385   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15386    (set (match_dup 0) (neg:P (match_dup 0)))]
15387   "")
15388
15389 (define_insn_and_split "*gtu<mode>_compare"
15390   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15391         (compare:CC
15392          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
15393                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
15394          (const_int 0)))
15395    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
15396         (gtu:P (match_dup 1) (match_dup 2)))]
15397   ""
15398   "#"
15399   ""
15400   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15401    (parallel [(set (match_dup 3)
15402                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
15403               (set (match_dup 0) (neg:P (match_dup 0)))])]
15404   "")
15405
15406 (define_insn_and_split "*plus_gtu<mode>"
15407   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
15408         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15409                        (match_operand:P 2 "reg_or_short_operand" "rI"))
15410                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
15411   ""
15412   "#"
15413   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
15414   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15415    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
15416   "")
15417
15418 (define_insn_and_split "*plus_gtu<mode>_compare"
15419   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
15420         (compare:CC
15421          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
15422                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
15423                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
15424          (const_int 0)))
15425    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
15426         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
15427   ""
15428   "#"
15429   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
15430   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15431    (parallel [(set (match_dup 4)
15432                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
15433                                (const_int 0)))
15434               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
15435   "")
15436
15437 (define_insn "*neg_gtu<mode>"
15438   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15439         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15440                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
15441   ""
15442   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
15443   [(set_attr "type" "two")
15444    (set_attr "length" "8")])
15445
15446 \f
15447 ;; Define both directions of branch and return.  If we need a reload
15448 ;; register, we'd rather use CR0 since it is much easier to copy a
15449 ;; register CC value to there.
15450
15451 (define_insn ""
15452   [(set (pc)
15453         (if_then_else (match_operator 1 "branch_comparison_operator"
15454                                       [(match_operand 2
15455                                                       "cc_reg_operand" "y")
15456                                        (const_int 0)])
15457                       (label_ref (match_operand 0 "" ""))
15458                       (pc)))]
15459   ""
15460   "*
15461 {
15462   return output_cbranch (operands[1], \"%l0\", 0, insn);
15463 }"
15464   [(set_attr "type" "branch")])
15465
15466 (define_insn ""
15467   [(set (pc)
15468         (if_then_else (match_operator 0 "branch_comparison_operator"
15469                                       [(match_operand 1
15470                                                       "cc_reg_operand" "y")
15471                                        (const_int 0)])
15472                       (any_return)
15473                       (pc)))]
15474   "<return_pred>"
15475   "*
15476 {
15477   return output_cbranch (operands[0], NULL, 0, insn);
15478 }"
15479   [(set_attr "type" "jmpreg")
15480    (set_attr "length" "4")])
15481
15482 (define_insn ""
15483   [(set (pc)
15484         (if_then_else (match_operator 1 "branch_comparison_operator"
15485                                       [(match_operand 2
15486                                                       "cc_reg_operand" "y")
15487                                        (const_int 0)])
15488                       (pc)
15489                       (label_ref (match_operand 0 "" ""))))]
15490   ""
15491   "*
15492 {
15493   return output_cbranch (operands[1], \"%l0\", 1, insn);
15494 }"
15495   [(set_attr "type" "branch")])
15496
15497 (define_insn ""
15498   [(set (pc)
15499         (if_then_else (match_operator 0 "branch_comparison_operator"
15500                                       [(match_operand 1
15501                                                       "cc_reg_operand" "y")
15502                                        (const_int 0)])
15503                       (pc)
15504                       (any_return)))]
15505   "<return_pred>"
15506   "*
15507 {
15508   return output_cbranch (operands[0], NULL, 1, insn);
15509 }"
15510   [(set_attr "type" "jmpreg")
15511    (set_attr "length" "4")])
15512
15513 ;; Logic on condition register values.
15514
15515 ; This pattern matches things like
15516 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
15517 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
15518 ;                                  (const_int 1)))
15519 ; which are generated by the branch logic.
15520 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
15521
15522 (define_insn "*cceq_ior_compare"
15523   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15524         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
15525                         [(match_operator:SI 2
15526                                       "branch_positive_comparison_operator"
15527                                       [(match_operand 3
15528                                                       "cc_reg_operand" "y,y")
15529                                        (const_int 0)])
15530                          (match_operator:SI 4
15531                                       "branch_positive_comparison_operator"
15532                                       [(match_operand 5
15533                                                       "cc_reg_operand" "0,y")
15534                                        (const_int 0)])])
15535                       (const_int 1)))]
15536   ""
15537   "cr%q1 %E0,%j2,%j4"
15538   [(set_attr "type" "cr_logical,delayed_cr")])
15539
15540 ; Why is the constant -1 here, but 1 in the previous pattern?
15541 ; Because ~1 has all but the low bit set.
15542 (define_insn ""
15543   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15544         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
15545                         [(not:SI (match_operator:SI 2
15546                                       "branch_positive_comparison_operator"
15547                                       [(match_operand 3
15548                                                       "cc_reg_operand" "y,y")
15549                                        (const_int 0)]))
15550                          (match_operator:SI 4
15551                                 "branch_positive_comparison_operator"
15552                                 [(match_operand 5
15553                                                 "cc_reg_operand" "0,y")
15554                                  (const_int 0)])])
15555                       (const_int -1)))]
15556   ""
15557   "cr%q1 %E0,%j2,%j4"
15558   [(set_attr "type" "cr_logical,delayed_cr")])
15559
15560 (define_insn "*cceq_rev_compare"
15561   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15562         (compare:CCEQ (match_operator:SI 1
15563                                       "branch_positive_comparison_operator"
15564                                       [(match_operand 2
15565                                                       "cc_reg_operand" "0,y")
15566                                        (const_int 0)])
15567                       (const_int 0)))]
15568   ""
15569   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
15570   [(set_attr "type" "cr_logical,delayed_cr")])
15571
15572 ;; If we are comparing the result of two comparisons, this can be done
15573 ;; using creqv or crxor.
15574
15575 (define_insn_and_split ""
15576   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
15577         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
15578                               [(match_operand 2 "cc_reg_operand" "y")
15579                                (const_int 0)])
15580                       (match_operator 3 "branch_comparison_operator"
15581                               [(match_operand 4 "cc_reg_operand" "y")
15582                                (const_int 0)])))]
15583   ""
15584   "#"
15585   ""
15586   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
15587                                     (match_dup 5)))]
15588   "
15589 {
15590   int positive_1, positive_2;
15591
15592   positive_1 = branch_positive_comparison_operator (operands[1],
15593                                                     GET_MODE (operands[1]));
15594   positive_2 = branch_positive_comparison_operator (operands[3],
15595                                                     GET_MODE (operands[3]));
15596
15597   if (! positive_1)
15598     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
15599                                                             GET_CODE (operands[1])),
15600                                   SImode,
15601                                   operands[2], const0_rtx);
15602   else if (GET_MODE (operands[1]) != SImode)
15603     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
15604                                   operands[2], const0_rtx);
15605
15606   if (! positive_2)
15607     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
15608                                                             GET_CODE (operands[3])),
15609                                   SImode,
15610                                   operands[4], const0_rtx);
15611   else if (GET_MODE (operands[3]) != SImode)
15612     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
15613                                   operands[4], const0_rtx);
15614
15615   if (positive_1 == positive_2)
15616     {
15617       operands[1] = gen_rtx_NOT (SImode, operands[1]);
15618       operands[5] = constm1_rtx;
15619     }
15620   else
15621     {
15622       operands[5] = const1_rtx;
15623     }
15624 }")
15625
15626 ;; Unconditional branch and return.
15627
15628 (define_insn "jump"
15629   [(set (pc)
15630         (label_ref (match_operand 0 "" "")))]
15631   ""
15632   "b %l0"
15633   [(set_attr "type" "branch")])
15634
15635 (define_insn "<return_str>return"
15636   [(any_return)]
15637   "<return_pred>"
15638   "{br|blr}"
15639   [(set_attr "type" "jmpreg")])
15640
15641 (define_expand "indirect_jump"
15642   [(set (pc) (match_operand 0 "register_operand" ""))])
15643
15644 (define_insn "*indirect_jump<mode>"
15645   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
15646   ""
15647   "@
15648    bctr
15649    {br|blr}"
15650   [(set_attr "type" "jmpreg")])
15651
15652 ;; Table jump for switch statements:
15653 (define_expand "tablejump"
15654   [(use (match_operand 0 "" ""))
15655    (use (label_ref (match_operand 1 "" "")))]
15656   ""
15657   "
15658 {
15659   if (TARGET_32BIT)
15660     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
15661   else
15662     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
15663   DONE;
15664 }")
15665
15666 (define_expand "tablejumpsi"
15667   [(set (match_dup 3)
15668         (plus:SI (match_operand:SI 0 "" "")
15669                  (match_dup 2)))
15670    (parallel [(set (pc) (match_dup 3))
15671               (use (label_ref (match_operand 1 "" "")))])]
15672   "TARGET_32BIT"
15673   "
15674 { operands[0] = force_reg (SImode, operands[0]);
15675   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
15676   operands[3] = gen_reg_rtx (SImode);
15677 }")
15678
15679 (define_expand "tablejumpdi"
15680   [(set (match_dup 4)
15681         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
15682    (set (match_dup 3)
15683         (plus:DI (match_dup 4)
15684                  (match_dup 2)))
15685    (parallel [(set (pc) (match_dup 3))
15686               (use (label_ref (match_operand 1 "" "")))])]
15687   "TARGET_64BIT"
15688   "
15689 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
15690   operands[3] = gen_reg_rtx (DImode);
15691   operands[4] = gen_reg_rtx (DImode);
15692 }")
15693
15694 (define_insn "*tablejump<mode>_internal1"
15695   [(set (pc)
15696         (match_operand:P 0 "register_operand" "c,*l"))
15697    (use (label_ref (match_operand 1 "" "")))]
15698   ""
15699   "@
15700    bctr
15701    {br|blr}"
15702   [(set_attr "type" "jmpreg")])
15703
15704 (define_insn "nop"
15705   [(const_int 0)]
15706   ""
15707   "{cror 0,0,0|nop}")
15708
15709 (define_insn "group_ending_nop"
15710   [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
15711   ""
15712   "*
15713 {
15714   if (rs6000_cpu_attr == CPU_POWER6)
15715     return \"ori 1,1,0\";
15716   return \"ori 2,2,0\";
15717 }")
15718 \f
15719 ;; Define the subtract-one-and-jump insns, starting with the template
15720 ;; so loop.c knows what to generate.
15721
15722 (define_expand "doloop_end"
15723   [(use (match_operand 0 "" ""))        ; loop pseudo
15724    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
15725    (use (match_operand 2 "" ""))        ; max iterations
15726    (use (match_operand 3 "" ""))        ; loop level
15727    (use (match_operand 4 "" ""))]       ; label
15728   ""
15729   "
15730 {
15731   /* Only use this on innermost loops.  */
15732   if (INTVAL (operands[3]) > 1)
15733     FAIL;
15734   if (TARGET_64BIT)
15735     {
15736       if (GET_MODE (operands[0]) != DImode)
15737         FAIL;
15738       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
15739     }
15740   else
15741     {
15742       if (GET_MODE (operands[0]) != SImode)
15743         FAIL;
15744       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
15745     }
15746   DONE;
15747 }")
15748
15749 (define_expand "ctr<mode>"
15750   [(parallel [(set (pc)
15751                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
15752                                      (const_int 1))
15753                                  (label_ref (match_operand 1 "" ""))
15754                                  (pc)))
15755               (set (match_dup 0)
15756                    (plus:P (match_dup 0)
15757                             (const_int -1)))
15758               (clobber (match_scratch:CC 2 ""))
15759               (clobber (match_scratch:P 3 ""))])]
15760   ""
15761   "")
15762
15763 ;; We need to be able to do this for any operand, including MEM, or we
15764 ;; will cause reload to blow up since we don't allow output reloads on
15765 ;; JUMP_INSNs.
15766 ;; For the length attribute to be calculated correctly, the
15767 ;; label MUST be operand 0.
15768
15769 (define_insn "*ctr<mode>_internal1"
15770   [(set (pc)
15771         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15772                           (const_int 1))
15773                       (label_ref (match_operand 0 "" ""))
15774                       (pc)))
15775    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15776         (plus:P (match_dup 1)
15777                  (const_int -1)))
15778    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15779    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15780   ""
15781   "*
15782 {
15783   if (which_alternative != 0)
15784     return \"#\";
15785   else if (get_attr_length (insn) == 4)
15786     return \"{bdn|bdnz} %l0\";
15787   else
15788     return \"bdz $+8\;b %l0\";
15789 }"
15790   [(set_attr "type" "branch")
15791    (set_attr "length" "*,12,16,16")])
15792
15793 (define_insn "*ctr<mode>_internal2"
15794   [(set (pc)
15795         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15796                           (const_int 1))
15797                       (pc)
15798                       (label_ref (match_operand 0 "" ""))))
15799    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15800         (plus:P (match_dup 1)
15801                  (const_int -1)))
15802    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15803    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15804   ""
15805   "*
15806 {
15807   if (which_alternative != 0)
15808     return \"#\";
15809   else if (get_attr_length (insn) == 4)
15810     return \"bdz %l0\";
15811   else
15812     return \"{bdn|bdnz} $+8\;b %l0\";
15813 }"
15814   [(set_attr "type" "branch")
15815    (set_attr "length" "*,12,16,16")])
15816
15817 ;; Similar but use EQ
15818
15819 (define_insn "*ctr<mode>_internal5"
15820   [(set (pc)
15821         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15822                           (const_int 1))
15823                       (label_ref (match_operand 0 "" ""))
15824                       (pc)))
15825    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15826         (plus:P (match_dup 1)
15827                  (const_int -1)))
15828    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15829    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15830   ""
15831   "*
15832 {
15833   if (which_alternative != 0)
15834     return \"#\";
15835   else if (get_attr_length (insn) == 4)
15836     return \"bdz %l0\";
15837   else
15838     return \"{bdn|bdnz} $+8\;b %l0\";
15839 }"
15840   [(set_attr "type" "branch")
15841    (set_attr "length" "*,12,16,16")])
15842
15843 (define_insn "*ctr<mode>_internal6"
15844   [(set (pc)
15845         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15846                           (const_int 1))
15847                       (pc)
15848                       (label_ref (match_operand 0 "" ""))))
15849    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15850         (plus:P (match_dup 1)
15851                  (const_int -1)))
15852    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15853    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15854   ""
15855   "*
15856 {
15857   if (which_alternative != 0)
15858     return \"#\";
15859   else if (get_attr_length (insn) == 4)
15860     return \"{bdn|bdnz} %l0\";
15861   else
15862     return \"bdz $+8\;b %l0\";
15863 }"
15864   [(set_attr "type" "branch")
15865    (set_attr "length" "*,12,16,16")])
15866
15867 ;; Now the splitters if we could not allocate the CTR register
15868
15869 (define_split
15870   [(set (pc)
15871         (if_then_else (match_operator 2 "comparison_operator"
15872                                       [(match_operand:P 1 "gpc_reg_operand" "")
15873                                        (const_int 1)])
15874                       (match_operand 5 "" "")
15875                       (match_operand 6 "" "")))
15876    (set (match_operand:P 0 "gpc_reg_operand" "")
15877         (plus:P (match_dup 1) (const_int -1)))
15878    (clobber (match_scratch:CC 3 ""))
15879    (clobber (match_scratch:P 4 ""))]
15880   "reload_completed"
15881   [(parallel [(set (match_dup 3)
15882                    (compare:CC (plus:P (match_dup 1)
15883                                         (const_int -1))
15884                                (const_int 0)))
15885               (set (match_dup 0)
15886                    (plus:P (match_dup 1)
15887                             (const_int -1)))])
15888    (set (pc) (if_then_else (match_dup 7)
15889                            (match_dup 5)
15890                            (match_dup 6)))]
15891   "
15892 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15893                                 operands[3], const0_rtx); }")
15894
15895 (define_split
15896   [(set (pc)
15897         (if_then_else (match_operator 2 "comparison_operator"
15898                                       [(match_operand:P 1 "gpc_reg_operand" "")
15899                                        (const_int 1)])
15900                       (match_operand 5 "" "")
15901                       (match_operand 6 "" "")))
15902    (set (match_operand:P 0 "nonimmediate_operand" "")
15903         (plus:P (match_dup 1) (const_int -1)))
15904    (clobber (match_scratch:CC 3 ""))
15905    (clobber (match_scratch:P 4 ""))]
15906   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
15907   [(parallel [(set (match_dup 3)
15908                    (compare:CC (plus:P (match_dup 1)
15909                                         (const_int -1))
15910                                (const_int 0)))
15911               (set (match_dup 4)
15912                    (plus:P (match_dup 1)
15913                             (const_int -1)))])
15914    (set (match_dup 0)
15915         (match_dup 4))
15916    (set (pc) (if_then_else (match_dup 7)
15917                            (match_dup 5)
15918                            (match_dup 6)))]
15919   "
15920 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15921                                 operands[3], const0_rtx); }")
15922 \f
15923 (define_insn "trap"
15924   [(trap_if (const_int 1) (const_int 0))]
15925   ""
15926   "{t 31,0,0|trap}"
15927   [(set_attr "type" "trap")])
15928
15929 (define_expand "ctrap<mode>4"
15930   [(trap_if (match_operator 0 "ordered_comparison_operator"
15931                             [(match_operand:GPR 1 "register_operand")
15932                              (match_operand:GPR 2 "reg_or_short_operand")])
15933             (match_operand 3 "zero_constant" ""))]
15934   ""
15935   "")
15936
15937 (define_insn ""
15938   [(trap_if (match_operator 0 "ordered_comparison_operator"
15939                             [(match_operand:GPR 1 "register_operand" "r")
15940                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
15941             (const_int 0))]
15942   ""
15943   "{t|t<wd>}%V0%I2 %1,%2"
15944   [(set_attr "type" "trap")])
15945 \f
15946 ;; Insns related to generating the function prologue and epilogue.
15947
15948 (define_expand "prologue"
15949   [(use (const_int 0))]
15950   ""
15951 {
15952   rs6000_emit_prologue ();
15953   if (!TARGET_SCHED_PROLOG)
15954     emit_insn (gen_blockage ());
15955   DONE;
15956 })
15957
15958 (define_insn "*movesi_from_cr_one"
15959   [(match_parallel 0 "mfcr_operation"
15960                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15961                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
15962                                      (match_operand 3 "immediate_operand" "n")]
15963                           UNSPEC_MOVESI_FROM_CR))])]
15964   "TARGET_MFCRF"
15965   "*
15966 {
15967   int mask = 0;
15968   int i;
15969   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15970   {
15971     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15972     operands[4] = GEN_INT (mask);
15973     output_asm_insn (\"mfcr %1,%4\", operands);
15974   }
15975   return \"\";
15976 }"
15977   [(set_attr "type" "mfcrf")])
15978
15979 (define_insn "movesi_from_cr"
15980   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15981         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
15982                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
15983                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
15984                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
15985                    UNSPEC_MOVESI_FROM_CR))]
15986   ""
15987   "mfcr %0"
15988   [(set_attr "type" "mfcr")])
15989
15990 (define_insn "*stmw"
15991   [(match_parallel 0 "stmw_operation"
15992                    [(set (match_operand:SI 1 "memory_operand" "=m")
15993                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
15994   "TARGET_MULTIPLE"
15995   "{stm|stmw} %2,%1"
15996   [(set_attr "type" "store_ux")])
15997
15998 ; The following comment applies to:
15999 ;     save_gpregs_*
16000 ;     save_fpregs_*
16001 ;     restore_gpregs*
16002 ;     return_and_restore_gpregs*
16003 ;     return_and_restore_fpregs*
16004 ;     return_and_restore_fpregs_aix*
16005 ;
16006 ; The out-of-line save / restore functions expects one input argument.
16007 ; Since those are not standard call_insn's, we must avoid using
16008 ; MATCH_OPERAND for that argument. That way the register rename
16009 ; optimization will not try to rename this register.
16010 ; Each pattern is repeated for each possible register number used in 
16011 ; various ABIs (r11, r1, and for some functions r12)
16012
16013 (define_insn "*save_gpregs_<mode>_r11"
16014   [(match_parallel 0 "any_parallel_operand"
16015                    [(clobber (reg:P 65))
16016                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
16017                     (use (reg:P 11))
16018                     (set (match_operand:P 2 "memory_operand" "=m")
16019                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
16020   ""
16021   "bl %1"
16022   [(set_attr "type" "branch")
16023    (set_attr "length" "4")])
16024
16025 (define_insn "*save_gpregs_<mode>_r12"
16026   [(match_parallel 0 "any_parallel_operand"
16027                    [(clobber (reg:P 65))
16028                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
16029                     (use (reg:P 12))
16030                     (set (match_operand:P 2 "memory_operand" "=m")
16031                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
16032   ""
16033   "bl %1"
16034   [(set_attr "type" "branch")
16035    (set_attr "length" "4")])
16036
16037 (define_insn "*save_gpregs_<mode>_r1"
16038   [(match_parallel 0 "any_parallel_operand"
16039                    [(clobber (reg:P 65))
16040                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
16041                     (use (reg:P 1))
16042                     (set (match_operand:P 2 "memory_operand" "=m")
16043                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
16044   ""
16045   "bl %1"
16046   [(set_attr "type" "branch")
16047    (set_attr "length" "4")])
16048
16049 (define_insn "*save_fpregs_<mode>_r11"
16050   [(match_parallel 0 "any_parallel_operand"
16051                    [(clobber (reg:P 65))
16052                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
16053                     (use (reg:P 11))
16054                     (set (match_operand:DF 2 "memory_operand" "=m")
16055                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
16056   ""
16057   "bl %1"
16058   [(set_attr "type" "branch")
16059    (set_attr "length" "4")])
16060
16061 (define_insn "*save_fpregs_<mode>_r12"
16062   [(match_parallel 0 "any_parallel_operand"
16063                    [(clobber (reg:P 65))
16064                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
16065                     (use (reg:P 12))
16066                     (set (match_operand:DF 2 "memory_operand" "=m")
16067                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
16068   ""
16069   "bl %1"
16070   [(set_attr "type" "branch")
16071    (set_attr "length" "4")])
16072
16073 (define_insn "*save_fpregs_<mode>_r1"
16074   [(match_parallel 0 "any_parallel_operand"
16075                    [(clobber (reg:P 65))
16076                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
16077                     (use (reg:P 1))
16078                     (set (match_operand:DF 2 "memory_operand" "=m")
16079                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
16080   ""
16081   "bl %1"
16082   [(set_attr "type" "branch")
16083    (set_attr "length" "4")])
16084
16085 ; These are to explain that changes to the stack pointer should
16086 ; not be moved over stores to stack memory.
16087 (define_insn "stack_tie"
16088   [(set (match_operand:BLK 0 "memory_operand" "+m")
16089         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
16090   ""
16091   ""
16092   [(set_attr "length" "0")])
16093
16094 ; Like stack_tie, but depend on both fp and sp based memory.
16095 (define_insn "frame_tie"
16096   [(set (match_operand:BLK 0 "memory_operand" "+m")
16097         (unspec:BLK [(match_dup 0)
16098                      (match_operand:BLK 1 "memory_operand" "m")] UNSPEC_TIE))]
16099   ""
16100   ""
16101   [(set_attr "length" "0")])
16102
16103
16104 (define_expand "epilogue"
16105   [(use (const_int 0))]
16106   ""
16107 {
16108   if (!TARGET_SCHED_PROLOG)
16109     emit_insn (gen_blockage ());
16110   rs6000_emit_epilogue (FALSE);
16111   DONE;
16112 })
16113
16114 ; On some processors, doing the mtcrf one CC register at a time is
16115 ; faster (like on the 604e).  On others, doing them all at once is
16116 ; faster; for instance, on the 601 and 750.
16117
16118 (define_expand "movsi_to_cr_one"
16119   [(set (match_operand:CC 0 "cc_reg_operand" "")
16120         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
16121                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
16122   ""
16123   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
16124
16125 (define_insn "*movsi_to_cr"
16126   [(match_parallel 0 "mtcrf_operation"
16127                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
16128                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
16129                                      (match_operand 3 "immediate_operand" "n")]
16130                                     UNSPEC_MOVESI_TO_CR))])]
16131  ""
16132  "*
16133 {
16134   int mask = 0;
16135   int i;
16136   for (i = 0; i < XVECLEN (operands[0], 0); i++)
16137     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
16138   operands[4] = GEN_INT (mask);
16139   return \"mtcrf %4,%2\";
16140 }"
16141   [(set_attr "type" "mtcr")])
16142
16143 (define_insn "*mtcrfsi"
16144   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
16145         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
16146                     (match_operand 2 "immediate_operand" "n")]
16147                    UNSPEC_MOVESI_TO_CR))]
16148   "GET_CODE (operands[0]) == REG
16149    && CR_REGNO_P (REGNO (operands[0]))
16150    && GET_CODE (operands[2]) == CONST_INT
16151    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
16152   "mtcrf %R0,%1"
16153   [(set_attr "type" "mtcr")])
16154
16155 ; The load-multiple instructions have similar properties.
16156 ; Note that "load_multiple" is a name known to the machine-independent
16157 ; code that actually corresponds to the PowerPC load-string.
16158
16159 (define_insn "*lmw"
16160   [(match_parallel 0 "lmw_operation"
16161                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
16162                          (match_operand:SI 2 "memory_operand" "m"))])]
16163   "TARGET_MULTIPLE"
16164   "{lm|lmw} %1,%2"
16165   [(set_attr "type" "load_ux")
16166    (set_attr "cell_micro" "always")])
16167
16168 (define_insn "*return_internal_<mode>"
16169   [(simple_return)
16170    (use (match_operand:P 0 "register_operand" "lc"))]
16171   ""
16172   "b%T0"
16173   [(set_attr "type" "jmpreg")])
16174
16175 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
16176 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
16177
16178 ; The following comment applies to:
16179 ;     save_gpregs_*
16180 ;     save_fpregs_*
16181 ;     restore_gpregs*
16182 ;     return_and_restore_gpregs*
16183 ;     return_and_restore_fpregs*
16184 ;     return_and_restore_fpregs_aix*
16185 ;
16186 ; The out-of-line save / restore functions expects one input argument.
16187 ; Since those are not standard call_insn's, we must avoid using
16188 ; MATCH_OPERAND for that argument. That way the register rename
16189 ; optimization will not try to rename this register.
16190 ; Each pattern is repeated for each possible register number used in 
16191 ; various ABIs (r11, r1, and for some functions r12)
16192
16193 (define_insn "*restore_gpregs_<mode>_r11"
16194  [(match_parallel 0 "any_parallel_operand"
16195                   [(clobber (match_operand:P 1 "register_operand" "=l"))
16196                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16197                    (use (reg:P 11))
16198                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16199                         (match_operand:P 4 "memory_operand" "m"))])]
16200  ""
16201  "bl %2"
16202  [(set_attr "type" "branch")
16203   (set_attr "length" "4")])
16204
16205 (define_insn "*restore_gpregs_<mode>_r12"
16206  [(match_parallel 0 "any_parallel_operand"
16207                   [(clobber (match_operand:P 1 "register_operand" "=l"))
16208                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16209                    (use (reg:P 12))
16210                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16211                         (match_operand:P 4 "memory_operand" "m"))])]
16212  ""
16213  "bl %2"
16214  [(set_attr "type" "branch")
16215   (set_attr "length" "4")])
16216
16217 (define_insn "*restore_gpregs_<mode>_r1"
16218  [(match_parallel 0 "any_parallel_operand"
16219                   [(clobber (match_operand:P 1 "register_operand" "=l"))
16220                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16221                    (use (reg:P 1))
16222                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16223                         (match_operand:P 4 "memory_operand" "m"))])]
16224  ""
16225  "bl %2"
16226  [(set_attr "type" "branch")
16227   (set_attr "length" "4")])
16228
16229 (define_insn "*return_and_restore_gpregs_<mode>_r11"
16230  [(match_parallel 0 "any_parallel_operand"
16231                   [(return)
16232                    (clobber (match_operand:P 1 "register_operand" "=l"))
16233                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16234                    (use (reg:P 11))
16235                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16236                         (match_operand:P 4 "memory_operand" "m"))])]
16237  ""
16238  "b %2"
16239  [(set_attr "type" "branch")
16240   (set_attr "length" "4")])
16241
16242 (define_insn "*return_and_restore_gpregs_<mode>_r12"
16243  [(match_parallel 0 "any_parallel_operand"
16244                   [(return)
16245                    (clobber (match_operand:P 1 "register_operand" "=l"))
16246                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16247                    (use (reg:P 12))
16248                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16249                         (match_operand:P 4 "memory_operand" "m"))])]
16250  ""
16251  "b %2"
16252  [(set_attr "type" "branch")
16253   (set_attr "length" "4")])
16254
16255 (define_insn "*return_and_restore_gpregs_<mode>_r1"
16256  [(match_parallel 0 "any_parallel_operand"
16257                   [(return)
16258                    (clobber (match_operand:P 1 "register_operand" "=l"))
16259                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16260                    (use (reg:P 1))
16261                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16262                         (match_operand:P 4 "memory_operand" "m"))])]
16263  ""
16264  "b %2"
16265  [(set_attr "type" "branch")
16266   (set_attr "length" "4")])
16267
16268 (define_insn "*return_and_restore_fpregs_<mode>_r11"
16269  [(match_parallel 0 "any_parallel_operand"
16270                   [(return)
16271                    (clobber (match_operand:P 1 "register_operand" "=l"))
16272                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16273                    (use (reg:P 11))
16274                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16275                         (match_operand:DF 4 "memory_operand" "m"))])]
16276  ""
16277  "b %2"
16278  [(set_attr "type" "branch")
16279   (set_attr "length" "4")])
16280
16281 (define_insn "*return_and_restore_fpregs_<mode>_r12"
16282  [(match_parallel 0 "any_parallel_operand"
16283                   [(return)
16284                    (clobber (match_operand:P 1 "register_operand" "=l"))
16285                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16286                    (use (reg:P 12))
16287                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16288                         (match_operand:DF 4 "memory_operand" "m"))])]
16289  ""
16290  "b %2"
16291  [(set_attr "type" "branch")
16292   (set_attr "length" "4")])
16293
16294 (define_insn "*return_and_restore_fpregs_<mode>_r1"
16295  [(match_parallel 0 "any_parallel_operand"
16296                   [(return)
16297                    (clobber (match_operand:P 1 "register_operand" "=l"))
16298                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16299                    (use (reg:P 1))
16300                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16301                         (match_operand:DF 4 "memory_operand" "m"))])]
16302  ""
16303  "b %2"
16304  [(set_attr "type" "branch")
16305   (set_attr "length" "4")])
16306
16307 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
16308  [(match_parallel 0 "any_parallel_operand"
16309                   [(return)
16310                    (use (match_operand:P 1 "register_operand" "l"))
16311                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16312                    (use (reg:P 11))
16313                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16314                         (match_operand:DF 4 "memory_operand" "m"))])]
16315  ""
16316  "b %2"
16317  [(set_attr "type" "branch")
16318   (set_attr "length" "4")])
16319
16320 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
16321  [(match_parallel 0 "any_parallel_operand"
16322                   [(return)
16323                    (use (match_operand:P 1 "register_operand" "l"))
16324                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16325                    (use (reg:P 1))
16326                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16327                         (match_operand:DF 4 "memory_operand" "m"))])]
16328  ""
16329  "b %2"
16330  [(set_attr "type" "branch")
16331   (set_attr "length" "4")])
16332
16333 ; This is used in compiling the unwind routines.
16334 (define_expand "eh_return"
16335   [(use (match_operand 0 "general_operand" ""))]
16336   ""
16337   "
16338 {
16339   if (TARGET_32BIT)
16340     emit_insn (gen_eh_set_lr_si (operands[0]));
16341   else
16342     emit_insn (gen_eh_set_lr_di (operands[0]));
16343   DONE;
16344 }")
16345
16346 ; We can't expand this before we know where the link register is stored.
16347 (define_insn "eh_set_lr_<mode>"
16348   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
16349                     UNSPECV_EH_RR)
16350    (clobber (match_scratch:P 1 "=&b"))]
16351   ""
16352   "#")
16353
16354 (define_split
16355   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
16356    (clobber (match_scratch 1 ""))]
16357   "reload_completed"
16358   [(const_int 0)]
16359   "
16360 {
16361   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
16362   DONE;
16363 }")
16364
16365 (define_insn "prefetch"
16366   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
16367              (match_operand:SI 1 "const_int_operand" "n")
16368              (match_operand:SI 2 "const_int_operand" "n"))]
16369   "TARGET_POWERPC"
16370   "*
16371 {
16372   if (GET_CODE (operands[0]) == REG)
16373     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
16374   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
16375 }"
16376   [(set_attr "type" "load")])
16377 \f
16378 (define_insn "bpermd_<mode>"
16379   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
16380         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
16381                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
16382   "TARGET_POPCNTD"
16383   "bpermd %0,%1,%2"
16384   [(set_attr "type" "integer")])
16385
16386 \f
16387 ;; Builtin fma support.  Handle 
16388 ;; Note that the conditions for expansion are in the FMA_F iterator.
16389
16390 (define_expand "fma<mode>4"
16391   [(set (match_operand:FMA_F 0 "register_operand" "")
16392         (fma:FMA_F
16393           (match_operand:FMA_F 1 "register_operand" "")
16394           (match_operand:FMA_F 2 "register_operand" "")
16395           (match_operand:FMA_F 3 "register_operand" "")))]
16396   ""
16397   "")
16398
16399 ; Altivec only has fma and nfms.
16400 (define_expand "fms<mode>4"
16401   [(set (match_operand:FMA_F 0 "register_operand" "")
16402         (fma:FMA_F
16403           (match_operand:FMA_F 1 "register_operand" "")
16404           (match_operand:FMA_F 2 "register_operand" "")
16405           (neg:FMA_F (match_operand:FMA_F 3 "register_operand" ""))))]
16406   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
16407   "")
16408
16409 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
16410 (define_expand "fnma<mode>4"
16411   [(set (match_operand:FMA_F 0 "register_operand" "")
16412         (neg:FMA_F
16413           (fma:FMA_F
16414             (match_operand:FMA_F 1 "register_operand" "")
16415             (match_operand:FMA_F 2 "register_operand" "")
16416             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
16417   "!HONOR_SIGNED_ZEROS (<MODE>mode)"
16418   "")
16419
16420 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
16421 (define_expand "fnms<mode>4"
16422   [(set (match_operand:FMA_F 0 "register_operand" "")
16423         (neg:FMA_F
16424           (fma:FMA_F
16425             (match_operand:FMA_F 1 "register_operand" "")
16426             (match_operand:FMA_F 2 "register_operand" "")
16427             (match_operand:FMA_F 3 "register_operand" ""))))]
16428   "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
16429   "")
16430
16431 ; Not an official optab name, but used from builtins.
16432 (define_expand "nfma<mode>4"
16433   [(set (match_operand:FMA_F 0 "register_operand" "")
16434         (neg:FMA_F
16435           (fma:FMA_F
16436             (match_operand:FMA_F 1 "register_operand" "")
16437             (match_operand:FMA_F 2 "register_operand" "")
16438             (match_operand:FMA_F 3 "register_operand" ""))))]
16439   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
16440   "")
16441
16442 ; Not an official optab name, but used from builtins.
16443 (define_expand "nfms<mode>4"
16444   [(set (match_operand:FMA_F 0 "register_operand" "")
16445         (neg:FMA_F
16446           (fma:FMA_F
16447             (match_operand:FMA_F 1 "register_operand" "")
16448             (match_operand:FMA_F 2 "register_operand" "")
16449             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
16450   ""
16451   "")
16452
16453 \f
16454
16455 (include "sync.md")
16456 (include "vector.md")
16457 (include "vsx.md")
16458 (include "altivec.md")
16459 (include "spe.md")
16460 (include "dfp.md")
16461 (include "paired.md")