OSDN Git Service

Revert delta 190174
[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 ;; Call and call_value insns
12307 (define_expand "call"
12308   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12309                     (match_operand 1 "" ""))
12310               (use (match_operand 2 "" ""))
12311               (clobber (reg:SI LR_REGNO))])]
12312   ""
12313   "
12314 {
12315 #if TARGET_MACHO
12316   if (MACHOPIC_INDIRECT)
12317     operands[0] = machopic_indirect_call_target (operands[0]);
12318 #endif
12319
12320   gcc_assert (GET_CODE (operands[0]) == MEM);
12321   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12322
12323   operands[0] = XEXP (operands[0], 0);
12324
12325   if (GET_CODE (operands[0]) != SYMBOL_REF
12326       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
12327       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
12328     {
12329       if (INTVAL (operands[2]) & CALL_LONG)
12330         operands[0] = rs6000_longcall_ref (operands[0]);
12331
12332       switch (DEFAULT_ABI)
12333         {
12334         case ABI_V4:
12335         case ABI_DARWIN:
12336           operands[0] = force_reg (Pmode, operands[0]);
12337           break;
12338
12339         case ABI_AIX:
12340           /* AIX function pointers are really pointers to a three word
12341              area.  */
12342           rs6000_call_indirect_aix (NULL_RTX, operands[0], operands[1]);
12343           DONE;
12344
12345         default:
12346           gcc_unreachable ();
12347         }
12348     }
12349 }")
12350
12351 (define_expand "call_value"
12352   [(parallel [(set (match_operand 0 "" "")
12353                    (call (mem:SI (match_operand 1 "address_operand" ""))
12354                          (match_operand 2 "" "")))
12355               (use (match_operand 3 "" ""))
12356               (clobber (reg:SI LR_REGNO))])]
12357   ""
12358   "
12359 {
12360 #if TARGET_MACHO
12361   if (MACHOPIC_INDIRECT)
12362     operands[1] = machopic_indirect_call_target (operands[1]);
12363 #endif
12364
12365   gcc_assert (GET_CODE (operands[1]) == MEM);
12366   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12367
12368   operands[1] = XEXP (operands[1], 0);
12369
12370   if (GET_CODE (operands[1]) != SYMBOL_REF
12371       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
12372       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
12373     {
12374       if (INTVAL (operands[3]) & CALL_LONG)
12375         operands[1] = rs6000_longcall_ref (operands[1]);
12376
12377       switch (DEFAULT_ABI)
12378         {
12379         case ABI_V4:
12380         case ABI_DARWIN:
12381           operands[1] = force_reg (Pmode, operands[1]);
12382           break;
12383
12384         case ABI_AIX:
12385           /* AIX function pointers are really pointers to a three word
12386              area.  */
12387           rs6000_call_indirect_aix (operands[0], operands[1], operands[2]);
12388           DONE;
12389
12390         default:
12391           gcc_unreachable ();
12392         }
12393     }
12394 }")
12395
12396 ;; Call to function in current module.  No TOC pointer reload needed.
12397 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12398 ;; either the function was not prototyped, or it was prototyped as a
12399 ;; variable argument function.  It is > 0 if FP registers were passed
12400 ;; and < 0 if they were not.
12401
12402 (define_insn "*call_local32"
12403   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12404          (match_operand 1 "" "g,g"))
12405    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12406    (clobber (reg:SI LR_REGNO))]
12407   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12408   "*
12409 {
12410   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12411     output_asm_insn (\"crxor 6,6,6\", operands);
12412
12413   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12414     output_asm_insn (\"creqv 6,6,6\", operands);
12415
12416   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12417 }"
12418   [(set_attr "type" "branch")
12419    (set_attr "length" "4,8")])
12420
12421 (define_insn "*call_local64"
12422   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12423          (match_operand 1 "" "g,g"))
12424    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12425    (clobber (reg:SI LR_REGNO))]
12426   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12427   "*
12428 {
12429   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12430     output_asm_insn (\"crxor 6,6,6\", operands);
12431
12432   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12433     output_asm_insn (\"creqv 6,6,6\", operands);
12434
12435   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12436 }"
12437   [(set_attr "type" "branch")
12438    (set_attr "length" "4,8")])
12439
12440 (define_insn "*call_value_local32"
12441   [(set (match_operand 0 "" "")
12442         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12443               (match_operand 2 "" "g,g")))
12444    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12445    (clobber (reg:SI LR_REGNO))]
12446   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12447   "*
12448 {
12449   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12450     output_asm_insn (\"crxor 6,6,6\", operands);
12451
12452   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12453     output_asm_insn (\"creqv 6,6,6\", operands);
12454
12455   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12456 }"
12457   [(set_attr "type" "branch")
12458    (set_attr "length" "4,8")])
12459
12460
12461 (define_insn "*call_value_local64"
12462   [(set (match_operand 0 "" "")
12463         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12464               (match_operand 2 "" "g,g")))
12465    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12466    (clobber (reg:SI LR_REGNO))]
12467   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12468   "*
12469 {
12470   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12471     output_asm_insn (\"crxor 6,6,6\", operands);
12472
12473   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12474     output_asm_insn (\"creqv 6,6,6\", operands);
12475
12476   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12477 }"
12478   [(set_attr "type" "branch")
12479    (set_attr "length" "4,8")])
12480
12481 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
12482 ;; Operand0 is the addresss of the function to call
12483 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
12484 ;; Operand2 is the location in the function descriptor to load r2 from
12485 ;; Operand3 is the stack location to hold the current TOC pointer
12486
12487 (define_insn "call_indirect_aix<ptrsize>"
12488   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12489          (match_operand 1 "" "g,g"))
12490    (use (match_operand:P 2 "memory_operand" "m,m"))
12491    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "m,m"))
12492    (use (reg:P STATIC_CHAIN_REGNUM))
12493    (clobber (reg:P LR_REGNO))]
12494   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12495   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
12496   [(set_attr "type" "jmpreg")
12497    (set_attr "length" "12")])
12498
12499 ;; Like call_indirect_aix<ptrsize>, but no use of the static chain
12500 ;; Operand0 is the addresss of the function to call
12501 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
12502 ;; Operand2 is the location in the function descriptor to load r2 from
12503 ;; Operand3 is the stack location to hold the current TOC pointer
12504
12505 (define_insn "call_indirect_aix<ptrsize>_nor11"
12506   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12507          (match_operand 1 "" "g,g"))
12508    (use (match_operand:P 2 "memory_operand" "m,m"))
12509    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "m,m"))
12510    (clobber (reg:P LR_REGNO))]
12511   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12512   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
12513   [(set_attr "type" "jmpreg")
12514    (set_attr "length" "12")])
12515
12516 ;; Operand0 is the return result of the function
12517 ;; Operand1 is the addresss of the function to call
12518 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
12519 ;; Operand3 is the location in the function descriptor to load r2 from
12520 ;; Operand4 is the stack location to hold the current TOC pointer
12521
12522 (define_insn "call_value_indirect_aix<ptrsize>"
12523   [(set (match_operand 0 "" "")
12524         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12525               (match_operand 2 "" "g,g")))
12526    (use (match_operand:P 3 "memory_operand" "m,m"))
12527    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "m,m"))
12528    (use (reg:P STATIC_CHAIN_REGNUM))
12529    (clobber (reg:P LR_REGNO))]
12530   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12531   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12532   [(set_attr "type" "jmpreg")
12533    (set_attr "length" "12")])
12534
12535 ;; Like call_value_indirect_aix<ptrsize>, but no use of the static chain
12536 ;; Operand0 is the return result of the function
12537 ;; Operand1 is the addresss of the function to call
12538 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
12539 ;; Operand3 is the location in the function descriptor to load r2 from
12540 ;; Operand4 is the stack location to hold the current TOC pointer
12541
12542 (define_insn "call_value_indirect_aix<ptrsize>_nor11"
12543   [(set (match_operand 0 "" "")
12544         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12545               (match_operand 2 "" "g,g")))
12546    (use (match_operand:P 3 "memory_operand" "m,m"))
12547    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "m,m"))
12548    (clobber (reg:P LR_REGNO))]
12549   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12550   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12551   [(set_attr "type" "jmpreg")
12552    (set_attr "length" "12")])
12553
12554 ;; Call to function which may be in another module.  Restore the TOC
12555 ;; pointer (r2) after the call unless this is System V.
12556 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12557 ;; either the function was not prototyped, or it was prototyped as a
12558 ;; variable argument function.  It is > 0 if FP registers were passed
12559 ;; and < 0 if they were not.
12560
12561 (define_insn "*call_nonlocal_aix32"
12562   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
12563          (match_operand 1 "" "g"))
12564    (use (match_operand:SI 2 "immediate_operand" "O"))
12565    (clobber (reg:SI LR_REGNO))]
12566   "TARGET_32BIT
12567    && DEFAULT_ABI == ABI_AIX
12568    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12569   "bl %z0\;%."
12570   [(set_attr "type" "branch")
12571    (set_attr "length" "8")])
12572    
12573 (define_insn "*call_nonlocal_aix64"
12574   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
12575          (match_operand 1 "" "g"))
12576    (use (match_operand:SI 2 "immediate_operand" "O"))
12577    (clobber (reg:SI LR_REGNO))]
12578   "TARGET_64BIT
12579    && DEFAULT_ABI == ABI_AIX
12580    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12581   "bl %z0\;%."
12582   [(set_attr "type" "branch")
12583    (set_attr "length" "8")])
12584
12585 (define_insn "*call_value_nonlocal_aix32"
12586   [(set (match_operand 0 "" "")
12587         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12588               (match_operand 2 "" "g")))
12589    (use (match_operand:SI 3 "immediate_operand" "O"))
12590    (clobber (reg:SI LR_REGNO))]
12591   "TARGET_32BIT
12592    && DEFAULT_ABI == ABI_AIX
12593    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12594   "bl %z1\;%."
12595   [(set_attr "type" "branch")
12596    (set_attr "length" "8")])
12597
12598 (define_insn "*call_value_nonlocal_aix64"
12599   [(set (match_operand 0 "" "")
12600         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12601               (match_operand 2 "" "g")))
12602    (use (match_operand:SI 3 "immediate_operand" "O"))
12603    (clobber (reg:SI LR_REGNO))]
12604   "TARGET_64BIT
12605    && DEFAULT_ABI == ABI_AIX
12606    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12607   "bl %z1\;%."
12608   [(set_attr "type" "branch")
12609    (set_attr "length" "8")])
12610
12611 ;; A function pointer under System V is just a normal pointer
12612 ;; operands[0] is the function pointer
12613 ;; operands[1] is the stack size to clean up
12614 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12615 ;; which indicates how to set cr1
12616
12617 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12618   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12619          (match_operand 1 "" "g,g,g,g"))
12620    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12621    (clobber (reg:SI LR_REGNO))]
12622   "DEFAULT_ABI == ABI_V4
12623    || DEFAULT_ABI == ABI_DARWIN"
12624 {
12625   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12626     output_asm_insn ("crxor 6,6,6", operands);
12627
12628   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12629     output_asm_insn ("creqv 6,6,6", operands);
12630
12631   return "b%T0l";
12632 }
12633   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12634    (set_attr "length" "4,4,8,8")])
12635
12636 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12637   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12638          (match_operand 1 "" "g,g"))
12639    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12640    (clobber (reg:SI LR_REGNO))]
12641   "(DEFAULT_ABI == ABI_DARWIN
12642    || (DEFAULT_ABI == ABI_V4
12643        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12644 {
12645   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12646     output_asm_insn ("crxor 6,6,6", operands);
12647
12648   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12649     output_asm_insn ("creqv 6,6,6", operands);
12650
12651 #if TARGET_MACHO
12652   return output_call(insn, operands, 0, 2);
12653 #else
12654   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12655     {
12656       gcc_assert (!TARGET_SECURE_PLT);
12657       return "bl %z0@plt";
12658     }
12659   else
12660     return "bl %z0";
12661 #endif
12662 }
12663   "DEFAULT_ABI == ABI_V4
12664    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12665    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12666   [(parallel [(call (mem:SI (match_dup 0))
12667                     (match_dup 1))
12668               (use (match_dup 2))
12669               (use (match_dup 3))
12670               (clobber (reg:SI LR_REGNO))])]
12671 {
12672   operands[3] = pic_offset_table_rtx;
12673 }
12674   [(set_attr "type" "branch,branch")
12675    (set_attr "length" "4,8")])
12676
12677 (define_insn "*call_nonlocal_sysv_secure<mode>"
12678   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12679          (match_operand 1 "" "g,g"))
12680    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12681    (use (match_operand:SI 3 "register_operand" "r,r"))
12682    (clobber (reg:SI LR_REGNO))]
12683   "(DEFAULT_ABI == ABI_V4
12684     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12685     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
12686 {
12687   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12688     output_asm_insn ("crxor 6,6,6", operands);
12689
12690   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12691     output_asm_insn ("creqv 6,6,6", operands);
12692
12693   if (flag_pic == 2)
12694     /* The magic 32768 offset here and in the other sysv call insns
12695        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12696        See sysv4.h:toc_section.  */
12697     return "bl %z0+32768@plt";
12698   else
12699     return "bl %z0@plt";
12700 }
12701   [(set_attr "type" "branch,branch")
12702    (set_attr "length" "4,8")])
12703
12704 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12705   [(set (match_operand 0 "" "")
12706         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12707               (match_operand 2 "" "g,g,g,g")))
12708    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12709    (clobber (reg:SI LR_REGNO))]
12710   "DEFAULT_ABI == ABI_V4
12711    || DEFAULT_ABI == ABI_DARWIN"
12712 {
12713   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12714     output_asm_insn ("crxor 6,6,6", operands);
12715
12716   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12717     output_asm_insn ("creqv 6,6,6", operands);
12718
12719   return "b%T1l";
12720 }
12721   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12722    (set_attr "length" "4,4,8,8")])
12723
12724 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12725   [(set (match_operand 0 "" "")
12726         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12727               (match_operand 2 "" "g,g")))
12728    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12729    (clobber (reg:SI LR_REGNO))]
12730   "(DEFAULT_ABI == ABI_DARWIN
12731    || (DEFAULT_ABI == ABI_V4
12732        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12733 {
12734   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12735     output_asm_insn ("crxor 6,6,6", operands);
12736
12737   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12738     output_asm_insn ("creqv 6,6,6", operands);
12739
12740 #if TARGET_MACHO
12741   return output_call(insn, operands, 1, 3);
12742 #else
12743   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12744     {
12745       gcc_assert (!TARGET_SECURE_PLT);
12746       return "bl %z1@plt";
12747     }
12748   else
12749     return "bl %z1";
12750 #endif
12751 }
12752   "DEFAULT_ABI == ABI_V4
12753    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12754    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12755   [(parallel [(set (match_dup 0)
12756                    (call (mem:SI (match_dup 1))
12757                          (match_dup 2)))
12758               (use (match_dup 3))
12759               (use (match_dup 4))
12760               (clobber (reg:SI LR_REGNO))])]
12761 {
12762   operands[4] = pic_offset_table_rtx;
12763 }
12764   [(set_attr "type" "branch,branch")
12765    (set_attr "length" "4,8")])
12766
12767 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12768   [(set (match_operand 0 "" "")
12769         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12770               (match_operand 2 "" "g,g")))
12771    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12772    (use (match_operand:SI 4 "register_operand" "r,r"))
12773    (clobber (reg:SI LR_REGNO))]
12774   "(DEFAULT_ABI == ABI_V4
12775     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12776     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12777 {
12778   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12779     output_asm_insn ("crxor 6,6,6", operands);
12780
12781   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12782     output_asm_insn ("creqv 6,6,6", operands);
12783
12784   if (flag_pic == 2)
12785     return "bl %z1+32768@plt";
12786   else
12787     return "bl %z1@plt";
12788 }
12789   [(set_attr "type" "branch,branch")
12790    (set_attr "length" "4,8")])
12791
12792 ;; Call subroutine returning any type.
12793 (define_expand "untyped_call"
12794   [(parallel [(call (match_operand 0 "" "")
12795                     (const_int 0))
12796               (match_operand 1 "" "")
12797               (match_operand 2 "" "")])]
12798   ""
12799   "
12800 {
12801   int i;
12802
12803   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12804
12805   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12806     {
12807       rtx set = XVECEXP (operands[2], 0, i);
12808       emit_move_insn (SET_DEST (set), SET_SRC (set));
12809     }
12810
12811   /* The optimizer does not know that the call sets the function value
12812      registers we stored in the result block.  We avoid problems by
12813      claiming that all hard registers are used and clobbered at this
12814      point.  */
12815   emit_insn (gen_blockage ());
12816
12817   DONE;
12818 }")
12819
12820 ;; sibling call patterns
12821 (define_expand "sibcall"
12822   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12823                     (match_operand 1 "" ""))
12824               (use (match_operand 2 "" ""))
12825               (use (reg:SI LR_REGNO))
12826               (simple_return)])]
12827   ""
12828   "
12829 {
12830 #if TARGET_MACHO
12831   if (MACHOPIC_INDIRECT)
12832     operands[0] = machopic_indirect_call_target (operands[0]);
12833 #endif
12834
12835   gcc_assert (GET_CODE (operands[0]) == MEM);
12836   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12837
12838   operands[0] = XEXP (operands[0], 0);
12839 }")
12840
12841 ;; this and similar patterns must be marked as using LR, otherwise
12842 ;; dataflow will try to delete the store into it.  This is true
12843 ;; even when the actual reg to jump to is in CTR, when LR was
12844 ;; saved and restored around the PIC-setting BCL.
12845 (define_insn "*sibcall_local32"
12846   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12847          (match_operand 1 "" "g,g"))
12848    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12849    (use (reg:SI LR_REGNO))
12850    (simple_return)]
12851   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12852   "*
12853 {
12854   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12855     output_asm_insn (\"crxor 6,6,6\", operands);
12856
12857   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12858     output_asm_insn (\"creqv 6,6,6\", operands);
12859
12860   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12861 }"
12862   [(set_attr "type" "branch")
12863    (set_attr "length" "4,8")])
12864
12865 (define_insn "*sibcall_local64"
12866   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12867          (match_operand 1 "" "g,g"))
12868    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12869    (use (reg:SI LR_REGNO))
12870    (simple_return)]
12871   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12872   "*
12873 {
12874   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12875     output_asm_insn (\"crxor 6,6,6\", operands);
12876
12877   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12878     output_asm_insn (\"creqv 6,6,6\", operands);
12879
12880   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12881 }"
12882   [(set_attr "type" "branch")
12883    (set_attr "length" "4,8")])
12884
12885 (define_insn "*sibcall_value_local32"
12886   [(set (match_operand 0 "" "")
12887         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12888               (match_operand 2 "" "g,g")))
12889    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12890    (use (reg:SI LR_REGNO))
12891    (simple_return)]
12892   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12893   "*
12894 {
12895   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12896     output_asm_insn (\"crxor 6,6,6\", operands);
12897
12898   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12899     output_asm_insn (\"creqv 6,6,6\", operands);
12900
12901   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12902 }"
12903   [(set_attr "type" "branch")
12904    (set_attr "length" "4,8")])
12905
12906
12907 (define_insn "*sibcall_value_local64"
12908   [(set (match_operand 0 "" "")
12909         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12910               (match_operand 2 "" "g,g")))
12911    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12912    (use (reg:SI LR_REGNO))
12913    (simple_return)]
12914   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12915   "*
12916 {
12917   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12918     output_asm_insn (\"crxor 6,6,6\", operands);
12919
12920   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12921     output_asm_insn (\"creqv 6,6,6\", operands);
12922
12923   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12924 }"
12925   [(set_attr "type" "branch")
12926    (set_attr "length" "4,8")])
12927
12928 (define_insn "*sibcall_nonlocal_aix<mode>"
12929   [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
12930          (match_operand 1 "" "g,g"))
12931    (use (match_operand:SI 2 "immediate_operand" "O,O"))
12932    (use (reg:SI LR_REGNO))
12933    (simple_return)]
12934   "DEFAULT_ABI == ABI_AIX
12935    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12936   "@
12937    b %z0
12938    b%T0"
12939   [(set_attr "type" "branch")
12940    (set_attr "length" "4")])
12941
12942 (define_insn "*sibcall_value_nonlocal_aix<mode>"
12943   [(set (match_operand 0 "" "")
12944         (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
12945               (match_operand 2 "" "g,g")))
12946    (use (match_operand:SI 3 "immediate_operand" "O,O"))
12947    (use (reg:SI LR_REGNO))
12948    (simple_return)]
12949   "DEFAULT_ABI == ABI_AIX
12950    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12951   "@
12952    b %z1
12953    b%T1"
12954   [(set_attr "type" "branch")
12955    (set_attr "length" "4")])
12956
12957 (define_insn "*sibcall_nonlocal_sysv<mode>"
12958   [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c"))
12959          (match_operand 1 "" ""))
12960    (use (match_operand 2 "immediate_operand" "O,n,O,n"))
12961    (use (reg:SI LR_REGNO))
12962    (simple_return)]
12963   "(DEFAULT_ABI == ABI_DARWIN
12964     || DEFAULT_ABI == ABI_V4)
12965    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12966   "*
12967 {
12968   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12969     output_asm_insn (\"crxor 6,6,6\", operands);
12970
12971   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12972     output_asm_insn (\"creqv 6,6,6\", operands);
12973
12974   if (which_alternative >= 2)
12975     return \"b%T0\";
12976   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12977     {
12978       gcc_assert (!TARGET_SECURE_PLT);
12979       return \"b %z0@plt\";
12980     }
12981   else
12982     return \"b %z0\";
12983 }"
12984   [(set_attr "type" "branch")
12985    (set_attr "length" "4,8,4,8")])
12986
12987 (define_expand "sibcall_value"
12988   [(parallel [(set (match_operand 0 "register_operand" "")
12989                 (call (mem:SI (match_operand 1 "address_operand" ""))
12990                       (match_operand 2 "" "")))
12991               (use (match_operand 3 "" ""))
12992               (use (reg:SI LR_REGNO))
12993               (simple_return)])]
12994   ""
12995   "
12996 {
12997 #if TARGET_MACHO
12998   if (MACHOPIC_INDIRECT)
12999     operands[1] = machopic_indirect_call_target (operands[1]);
13000 #endif
13001
13002   gcc_assert (GET_CODE (operands[1]) == MEM);
13003   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
13004
13005   operands[1] = XEXP (operands[1], 0);
13006 }")
13007
13008 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
13009   [(set (match_operand 0 "" "")
13010         (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c"))
13011               (match_operand 2 "" "")))
13012    (use (match_operand:SI 3 "immediate_operand" "O,n,O,n"))
13013    (use (reg:SI LR_REGNO))
13014    (simple_return)]
13015   "(DEFAULT_ABI == ABI_DARWIN
13016     || DEFAULT_ABI == ABI_V4)
13017    && (INTVAL (operands[3]) & CALL_LONG) == 0"
13018   "*
13019 {
13020   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
13021     output_asm_insn (\"crxor 6,6,6\", operands);
13022
13023   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
13024     output_asm_insn (\"creqv 6,6,6\", operands);
13025
13026   if (which_alternative >= 2)
13027     return \"b%T1\";
13028   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
13029     {
13030       gcc_assert (!TARGET_SECURE_PLT);
13031       return \"b %z1@plt\";
13032     }
13033   else
13034     return \"b %z1\";
13035 }"
13036   [(set_attr "type" "branch")
13037    (set_attr "length" "4,8,4,8")])
13038
13039 (define_expand "sibcall_epilogue"
13040   [(use (const_int 0))]
13041   ""
13042 {
13043   if (!TARGET_SCHED_PROLOG)
13044     emit_insn (gen_blockage ());
13045   rs6000_emit_epilogue (TRUE);
13046   DONE;
13047 })
13048
13049 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
13050 ;; all of memory.  This blocks insns from being moved across this point.
13051
13052 (define_insn "blockage"
13053   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
13054   ""
13055   "")
13056
13057 (define_insn "probe_stack"
13058   [(set (match_operand 0 "memory_operand" "=m")
13059         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
13060   ""
13061   "*
13062 {
13063   operands[1] = gen_rtx_REG (Pmode, 0);
13064   return \"{st%U0%X0|stw%U0%X0} %1,%0\";
13065 }"
13066   [(set_attr "type" "store")
13067    (set_attr "length" "4")])
13068
13069 (define_insn "probe_stack_range<P:mode>"
13070   [(set (match_operand:P 0 "register_operand" "=r")
13071         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
13072                             (match_operand:P 2 "register_operand" "r")]
13073                            UNSPECV_PROBE_STACK_RANGE))]
13074   ""
13075   "* return output_probe_stack_range (operands[0], operands[2]);"
13076   [(set_attr "type" "three")])
13077 \f
13078 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
13079 ;; signed & unsigned, and one type of branch.
13080 ;;
13081 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
13082 ;; insns, and branches.
13083
13084 (define_expand "cbranch<mode>4"
13085   [(use (match_operator 0 "rs6000_cbranch_operator"
13086          [(match_operand:GPR 1 "gpc_reg_operand" "")
13087           (match_operand:GPR 2 "reg_or_short_operand" "")]))
13088    (use (match_operand 3 ""))]
13089   ""
13090   "
13091 {
13092   /* Take care of the possibility that operands[2] might be negative but
13093      this might be a logical operation.  That insn doesn't exist.  */
13094   if (GET_CODE (operands[2]) == CONST_INT
13095       && INTVAL (operands[2]) < 0)
13096     {
13097       operands[2] = force_reg (<MODE>mode, operands[2]);
13098       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
13099                                     GET_MODE (operands[0]),
13100                                     operands[1], operands[2]);
13101    }
13102
13103   rs6000_emit_cbranch (<MODE>mode, operands);
13104   DONE;
13105 }")
13106
13107 (define_expand "cbranch<mode>4"
13108   [(use (match_operator 0 "rs6000_cbranch_operator"
13109          [(match_operand:FP 1 "gpc_reg_operand" "")
13110           (match_operand:FP 2 "gpc_reg_operand" "")]))
13111    (use (match_operand 3 ""))]
13112   ""
13113   "
13114 {
13115   rs6000_emit_cbranch (<MODE>mode, operands);
13116   DONE;
13117 }")
13118
13119 (define_expand "cstore<mode>4"
13120   [(use (match_operator 1 "rs6000_cbranch_operator"
13121          [(match_operand:GPR 2 "gpc_reg_operand" "")
13122           (match_operand:GPR 3 "reg_or_short_operand" "")]))
13123    (clobber (match_operand:SI 0 "register_operand"))]
13124   ""
13125   "
13126 {
13127   /* Take care of the possibility that operands[3] might be negative but
13128      this might be a logical operation.  That insn doesn't exist.  */
13129   if (GET_CODE (operands[3]) == CONST_INT
13130       && INTVAL (operands[3]) < 0)
13131     {
13132       operands[3] = force_reg (<MODE>mode, operands[3]);
13133       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
13134                                     GET_MODE (operands[1]),
13135                                     operands[2], operands[3]);
13136     }
13137
13138   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
13139      For SEQ, likewise, except that comparisons with zero should be done
13140      with an scc insns.  However, due to the order that combine see the
13141      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
13142      the cases we don't want to handle or are best handled by portable
13143      code.  */
13144   if (GET_CODE (operands[1]) == NE)
13145     FAIL;
13146   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
13147        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
13148       && operands[3] == const0_rtx)
13149     FAIL;
13150   rs6000_emit_sCOND (<MODE>mode, operands);
13151   DONE;
13152 }")
13153
13154 (define_expand "cstore<mode>4"
13155   [(use (match_operator 1 "rs6000_cbranch_operator"
13156          [(match_operand:FP 2 "gpc_reg_operand" "")
13157           (match_operand:FP 3 "gpc_reg_operand" "")]))
13158    (clobber (match_operand:SI 0 "register_operand"))]
13159   ""
13160   "
13161 {
13162   rs6000_emit_sCOND (<MODE>mode, operands);
13163   DONE;
13164 }")
13165
13166
13167 (define_expand "stack_protect_set"
13168   [(match_operand 0 "memory_operand" "")
13169    (match_operand 1 "memory_operand" "")]
13170   ""
13171 {
13172 #ifdef TARGET_THREAD_SSP_OFFSET
13173   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
13174   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
13175   operands[1] = gen_rtx_MEM (Pmode, addr);
13176 #endif
13177   if (TARGET_64BIT)
13178     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
13179   else
13180     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
13181   DONE;
13182 })
13183
13184 (define_insn "stack_protect_setsi"
13185   [(set (match_operand:SI 0 "memory_operand" "=m")
13186         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
13187    (set (match_scratch:SI 2 "=&r") (const_int 0))]
13188   "TARGET_32BIT"
13189   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
13190   [(set_attr "type" "three")
13191    (set_attr "length" "12")])
13192
13193 (define_insn "stack_protect_setdi"
13194   [(set (match_operand:DI 0 "memory_operand" "=m")
13195         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
13196    (set (match_scratch:DI 2 "=&r") (const_int 0))]
13197   "TARGET_64BIT"
13198   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
13199   [(set_attr "type" "three")
13200    (set_attr "length" "12")])
13201
13202 (define_expand "stack_protect_test"
13203   [(match_operand 0 "memory_operand" "")
13204    (match_operand 1 "memory_operand" "")
13205    (match_operand 2 "" "")]
13206   ""
13207 {
13208   rtx test, op0, op1;
13209 #ifdef TARGET_THREAD_SSP_OFFSET
13210   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
13211   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
13212   operands[1] = gen_rtx_MEM (Pmode, addr);
13213 #endif
13214   op0 = operands[0];
13215   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
13216   test = gen_rtx_EQ (VOIDmode, op0, op1);
13217   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
13218   DONE;
13219 })
13220
13221 (define_insn "stack_protect_testsi"
13222   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13223         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
13224                       (match_operand:SI 2 "memory_operand" "m,m")]
13225                      UNSPEC_SP_TEST))
13226    (set (match_scratch:SI 4 "=r,r") (const_int 0))
13227    (clobber (match_scratch:SI 3 "=&r,&r"))]
13228   "TARGET_32BIT"
13229   "@
13230    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
13231    {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"
13232   [(set_attr "length" "16,20")])
13233
13234 (define_insn "stack_protect_testdi"
13235   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13236         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
13237                       (match_operand:DI 2 "memory_operand" "m,m")]
13238                      UNSPEC_SP_TEST))
13239    (set (match_scratch:DI 4 "=r,r") (const_int 0))
13240    (clobber (match_scratch:DI 3 "=&r,&r"))]
13241   "TARGET_64BIT"
13242   "@
13243    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
13244    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
13245   [(set_attr "length" "16,20")])
13246
13247 \f
13248 ;; Here are the actual compare insns.
13249 (define_insn "*cmp<mode>_internal1"
13250   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
13251         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
13252                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
13253   ""
13254   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
13255   [(set_attr "type" "cmp")])
13256
13257 ;; If we are comparing a register for equality with a large constant,
13258 ;; we can do this with an XOR followed by a compare.  But this is profitable
13259 ;; only if the large constant is only used for the comparison (and in this
13260 ;; case we already have a register to reuse as scratch).
13261 ;;
13262 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
13263 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
13264
13265 (define_peephole2
13266   [(set (match_operand:SI 0 "register_operand")
13267         (match_operand:SI 1 "logical_const_operand" ""))
13268    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
13269                        [(match_dup 0)
13270                         (match_operand:SI 2 "logical_const_operand" "")]))
13271    (set (match_operand:CC 4 "cc_reg_operand" "")
13272         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
13273                     (match_dup 0)))
13274    (set (pc)
13275         (if_then_else (match_operator 6 "equality_operator"
13276                        [(match_dup 4) (const_int 0)])
13277                       (match_operand 7 "" "")
13278                       (match_operand 8 "" "")))]
13279   "peep2_reg_dead_p (3, operands[0])
13280    && peep2_reg_dead_p (4, operands[4])"
13281  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
13282   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
13283   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
13284  
13285 {
13286   /* Get the constant we are comparing against, and see what it looks like
13287      when sign-extended from 16 to 32 bits.  Then see what constant we could
13288      XOR with SEXTC to get the sign-extended value.  */
13289   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
13290                                               SImode,
13291                                               operands[1], operands[2]);
13292   HOST_WIDE_INT c = INTVAL (cnst);
13293   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
13294   HOST_WIDE_INT xorv = c ^ sextc;
13295
13296   operands[9] = GEN_INT (xorv);
13297   operands[10] = GEN_INT (sextc);
13298 })
13299
13300 (define_insn "*cmpsi_internal2"
13301   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13302         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13303                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
13304   ""
13305   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
13306   [(set_attr "type" "cmp")])
13307
13308 (define_insn "*cmpdi_internal2"
13309   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13310         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
13311                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
13312   ""
13313   "cmpld%I2 %0,%1,%b2"
13314   [(set_attr "type" "cmp")])
13315
13316 ;; The following two insns don't exist as single insns, but if we provide
13317 ;; them, we can swap an add and compare, which will enable us to overlap more
13318 ;; of the required delay between a compare and branch.  We generate code for
13319 ;; them by splitting.
13320
13321 (define_insn ""
13322   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13323         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
13324                     (match_operand:SI 2 "short_cint_operand" "i")))
13325    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13326         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13327   ""
13328   "#"
13329   [(set_attr "length" "8")])
13330
13331 (define_insn ""
13332   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
13333         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13334                        (match_operand:SI 2 "u_short_cint_operand" "i")))
13335    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13336         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13337   ""
13338   "#"
13339   [(set_attr "length" "8")])
13340
13341 (define_split
13342   [(set (match_operand:CC 3 "cc_reg_operand" "")
13343         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
13344                     (match_operand:SI 2 "short_cint_operand" "")))
13345    (set (match_operand:SI 0 "gpc_reg_operand" "")
13346         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13347   ""
13348   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
13349    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13350
13351 (define_split
13352   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
13353         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
13354                        (match_operand:SI 2 "u_short_cint_operand" "")))
13355    (set (match_operand:SI 0 "gpc_reg_operand" "")
13356         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13357   ""
13358   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
13359    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13360
13361 (define_insn "*cmpsf_internal1"
13362   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13363         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
13364                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
13365   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
13366   "fcmpu %0,%1,%2"
13367   [(set_attr "type" "fpcompare")])
13368
13369 (define_insn "*cmpdf_internal1"
13370   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13371         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
13372                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
13373   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
13374    && !VECTOR_UNIT_VSX_P (DFmode)"
13375   "fcmpu %0,%1,%2"
13376   [(set_attr "type" "fpcompare")])
13377
13378 ;; Only need to compare second words if first words equal
13379 (define_insn "*cmptf_internal1"
13380   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13381         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13382                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
13383   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
13384    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13385   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
13386   [(set_attr "type" "fpcompare")
13387    (set_attr "length" "12")])
13388
13389 (define_insn_and_split "*cmptf_internal2"
13390   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13391         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13392                       (match_operand:TF 2 "gpc_reg_operand" "d")))
13393     (clobber (match_scratch:DF 3 "=d"))
13394     (clobber (match_scratch:DF 4 "=d"))
13395     (clobber (match_scratch:DF 5 "=d"))
13396     (clobber (match_scratch:DF 6 "=d"))
13397     (clobber (match_scratch:DF 7 "=d"))
13398     (clobber (match_scratch:DF 8 "=d"))
13399     (clobber (match_scratch:DF 9 "=d"))
13400     (clobber (match_scratch:DF 10 "=d"))
13401     (clobber (match_scratch:GPR 11 "=b"))]
13402   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
13403    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13404   "#"
13405   "&& reload_completed"
13406   [(set (match_dup 3) (match_dup 14))
13407    (set (match_dup 4) (match_dup 15))
13408    (set (match_dup 9) (abs:DF (match_dup 5)))
13409    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
13410    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
13411                            (label_ref (match_dup 12))
13412                            (pc)))
13413    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
13414    (set (pc) (label_ref (match_dup 13)))
13415    (match_dup 12)
13416    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
13417    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
13418    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
13419    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
13420    (match_dup 13)]
13421 {
13422   REAL_VALUE_TYPE rv;
13423   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
13424   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
13425
13426   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
13427   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
13428   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
13429   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
13430   operands[12] = gen_label_rtx ();
13431   operands[13] = gen_label_rtx ();
13432   real_inf (&rv);
13433   operands[14] = force_const_mem (DFmode,
13434                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
13435   operands[15] = force_const_mem (DFmode,
13436                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
13437                                                                 DFmode));
13438   if (TARGET_TOC)
13439     {
13440       rtx tocref;
13441       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
13442       operands[14] = gen_const_mem (DFmode, tocref);
13443       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
13444       operands[15] = gen_const_mem (DFmode, tocref);
13445       set_mem_alias_set (operands[14], get_TOC_alias_set ());
13446       set_mem_alias_set (operands[15], get_TOC_alias_set ());
13447     }
13448 })
13449 \f
13450 ;; Now we have the scc insns.  We can do some combinations because of the
13451 ;; way the machine works.
13452 ;;
13453 ;; Note that this is probably faster if we can put an insn between the
13454 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
13455 ;; cases the insns below which don't use an intermediate CR field will
13456 ;; be used instead.
13457 (define_insn ""
13458   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13459         (match_operator:SI 1 "scc_comparison_operator"
13460                            [(match_operand 2 "cc_reg_operand" "y")
13461                             (const_int 0)]))]
13462   ""
13463   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
13464   [(set (attr "type")
13465      (cond [(match_test "TARGET_MFCRF")
13466                 (const_string "mfcrf")
13467            ]
13468         (const_string "mfcr")))
13469    (set_attr "length" "8")])
13470
13471 ;; Same as above, but get the GT bit.
13472 (define_insn "move_from_CR_gt_bit"
13473   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13474         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
13475   "TARGET_HARD_FLOAT && !TARGET_FPRS"
13476   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
13477   [(set_attr "type" "mfcr")
13478    (set_attr "length" "8")])
13479
13480 ;; Same as above, but get the OV/ORDERED bit.
13481 (define_insn "move_from_CR_ov_bit"
13482   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13483         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
13484   "TARGET_ISEL"
13485   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
13486   [(set_attr "type" "mfcr")
13487    (set_attr "length" "8")])
13488
13489 (define_insn ""
13490   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13491         (match_operator:DI 1 "scc_comparison_operator"
13492                            [(match_operand 2 "cc_reg_operand" "y")
13493                             (const_int 0)]))]
13494   "TARGET_POWERPC64"
13495   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
13496   [(set (attr "type")
13497      (cond [(match_test "TARGET_MFCRF")
13498                 (const_string "mfcrf")
13499            ]
13500         (const_string "mfcr")))
13501    (set_attr "length" "8")])
13502
13503 (define_insn ""
13504   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13505         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13506                                        [(match_operand 2 "cc_reg_operand" "y,y")
13507                                         (const_int 0)])
13508                     (const_int 0)))
13509    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
13510         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13511   "TARGET_32BIT"
13512   "@
13513    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
13514    #"
13515   [(set_attr "type" "delayed_compare")
13516    (set_attr "length" "8,16")])
13517
13518 (define_split
13519   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13520         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13521                                        [(match_operand 2 "cc_reg_operand" "")
13522                                         (const_int 0)])
13523                     (const_int 0)))
13524    (set (match_operand:SI 3 "gpc_reg_operand" "")
13525         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13526   "TARGET_32BIT && reload_completed"
13527   [(set (match_dup 3)
13528         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
13529    (set (match_dup 0)
13530         (compare:CC (match_dup 3)
13531                     (const_int 0)))]
13532   "")
13533
13534 (define_insn ""
13535   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13536         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13537                                       [(match_operand 2 "cc_reg_operand" "y")
13538                                        (const_int 0)])
13539                    (match_operand:SI 3 "const_int_operand" "n")))]
13540   ""
13541   "*
13542 {
13543   int is_bit = ccr_bit (operands[1], 1);
13544   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13545   int count;
13546
13547   if (is_bit >= put_bit)
13548     count = is_bit - put_bit;
13549   else
13550     count = 32 - (put_bit - is_bit);
13551
13552   operands[4] = GEN_INT (count);
13553   operands[5] = GEN_INT (put_bit);
13554
13555   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
13556 }"
13557   [(set (attr "type")
13558      (cond [(match_test "TARGET_MFCRF")
13559                 (const_string "mfcrf")
13560            ]
13561         (const_string "mfcr")))
13562    (set_attr "length" "8")])
13563
13564 (define_insn ""
13565   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13566         (compare:CC
13567          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13568                                        [(match_operand 2 "cc_reg_operand" "y,y")
13569                                         (const_int 0)])
13570                     (match_operand:SI 3 "const_int_operand" "n,n"))
13571          (const_int 0)))
13572    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
13573         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13574                    (match_dup 3)))]
13575   ""
13576   "*
13577 {
13578   int is_bit = ccr_bit (operands[1], 1);
13579   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13580   int count;
13581
13582   /* Force split for non-cc0 compare.  */
13583   if (which_alternative == 1)
13584      return \"#\";
13585
13586   if (is_bit >= put_bit)
13587     count = is_bit - put_bit;
13588   else
13589     count = 32 - (put_bit - is_bit);
13590
13591   operands[5] = GEN_INT (count);
13592   operands[6] = GEN_INT (put_bit);
13593
13594   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
13595 }"
13596   [(set_attr "type" "delayed_compare")
13597    (set_attr "length" "8,16")])
13598
13599 (define_split
13600   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13601         (compare:CC
13602          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13603                                        [(match_operand 2 "cc_reg_operand" "")
13604                                         (const_int 0)])
13605                     (match_operand:SI 3 "const_int_operand" ""))
13606          (const_int 0)))
13607    (set (match_operand:SI 4 "gpc_reg_operand" "")
13608         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13609                    (match_dup 3)))]
13610   "reload_completed"
13611   [(set (match_dup 4)
13612         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13613                    (match_dup 3)))
13614    (set (match_dup 0)
13615         (compare:CC (match_dup 4)
13616                     (const_int 0)))]
13617   "")
13618
13619 ;; There is a 3 cycle delay between consecutive mfcr instructions
13620 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13621
13622 (define_peephole
13623   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13624         (match_operator:SI 1 "scc_comparison_operator"
13625                            [(match_operand 2 "cc_reg_operand" "y")
13626                             (const_int 0)]))
13627    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13628         (match_operator:SI 4 "scc_comparison_operator"
13629                            [(match_operand 5 "cc_reg_operand" "y")
13630                             (const_int 0)]))]
13631   "REGNO (operands[2]) != REGNO (operands[5])"
13632   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13633   [(set_attr "type" "mfcr")
13634    (set_attr "length" "12")])
13635
13636 (define_peephole
13637   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13638         (match_operator:DI 1 "scc_comparison_operator"
13639                            [(match_operand 2 "cc_reg_operand" "y")
13640                             (const_int 0)]))
13641    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13642         (match_operator:DI 4 "scc_comparison_operator"
13643                            [(match_operand 5 "cc_reg_operand" "y")
13644                             (const_int 0)]))]
13645   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13646   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
13647   [(set_attr "type" "mfcr")
13648    (set_attr "length" "12")])
13649
13650 ;; There are some scc insns that can be done directly, without a compare.
13651 ;; These are faster because they don't involve the communications between
13652 ;; the FXU and branch units.   In fact, we will be replacing all of the
13653 ;; integer scc insns here or in the portable methods in emit_store_flag.
13654 ;;
13655 ;; Also support (neg (scc ..)) since that construct is used to replace
13656 ;; branches, (plus (scc ..) ..) since that construct is common and
13657 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13658 ;; cases where it is no more expensive than (neg (scc ..)).
13659
13660 ;; Have reload force a constant into a register for the simple insns that
13661 ;; otherwise won't accept constants.  We do this because it is faster than
13662 ;; the cmp/mfcr sequence we would otherwise generate.
13663
13664 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13665                               (DI "rKJI")])
13666
13667 (define_insn_and_split "*eq<mode>"
13668   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13669         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13670                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13671   "!TARGET_POWER"
13672   "#"
13673   "!TARGET_POWER"
13674   [(set (match_dup 0)
13675         (clz:GPR (match_dup 3)))
13676    (set (match_dup 0)
13677         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13678   {
13679     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13680       {
13681         /* Use output operand as intermediate.  */
13682         operands[3] = operands[0];
13683
13684         if (logical_operand (operands[2], <MODE>mode))
13685           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13686                                   gen_rtx_XOR (<MODE>mode,
13687                                                operands[1], operands[2])));
13688         else
13689           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13690                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13691                                                 negate_rtx (<MODE>mode,
13692                                                             operands[2]))));
13693       }
13694     else
13695       operands[3] = operands[1];
13696
13697     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13698   })
13699
13700 (define_insn_and_split "*eq<mode>_compare"
13701   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13702         (compare:CC
13703          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13704                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13705          (const_int 0)))
13706    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13707         (eq:P (match_dup 1) (match_dup 2)))]
13708   "!TARGET_POWER && optimize_size"
13709   "#"
13710   "!TARGET_POWER && optimize_size"
13711   [(set (match_dup 0)
13712         (clz:P (match_dup 4)))
13713    (parallel [(set (match_dup 3)
13714                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13715                                (const_int 0)))
13716               (set (match_dup 0)
13717                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13718   {
13719     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13720       {
13721         /* Use output operand as intermediate.  */
13722         operands[4] = operands[0];
13723
13724         if (logical_operand (operands[2], <MODE>mode))
13725           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13726                                   gen_rtx_XOR (<MODE>mode,
13727                                                operands[1], operands[2])));
13728         else
13729           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13730                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13731                                                 negate_rtx (<MODE>mode,
13732                                                             operands[2]))));
13733       }
13734     else
13735       operands[4] = operands[1];
13736
13737     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13738   })
13739
13740 (define_insn "*eqsi_power"
13741   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
13742         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13743                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
13744    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
13745   "TARGET_POWER"
13746   "@
13747    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13748    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
13749    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13750    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
13751    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
13752   [(set_attr "type" "three,two,three,three,three")
13753    (set_attr "length" "12,8,12,12,12")])
13754
13755 ;; We have insns of the form shown by the first define_insn below.  If
13756 ;; there is something inside the comparison operation, we must split it.
13757 (define_split
13758   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13759         (plus:SI (match_operator 1 "comparison_operator"
13760                                  [(match_operand:SI 2 "" "")
13761                                   (match_operand:SI 3
13762                                                     "reg_or_cint_operand" "")])
13763                  (match_operand:SI 4 "gpc_reg_operand" "")))
13764    (clobber (match_operand:SI 5 "register_operand" ""))]
13765   "! gpc_reg_operand (operands[2], SImode)"
13766   [(set (match_dup 5) (match_dup 2))
13767    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
13768                                (match_dup 4)))])
13769
13770 (define_insn "*plus_eqsi"
13771   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13772         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13773                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13774                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13775   "TARGET_32BIT"
13776   "@
13777    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13778    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
13779    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13780    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
13781    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
13782   [(set_attr "type" "three,two,three,three,three")
13783    (set_attr "length" "12,8,12,12,12")])
13784
13785 (define_insn "*compare_plus_eqsi"
13786   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13787         (compare:CC
13788          (plus:SI
13789           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13790                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13791           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13792          (const_int 0)))
13793    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13794   "TARGET_32BIT && optimize_size"
13795   "@
13796    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13797    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
13798    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13799    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13800    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13801    #
13802    #
13803    #
13804    #
13805    #"
13806   [(set_attr "type" "compare")
13807    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13808
13809 (define_split
13810   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13811         (compare:CC
13812          (plus:SI
13813           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13814                  (match_operand:SI 2 "scc_eq_operand" ""))
13815           (match_operand:SI 3 "gpc_reg_operand" ""))
13816          (const_int 0)))
13817    (clobber (match_scratch:SI 4 ""))]
13818   "TARGET_32BIT && optimize_size && reload_completed"
13819   [(set (match_dup 4)
13820         (plus:SI (eq:SI (match_dup 1)
13821                  (match_dup 2))
13822           (match_dup 3)))
13823    (set (match_dup 0)
13824         (compare:CC (match_dup 4)
13825                     (const_int 0)))]
13826   "")
13827
13828 (define_insn "*plus_eqsi_compare"
13829   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13830         (compare:CC
13831          (plus:SI
13832           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13833                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13834           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13835          (const_int 0)))
13836    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13837         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13838   "TARGET_32BIT && optimize_size"
13839   "@
13840    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13841    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
13842    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13843    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13844    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13845    #
13846    #
13847    #
13848    #
13849    #"
13850   [(set_attr "type" "compare")
13851    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13852
13853 (define_split
13854   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13855         (compare:CC
13856          (plus:SI
13857           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13858                  (match_operand:SI 2 "scc_eq_operand" ""))
13859           (match_operand:SI 3 "gpc_reg_operand" ""))
13860          (const_int 0)))
13861    (set (match_operand:SI 0 "gpc_reg_operand" "")
13862         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13863   "TARGET_32BIT && optimize_size && reload_completed"
13864   [(set (match_dup 0)
13865         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13866    (set (match_dup 4)
13867         (compare:CC (match_dup 0)
13868                     (const_int 0)))]
13869   "")
13870
13871 (define_insn "*neg_eq0<mode>"
13872   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13873         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13874                      (const_int 0))))]
13875   ""
13876   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
13877   [(set_attr "type" "two")
13878    (set_attr "length" "8")])
13879
13880 (define_insn_and_split "*neg_eq<mode>"
13881   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13882         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
13883                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
13884   ""
13885   "#"
13886   ""
13887   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
13888   {
13889     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13890       {
13891         /* Use output operand as intermediate.  */
13892         operands[3] = operands[0];
13893
13894         if (logical_operand (operands[2], <MODE>mode))
13895           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13896                                   gen_rtx_XOR (<MODE>mode,
13897                                                operands[1], operands[2])));
13898         else
13899           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13900                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13901                                                 negate_rtx (<MODE>mode,
13902                                                             operands[2]))));
13903       }
13904     else
13905       operands[3] = operands[1];
13906   })
13907
13908 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
13909 ;; since it nabs/sr is just as fast.
13910 (define_insn "*ne0si"
13911   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13912         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
13913                      (const_int 31)))
13914    (clobber (match_scratch:SI 2 "=&r"))]
13915   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
13916   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
13917   [(set_attr "type" "two")
13918    (set_attr "length" "8")])
13919
13920 (define_insn "*ne0di"
13921   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13922         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
13923                      (const_int 63)))
13924    (clobber (match_scratch:DI 2 "=&r"))]
13925   "TARGET_64BIT"
13926   "addic %2,%1,-1\;subfe %0,%2,%1"
13927   [(set_attr "type" "two")
13928    (set_attr "length" "8")])
13929
13930 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
13931 (define_insn "*plus_ne0si"
13932   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13933         (plus:SI (lshiftrt:SI
13934                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
13935                   (const_int 31))
13936                  (match_operand:SI 2 "gpc_reg_operand" "r")))
13937    (clobber (match_scratch:SI 3 "=&r"))]
13938   "TARGET_32BIT"
13939   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
13940   [(set_attr "type" "two")
13941    (set_attr "length" "8")])
13942
13943 (define_insn "*plus_ne0di"
13944   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13945         (plus:DI (lshiftrt:DI
13946                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
13947                   (const_int 63))
13948                  (match_operand:DI 2 "gpc_reg_operand" "r")))
13949    (clobber (match_scratch:DI 3 "=&r"))]
13950   "TARGET_64BIT"
13951   "addic %3,%1,-1\;addze %0,%2"
13952   [(set_attr "type" "two")
13953    (set_attr "length" "8")])
13954
13955 (define_insn "*compare_plus_ne0si"
13956   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13957         (compare:CC
13958          (plus:SI (lshiftrt:SI
13959                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
13960                    (const_int 31))
13961                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13962          (const_int 0)))
13963    (clobber (match_scratch:SI 3 "=&r,&r"))
13964    (clobber (match_scratch:SI 4 "=X,&r"))]
13965   "TARGET_32BIT"
13966   "@
13967    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
13968    #"
13969   [(set_attr "type" "compare")
13970    (set_attr "length" "8,12")])
13971
13972 (define_split
13973   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13974         (compare:CC
13975          (plus:SI (lshiftrt:SI
13976                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
13977                    (const_int 31))
13978                   (match_operand:SI 2 "gpc_reg_operand" ""))
13979          (const_int 0)))
13980    (clobber (match_scratch:SI 3 ""))
13981    (clobber (match_scratch:SI 4 ""))]
13982   "TARGET_32BIT && reload_completed"
13983   [(parallel [(set (match_dup 3)
13984                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
13985                                          (const_int 31))
13986                             (match_dup 2)))
13987               (clobber (match_dup 4))])
13988    (set (match_dup 0)
13989         (compare:CC (match_dup 3)
13990                     (const_int 0)))]
13991   "")
13992
13993 (define_insn "*compare_plus_ne0di"
13994   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13995         (compare:CC
13996          (plus:DI (lshiftrt:DI
13997                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
13998                    (const_int 63))
13999                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14000          (const_int 0)))
14001    (clobber (match_scratch:DI 3 "=&r,&r"))]
14002   "TARGET_64BIT"
14003   "@
14004    addic %3,%1,-1\;addze. %3,%2
14005    #"
14006   [(set_attr "type" "compare")
14007    (set_attr "length" "8,12")])
14008
14009 (define_split
14010   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14011         (compare:CC
14012          (plus:DI (lshiftrt:DI
14013                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
14014                    (const_int 63))
14015                   (match_operand:DI 2 "gpc_reg_operand" ""))
14016          (const_int 0)))
14017    (clobber (match_scratch:DI 3 ""))]
14018   "TARGET_64BIT && reload_completed"
14019   [(set (match_dup 3)
14020         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
14021                    (const_int 63))
14022                   (match_dup 2)))
14023    (set (match_dup 0)
14024         (compare:CC (match_dup 3)
14025                     (const_int 0)))]
14026   "")
14027
14028 (define_insn "*plus_ne0si_compare"
14029   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14030         (compare:CC
14031          (plus:SI (lshiftrt:SI
14032                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
14033                    (const_int 31))
14034                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14035          (const_int 0)))
14036    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14037         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14038                  (match_dup 2)))
14039    (clobber (match_scratch:SI 3 "=&r,&r"))]
14040   "TARGET_32BIT"
14041   "@
14042    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
14043    #"
14044   [(set_attr "type" "compare")
14045    (set_attr "length" "8,12")])
14046
14047 (define_split
14048   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14049         (compare:CC
14050          (plus:SI (lshiftrt:SI
14051                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
14052                    (const_int 31))
14053                   (match_operand:SI 2 "gpc_reg_operand" ""))
14054          (const_int 0)))
14055    (set (match_operand:SI 0 "gpc_reg_operand" "")
14056         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14057                  (match_dup 2)))
14058    (clobber (match_scratch:SI 3 ""))]
14059   "TARGET_32BIT && reload_completed"
14060   [(parallel [(set (match_dup 0)
14061         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
14062                  (match_dup 2)))
14063    (clobber (match_dup 3))])
14064    (set (match_dup 4)
14065         (compare:CC (match_dup 0)
14066                     (const_int 0)))]
14067   "")
14068
14069 (define_insn "*plus_ne0di_compare"
14070   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14071         (compare:CC
14072          (plus:DI (lshiftrt:DI
14073                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
14074                    (const_int 63))
14075                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14076          (const_int 0)))
14077    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
14078         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14079                  (match_dup 2)))
14080    (clobber (match_scratch:DI 3 "=&r,&r"))]
14081   "TARGET_64BIT"
14082   "@
14083    addic %3,%1,-1\;addze. %0,%2
14084    #"
14085   [(set_attr "type" "compare")
14086    (set_attr "length" "8,12")])
14087
14088 (define_split
14089   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
14090         (compare:CC
14091          (plus:DI (lshiftrt:DI
14092                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
14093                    (const_int 63))
14094                   (match_operand:DI 2 "gpc_reg_operand" ""))
14095          (const_int 0)))
14096    (set (match_operand:DI 0 "gpc_reg_operand" "")
14097         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14098                  (match_dup 2)))
14099    (clobber (match_scratch:DI 3 ""))]
14100   "TARGET_64BIT && reload_completed"
14101   [(parallel [(set (match_dup 0)
14102         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
14103                  (match_dup 2)))
14104    (clobber (match_dup 3))])
14105    (set (match_dup 4)
14106         (compare:CC (match_dup 0)
14107                     (const_int 0)))]
14108   "")
14109
14110 (define_insn ""
14111   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14112         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14113                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
14114    (clobber (match_scratch:SI 3 "=r,X"))]
14115   "TARGET_POWER"
14116   "@
14117    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
14118    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
14119   [(set_attr "length" "12")])
14120
14121 (define_insn ""
14122   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14123         (compare:CC
14124          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14125                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14126          (const_int 0)))
14127    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
14128         (le:SI (match_dup 1) (match_dup 2)))
14129    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
14130   "TARGET_POWER"
14131   "@
14132    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14133    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
14134    #
14135    #"
14136   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
14137    (set_attr "length" "12,12,16,16")])
14138
14139 (define_split
14140   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14141         (compare:CC
14142          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14143                 (match_operand:SI 2 "reg_or_short_operand" ""))
14144          (const_int 0)))
14145    (set (match_operand:SI 0 "gpc_reg_operand" "")
14146         (le:SI (match_dup 1) (match_dup 2)))
14147    (clobber (match_scratch:SI 3 ""))]
14148   "TARGET_POWER && reload_completed"
14149   [(parallel [(set (match_dup 0)
14150         (le:SI (match_dup 1) (match_dup 2)))
14151    (clobber (match_dup 3))])
14152    (set (match_dup 4)
14153         (compare:CC (match_dup 0)
14154                     (const_int 0)))]
14155   "")
14156
14157 (define_insn ""
14158   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14159         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14160                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
14161                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
14162   "TARGET_POWER"
14163   "@
14164    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
14165    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
14166   [(set_attr "length" "12")])
14167
14168 (define_insn ""
14169   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14170         (compare:CC
14171          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14172                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14173                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14174          (const_int 0)))
14175    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14176   "TARGET_POWER"
14177   "@
14178    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14179    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
14180    #
14181    #"
14182   [(set_attr "type" "compare")
14183    (set_attr "length" "12,12,16,16")])
14184
14185 (define_split
14186   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14187         (compare:CC
14188          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14189                          (match_operand:SI 2 "reg_or_short_operand" ""))
14190                   (match_operand:SI 3 "gpc_reg_operand" ""))
14191          (const_int 0)))
14192    (clobber (match_scratch:SI 4 ""))]
14193   "TARGET_POWER && reload_completed"
14194   [(set (match_dup 4)
14195         (plus:SI (le:SI (match_dup 1) (match_dup 2))
14196                  (match_dup 3)))
14197    (set (match_dup 0)
14198         (compare:CC (match_dup 4)
14199                     (const_int 0)))]
14200   "")
14201
14202 (define_insn ""
14203   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14204         (compare:CC
14205          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14206                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
14207                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14208          (const_int 0)))
14209    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14210         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14211   "TARGET_POWER"
14212   "@
14213    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14214    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
14215    #
14216    #"
14217   [(set_attr "type" "compare")
14218    (set_attr "length" "12,12,16,16")])
14219
14220 (define_split
14221   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14222         (compare:CC
14223          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
14224                          (match_operand:SI 2 "reg_or_short_operand" ""))
14225                   (match_operand:SI 3 "gpc_reg_operand" ""))
14226          (const_int 0)))
14227    (set (match_operand:SI 0 "gpc_reg_operand" "")
14228         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14229   "TARGET_POWER && reload_completed"
14230   [(set (match_dup 0)
14231         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14232    (set (match_dup 4)
14233         (compare:CC (match_dup 0)
14234                     (const_int 0)))]
14235   "")
14236
14237 (define_insn ""
14238   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14239         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14240                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
14241   "TARGET_POWER"
14242   "@
14243    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
14244    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
14245   [(set_attr "length" "12")])
14246
14247 (define_insn "*leu<mode>"
14248   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14249         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14250                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14251   ""
14252   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14253   [(set_attr "type" "three")
14254    (set_attr "length" "12")])
14255
14256 (define_insn "*leu<mode>_compare"
14257   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14258         (compare:CC
14259          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14260                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14261          (const_int 0)))
14262    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14263         (leu:P (match_dup 1) (match_dup 2)))]
14264   ""
14265   "@
14266    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14267    #"
14268   [(set_attr "type" "compare")
14269    (set_attr "length" "12,16")])
14270
14271 (define_split
14272   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14273         (compare:CC
14274          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
14275                 (match_operand:P 2 "reg_or_short_operand" ""))
14276          (const_int 0)))
14277    (set (match_operand:P 0 "gpc_reg_operand" "")
14278         (leu:P (match_dup 1) (match_dup 2)))]
14279   "reload_completed"
14280   [(set (match_dup 0)
14281         (leu:P (match_dup 1) (match_dup 2)))
14282    (set (match_dup 3)
14283         (compare:CC (match_dup 0)
14284                     (const_int 0)))]
14285   "")
14286
14287 (define_insn "*plus_leu<mode>"
14288   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14289         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14290                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14291                 (match_operand:P 3 "gpc_reg_operand" "r")))]
14292   ""
14293   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
14294   [(set_attr "type" "two")
14295    (set_attr "length" "8")])
14296
14297 (define_insn ""
14298   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14299         (compare:CC
14300          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14301                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14302                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14303          (const_int 0)))
14304    (clobber (match_scratch:SI 4 "=&r,&r"))]
14305   "TARGET_32BIT"
14306   "@
14307    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
14308    #"
14309   [(set_attr "type" "compare")
14310    (set_attr "length" "8,12")])
14311
14312 (define_split
14313   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14314         (compare:CC
14315          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14316                           (match_operand:SI 2 "reg_or_short_operand" ""))
14317                   (match_operand:SI 3 "gpc_reg_operand" ""))
14318          (const_int 0)))
14319    (clobber (match_scratch:SI 4 ""))]
14320   "TARGET_32BIT && reload_completed"
14321   [(set (match_dup 4)
14322         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
14323                   (match_dup 3)))
14324    (set (match_dup 0)
14325         (compare:CC (match_dup 4)
14326                     (const_int 0)))]
14327   "")
14328
14329 (define_insn ""
14330   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14331         (compare:CC
14332          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14333                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14334                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14335          (const_int 0)))
14336    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14337         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14338   "TARGET_32BIT"
14339   "@
14340    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
14341    #"
14342   [(set_attr "type" "compare")
14343    (set_attr "length" "8,12")])
14344
14345 (define_split
14346   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14347         (compare:CC
14348          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14349                           (match_operand:SI 2 "reg_or_short_operand" ""))
14350                   (match_operand:SI 3 "gpc_reg_operand" ""))
14351          (const_int 0)))
14352    (set (match_operand:SI 0 "gpc_reg_operand" "")
14353         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14354   "TARGET_32BIT && reload_completed"
14355   [(set (match_dup 0)
14356         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14357    (set (match_dup 4)
14358         (compare:CC (match_dup 0)
14359                     (const_int 0)))]
14360   "")
14361
14362 (define_insn "*neg_leu<mode>"
14363   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14364         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14365                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14366   ""
14367   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
14368    [(set_attr "type" "three")
14369     (set_attr "length" "12")])
14370
14371 (define_insn "*and_neg_leu<mode>"
14372   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14373         (and:P (neg:P
14374                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
14375                         (match_operand:P 2 "reg_or_short_operand" "rI")))
14376                 (match_operand:P 3 "gpc_reg_operand" "r")))]
14377   ""
14378   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
14379   [(set_attr "type" "three")
14380    (set_attr "length" "12")])
14381
14382 (define_insn ""
14383   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14384         (compare:CC
14385          (and:SI (neg:SI
14386                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14387                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
14388                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14389          (const_int 0)))
14390    (clobber (match_scratch:SI 4 "=&r,&r"))]
14391   "TARGET_32BIT"
14392   "@
14393    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14394    #"
14395   [(set_attr "type" "compare")
14396    (set_attr "length" "12,16")])
14397
14398 (define_split
14399   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14400         (compare:CC
14401          (and:SI (neg:SI
14402                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14403                           (match_operand:SI 2 "reg_or_short_operand" "")))
14404                  (match_operand:SI 3 "gpc_reg_operand" ""))
14405          (const_int 0)))
14406    (clobber (match_scratch:SI 4 ""))]
14407   "TARGET_32BIT && reload_completed"
14408   [(set (match_dup 4)
14409         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
14410                 (match_dup 3)))
14411    (set (match_dup 0)
14412         (compare:CC (match_dup 4)
14413                     (const_int 0)))]
14414   "")
14415
14416 (define_insn ""
14417   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14418         (compare:CC
14419          (and:SI (neg:SI
14420                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14421                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
14422                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14423          (const_int 0)))
14424    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14425         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14426   "TARGET_32BIT"
14427   "@
14428    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14429    #"
14430   [(set_attr "type" "compare")
14431    (set_attr "length" "12,16")])
14432
14433 (define_split
14434   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14435         (compare:CC
14436          (and:SI (neg:SI
14437                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14438                           (match_operand:SI 2 "reg_or_short_operand" "")))
14439                  (match_operand:SI 3 "gpc_reg_operand" ""))
14440          (const_int 0)))
14441    (set (match_operand:SI 0 "gpc_reg_operand" "")
14442         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14443   "TARGET_32BIT && reload_completed"
14444   [(set (match_dup 0)
14445         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
14446                 (match_dup 3)))
14447    (set (match_dup 4)
14448         (compare:CC (match_dup 0)
14449                     (const_int 0)))]
14450   "")
14451
14452 (define_insn ""
14453   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14454         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14455                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
14456   "TARGET_POWER"
14457   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
14458    [(set_attr "length" "12")])
14459
14460 (define_insn ""
14461   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14462         (compare:CC
14463          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14464                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14465          (const_int 0)))
14466    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14467         (lt:SI (match_dup 1) (match_dup 2)))]
14468   "TARGET_POWER"
14469   "@
14470    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
14471    #"
14472   [(set_attr "type" "delayed_compare")
14473    (set_attr "length" "12,16")])
14474
14475 (define_split
14476   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14477         (compare:CC
14478          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14479                 (match_operand:SI 2 "reg_or_short_operand" ""))
14480          (const_int 0)))
14481    (set (match_operand:SI 0 "gpc_reg_operand" "")
14482         (lt:SI (match_dup 1) (match_dup 2)))]
14483   "TARGET_POWER && reload_completed"
14484   [(set (match_dup 0)
14485         (lt:SI (match_dup 1) (match_dup 2)))
14486    (set (match_dup 3)
14487         (compare:CC (match_dup 0)
14488                     (const_int 0)))]
14489   "")
14490
14491 (define_insn ""
14492   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14493         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14494                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14495                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14496   "TARGET_POWER"
14497   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
14498   [(set_attr "length" "12")])
14499
14500 (define_insn ""
14501   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14502         (compare:CC
14503          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14504                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14505                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14506          (const_int 0)))
14507    (clobber (match_scratch:SI 4 "=&r,&r"))]
14508   "TARGET_POWER"
14509   "@
14510    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
14511    #"
14512   [(set_attr "type" "compare")
14513    (set_attr "length" "12,16")])
14514
14515 (define_split
14516   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14517         (compare:CC
14518          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14519                          (match_operand:SI 2 "reg_or_short_operand" ""))
14520                   (match_operand:SI 3 "gpc_reg_operand" ""))
14521          (const_int 0)))
14522    (clobber (match_scratch:SI 4 ""))]
14523   "TARGET_POWER && reload_completed"
14524   [(set (match_dup 4)
14525         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
14526                  (match_dup 3)))
14527    (set (match_dup 0)
14528         (compare:CC (match_dup 4)
14529                     (const_int 0)))]
14530   "")
14531
14532 (define_insn ""
14533   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14534         (compare:CC
14535          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14536                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14537                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14538          (const_int 0)))
14539    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14540         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14541   "TARGET_POWER"
14542   "@
14543    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
14544    #"
14545   [(set_attr "type" "compare")
14546    (set_attr "length" "12,16")])
14547
14548 (define_split
14549   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14550         (compare:CC
14551          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14552                          (match_operand:SI 2 "reg_or_short_operand" ""))
14553                   (match_operand:SI 3 "gpc_reg_operand" ""))
14554          (const_int 0)))
14555    (set (match_operand:SI 0 "gpc_reg_operand" "")
14556         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14557   "TARGET_POWER && reload_completed"
14558   [(set (match_dup 0)
14559         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14560    (set (match_dup 4)
14561         (compare:CC (match_dup 0)
14562                     (const_int 0)))]
14563   "")
14564
14565 (define_insn ""
14566   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14567         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14568                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14569   "TARGET_POWER"
14570   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
14571   [(set_attr "length" "12")])
14572
14573 (define_insn_and_split "*ltu<mode>"
14574   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14575         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14576                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14577   ""
14578   "#"
14579   ""
14580   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14581    (set (match_dup 0) (neg:P (match_dup 0)))]
14582   "")
14583
14584 (define_insn_and_split "*ltu<mode>_compare"
14585   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14586         (compare:CC
14587          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14588                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14589          (const_int 0)))
14590    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14591         (ltu:P (match_dup 1) (match_dup 2)))]
14592   ""
14593   "#"
14594   ""
14595   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14596    (parallel [(set (match_dup 3)
14597                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14598               (set (match_dup 0) (neg:P (match_dup 0)))])]
14599   "")
14600
14601 (define_insn_and_split "*plus_ltu<mode>"
14602   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
14603         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14604                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14605                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
14606   ""
14607   "#"
14608   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14609   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14610    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14611   "")
14612
14613 (define_insn_and_split "*plus_ltu<mode>_compare"
14614   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14615         (compare:CC
14616          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14617                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14618                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14619          (const_int 0)))
14620    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14621         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14622   ""
14623   "#"
14624   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14625   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14626    (parallel [(set (match_dup 4)
14627                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14628                                (const_int 0)))
14629               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14630   "")
14631
14632 (define_insn "*neg_ltu<mode>"
14633   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14634         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14635                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
14636   ""
14637   "@
14638    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
14639    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
14640   [(set_attr "type" "two")
14641    (set_attr "length" "8")])
14642
14643 (define_insn ""
14644   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14645         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14646                (match_operand:SI 2 "reg_or_short_operand" "rI")))
14647    (clobber (match_scratch:SI 3 "=r"))]
14648   "TARGET_POWER"
14649   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
14650    [(set_attr "length" "12")])
14651
14652 (define_insn ""
14653   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14654         (compare:CC
14655          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14656                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14657          (const_int 0)))
14658    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14659         (ge:SI (match_dup 1) (match_dup 2)))
14660    (clobber (match_scratch:SI 3 "=r,r"))]
14661   "TARGET_POWER"
14662   "@
14663    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
14664    #"
14665   [(set_attr "type" "compare")
14666    (set_attr "length" "12,16")])
14667
14668 (define_split
14669   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14670         (compare:CC
14671          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14672                 (match_operand:SI 2 "reg_or_short_operand" ""))
14673          (const_int 0)))
14674    (set (match_operand:SI 0 "gpc_reg_operand" "")
14675         (ge:SI (match_dup 1) (match_dup 2)))
14676    (clobber (match_scratch:SI 3 ""))]
14677   "TARGET_POWER && reload_completed"
14678   [(parallel [(set (match_dup 0)
14679                    (ge:SI (match_dup 1) (match_dup 2)))
14680               (clobber (match_dup 3))])
14681    (set (match_dup 4)
14682         (compare:CC (match_dup 0)
14683                     (const_int 0)))]
14684   "")
14685
14686 (define_insn ""
14687   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
14688         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14689                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
14690                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
14691   "TARGET_POWER"
14692   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
14693   [(set_attr "length" "12")])
14694
14695 (define_insn ""
14696   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14697         (compare:CC
14698          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14699                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14700                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14701          (const_int 0)))
14702    (clobber (match_scratch:SI 4 "=&r,&r"))]
14703   "TARGET_POWER"
14704   "@
14705    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
14706    #"
14707   [(set_attr "type" "compare")
14708    (set_attr "length" "12,16")])
14709
14710 (define_split
14711   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14712         (compare:CC
14713          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14714                          (match_operand:SI 2 "reg_or_short_operand" ""))
14715                   (match_operand:SI 3 "gpc_reg_operand" ""))
14716          (const_int 0)))
14717    (clobber (match_scratch:SI 4 ""))]
14718   "TARGET_POWER && reload_completed"
14719   [(set (match_dup 4)
14720         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
14721                  (match_dup 3)))
14722    (set (match_dup 0)
14723         (compare:CC (match_dup 4)
14724                     (const_int 0)))]
14725   "")
14726
14727 (define_insn ""
14728   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
14729         (compare:CC
14730          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14731                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
14732                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
14733          (const_int 0)))
14734    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14735         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14736   "TARGET_POWER"
14737   "@
14738    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
14739    #"
14740   [(set_attr "type" "compare")
14741    (set_attr "length" "12,16")])
14742
14743 (define_split
14744   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14745         (compare:CC
14746          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
14747                          (match_operand:SI 2 "reg_or_short_operand" ""))
14748                   (match_operand:SI 3 "gpc_reg_operand" ""))
14749          (const_int 0)))
14750    (set (match_operand:SI 0 "gpc_reg_operand" "")
14751         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14752   "TARGET_POWER && reload_completed"
14753   [(set (match_dup 0)
14754         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14755    (set (match_dup 4)
14756         (compare:CC (match_dup 0)
14757                     (const_int 0)))]
14758   "")
14759
14760 (define_insn ""
14761   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14762         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14763                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
14764   "TARGET_POWER"
14765   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
14766   [(set_attr "length" "12")])
14767
14768 (define_insn "*geu<mode>"
14769   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14770         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14771                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14772   ""
14773   "@
14774    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
14775    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
14776   [(set_attr "type" "three")
14777    (set_attr "length" "12")])
14778
14779 (define_insn "*geu<mode>_compare"
14780   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14781         (compare:CC
14782          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14783                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14784          (const_int 0)))
14785    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14786         (geu:P (match_dup 1) (match_dup 2)))]
14787   ""
14788   "@
14789    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14790    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
14791    #
14792    #"
14793   [(set_attr "type" "compare")
14794    (set_attr "length" "12,12,16,16")])
14795
14796 (define_split
14797   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14798         (compare:CC
14799          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
14800                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
14801          (const_int 0)))
14802    (set (match_operand:P 0 "gpc_reg_operand" "")
14803         (geu:P (match_dup 1) (match_dup 2)))]
14804   "reload_completed"
14805   [(set (match_dup 0)
14806         (geu:P (match_dup 1) (match_dup 2)))
14807    (set (match_dup 3)
14808         (compare:CC (match_dup 0)
14809                     (const_int 0)))]
14810   "")
14811
14812 (define_insn "*plus_geu<mode>"
14813   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14814         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14815                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14816                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14817   ""
14818   "@
14819    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
14820    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
14821   [(set_attr "type" "two")
14822    (set_attr "length" "8")])
14823
14824 (define_insn ""
14825   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14826         (compare:CC
14827          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14828                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14829                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14830          (const_int 0)))
14831    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14832   "TARGET_32BIT"
14833   "@
14834    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
14835    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
14836    #
14837    #"
14838   [(set_attr "type" "compare")
14839    (set_attr "length" "8,8,12,12")])
14840
14841 (define_split
14842   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14843         (compare:CC
14844          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14845                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14846                   (match_operand:SI 3 "gpc_reg_operand" ""))
14847          (const_int 0)))
14848    (clobber (match_scratch:SI 4 ""))]
14849   "TARGET_32BIT && reload_completed"
14850   [(set (match_dup 4)
14851         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
14852                   (match_dup 3)))
14853    (set (match_dup 0)
14854         (compare:CC (match_dup 4)
14855                     (const_int 0)))]
14856   "")
14857
14858 (define_insn ""
14859   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14860         (compare:CC
14861          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14862                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14863                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14864          (const_int 0)))
14865    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14866         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14867   "TARGET_32BIT"
14868   "@
14869    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
14870    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
14871    #
14872    #"
14873   [(set_attr "type" "compare")
14874    (set_attr "length" "8,8,12,12")])
14875
14876 (define_split
14877   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14878         (compare:CC
14879          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14880                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14881                   (match_operand:SI 3 "gpc_reg_operand" ""))
14882          (const_int 0)))
14883    (set (match_operand:SI 0 "gpc_reg_operand" "")
14884         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14885   "TARGET_32BIT && reload_completed"
14886   [(set (match_dup 0)
14887         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14888    (set (match_dup 4)
14889         (compare:CC (match_dup 0)
14890                     (const_int 0)))]
14891   "")
14892
14893 (define_insn "*neg_geu<mode>"
14894   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14895         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14896                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
14897   ""
14898   "@
14899    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
14900    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
14901   [(set_attr "type" "three")
14902    (set_attr "length" "12")])
14903
14904 (define_insn "*and_neg_geu<mode>"
14905   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14906         (and:P (neg:P
14907                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14908                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
14909                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14910   ""
14911   "@
14912    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
14913    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
14914   [(set_attr "type" "three")
14915    (set_attr "length" "12")])
14916
14917 (define_insn ""
14918   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14919         (compare:CC
14920          (and:SI (neg:SI
14921                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14922                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14923                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14924          (const_int 0)))
14925    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14926   "TARGET_32BIT"
14927   "@
14928    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14929    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
14930    #
14931    #"
14932   [(set_attr "type" "compare")
14933    (set_attr "length" "12,12,16,16")])
14934
14935 (define_split
14936   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14937         (compare:CC
14938          (and:SI (neg:SI
14939                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14940                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14941                  (match_operand:SI 3 "gpc_reg_operand" ""))
14942          (const_int 0)))
14943    (clobber (match_scratch:SI 4 ""))]
14944   "TARGET_32BIT && reload_completed"
14945   [(set (match_dup 4)
14946         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
14947                 (match_dup 3)))
14948    (set (match_dup 0)
14949         (compare:CC (match_dup 4)
14950                     (const_int 0)))]
14951   "")
14952
14953 (define_insn ""
14954   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14955         (compare:CC
14956          (and:SI (neg:SI
14957                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14958                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14959                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14960          (const_int 0)))
14961    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14962         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14963   "TARGET_32BIT"
14964   "@
14965    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14966    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
14967    #
14968    #"
14969   [(set_attr "type" "compare")
14970    (set_attr "length" "12,12,16,16")])
14971
14972 (define_split
14973   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14974         (compare:CC
14975          (and:SI (neg:SI
14976                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14977                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14978                  (match_operand:SI 3 "gpc_reg_operand" ""))
14979          (const_int 0)))
14980    (set (match_operand:SI 0 "gpc_reg_operand" "")
14981         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14982   "TARGET_32BIT && reload_completed"
14983   [(set (match_dup 0)
14984         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
14985    (set (match_dup 4)
14986         (compare:CC (match_dup 0)
14987                     (const_int 0)))]
14988   "")
14989
14990 (define_insn ""
14991   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14992         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
14993                (match_operand:SI 2 "reg_or_short_operand" "r")))]
14994   "TARGET_POWER"
14995   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
14996   [(set_attr "length" "12")])
14997
14998 (define_insn ""
14999   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15000         (compare:CC
15001          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15002                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15003          (const_int 0)))
15004    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
15005         (gt:SI (match_dup 1) (match_dup 2)))]
15006   "TARGET_POWER"
15007   "@
15008    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
15009    #"
15010   [(set_attr "type" "delayed_compare")
15011    (set_attr "length" "12,16")])
15012
15013 (define_split
15014   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
15015         (compare:CC
15016          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15017                 (match_operand:SI 2 "reg_or_short_operand" ""))
15018          (const_int 0)))
15019    (set (match_operand:SI 0 "gpc_reg_operand" "")
15020         (gt:SI (match_dup 1) (match_dup 2)))]
15021   "TARGET_POWER && reload_completed"
15022   [(set (match_dup 0)
15023         (gt:SI (match_dup 1) (match_dup 2)))
15024    (set (match_dup 3)
15025         (compare:CC (match_dup 0)
15026                     (const_int 0)))]
15027   "")
15028
15029 (define_insn "*plus_gt0<mode>"
15030   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
15031         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
15032                       (const_int 0))
15033                  (match_operand:P 2 "gpc_reg_operand" "r")))]
15034   ""
15035   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
15036   [(set_attr "type" "three")
15037    (set_attr "length" "12")])
15038
15039 (define_insn ""
15040   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15041         (compare:CC
15042          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15043                          (const_int 0))
15044                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
15045          (const_int 0)))
15046    (clobber (match_scratch:SI 3 "=&r,&r"))]
15047   "TARGET_32BIT"
15048   "@
15049    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
15050    #"
15051   [(set_attr "type" "compare")
15052    (set_attr "length" "12,16")])
15053
15054 (define_split
15055   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15056         (compare:CC
15057          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15058                          (const_int 0))
15059                   (match_operand:SI 2 "gpc_reg_operand" ""))
15060          (const_int 0)))
15061    (clobber (match_scratch:SI 3 ""))]
15062   "TARGET_32BIT && reload_completed"
15063   [(set (match_dup 3)
15064         (plus:SI (gt:SI (match_dup 1) (const_int 0))
15065                   (match_dup 2)))
15066    (set (match_dup 0)
15067         (compare:CC (match_dup 3)
15068                     (const_int 0)))]
15069   "")
15070
15071 (define_insn ""
15072   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15073         (compare:CC
15074          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
15075                          (const_int 0))
15076                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
15077          (const_int 0)))
15078    (clobber (match_scratch:DI 3 "=&r,&r"))]
15079   "TARGET_64BIT"
15080   "@
15081    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
15082    #"
15083   [(set_attr "type" "compare")
15084    (set_attr "length" "12,16")])
15085
15086 (define_split
15087   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
15088         (compare:CC
15089          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
15090                          (const_int 0))
15091                   (match_operand:DI 2 "gpc_reg_operand" ""))
15092          (const_int 0)))
15093    (clobber (match_scratch:DI 3 ""))]
15094   "TARGET_64BIT && reload_completed"
15095   [(set (match_dup 3)
15096         (plus:DI (gt:DI (match_dup 1) (const_int 0))
15097                  (match_dup 2)))
15098    (set (match_dup 0)
15099         (compare:CC (match_dup 3)
15100                     (const_int 0)))]
15101   "")
15102
15103 (define_insn ""
15104   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15105         (compare:CC
15106          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15107                          (const_int 0))
15108                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
15109          (const_int 0)))
15110    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
15111         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
15112   "TARGET_32BIT"
15113   "@
15114    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
15115    #"
15116   [(set_attr "type" "compare")
15117    (set_attr "length" "12,16")])
15118
15119 (define_split
15120   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
15121         (compare:CC
15122          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15123                          (const_int 0))
15124                   (match_operand:SI 2 "gpc_reg_operand" ""))
15125          (const_int 0)))
15126    (set (match_operand:SI 0 "gpc_reg_operand" "")
15127         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
15128   "TARGET_32BIT && reload_completed"
15129   [(set (match_dup 0)
15130         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
15131    (set (match_dup 3)
15132         (compare:CC (match_dup 0)
15133                     (const_int 0)))]
15134   "")
15135
15136 (define_insn ""
15137   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15138         (compare:CC
15139          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
15140                          (const_int 0))
15141                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
15142          (const_int 0)))
15143    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
15144         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
15145   "TARGET_64BIT"
15146   "@
15147    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
15148    #"
15149   [(set_attr "type" "compare")
15150    (set_attr "length" "12,16")])
15151
15152 (define_split
15153   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
15154         (compare:CC
15155          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
15156                          (const_int 0))
15157                   (match_operand:DI 2 "gpc_reg_operand" ""))
15158          (const_int 0)))
15159    (set (match_operand:DI 0 "gpc_reg_operand" "")
15160         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
15161   "TARGET_64BIT && reload_completed"
15162   [(set (match_dup 0)
15163         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
15164    (set (match_dup 3)
15165         (compare:CC (match_dup 0)
15166                     (const_int 0)))]
15167   "")
15168
15169 (define_insn ""
15170   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
15171         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
15172                         (match_operand:SI 2 "reg_or_short_operand" "r"))
15173                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
15174   "TARGET_POWER"
15175   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
15176   [(set_attr "length" "12")])
15177
15178 (define_insn ""
15179   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
15180         (compare:CC
15181          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15182                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15183                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
15184          (const_int 0)))
15185    (clobber (match_scratch:SI 4 "=&r,&r"))]
15186   "TARGET_POWER"
15187   "@
15188    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
15189    #"
15190   [(set_attr "type" "compare")
15191    (set_attr "length" "12,16")])
15192
15193 (define_split
15194   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
15195         (compare:CC
15196          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15197                          (match_operand:SI 2 "reg_or_short_operand" ""))
15198                   (match_operand:SI 3 "gpc_reg_operand" ""))
15199          (const_int 0)))
15200    (clobber (match_scratch:SI 4 ""))]
15201   "TARGET_POWER && reload_completed"
15202   [(set (match_dup 4)
15203         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
15204    (set (match_dup 0)
15205         (compare:CC (match_dup 4)
15206                     (const_int 0)))]
15207   "")
15208
15209 (define_insn ""
15210   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
15211         (compare:CC
15212          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
15213                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
15214                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
15215          (const_int 0)))
15216    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
15217         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15218   "TARGET_POWER"
15219   "@
15220    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
15221    #"
15222   [(set_attr "type" "compare")
15223    (set_attr "length" "12,16")])
15224
15225 (define_split
15226   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
15227         (compare:CC
15228          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
15229                          (match_operand:SI 2 "reg_or_short_operand" ""))
15230                   (match_operand:SI 3 "gpc_reg_operand" ""))
15231          (const_int 0)))
15232    (set (match_operand:SI 0 "gpc_reg_operand" "")
15233         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
15234   "TARGET_POWER && reload_completed"
15235   [(set (match_dup 0)
15236         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
15237    (set (match_dup 4)
15238         (compare:CC (match_dup 0)
15239                     (const_int 0)))]
15240   "")
15241
15242 (define_insn ""
15243   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15244         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
15245                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
15246   "TARGET_POWER"
15247   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
15248   [(set_attr "length" "12")])
15249
15250 (define_insn_and_split "*gtu<mode>"
15251   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15252         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15253                (match_operand:P 2 "reg_or_short_operand" "rI")))]
15254   ""
15255   "#"
15256   ""
15257   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15258    (set (match_dup 0) (neg:P (match_dup 0)))]
15259   "")
15260
15261 (define_insn_and_split "*gtu<mode>_compare"
15262   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
15263         (compare:CC
15264          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
15265                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
15266          (const_int 0)))
15267    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
15268         (gtu:P (match_dup 1) (match_dup 2)))]
15269   ""
15270   "#"
15271   ""
15272   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15273    (parallel [(set (match_dup 3)
15274                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
15275               (set (match_dup 0) (neg:P (match_dup 0)))])]
15276   "")
15277
15278 (define_insn_and_split "*plus_gtu<mode>"
15279   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
15280         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15281                        (match_operand:P 2 "reg_or_short_operand" "rI"))
15282                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
15283   ""
15284   "#"
15285   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
15286   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15287    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
15288   "")
15289
15290 (define_insn_and_split "*plus_gtu<mode>_compare"
15291   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
15292         (compare:CC
15293          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
15294                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
15295                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
15296          (const_int 0)))
15297    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
15298         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
15299   ""
15300   "#"
15301   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
15302   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
15303    (parallel [(set (match_dup 4)
15304                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
15305                                (const_int 0)))
15306               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
15307   "")
15308
15309 (define_insn "*neg_gtu<mode>"
15310   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15311         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
15312                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
15313   ""
15314   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
15315   [(set_attr "type" "two")
15316    (set_attr "length" "8")])
15317
15318 \f
15319 ;; Define both directions of branch and return.  If we need a reload
15320 ;; register, we'd rather use CR0 since it is much easier to copy a
15321 ;; register CC value to there.
15322
15323 (define_insn ""
15324   [(set (pc)
15325         (if_then_else (match_operator 1 "branch_comparison_operator"
15326                                       [(match_operand 2
15327                                                       "cc_reg_operand" "y")
15328                                        (const_int 0)])
15329                       (label_ref (match_operand 0 "" ""))
15330                       (pc)))]
15331   ""
15332   "*
15333 {
15334   return output_cbranch (operands[1], \"%l0\", 0, insn);
15335 }"
15336   [(set_attr "type" "branch")])
15337
15338 (define_insn ""
15339   [(set (pc)
15340         (if_then_else (match_operator 0 "branch_comparison_operator"
15341                                       [(match_operand 1
15342                                                       "cc_reg_operand" "y")
15343                                        (const_int 0)])
15344                       (any_return)
15345                       (pc)))]
15346   "<return_pred>"
15347   "*
15348 {
15349   return output_cbranch (operands[0], NULL, 0, insn);
15350 }"
15351   [(set_attr "type" "jmpreg")
15352    (set_attr "length" "4")])
15353
15354 (define_insn ""
15355   [(set (pc)
15356         (if_then_else (match_operator 1 "branch_comparison_operator"
15357                                       [(match_operand 2
15358                                                       "cc_reg_operand" "y")
15359                                        (const_int 0)])
15360                       (pc)
15361                       (label_ref (match_operand 0 "" ""))))]
15362   ""
15363   "*
15364 {
15365   return output_cbranch (operands[1], \"%l0\", 1, insn);
15366 }"
15367   [(set_attr "type" "branch")])
15368
15369 (define_insn ""
15370   [(set (pc)
15371         (if_then_else (match_operator 0 "branch_comparison_operator"
15372                                       [(match_operand 1
15373                                                       "cc_reg_operand" "y")
15374                                        (const_int 0)])
15375                       (pc)
15376                       (any_return)))]
15377   "<return_pred>"
15378   "*
15379 {
15380   return output_cbranch (operands[0], NULL, 1, insn);
15381 }"
15382   [(set_attr "type" "jmpreg")
15383    (set_attr "length" "4")])
15384
15385 ;; Logic on condition register values.
15386
15387 ; This pattern matches things like
15388 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
15389 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
15390 ;                                  (const_int 1)))
15391 ; which are generated by the branch logic.
15392 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
15393
15394 (define_insn "*cceq_ior_compare"
15395   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15396         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
15397                         [(match_operator:SI 2
15398                                       "branch_positive_comparison_operator"
15399                                       [(match_operand 3
15400                                                       "cc_reg_operand" "y,y")
15401                                        (const_int 0)])
15402                          (match_operator:SI 4
15403                                       "branch_positive_comparison_operator"
15404                                       [(match_operand 5
15405                                                       "cc_reg_operand" "0,y")
15406                                        (const_int 0)])])
15407                       (const_int 1)))]
15408   ""
15409   "cr%q1 %E0,%j2,%j4"
15410   [(set_attr "type" "cr_logical,delayed_cr")])
15411
15412 ; Why is the constant -1 here, but 1 in the previous pattern?
15413 ; Because ~1 has all but the low bit set.
15414 (define_insn ""
15415   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15416         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
15417                         [(not:SI (match_operator:SI 2
15418                                       "branch_positive_comparison_operator"
15419                                       [(match_operand 3
15420                                                       "cc_reg_operand" "y,y")
15421                                        (const_int 0)]))
15422                          (match_operator:SI 4
15423                                 "branch_positive_comparison_operator"
15424                                 [(match_operand 5
15425                                                 "cc_reg_operand" "0,y")
15426                                  (const_int 0)])])
15427                       (const_int -1)))]
15428   ""
15429   "cr%q1 %E0,%j2,%j4"
15430   [(set_attr "type" "cr_logical,delayed_cr")])
15431
15432 (define_insn "*cceq_rev_compare"
15433   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
15434         (compare:CCEQ (match_operator:SI 1
15435                                       "branch_positive_comparison_operator"
15436                                       [(match_operand 2
15437                                                       "cc_reg_operand" "0,y")
15438                                        (const_int 0)])
15439                       (const_int 0)))]
15440   ""
15441   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
15442   [(set_attr "type" "cr_logical,delayed_cr")])
15443
15444 ;; If we are comparing the result of two comparisons, this can be done
15445 ;; using creqv or crxor.
15446
15447 (define_insn_and_split ""
15448   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
15449         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
15450                               [(match_operand 2 "cc_reg_operand" "y")
15451                                (const_int 0)])
15452                       (match_operator 3 "branch_comparison_operator"
15453                               [(match_operand 4 "cc_reg_operand" "y")
15454                                (const_int 0)])))]
15455   ""
15456   "#"
15457   ""
15458   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
15459                                     (match_dup 5)))]
15460   "
15461 {
15462   int positive_1, positive_2;
15463
15464   positive_1 = branch_positive_comparison_operator (operands[1],
15465                                                     GET_MODE (operands[1]));
15466   positive_2 = branch_positive_comparison_operator (operands[3],
15467                                                     GET_MODE (operands[3]));
15468
15469   if (! positive_1)
15470     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
15471                                                             GET_CODE (operands[1])),
15472                                   SImode,
15473                                   operands[2], const0_rtx);
15474   else if (GET_MODE (operands[1]) != SImode)
15475     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
15476                                   operands[2], const0_rtx);
15477
15478   if (! positive_2)
15479     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
15480                                                             GET_CODE (operands[3])),
15481                                   SImode,
15482                                   operands[4], const0_rtx);
15483   else if (GET_MODE (operands[3]) != SImode)
15484     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
15485                                   operands[4], const0_rtx);
15486
15487   if (positive_1 == positive_2)
15488     {
15489       operands[1] = gen_rtx_NOT (SImode, operands[1]);
15490       operands[5] = constm1_rtx;
15491     }
15492   else
15493     {
15494       operands[5] = const1_rtx;
15495     }
15496 }")
15497
15498 ;; Unconditional branch and return.
15499
15500 (define_insn "jump"
15501   [(set (pc)
15502         (label_ref (match_operand 0 "" "")))]
15503   ""
15504   "b %l0"
15505   [(set_attr "type" "branch")])
15506
15507 (define_insn "<return_str>return"
15508   [(any_return)]
15509   "<return_pred>"
15510   "{br|blr}"
15511   [(set_attr "type" "jmpreg")])
15512
15513 (define_expand "indirect_jump"
15514   [(set (pc) (match_operand 0 "register_operand" ""))])
15515
15516 (define_insn "*indirect_jump<mode>"
15517   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
15518   ""
15519   "@
15520    bctr
15521    {br|blr}"
15522   [(set_attr "type" "jmpreg")])
15523
15524 ;; Table jump for switch statements:
15525 (define_expand "tablejump"
15526   [(use (match_operand 0 "" ""))
15527    (use (label_ref (match_operand 1 "" "")))]
15528   ""
15529   "
15530 {
15531   if (TARGET_32BIT)
15532     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
15533   else
15534     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
15535   DONE;
15536 }")
15537
15538 (define_expand "tablejumpsi"
15539   [(set (match_dup 3)
15540         (plus:SI (match_operand:SI 0 "" "")
15541                  (match_dup 2)))
15542    (parallel [(set (pc) (match_dup 3))
15543               (use (label_ref (match_operand 1 "" "")))])]
15544   "TARGET_32BIT"
15545   "
15546 { operands[0] = force_reg (SImode, operands[0]);
15547   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
15548   operands[3] = gen_reg_rtx (SImode);
15549 }")
15550
15551 (define_expand "tablejumpdi"
15552   [(set (match_dup 4)
15553         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
15554    (set (match_dup 3)
15555         (plus:DI (match_dup 4)
15556                  (match_dup 2)))
15557    (parallel [(set (pc) (match_dup 3))
15558               (use (label_ref (match_operand 1 "" "")))])]
15559   "TARGET_64BIT"
15560   "
15561 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
15562   operands[3] = gen_reg_rtx (DImode);
15563   operands[4] = gen_reg_rtx (DImode);
15564 }")
15565
15566 (define_insn "*tablejump<mode>_internal1"
15567   [(set (pc)
15568         (match_operand:P 0 "register_operand" "c,*l"))
15569    (use (label_ref (match_operand 1 "" "")))]
15570   ""
15571   "@
15572    bctr
15573    {br|blr}"
15574   [(set_attr "type" "jmpreg")])
15575
15576 (define_insn "nop"
15577   [(const_int 0)]
15578   ""
15579   "{cror 0,0,0|nop}")
15580
15581 (define_insn "group_ending_nop"
15582   [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
15583   ""
15584   "*
15585 {
15586   if (rs6000_cpu_attr == CPU_POWER6)
15587     return \"ori 1,1,0\";
15588   return \"ori 2,2,0\";
15589 }")
15590 \f
15591 ;; Define the subtract-one-and-jump insns, starting with the template
15592 ;; so loop.c knows what to generate.
15593
15594 (define_expand "doloop_end"
15595   [(use (match_operand 0 "" ""))        ; loop pseudo
15596    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
15597    (use (match_operand 2 "" ""))        ; max iterations
15598    (use (match_operand 3 "" ""))        ; loop level
15599    (use (match_operand 4 "" ""))]       ; label
15600   ""
15601   "
15602 {
15603   /* Only use this on innermost loops.  */
15604   if (INTVAL (operands[3]) > 1)
15605     FAIL;
15606   if (TARGET_64BIT)
15607     {
15608       if (GET_MODE (operands[0]) != DImode)
15609         FAIL;
15610       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
15611     }
15612   else
15613     {
15614       if (GET_MODE (operands[0]) != SImode)
15615         FAIL;
15616       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
15617     }
15618   DONE;
15619 }")
15620
15621 (define_expand "ctr<mode>"
15622   [(parallel [(set (pc)
15623                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
15624                                      (const_int 1))
15625                                  (label_ref (match_operand 1 "" ""))
15626                                  (pc)))
15627               (set (match_dup 0)
15628                    (plus:P (match_dup 0)
15629                             (const_int -1)))
15630               (clobber (match_scratch:CC 2 ""))
15631               (clobber (match_scratch:P 3 ""))])]
15632   ""
15633   "")
15634
15635 ;; We need to be able to do this for any operand, including MEM, or we
15636 ;; will cause reload to blow up since we don't allow output reloads on
15637 ;; JUMP_INSNs.
15638 ;; For the length attribute to be calculated correctly, the
15639 ;; label MUST be operand 0.
15640
15641 (define_insn "*ctr<mode>_internal1"
15642   [(set (pc)
15643         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15644                           (const_int 1))
15645                       (label_ref (match_operand 0 "" ""))
15646                       (pc)))
15647    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15648         (plus:P (match_dup 1)
15649                  (const_int -1)))
15650    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15651    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15652   ""
15653   "*
15654 {
15655   if (which_alternative != 0)
15656     return \"#\";
15657   else if (get_attr_length (insn) == 4)
15658     return \"{bdn|bdnz} %l0\";
15659   else
15660     return \"bdz $+8\;b %l0\";
15661 }"
15662   [(set_attr "type" "branch")
15663    (set_attr "length" "*,12,16,16")])
15664
15665 (define_insn "*ctr<mode>_internal2"
15666   [(set (pc)
15667         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15668                           (const_int 1))
15669                       (pc)
15670                       (label_ref (match_operand 0 "" ""))))
15671    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15672         (plus:P (match_dup 1)
15673                  (const_int -1)))
15674    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15675    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15676   ""
15677   "*
15678 {
15679   if (which_alternative != 0)
15680     return \"#\";
15681   else if (get_attr_length (insn) == 4)
15682     return \"bdz %l0\";
15683   else
15684     return \"{bdn|bdnz} $+8\;b %l0\";
15685 }"
15686   [(set_attr "type" "branch")
15687    (set_attr "length" "*,12,16,16")])
15688
15689 ;; Similar but use EQ
15690
15691 (define_insn "*ctr<mode>_internal5"
15692   [(set (pc)
15693         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15694                           (const_int 1))
15695                       (label_ref (match_operand 0 "" ""))
15696                       (pc)))
15697    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15698         (plus:P (match_dup 1)
15699                  (const_int -1)))
15700    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15701    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15702   ""
15703   "*
15704 {
15705   if (which_alternative != 0)
15706     return \"#\";
15707   else if (get_attr_length (insn) == 4)
15708     return \"bdz %l0\";
15709   else
15710     return \"{bdn|bdnz} $+8\;b %l0\";
15711 }"
15712   [(set_attr "type" "branch")
15713    (set_attr "length" "*,12,16,16")])
15714
15715 (define_insn "*ctr<mode>_internal6"
15716   [(set (pc)
15717         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
15718                           (const_int 1))
15719                       (pc)
15720                       (label_ref (match_operand 0 "" ""))))
15721    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
15722         (plus:P (match_dup 1)
15723                  (const_int -1)))
15724    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
15725    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
15726   ""
15727   "*
15728 {
15729   if (which_alternative != 0)
15730     return \"#\";
15731   else if (get_attr_length (insn) == 4)
15732     return \"{bdn|bdnz} %l0\";
15733   else
15734     return \"bdz $+8\;b %l0\";
15735 }"
15736   [(set_attr "type" "branch")
15737    (set_attr "length" "*,12,16,16")])
15738
15739 ;; Now the splitters if we could not allocate the CTR register
15740
15741 (define_split
15742   [(set (pc)
15743         (if_then_else (match_operator 2 "comparison_operator"
15744                                       [(match_operand:P 1 "gpc_reg_operand" "")
15745                                        (const_int 1)])
15746                       (match_operand 5 "" "")
15747                       (match_operand 6 "" "")))
15748    (set (match_operand:P 0 "gpc_reg_operand" "")
15749         (plus:P (match_dup 1) (const_int -1)))
15750    (clobber (match_scratch:CC 3 ""))
15751    (clobber (match_scratch:P 4 ""))]
15752   "reload_completed"
15753   [(parallel [(set (match_dup 3)
15754                    (compare:CC (plus:P (match_dup 1)
15755                                         (const_int -1))
15756                                (const_int 0)))
15757               (set (match_dup 0)
15758                    (plus:P (match_dup 1)
15759                             (const_int -1)))])
15760    (set (pc) (if_then_else (match_dup 7)
15761                            (match_dup 5)
15762                            (match_dup 6)))]
15763   "
15764 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15765                                 operands[3], const0_rtx); }")
15766
15767 (define_split
15768   [(set (pc)
15769         (if_then_else (match_operator 2 "comparison_operator"
15770                                       [(match_operand:P 1 "gpc_reg_operand" "")
15771                                        (const_int 1)])
15772                       (match_operand 5 "" "")
15773                       (match_operand 6 "" "")))
15774    (set (match_operand:P 0 "nonimmediate_operand" "")
15775         (plus:P (match_dup 1) (const_int -1)))
15776    (clobber (match_scratch:CC 3 ""))
15777    (clobber (match_scratch:P 4 ""))]
15778   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
15779   [(parallel [(set (match_dup 3)
15780                    (compare:CC (plus:P (match_dup 1)
15781                                         (const_int -1))
15782                                (const_int 0)))
15783               (set (match_dup 4)
15784                    (plus:P (match_dup 1)
15785                             (const_int -1)))])
15786    (set (match_dup 0)
15787         (match_dup 4))
15788    (set (pc) (if_then_else (match_dup 7)
15789                            (match_dup 5)
15790                            (match_dup 6)))]
15791   "
15792 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
15793                                 operands[3], const0_rtx); }")
15794 \f
15795 (define_insn "trap"
15796   [(trap_if (const_int 1) (const_int 0))]
15797   ""
15798   "{t 31,0,0|trap}"
15799   [(set_attr "type" "trap")])
15800
15801 (define_expand "ctrap<mode>4"
15802   [(trap_if (match_operator 0 "ordered_comparison_operator"
15803                             [(match_operand:GPR 1 "register_operand")
15804                              (match_operand:GPR 2 "reg_or_short_operand")])
15805             (match_operand 3 "zero_constant" ""))]
15806   ""
15807   "")
15808
15809 (define_insn ""
15810   [(trap_if (match_operator 0 "ordered_comparison_operator"
15811                             [(match_operand:GPR 1 "register_operand" "r")
15812                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
15813             (const_int 0))]
15814   ""
15815   "{t|t<wd>}%V0%I2 %1,%2"
15816   [(set_attr "type" "trap")])
15817 \f
15818 ;; Insns related to generating the function prologue and epilogue.
15819
15820 (define_expand "prologue"
15821   [(use (const_int 0))]
15822   ""
15823 {
15824   rs6000_emit_prologue ();
15825   if (!TARGET_SCHED_PROLOG)
15826     emit_insn (gen_blockage ());
15827   DONE;
15828 })
15829
15830 (define_insn "*movesi_from_cr_one"
15831   [(match_parallel 0 "mfcr_operation"
15832                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15833                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
15834                                      (match_operand 3 "immediate_operand" "n")]
15835                           UNSPEC_MOVESI_FROM_CR))])]
15836   "TARGET_MFCRF"
15837   "*
15838 {
15839   int mask = 0;
15840   int i;
15841   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15842   {
15843     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15844     operands[4] = GEN_INT (mask);
15845     output_asm_insn (\"mfcr %1,%4\", operands);
15846   }
15847   return \"\";
15848 }"
15849   [(set_attr "type" "mfcrf")])
15850
15851 (define_insn "movesi_from_cr"
15852   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15853         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
15854                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
15855                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
15856                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
15857                    UNSPEC_MOVESI_FROM_CR))]
15858   ""
15859   "mfcr %0"
15860   [(set_attr "type" "mfcr")])
15861
15862 (define_insn "*stmw"
15863   [(match_parallel 0 "stmw_operation"
15864                    [(set (match_operand:SI 1 "memory_operand" "=m")
15865                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
15866   "TARGET_MULTIPLE"
15867   "{stm|stmw} %2,%1"
15868   [(set_attr "type" "store_ux")])
15869
15870 ; The following comment applies to:
15871 ;     save_gpregs_*
15872 ;     save_fpregs_*
15873 ;     restore_gpregs*
15874 ;     return_and_restore_gpregs*
15875 ;     return_and_restore_fpregs*
15876 ;     return_and_restore_fpregs_aix*
15877 ;
15878 ; The out-of-line save / restore functions expects one input argument.
15879 ; Since those are not standard call_insn's, we must avoid using
15880 ; MATCH_OPERAND for that argument. That way the register rename
15881 ; optimization will not try to rename this register.
15882 ; Each pattern is repeated for each possible register number used in 
15883 ; various ABIs (r11, r1, and for some functions r12)
15884
15885 (define_insn "*save_gpregs_<mode>_r11"
15886   [(match_parallel 0 "any_parallel_operand"
15887                    [(clobber (reg:P 65))
15888                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15889                     (use (reg:P 11))
15890                     (set (match_operand:P 2 "memory_operand" "=m")
15891                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
15892   ""
15893   "bl %1"
15894   [(set_attr "type" "branch")
15895    (set_attr "length" "4")])
15896
15897 (define_insn "*save_gpregs_<mode>_r12"
15898   [(match_parallel 0 "any_parallel_operand"
15899                    [(clobber (reg:P 65))
15900                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15901                     (use (reg:P 12))
15902                     (set (match_operand:P 2 "memory_operand" "=m")
15903                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
15904   ""
15905   "bl %1"
15906   [(set_attr "type" "branch")
15907    (set_attr "length" "4")])
15908
15909 (define_insn "*save_gpregs_<mode>_r1"
15910   [(match_parallel 0 "any_parallel_operand"
15911                    [(clobber (reg:P 65))
15912                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15913                     (use (reg:P 1))
15914                     (set (match_operand:P 2 "memory_operand" "=m")
15915                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
15916   ""
15917   "bl %1"
15918   [(set_attr "type" "branch")
15919    (set_attr "length" "4")])
15920
15921 (define_insn "*save_fpregs_<mode>_r11"
15922   [(match_parallel 0 "any_parallel_operand"
15923                    [(clobber (reg:P 65))
15924                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15925                     (use (reg:P 11))
15926                     (set (match_operand:DF 2 "memory_operand" "=m")
15927                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15928   ""
15929   "bl %1"
15930   [(set_attr "type" "branch")
15931    (set_attr "length" "4")])
15932
15933 (define_insn "*save_fpregs_<mode>_r12"
15934   [(match_parallel 0 "any_parallel_operand"
15935                    [(clobber (reg:P 65))
15936                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15937                     (use (reg:P 12))
15938                     (set (match_operand:DF 2 "memory_operand" "=m")
15939                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15940   ""
15941   "bl %1"
15942   [(set_attr "type" "branch")
15943    (set_attr "length" "4")])
15944
15945 (define_insn "*save_fpregs_<mode>_r1"
15946   [(match_parallel 0 "any_parallel_operand"
15947                    [(clobber (reg:P 65))
15948                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15949                     (use (reg:P 1))
15950                     (set (match_operand:DF 2 "memory_operand" "=m")
15951                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15952   ""
15953   "bl %1"
15954   [(set_attr "type" "branch")
15955    (set_attr "length" "4")])
15956
15957 ; These are to explain that changes to the stack pointer should
15958 ; not be moved over stores to stack memory.
15959 (define_insn "stack_tie"
15960   [(set (match_operand:BLK 0 "memory_operand" "+m")
15961         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
15962   ""
15963   ""
15964   [(set_attr "length" "0")])
15965
15966 ; Like stack_tie, but depend on both fp and sp based memory.
15967 (define_insn "frame_tie"
15968   [(set (match_operand:BLK 0 "memory_operand" "+m")
15969         (unspec:BLK [(match_dup 0)
15970                      (match_operand:BLK 1 "memory_operand" "m")] UNSPEC_TIE))]
15971   ""
15972   ""
15973   [(set_attr "length" "0")])
15974
15975
15976 (define_expand "epilogue"
15977   [(use (const_int 0))]
15978   ""
15979 {
15980   if (!TARGET_SCHED_PROLOG)
15981     emit_insn (gen_blockage ());
15982   rs6000_emit_epilogue (FALSE);
15983   DONE;
15984 })
15985
15986 ; On some processors, doing the mtcrf one CC register at a time is
15987 ; faster (like on the 604e).  On others, doing them all at once is
15988 ; faster; for instance, on the 601 and 750.
15989
15990 (define_expand "movsi_to_cr_one"
15991   [(set (match_operand:CC 0 "cc_reg_operand" "")
15992         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
15993                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
15994   ""
15995   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
15996
15997 (define_insn "*movsi_to_cr"
15998   [(match_parallel 0 "mtcrf_operation"
15999                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
16000                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
16001                                      (match_operand 3 "immediate_operand" "n")]
16002                                     UNSPEC_MOVESI_TO_CR))])]
16003  ""
16004  "*
16005 {
16006   int mask = 0;
16007   int i;
16008   for (i = 0; i < XVECLEN (operands[0], 0); i++)
16009     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
16010   operands[4] = GEN_INT (mask);
16011   return \"mtcrf %4,%2\";
16012 }"
16013   [(set_attr "type" "mtcr")])
16014
16015 (define_insn "*mtcrfsi"
16016   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
16017         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
16018                     (match_operand 2 "immediate_operand" "n")]
16019                    UNSPEC_MOVESI_TO_CR))]
16020   "GET_CODE (operands[0]) == REG
16021    && CR_REGNO_P (REGNO (operands[0]))
16022    && GET_CODE (operands[2]) == CONST_INT
16023    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
16024   "mtcrf %R0,%1"
16025   [(set_attr "type" "mtcr")])
16026
16027 ; The load-multiple instructions have similar properties.
16028 ; Note that "load_multiple" is a name known to the machine-independent
16029 ; code that actually corresponds to the PowerPC load-string.
16030
16031 (define_insn "*lmw"
16032   [(match_parallel 0 "lmw_operation"
16033                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
16034                          (match_operand:SI 2 "memory_operand" "m"))])]
16035   "TARGET_MULTIPLE"
16036   "{lm|lmw} %1,%2"
16037   [(set_attr "type" "load_ux")
16038    (set_attr "cell_micro" "always")])
16039
16040 (define_insn "*return_internal_<mode>"
16041   [(simple_return)
16042    (use (match_operand:P 0 "register_operand" "lc"))]
16043   ""
16044   "b%T0"
16045   [(set_attr "type" "jmpreg")])
16046
16047 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
16048 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
16049
16050 ; The following comment applies to:
16051 ;     save_gpregs_*
16052 ;     save_fpregs_*
16053 ;     restore_gpregs*
16054 ;     return_and_restore_gpregs*
16055 ;     return_and_restore_fpregs*
16056 ;     return_and_restore_fpregs_aix*
16057 ;
16058 ; The out-of-line save / restore functions expects one input argument.
16059 ; Since those are not standard call_insn's, we must avoid using
16060 ; MATCH_OPERAND for that argument. That way the register rename
16061 ; optimization will not try to rename this register.
16062 ; Each pattern is repeated for each possible register number used in 
16063 ; various ABIs (r11, r1, and for some functions r12)
16064
16065 (define_insn "*restore_gpregs_<mode>_r11"
16066  [(match_parallel 0 "any_parallel_operand"
16067                   [(clobber (match_operand:P 1 "register_operand" "=l"))
16068                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16069                    (use (reg:P 11))
16070                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16071                         (match_operand:P 4 "memory_operand" "m"))])]
16072  ""
16073  "bl %2"
16074  [(set_attr "type" "branch")
16075   (set_attr "length" "4")])
16076
16077 (define_insn "*restore_gpregs_<mode>_r12"
16078  [(match_parallel 0 "any_parallel_operand"
16079                   [(clobber (match_operand:P 1 "register_operand" "=l"))
16080                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16081                    (use (reg:P 12))
16082                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16083                         (match_operand:P 4 "memory_operand" "m"))])]
16084  ""
16085  "bl %2"
16086  [(set_attr "type" "branch")
16087   (set_attr "length" "4")])
16088
16089 (define_insn "*restore_gpregs_<mode>_r1"
16090  [(match_parallel 0 "any_parallel_operand"
16091                   [(clobber (match_operand:P 1 "register_operand" "=l"))
16092                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16093                    (use (reg:P 1))
16094                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16095                         (match_operand:P 4 "memory_operand" "m"))])]
16096  ""
16097  "bl %2"
16098  [(set_attr "type" "branch")
16099   (set_attr "length" "4")])
16100
16101 (define_insn "*return_and_restore_gpregs_<mode>_r11"
16102  [(match_parallel 0 "any_parallel_operand"
16103                   [(return)
16104                    (clobber (match_operand:P 1 "register_operand" "=l"))
16105                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16106                    (use (reg:P 11))
16107                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16108                         (match_operand:P 4 "memory_operand" "m"))])]
16109  ""
16110  "b %2"
16111  [(set_attr "type" "branch")
16112   (set_attr "length" "4")])
16113
16114 (define_insn "*return_and_restore_gpregs_<mode>_r12"
16115  [(match_parallel 0 "any_parallel_operand"
16116                   [(return)
16117                    (clobber (match_operand:P 1 "register_operand" "=l"))
16118                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16119                    (use (reg:P 12))
16120                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16121                         (match_operand:P 4 "memory_operand" "m"))])]
16122  ""
16123  "b %2"
16124  [(set_attr "type" "branch")
16125   (set_attr "length" "4")])
16126
16127 (define_insn "*return_and_restore_gpregs_<mode>_r1"
16128  [(match_parallel 0 "any_parallel_operand"
16129                   [(return)
16130                    (clobber (match_operand:P 1 "register_operand" "=l"))
16131                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16132                    (use (reg:P 1))
16133                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
16134                         (match_operand:P 4 "memory_operand" "m"))])]
16135  ""
16136  "b %2"
16137  [(set_attr "type" "branch")
16138   (set_attr "length" "4")])
16139
16140 (define_insn "*return_and_restore_fpregs_<mode>_r11"
16141  [(match_parallel 0 "any_parallel_operand"
16142                   [(return)
16143                    (clobber (match_operand:P 1 "register_operand" "=l"))
16144                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16145                    (use (reg:P 11))
16146                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16147                         (match_operand:DF 4 "memory_operand" "m"))])]
16148  ""
16149  "b %2"
16150  [(set_attr "type" "branch")
16151   (set_attr "length" "4")])
16152
16153 (define_insn "*return_and_restore_fpregs_<mode>_r12"
16154  [(match_parallel 0 "any_parallel_operand"
16155                   [(return)
16156                    (clobber (match_operand:P 1 "register_operand" "=l"))
16157                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16158                    (use (reg:P 12))
16159                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16160                         (match_operand:DF 4 "memory_operand" "m"))])]
16161  ""
16162  "b %2"
16163  [(set_attr "type" "branch")
16164   (set_attr "length" "4")])
16165
16166 (define_insn "*return_and_restore_fpregs_<mode>_r1"
16167  [(match_parallel 0 "any_parallel_operand"
16168                   [(return)
16169                    (clobber (match_operand:P 1 "register_operand" "=l"))
16170                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16171                    (use (reg:P 1))
16172                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16173                         (match_operand:DF 4 "memory_operand" "m"))])]
16174  ""
16175  "b %2"
16176  [(set_attr "type" "branch")
16177   (set_attr "length" "4")])
16178
16179 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
16180  [(match_parallel 0 "any_parallel_operand"
16181                   [(return)
16182                    (use (match_operand:P 1 "register_operand" "l"))
16183                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16184                    (use (reg:P 11))
16185                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16186                         (match_operand:DF 4 "memory_operand" "m"))])]
16187  ""
16188  "b %2"
16189  [(set_attr "type" "branch")
16190   (set_attr "length" "4")])
16191
16192 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
16193  [(match_parallel 0 "any_parallel_operand"
16194                   [(return)
16195                    (use (match_operand:P 1 "register_operand" "l"))
16196                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
16197                    (use (reg:P 1))
16198                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
16199                         (match_operand:DF 4 "memory_operand" "m"))])]
16200  ""
16201  "b %2"
16202  [(set_attr "type" "branch")
16203   (set_attr "length" "4")])
16204
16205 ; This is used in compiling the unwind routines.
16206 (define_expand "eh_return"
16207   [(use (match_operand 0 "general_operand" ""))]
16208   ""
16209   "
16210 {
16211   if (TARGET_32BIT)
16212     emit_insn (gen_eh_set_lr_si (operands[0]));
16213   else
16214     emit_insn (gen_eh_set_lr_di (operands[0]));
16215   DONE;
16216 }")
16217
16218 ; We can't expand this before we know where the link register is stored.
16219 (define_insn "eh_set_lr_<mode>"
16220   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
16221                     UNSPECV_EH_RR)
16222    (clobber (match_scratch:P 1 "=&b"))]
16223   ""
16224   "#")
16225
16226 (define_split
16227   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
16228    (clobber (match_scratch 1 ""))]
16229   "reload_completed"
16230   [(const_int 0)]
16231   "
16232 {
16233   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
16234   DONE;
16235 }")
16236
16237 (define_insn "prefetch"
16238   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
16239              (match_operand:SI 1 "const_int_operand" "n")
16240              (match_operand:SI 2 "const_int_operand" "n"))]
16241   "TARGET_POWERPC"
16242   "*
16243 {
16244   if (GET_CODE (operands[0]) == REG)
16245     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
16246   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
16247 }"
16248   [(set_attr "type" "load")])
16249 \f
16250 (define_insn "bpermd_<mode>"
16251   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
16252         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
16253                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
16254   "TARGET_POPCNTD"
16255   "bpermd %0,%1,%2"
16256   [(set_attr "type" "integer")])
16257
16258 \f
16259 ;; Builtin fma support.  Handle 
16260 ;; Note that the conditions for expansion are in the FMA_F iterator.
16261
16262 (define_expand "fma<mode>4"
16263   [(set (match_operand:FMA_F 0 "register_operand" "")
16264         (fma:FMA_F
16265           (match_operand:FMA_F 1 "register_operand" "")
16266           (match_operand:FMA_F 2 "register_operand" "")
16267           (match_operand:FMA_F 3 "register_operand" "")))]
16268   ""
16269   "")
16270
16271 ; Altivec only has fma and nfms.
16272 (define_expand "fms<mode>4"
16273   [(set (match_operand:FMA_F 0 "register_operand" "")
16274         (fma:FMA_F
16275           (match_operand:FMA_F 1 "register_operand" "")
16276           (match_operand:FMA_F 2 "register_operand" "")
16277           (neg:FMA_F (match_operand:FMA_F 3 "register_operand" ""))))]
16278   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
16279   "")
16280
16281 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
16282 (define_expand "fnma<mode>4"
16283   [(set (match_operand:FMA_F 0 "register_operand" "")
16284         (neg:FMA_F
16285           (fma:FMA_F
16286             (match_operand:FMA_F 1 "register_operand" "")
16287             (match_operand:FMA_F 2 "register_operand" "")
16288             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
16289   "!HONOR_SIGNED_ZEROS (<MODE>mode)"
16290   "")
16291
16292 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
16293 (define_expand "fnms<mode>4"
16294   [(set (match_operand:FMA_F 0 "register_operand" "")
16295         (neg:FMA_F
16296           (fma:FMA_F
16297             (match_operand:FMA_F 1 "register_operand" "")
16298             (match_operand:FMA_F 2 "register_operand" "")
16299             (match_operand:FMA_F 3 "register_operand" ""))))]
16300   "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
16301   "")
16302
16303 ; Not an official optab name, but used from builtins.
16304 (define_expand "nfma<mode>4"
16305   [(set (match_operand:FMA_F 0 "register_operand" "")
16306         (neg:FMA_F
16307           (fma:FMA_F
16308             (match_operand:FMA_F 1 "register_operand" "")
16309             (match_operand:FMA_F 2 "register_operand" "")
16310             (match_operand:FMA_F 3 "register_operand" ""))))]
16311   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
16312   "")
16313
16314 ; Not an official optab name, but used from builtins.
16315 (define_expand "nfms<mode>4"
16316   [(set (match_operand:FMA_F 0 "register_operand" "")
16317         (neg:FMA_F
16318           (fma:FMA_F
16319             (match_operand:FMA_F 1 "register_operand" "")
16320             (match_operand:FMA_F 2 "register_operand" "")
16321             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
16322   ""
16323   "")
16324
16325 \f
16326
16327 (include "sync.md")
16328 (include "vector.md")
16329 (include "vsx.md")
16330 (include "altivec.md")
16331 (include "spe.md")
16332 (include "dfp.md")
16333 (include "paired.md")