rs6000.h (LONG_DOUBLE_LARGE_FIRST): Define.
[platform/upstream/gcc.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990-2013 Free Software Foundation, Inc.
3 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
4
5 ;; This file is part of GCC.
6
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 3, or (at your
10 ;; option) any later version.
11
12 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15 ;; License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
22
23 ;;
24 ;; REGNOS
25 ;;
26
27 (define_constants
28   [(FIRST_GPR_REGNO             0)
29    (STACK_POINTER_REGNUM        1)
30    (TOC_REGNUM                  2)
31    (STATIC_CHAIN_REGNUM         11)
32    (HARD_FRAME_POINTER_REGNUM   31)
33    (LAST_GPR_REGNO              31)
34    (FIRST_FPR_REGNO             32)
35    (LAST_FPR_REGNO              63)
36    (LR_REGNO                    65)
37    (CTR_REGNO                   66)
38    (ARG_POINTER_REGNUM          67)
39    (CR0_REGNO                   68)
40    (CR1_REGNO                   69)
41    (CR2_REGNO                   70)
42    (CR3_REGNO                   71)
43    (CR4_REGNO                   72)
44    (CR5_REGNO                   73)
45    (CR6_REGNO                   74)
46    (CR7_REGNO                   75)
47    (MAX_CR_REGNO                75)
48    (CA_REGNO                    76)
49    (FIRST_ALTIVEC_REGNO         77)
50    (LAST_ALTIVEC_REGNO          108)
51    (VRSAVE_REGNO                109)
52    (VSCR_REGNO                  110)
53    (SPE_ACC_REGNO               111)
54    (SPEFSCR_REGNO               112)
55    (FRAME_POINTER_REGNUM        113)
56
57    ; ABI defined stack offsets for storing the TOC pointer with AIX calls.
58    (TOC_SAVE_OFFSET_32BIT       20)
59    (TOC_SAVE_OFFSET_64BIT       40)
60
61    ; Function TOC offset in the AIX function descriptor.
62    (AIX_FUNC_DESC_TOC_32BIT     4)
63    (AIX_FUNC_DESC_TOC_64BIT     8)
64
65    ; Static chain offset in the AIX function descriptor.
66    (AIX_FUNC_DESC_SC_32BIT      8)
67    (AIX_FUNC_DESC_SC_64BIT      16)
68   ])
69
70 ;;
71 ;; UNSPEC usage
72 ;;
73
74 (define_c_enum "unspec"
75   [UNSPEC_FRSP                  ; frsp for POWER machines
76    UNSPEC_PROBE_STACK           ; probe stack memory reference
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    UNSPEC_P8V_FMRGOW
131    UNSPEC_P8V_MTVSRWZ
132    UNSPEC_P8V_RELOAD_FROM_GPR
133    UNSPEC_P8V_MTVSRD
134    UNSPEC_P8V_XXPERMDI
135    UNSPEC_P8V_RELOAD_FROM_VSX
136    UNSPEC_FUSION_GPR
137   ])
138
139 ;;
140 ;; UNSPEC_VOLATILE usage
141 ;;
142
143 (define_c_enum "unspecv"
144   [UNSPECV_BLOCK
145    UNSPECV_LL                   ; load-locked
146    UNSPECV_SC                   ; store-conditional
147    UNSPECV_PROBE_STACK_RANGE    ; probe range of stack addresses
148    UNSPECV_EH_RR                ; eh_reg_restore
149    UNSPECV_ISYNC                ; isync instruction
150    UNSPECV_MFTB                 ; move from time base
151   ])
152
153 \f
154 ;; Define an insn type attribute.  This is used in function unit delay
155 ;; computations.
156 (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,popcnt,crypto"
157   (const_string "integer"))
158
159 ;; Define floating point instruction sub-types for use with Xfpu.md
160 (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"))
161
162 ;; Length (in bytes).
163 ; '(pc)' in the following doesn't include the instruction itself; it is
164 ; calculated as if the instruction had zero size.
165 (define_attr "length" ""
166   (if_then_else (eq_attr "type" "branch")
167                 (if_then_else (and (ge (minus (match_dup 0) (pc))
168                                        (const_int -32768))
169                                    (lt (minus (match_dup 0) (pc))
170                                        (const_int 32764)))
171                               (const_int 4)
172                               (const_int 8))
173                 (const_int 4)))
174
175 ;; Processor type -- this attribute must exactly match the processor_type
176 ;; enumeration in rs6000-opts.h.
177 (define_attr "cpu"
178   "ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,
179    ppc750,ppc7400,ppc7450,
180    ppc403,ppc405,ppc440,ppc476,
181    ppc8540,ppc8548,ppce300c2,ppce300c3,ppce500mc,ppce500mc64,ppce5500,ppce6500,
182    power4,power5,power6,power7,power8,
183    rs64a,mpccore,cell,ppca2,titan"
184   (const (symbol_ref "rs6000_cpu_attr")))
185
186
187 ;; If this instruction is microcoded on the CELL processor
188 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
189 (define_attr "cell_micro" "not,conditional,always"
190   (if_then_else (eq_attr "type" "compare,delayed_compare,imul_compare,lmul_compare,load_ext,load_ext_ux,var_shift_rotate,var_delayed_compare")
191                 (const_string "always")
192                 (const_string "not")))
193
194 (automata_option "ndfa")
195
196 (include "rs64.md")
197 (include "mpc.md")
198 (include "40x.md")
199 (include "440.md")
200 (include "476.md")
201 (include "601.md")
202 (include "603.md")
203 (include "6xx.md")
204 (include "7xx.md")
205 (include "7450.md")
206 (include "8540.md")
207 (include "e300c2c3.md")
208 (include "e500mc.md")
209 (include "e500mc64.md")
210 (include "e5500.md")
211 (include "e6500.md")
212 (include "power4.md")
213 (include "power5.md")
214 (include "power6.md")
215 (include "power7.md")
216 (include "cell.md")
217 (include "xfpu.md")
218 (include "a2.md")
219 (include "titan.md")
220
221 (include "predicates.md")
222 (include "constraints.md")
223
224 (include "darwin.md")
225
226 \f
227 ;; Mode iterators
228
229 ; This mode iterator allows :GPR to be used to indicate the allowable size
230 ; of whole values in GPRs.
231 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
232
233 ; Any supported integer mode.
234 (define_mode_iterator INT [QI HI SI DI TI PTI])
235
236 ; Any supported integer mode that fits in one register.
237 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
238
239 ; extend modes for DImode
240 (define_mode_iterator QHSI [QI HI SI])
241
242 ; QImode or HImode for small atomic ops
243 (define_mode_iterator QHI [QI HI])
244
245 ; HImode or SImode for sign extended fusion ops
246 (define_mode_iterator HSI [HI SI])
247
248 ; SImode or DImode, even if DImode doesn't fit in GPRs.
249 (define_mode_iterator SDI [SI DI])
250
251 ; The size of a pointer.  Also, the size of the value that a record-condition
252 ; (one with a '.') will compare; and the size used for arithmetic carries.
253 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
254
255 ; Iterator to add PTImode along with TImode (TImode can go in VSX registers,
256 ; PTImode is GPR only)
257 (define_mode_iterator TI2 [TI PTI])
258
259 ; Any hardware-supported floating-point mode
260 (define_mode_iterator FP [
261   (SF "TARGET_HARD_FLOAT 
262    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) || TARGET_E500_SINGLE)")
263   (DF "TARGET_HARD_FLOAT 
264    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)")
265   (TF "!TARGET_IEEEQUAD
266    && TARGET_HARD_FLOAT
267    && (TARGET_FPRS || TARGET_E500_DOUBLE)
268    && TARGET_LONG_DOUBLE_128")
269   (DD "TARGET_DFP")
270   (TD "TARGET_DFP")])
271
272 ; Any fma capable floating-point mode.
273 (define_mode_iterator FMA_F [
274   (SF "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT")
275   (DF "(TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
276        || VECTOR_UNIT_VSX_P (DFmode)")
277   (V2SF "TARGET_PAIRED_FLOAT")
278   (V4SF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)")
279   (V2DF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)")
280   ])
281
282 ; Floating point move iterators to combine binary and decimal moves
283 (define_mode_iterator FMOVE32 [SF SD])
284 (define_mode_iterator FMOVE64 [DF DD])
285 (define_mode_iterator FMOVE64X [DI DF DD])
286 (define_mode_iterator FMOVE128 [(TF "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128")
287                                 (TD "TARGET_HARD_FLOAT && TARGET_FPRS")])
288
289 ; Iterators for 128 bit types for direct move
290 (define_mode_iterator FMOVE128_GPR [(TI    "TARGET_VSX_TIMODE")
291                                     (V16QI "")
292                                     (V8HI  "")
293                                     (V4SI  "")
294                                     (V4SF  "")
295                                     (V2DI  "")
296                                     (V2DF  "")])
297
298 ; Whether a floating point move is ok, don't allow SD without hardware FP
299 (define_mode_attr fmove_ok [(SF "")
300                             (DF "")
301                             (SD "TARGET_HARD_FLOAT && TARGET_FPRS")
302                             (DD "")])
303
304 ; Convert REAL_VALUE to the appropriate bits
305 (define_mode_attr real_value_to_target [(SF "REAL_VALUE_TO_TARGET_SINGLE")
306                                         (DF "REAL_VALUE_TO_TARGET_DOUBLE")
307                                         (SD "REAL_VALUE_TO_TARGET_DECIMAL32")
308                                         (DD "REAL_VALUE_TO_TARGET_DECIMAL64")])
309
310 ; Definitions for load to 32-bit fpr register
311 (define_mode_attr f32_lr [(SF "f")               (SD "wz")])
312 (define_mode_attr f32_lm [(SF "m")               (SD "Z")])
313 (define_mode_attr f32_li [(SF "lfs%U1%X1 %0,%1") (SD "lfiwzx %0,%y1")])
314 (define_mode_attr f32_lv [(SF "lxsspx %0,%y1")   (SD "lxsiwzx %0,%y1")])
315
316 ; Definitions for store from 32-bit fpr register
317 (define_mode_attr f32_sr [(SF "f")                (SD "wx")])
318 (define_mode_attr f32_sm [(SF "m")                (SD "Z")])
319 (define_mode_attr f32_si [(SF "stfs%U0%X0 %1,%0") (SD "stfiwx %1,%y0")])
320 (define_mode_attr f32_sv [(SF "stxsspx %1,%y0")   (SD "stxsiwzx %1,%y0")])
321
322 ; Definitions for 32-bit fpr direct move
323 (define_mode_attr f32_dm [(SF "wn") (SD "wm")])
324
325 ; These modes do not fit in integer registers in 32-bit mode.
326 ; but on e500v2, the gpr are 64 bit registers
327 (define_mode_iterator DIFD [DI (DF "!TARGET_E500_DOUBLE") DD])
328
329 ; Iterator for reciprocal estimate instructions
330 (define_mode_iterator RECIPF [SF DF V4SF V2DF])
331
332 ; Iterator for just SF/DF
333 (define_mode_iterator SFDF [SF DF])
334
335 ; Conditional returns.
336 (define_code_iterator any_return [return simple_return])
337 (define_code_attr return_pred [(return "direct_return ()")
338                                (simple_return "1")])
339 (define_code_attr return_str [(return "") (simple_return "simple_")])
340
341 ; Various instructions that come in SI and DI forms.
342 ; A generic w/d attribute, for things like cmpw/cmpd.
343 (define_mode_attr wd [(QI    "b")
344                       (HI    "h")
345                       (SI    "w")
346                       (DI    "d")
347                       (V16QI "b")
348                       (V8HI  "h")
349                       (V4SI  "w")
350                       (V2DI  "d")])
351
352 ; DImode bits
353 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
354
355 ;; ISEL/ISEL64 target selection
356 (define_mode_attr sel [(SI "") (DI "64")])
357
358 ;; Suffix for reload patterns
359 (define_mode_attr ptrsize [(SI "32bit")
360                            (DI "64bit")])
361
362 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
363                             (DI "TARGET_64BIT")])
364
365 (define_mode_attr mptrsize [(SI "si")
366                             (DI "di")])
367
368 (define_mode_attr ptrload [(SI "lwz")
369                            (DI "ld")])
370
371 (define_mode_attr ptrm [(SI "m")
372                         (DI "Y")])
373
374 (define_mode_attr rreg [(SF   "f")
375                         (DF   "ws")
376                         (V4SF "wf")
377                         (V2DF "wd")])
378
379 (define_mode_attr rreg2 [(SF   "f")
380                          (DF   "d")])
381
382 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
383                                  (DF "TARGET_FCFID")])
384
385 (define_mode_attr E500_CONVERT [(SF "!TARGET_FPRS")
386                                 (DF "TARGET_E500_DOUBLE")])
387
388 (define_mode_attr TARGET_FLOAT [(SF "TARGET_SINGLE_FLOAT")
389                                 (DF "TARGET_DOUBLE_FLOAT")])
390 \f
391 ;; Start with fixed-point load and store insns.  Here we put only the more
392 ;; complex forms.  Basic data transfer is done later.
393
394 (define_expand "zero_extend<mode>di2"
395   [(set (match_operand:DI 0 "gpc_reg_operand" "")
396         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
397   "TARGET_POWERPC64"
398   "")
399
400 (define_insn "*zero_extend<mode>di2_internal1"
401   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
402         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
403   "TARGET_POWERPC64 && (<MODE>mode != SImode || !TARGET_LFIWZX)"
404   "@
405    l<wd>z%U1%X1 %0,%1
406    rldicl %0,%1,0,<dbits>"
407   [(set_attr_alternative "type"
408       [(if_then_else
409          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
410          (const_string "load_ux")
411          (if_then_else
412            (match_test "update_address_mem (operands[1], VOIDmode)")
413            (const_string "load_u")
414            (const_string "load")))
415        (const_string "*")])])
416
417 (define_insn "*zero_extend<mode>di2_internal2"
418   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
419         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
420                     (const_int 0)))
421    (clobber (match_scratch:DI 2 "=r,r"))]
422   "TARGET_64BIT"
423   "@
424    rldicl. %2,%1,0,<dbits>
425    #"
426   [(set_attr "type" "compare")
427    (set_attr "length" "4,8")])
428
429 (define_split
430   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
431         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
432                     (const_int 0)))
433    (clobber (match_scratch:DI 2 ""))]
434   "TARGET_POWERPC64 && reload_completed"
435   [(set (match_dup 2)
436         (zero_extend:DI (match_dup 1)))
437    (set (match_dup 0)
438         (compare:CC (match_dup 2)
439                     (const_int 0)))]
440   "")
441
442 (define_insn "*zero_extend<mode>di2_internal3"
443   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
444         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
445                     (const_int 0)))
446    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
447         (zero_extend:DI (match_dup 1)))]
448   "TARGET_64BIT"
449   "@
450    rldicl. %0,%1,0,<dbits>
451    #"
452   [(set_attr "type" "compare")
453    (set_attr "length" "4,8")])
454
455 (define_split
456   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
457         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
458                     (const_int 0)))
459    (set (match_operand:DI 0 "gpc_reg_operand" "")
460         (zero_extend:DI (match_dup 1)))]
461   "TARGET_POWERPC64 && reload_completed"
462   [(set (match_dup 0)
463         (zero_extend:DI (match_dup 1)))
464    (set (match_dup 2)
465         (compare:CC (match_dup 0)
466                     (const_int 0)))]
467   "")
468
469 (define_insn "*zero_extendsidi2_lfiwzx"
470   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,??wm,!wz,!wm")
471         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r,r,Z,Z")))]
472   "TARGET_POWERPC64 && TARGET_LFIWZX"
473   "@
474    lwz%U1%X1 %0,%1
475    rldicl %0,%1,0,32
476    mtvsrwz %x0,%1
477    lfiwzx %0,%y1
478    lxsiwzx %x0,%y1"
479   [(set_attr_alternative "type"
480       [(if_then_else
481          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
482          (const_string "load_ux")
483          (if_then_else
484            (match_test "update_address_mem (operands[1], VOIDmode)")
485            (const_string "load_u")
486            (const_string "load")))
487        (const_string "*")
488        (const_string "mffgpr")
489        (const_string "fpload")
490        (const_string "fpload")])])
491
492 (define_insn "extendqidi2"
493   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
494         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
495   "TARGET_POWERPC64"
496   "extsb %0,%1"
497   [(set_attr "type" "exts")])
498
499 (define_insn ""
500   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
501         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
502                     (const_int 0)))
503    (clobber (match_scratch:DI 2 "=r,r"))]
504   "TARGET_64BIT"
505   "@
506    extsb. %2,%1
507    #"
508   [(set_attr "type" "compare")
509    (set_attr "length" "4,8")])
510
511 (define_split
512   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
513         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
514                     (const_int 0)))
515    (clobber (match_scratch:DI 2 ""))]
516   "TARGET_POWERPC64 && reload_completed"
517   [(set (match_dup 2)
518         (sign_extend:DI (match_dup 1)))
519    (set (match_dup 0)
520         (compare:CC (match_dup 2)
521                     (const_int 0)))]
522   "")
523
524 (define_insn ""
525   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
526         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
527                     (const_int 0)))
528    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
529         (sign_extend:DI (match_dup 1)))]
530   "TARGET_64BIT"
531   "@
532    extsb. %0,%1
533    #"
534   [(set_attr "type" "compare")
535    (set_attr "length" "4,8")])
536
537 (define_split
538   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
539         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
540                     (const_int 0)))
541    (set (match_operand:DI 0 "gpc_reg_operand" "")
542         (sign_extend:DI (match_dup 1)))]
543   "TARGET_POWERPC64 && reload_completed"
544   [(set (match_dup 0)
545         (sign_extend:DI (match_dup 1)))
546    (set (match_dup 2)
547         (compare:CC (match_dup 0)
548                     (const_int 0)))]
549   "")
550
551 (define_expand "extendhidi2"
552   [(set (match_operand:DI 0 "gpc_reg_operand" "")
553         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
554   "TARGET_POWERPC64"
555   "")
556
557 (define_insn ""
558   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
559         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
560   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
561   "@
562    lha%U1%X1 %0,%1
563    extsh %0,%1"
564   [(set_attr_alternative "type"
565       [(if_then_else
566          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
567          (const_string "load_ext_ux")
568          (if_then_else
569            (match_test "update_address_mem (operands[1], VOIDmode)")
570            (const_string "load_ext_u")
571            (const_string "load_ext")))
572        (const_string "exts")])])
573
574 (define_insn ""
575   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
576         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
577   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
578   "extsh %0,%1"
579   [(set_attr "type" "exts")])
580
581 (define_insn ""
582   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
583         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
584                     (const_int 0)))
585    (clobber (match_scratch:DI 2 "=r,r"))]
586   "TARGET_64BIT"
587   "@
588    extsh. %2,%1
589    #"
590   [(set_attr "type" "compare")
591    (set_attr "length" "4,8")])
592
593 (define_split
594   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
595         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
596                     (const_int 0)))
597    (clobber (match_scratch:DI 2 ""))]
598   "TARGET_POWERPC64 && reload_completed"
599   [(set (match_dup 2)
600         (sign_extend:DI (match_dup 1)))
601    (set (match_dup 0)
602         (compare:CC (match_dup 2)
603                     (const_int 0)))]
604   "")
605
606 (define_insn ""
607   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
608         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
609                     (const_int 0)))
610    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
611         (sign_extend:DI (match_dup 1)))]
612   "TARGET_64BIT"
613   "@
614    extsh. %0,%1
615    #"
616   [(set_attr "type" "compare")
617    (set_attr "length" "4,8")])
618
619 (define_split
620   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
621         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
622                     (const_int 0)))
623    (set (match_operand:DI 0 "gpc_reg_operand" "")
624         (sign_extend:DI (match_dup 1)))]
625   "TARGET_POWERPC64 && reload_completed"
626   [(set (match_dup 0)
627         (sign_extend:DI (match_dup 1)))
628    (set (match_dup 2)
629         (compare:CC (match_dup 0)
630                     (const_int 0)))]
631   "")
632
633 (define_expand "extendsidi2"
634   [(set (match_operand:DI 0 "gpc_reg_operand" "")
635         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
636   "TARGET_POWERPC64"
637   "")
638
639 (define_insn "*extendsidi2_lfiwax"
640   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,??wm,!wl,!wm")
641         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r,r,Z,Z")))]
642   "TARGET_POWERPC64 && TARGET_LFIWAX"
643   "@
644    lwa%U1%X1 %0,%1
645    extsw %0,%1
646    mtvsrwa %x0,%1
647    lfiwax %0,%y1
648    lxsiwax %x0,%y1"
649   [(set_attr_alternative "type"
650       [(if_then_else
651          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
652          (const_string "load_ext_ux")
653          (if_then_else
654            (match_test "update_address_mem (operands[1], VOIDmode)")
655            (const_string "load_ext_u")
656            (const_string "load_ext")))
657        (const_string "exts")
658        (const_string "mffgpr")
659        (const_string "fpload")
660        (const_string "fpload")])])
661
662 (define_insn "*extendsidi2_nocell"
663   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
664         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
665   "TARGET_POWERPC64 && rs6000_gen_cell_microcode && !TARGET_LFIWAX"
666   "@
667    lwa%U1%X1 %0,%1
668    extsw %0,%1"
669   [(set_attr_alternative "type"
670       [(if_then_else
671          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
672          (const_string "load_ext_ux")
673          (if_then_else
674            (match_test "update_address_mem (operands[1], VOIDmode)")
675            (const_string "load_ext_u")
676            (const_string "load_ext")))
677        (const_string "exts")])])
678
679 (define_insn "*extendsidi2_nocell"
680   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
681         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
682   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
683   "extsw %0,%1"
684   [(set_attr "type" "exts")])
685
686 (define_insn ""
687   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
688         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
689                     (const_int 0)))
690    (clobber (match_scratch:DI 2 "=r,r"))]
691   "TARGET_64BIT"
692   "@
693    extsw. %2,%1
694    #"
695   [(set_attr "type" "compare")
696    (set_attr "length" "4,8")])
697
698 (define_split
699   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
700         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
701                     (const_int 0)))
702    (clobber (match_scratch:DI 2 ""))]
703   "TARGET_POWERPC64 && reload_completed"
704   [(set (match_dup 2)
705         (sign_extend:DI (match_dup 1)))
706    (set (match_dup 0)
707         (compare:CC (match_dup 2)
708                     (const_int 0)))]
709   "")
710
711 (define_insn ""
712   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
713         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
714                     (const_int 0)))
715    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
716         (sign_extend:DI (match_dup 1)))]
717   "TARGET_64BIT"
718   "@
719    extsw. %0,%1
720    #"
721   [(set_attr "type" "compare")
722    (set_attr "length" "4,8")])
723
724 (define_split
725   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
726         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
727                     (const_int 0)))
728    (set (match_operand:DI 0 "gpc_reg_operand" "")
729         (sign_extend:DI (match_dup 1)))]
730   "TARGET_POWERPC64 && reload_completed"
731   [(set (match_dup 0)
732         (sign_extend:DI (match_dup 1)))
733    (set (match_dup 2)
734         (compare:CC (match_dup 0)
735                     (const_int 0)))]
736   "")
737
738 (define_expand "zero_extendqisi2"
739   [(set (match_operand:SI 0 "gpc_reg_operand" "")
740         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
741   ""
742   "")
743
744 (define_insn ""
745   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
746         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
747   ""
748   "@
749    lbz%U1%X1 %0,%1
750    rlwinm %0,%1,0,0xff"
751   [(set_attr_alternative "type"
752       [(if_then_else
753          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
754          (const_string "load_ux")
755          (if_then_else
756            (match_test "update_address_mem (operands[1], VOIDmode)")
757            (const_string "load_u")
758            (const_string "load")))
759        (const_string "*")])])
760
761 (define_insn ""
762   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
763         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
764                     (const_int 0)))
765    (clobber (match_scratch:SI 2 "=r,r"))]
766   ""
767   "@
768    andi. %2,%1,0xff
769    #"
770   [(set_attr "type" "fast_compare,compare")
771    (set_attr "length" "4,8")])
772
773 (define_split
774   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
775         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
776                     (const_int 0)))
777    (clobber (match_scratch:SI 2 ""))]
778   "reload_completed"
779   [(set (match_dup 2)
780         (zero_extend:SI (match_dup 1)))
781    (set (match_dup 0)
782         (compare:CC (match_dup 2)
783                     (const_int 0)))]
784   "")
785
786 (define_insn ""
787   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
788         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
789                     (const_int 0)))
790    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
791         (zero_extend:SI (match_dup 1)))]
792   ""
793   "@
794    andi. %0,%1,0xff
795    #"
796   [(set_attr "type" "fast_compare,compare")
797    (set_attr "length" "4,8")])
798
799 (define_split
800   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
801         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
802                     (const_int 0)))
803    (set (match_operand:SI 0 "gpc_reg_operand" "")
804         (zero_extend:SI (match_dup 1)))]
805   "reload_completed"
806   [(set (match_dup 0)
807         (zero_extend:SI (match_dup 1)))
808    (set (match_dup 2)
809         (compare:CC (match_dup 0)
810                     (const_int 0)))]
811   "")
812
813 (define_insn "extendqisi2"
814   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
815         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
816   ""
817   "extsb %0,%1"
818   [(set_attr "type" "exts")])
819
820 (define_insn ""
821   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
822         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
823                     (const_int 0)))
824    (clobber (match_scratch:SI 2 "=r,r"))]
825   ""
826   "@
827    extsb. %2,%1
828    #"
829   [(set_attr "type" "compare")
830    (set_attr "length" "4,8")])
831
832 (define_split
833   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
834         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
835                     (const_int 0)))
836    (clobber (match_scratch:SI 2 ""))]
837   "reload_completed"
838   [(set (match_dup 2)
839         (sign_extend:SI (match_dup 1)))
840    (set (match_dup 0)
841         (compare:CC (match_dup 2)
842                     (const_int 0)))]
843   "")
844
845 (define_insn ""
846   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
847         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
848                     (const_int 0)))
849    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
850         (sign_extend:SI (match_dup 1)))]
851   ""
852   "@
853    extsb. %0,%1
854    #"
855   [(set_attr "type" "compare")
856    (set_attr "length" "4,8")])
857
858 (define_split
859   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
860         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
861                     (const_int 0)))
862    (set (match_operand:SI 0 "gpc_reg_operand" "")
863         (sign_extend:SI (match_dup 1)))]
864   "reload_completed"
865   [(set (match_dup 0)
866         (sign_extend:SI (match_dup 1)))
867    (set (match_dup 2)
868         (compare:CC (match_dup 0)
869                     (const_int 0)))]
870   "")
871
872 (define_insn ""
873   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
874         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
875   ""
876   "@
877    lbz%U1%X1 %0,%1
878    rlwinm %0,%1,0,0xff"
879   [(set_attr_alternative "type"
880       [(if_then_else
881          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
882          (const_string "load_ux")
883          (if_then_else
884            (match_test "update_address_mem (operands[1], VOIDmode)")
885            (const_string "load_u")
886            (const_string "load")))
887        (const_string "*")])])
888
889 (define_insn ""
890   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
891         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
892                     (const_int 0)))
893    (clobber (match_scratch:HI 2 "=r,r"))]
894   ""
895   "@
896    andi. %2,%1,0xff
897    #"
898   [(set_attr "type" "fast_compare,compare")
899    (set_attr "length" "4,8")])
900
901 (define_split
902   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
903         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
904                     (const_int 0)))
905    (clobber (match_scratch:HI 2 ""))]
906   "reload_completed"
907   [(set (match_dup 2)
908         (zero_extend:HI (match_dup 1)))
909    (set (match_dup 0)
910         (compare:CC (match_dup 2)
911                     (const_int 0)))]
912   "")
913
914 (define_insn ""
915   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
916         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
917                     (const_int 0)))
918    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
919         (zero_extend:HI (match_dup 1)))]
920   ""
921   "@
922    andi. %0,%1,0xff
923    #"
924   [(set_attr "type" "fast_compare,compare")
925    (set_attr "length" "4,8")])
926
927 (define_split
928   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
929         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
930                     (const_int 0)))
931    (set (match_operand:HI 0 "gpc_reg_operand" "")
932         (zero_extend:HI (match_dup 1)))]
933   "reload_completed"
934   [(set (match_dup 0)
935         (zero_extend:HI (match_dup 1)))
936    (set (match_dup 2)
937         (compare:CC (match_dup 0)
938                     (const_int 0)))]
939   "")
940
941 (define_insn "extendqihi2"
942   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
943         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
944   ""
945   "extsb %0,%1"
946   [(set_attr "type" "exts")])
947
948 (define_insn ""
949   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
950         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
951                     (const_int 0)))
952    (clobber (match_scratch:HI 2 "=r,r"))]
953   ""
954   "@
955    extsb. %2,%1
956    #"
957   [(set_attr "type" "compare")
958    (set_attr "length" "4,8")])
959
960 (define_split
961   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
962         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
963                     (const_int 0)))
964    (clobber (match_scratch:HI 2 ""))]
965   "reload_completed"
966   [(set (match_dup 2)
967         (sign_extend:HI (match_dup 1)))
968    (set (match_dup 0)
969         (compare:CC (match_dup 2)
970                     (const_int 0)))]
971   "")
972
973 (define_insn ""
974   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
975         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
976                     (const_int 0)))
977    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
978         (sign_extend:HI (match_dup 1)))]
979   ""
980   "@
981    extsb. %0,%1
982    #"
983   [(set_attr "type" "compare")
984    (set_attr "length" "4,8")])
985
986 (define_split
987   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
988         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
989                     (const_int 0)))
990    (set (match_operand:HI 0 "gpc_reg_operand" "")
991         (sign_extend:HI (match_dup 1)))]
992   "reload_completed"
993   [(set (match_dup 0)
994         (sign_extend:HI (match_dup 1)))
995    (set (match_dup 2)
996         (compare:CC (match_dup 0)
997                     (const_int 0)))]
998   "")
999
1000 (define_expand "zero_extendhisi2"
1001   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1002         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1003   ""
1004   "")
1005
1006 (define_insn ""
1007   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1008         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1009   ""
1010   "@
1011    lhz%U1%X1 %0,%1
1012    rlwinm %0,%1,0,0xffff"
1013   [(set_attr_alternative "type"
1014       [(if_then_else
1015          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
1016          (const_string "load_ux")
1017          (if_then_else
1018            (match_test "update_address_mem (operands[1], VOIDmode)")
1019            (const_string "load_u")
1020            (const_string "load")))
1021        (const_string "*")])])
1022
1023 (define_insn ""
1024   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1025         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1026                     (const_int 0)))
1027    (clobber (match_scratch:SI 2 "=r,r"))]
1028   ""
1029   "@
1030    andi. %2,%1,0xffff
1031    #"
1032   [(set_attr "type" "fast_compare,compare")
1033    (set_attr "length" "4,8")])
1034
1035 (define_split
1036   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1037         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1038                     (const_int 0)))
1039    (clobber (match_scratch:SI 2 ""))]
1040   "reload_completed"
1041   [(set (match_dup 2)
1042         (zero_extend:SI (match_dup 1)))
1043    (set (match_dup 0)
1044         (compare:CC (match_dup 2)
1045                     (const_int 0)))]
1046   "")
1047
1048 (define_insn ""
1049   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1050         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1051                     (const_int 0)))
1052    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1053         (zero_extend:SI (match_dup 1)))]
1054   ""
1055   "@
1056    andi. %0,%1,0xffff
1057    #"
1058   [(set_attr "type" "fast_compare,compare")
1059    (set_attr "length" "4,8")])
1060
1061 (define_split
1062   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1063         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1064                     (const_int 0)))
1065    (set (match_operand:SI 0 "gpc_reg_operand" "")
1066         (zero_extend:SI (match_dup 1)))]
1067   "reload_completed"
1068   [(set (match_dup 0)
1069         (zero_extend:SI (match_dup 1)))
1070    (set (match_dup 2)
1071         (compare:CC (match_dup 0)
1072                     (const_int 0)))]
1073   "")
1074
1075 (define_expand "extendhisi2"
1076   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1077         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1078   ""
1079   "")
1080
1081 (define_insn ""
1082   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1083         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1084   "rs6000_gen_cell_microcode"
1085   "@
1086    lha%U1%X1 %0,%1
1087    extsh %0,%1"
1088   [(set_attr_alternative "type"
1089       [(if_then_else
1090          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
1091          (const_string "load_ext_ux")
1092          (if_then_else
1093            (match_test "update_address_mem (operands[1], VOIDmode)")
1094            (const_string "load_ext_u")
1095            (const_string "load_ext")))
1096        (const_string "exts")])])
1097
1098 (define_insn ""
1099   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1100         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
1101   "!rs6000_gen_cell_microcode"
1102   "extsh %0,%1"
1103   [(set_attr "type" "exts")])
1104
1105 (define_insn ""
1106   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1107         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1108                     (const_int 0)))
1109    (clobber (match_scratch:SI 2 "=r,r"))]
1110   ""
1111   "@
1112    extsh. %2,%1
1113    #"
1114   [(set_attr "type" "compare")
1115    (set_attr "length" "4,8")])
1116
1117 (define_split
1118   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1119         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1120                     (const_int 0)))
1121    (clobber (match_scratch:SI 2 ""))]
1122   "reload_completed"
1123   [(set (match_dup 2)
1124         (sign_extend:SI (match_dup 1)))
1125    (set (match_dup 0)
1126         (compare:CC (match_dup 2)
1127                     (const_int 0)))]
1128   "")
1129
1130 (define_insn ""
1131   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1132         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1133                     (const_int 0)))
1134    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1135         (sign_extend:SI (match_dup 1)))]
1136   ""
1137   "@
1138    extsh. %0,%1
1139    #"
1140   [(set_attr "type" "compare")
1141    (set_attr "length" "4,8")])
1142
1143 (define_split
1144   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1145         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1146                     (const_int 0)))
1147    (set (match_operand:SI 0 "gpc_reg_operand" "")
1148         (sign_extend:SI (match_dup 1)))]
1149   "reload_completed"
1150   [(set (match_dup 0)
1151         (sign_extend:SI (match_dup 1)))
1152    (set (match_dup 2)
1153         (compare:CC (match_dup 0)
1154                     (const_int 0)))]
1155   "")
1156 \f
1157 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
1158
1159 (define_insn "*macchwc"
1160   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1161         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1162                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1163                                        (const_int 16))
1164                                       (sign_extend:SI
1165                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1166                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1167                     (const_int 0)))
1168    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1169         (plus:SI (mult:SI (ashiftrt:SI
1170                            (match_dup 2)
1171                            (const_int 16))
1172                           (sign_extend:SI
1173                            (match_dup 1)))
1174                  (match_dup 4)))]
1175   "TARGET_MULHW"
1176   "macchw. %0,%1,%2"
1177   [(set_attr "type" "imul3")])
1178
1179 (define_insn "*macchw"
1180   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1181         (plus:SI (mult:SI (ashiftrt:SI
1182                            (match_operand:SI 2 "gpc_reg_operand" "r")
1183                            (const_int 16))
1184                           (sign_extend:SI
1185                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1186                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1187   "TARGET_MULHW"
1188   "macchw %0,%1,%2"
1189   [(set_attr "type" "imul3")])
1190
1191 (define_insn "*macchwuc"
1192   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1193         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1194                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1195                                        (const_int 16))
1196                                       (zero_extend:SI
1197                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1198                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1199                     (const_int 0)))
1200    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1201         (plus:SI (mult:SI (lshiftrt:SI
1202                            (match_dup 2)
1203                            (const_int 16))
1204                           (zero_extend:SI
1205                            (match_dup 1)))
1206                  (match_dup 4)))]
1207   "TARGET_MULHW"
1208   "macchwu. %0,%1,%2"
1209   [(set_attr "type" "imul3")])
1210
1211 (define_insn "*macchwu"
1212   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1213         (plus:SI (mult:SI (lshiftrt:SI
1214                            (match_operand:SI 2 "gpc_reg_operand" "r")
1215                            (const_int 16))
1216                           (zero_extend:SI
1217                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1218                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1219   "TARGET_MULHW"
1220   "macchwu %0,%1,%2"
1221   [(set_attr "type" "imul3")])
1222
1223 (define_insn "*machhwc"
1224   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1225         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1226                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1227                                        (const_int 16))
1228                                       (ashiftrt:SI
1229                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1230                                        (const_int 16)))
1231                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1232                     (const_int 0)))
1233    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1234         (plus:SI (mult:SI (ashiftrt:SI
1235                            (match_dup 1)
1236                            (const_int 16))
1237                           (ashiftrt:SI
1238                            (match_dup 2)
1239                            (const_int 16)))
1240                  (match_dup 4)))]
1241   "TARGET_MULHW"
1242   "machhw. %0,%1,%2"
1243   [(set_attr "type" "imul3")])
1244
1245 (define_insn "*machhw"
1246   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1247         (plus:SI (mult:SI (ashiftrt:SI
1248                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1249                            (const_int 16))
1250                           (ashiftrt:SI
1251                            (match_operand:SI 2 "gpc_reg_operand" "r")
1252                            (const_int 16)))
1253                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1254   "TARGET_MULHW"
1255   "machhw %0,%1,%2"
1256   [(set_attr "type" "imul3")])
1257
1258 (define_insn "*machhwuc"
1259   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1260         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1261                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1262                                        (const_int 16))
1263                                       (lshiftrt:SI
1264                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1265                                        (const_int 16)))
1266                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1267                     (const_int 0)))
1268    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1269         (plus:SI (mult:SI (lshiftrt:SI
1270                            (match_dup 1)
1271                            (const_int 16))
1272                           (lshiftrt:SI
1273                            (match_dup 2)
1274                            (const_int 16)))
1275                  (match_dup 4)))]
1276   "TARGET_MULHW"
1277   "machhwu. %0,%1,%2"
1278   [(set_attr "type" "imul3")])
1279
1280 (define_insn "*machhwu"
1281   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1282         (plus:SI (mult:SI (lshiftrt:SI
1283                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1284                            (const_int 16))
1285                           (lshiftrt:SI
1286                            (match_operand:SI 2 "gpc_reg_operand" "r")
1287                            (const_int 16)))
1288                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1289   "TARGET_MULHW"
1290   "machhwu %0,%1,%2"
1291   [(set_attr "type" "imul3")])
1292
1293 (define_insn "*maclhwc"
1294   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1295         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1296                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1297                                       (sign_extend:SI
1298                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1299                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1300                     (const_int 0)))
1301    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1302         (plus:SI (mult:SI (sign_extend:SI
1303                            (match_dup 1))
1304                           (sign_extend:SI
1305                            (match_dup 2)))
1306                  (match_dup 4)))]
1307   "TARGET_MULHW"
1308   "maclhw. %0,%1,%2"
1309   [(set_attr "type" "imul3")])
1310
1311 (define_insn "*maclhw"
1312   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1313         (plus:SI (mult:SI (sign_extend:SI
1314                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1315                           (sign_extend:SI
1316                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1317                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1318   "TARGET_MULHW"
1319   "maclhw %0,%1,%2"
1320   [(set_attr "type" "imul3")])
1321
1322 (define_insn "*maclhwuc"
1323   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1324         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1325                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1326                                       (zero_extend:SI
1327                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1328                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1329                     (const_int 0)))
1330    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1331         (plus:SI (mult:SI (zero_extend:SI
1332                            (match_dup 1))
1333                           (zero_extend:SI
1334                            (match_dup 2)))
1335                  (match_dup 4)))]
1336   "TARGET_MULHW"
1337   "maclhwu. %0,%1,%2"
1338   [(set_attr "type" "imul3")])
1339
1340 (define_insn "*maclhwu"
1341   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1342         (plus:SI (mult:SI (zero_extend:SI
1343                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1344                           (zero_extend:SI
1345                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1346                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1347   "TARGET_MULHW"
1348   "maclhwu %0,%1,%2"
1349   [(set_attr "type" "imul3")])
1350
1351 (define_insn "*nmacchwc"
1352   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1353         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1354                               (mult:SI (ashiftrt:SI
1355                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1356                                         (const_int 16))
1357                                        (sign_extend:SI
1358                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1359                     (const_int 0)))
1360    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1361         (minus:SI (match_dup 4)
1362                   (mult:SI (ashiftrt:SI
1363                             (match_dup 2)
1364                             (const_int 16))
1365                            (sign_extend:SI
1366                             (match_dup 1)))))]
1367   "TARGET_MULHW"
1368   "nmacchw. %0,%1,%2"
1369   [(set_attr "type" "imul3")])
1370
1371 (define_insn "*nmacchw"
1372   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1373         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1374                   (mult:SI (ashiftrt:SI
1375                             (match_operand:SI 2 "gpc_reg_operand" "r")
1376                             (const_int 16))
1377                            (sign_extend:SI
1378                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1379   "TARGET_MULHW"
1380   "nmacchw %0,%1,%2"
1381   [(set_attr "type" "imul3")])
1382
1383 (define_insn "*nmachhwc"
1384   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1385         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1386                               (mult:SI (ashiftrt:SI
1387                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1388                                         (const_int 16))
1389                                        (ashiftrt:SI
1390                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1391                                         (const_int 16))))
1392                     (const_int 0)))
1393    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1394         (minus:SI (match_dup 4)
1395                   (mult:SI (ashiftrt:SI
1396                             (match_dup 1)
1397                             (const_int 16))
1398                            (ashiftrt:SI
1399                             (match_dup 2)
1400                             (const_int 16)))))]
1401   "TARGET_MULHW"
1402   "nmachhw. %0,%1,%2"
1403   [(set_attr "type" "imul3")])
1404
1405 (define_insn "*nmachhw"
1406   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1407         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1408                   (mult:SI (ashiftrt:SI
1409                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1410                             (const_int 16))
1411                            (ashiftrt:SI
1412                             (match_operand:SI 2 "gpc_reg_operand" "r")
1413                             (const_int 16)))))]
1414   "TARGET_MULHW"
1415   "nmachhw %0,%1,%2"
1416   [(set_attr "type" "imul3")])
1417
1418 (define_insn "*nmaclhwc"
1419   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1420         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1421                               (mult:SI (sign_extend:SI
1422                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1423                                        (sign_extend:SI
1424                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1425                     (const_int 0)))
1426    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1427         (minus:SI (match_dup 4)
1428                   (mult:SI (sign_extend:SI
1429                             (match_dup 1))
1430                            (sign_extend:SI
1431                             (match_dup 2)))))]
1432   "TARGET_MULHW"
1433   "nmaclhw. %0,%1,%2"
1434   [(set_attr "type" "imul3")])
1435
1436 (define_insn "*nmaclhw"
1437   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1438         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1439                   (mult:SI (sign_extend:SI
1440                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1441                            (sign_extend:SI
1442                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1443   "TARGET_MULHW"
1444   "nmaclhw %0,%1,%2"
1445   [(set_attr "type" "imul3")])
1446
1447 (define_insn "*mulchwc"
1448   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1449         (compare:CC (mult:SI (ashiftrt:SI
1450                               (match_operand:SI 2 "gpc_reg_operand" "r")
1451                               (const_int 16))
1452                              (sign_extend:SI
1453                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1454                     (const_int 0)))
1455    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1456         (mult:SI (ashiftrt:SI
1457                   (match_dup 2)
1458                   (const_int 16))
1459                  (sign_extend:SI
1460                   (match_dup 1))))]
1461   "TARGET_MULHW"
1462   "mulchw. %0,%1,%2"
1463   [(set_attr "type" "imul3")])
1464
1465 (define_insn "*mulchw"
1466   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1467         (mult:SI (ashiftrt:SI
1468                   (match_operand:SI 2 "gpc_reg_operand" "r")
1469                   (const_int 16))
1470                  (sign_extend:SI
1471                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1472   "TARGET_MULHW"
1473   "mulchw %0,%1,%2"
1474   [(set_attr "type" "imul3")])
1475
1476 (define_insn "*mulchwuc"
1477   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1478         (compare:CC (mult:SI (lshiftrt:SI
1479                               (match_operand:SI 2 "gpc_reg_operand" "r")
1480                               (const_int 16))
1481                              (zero_extend:SI
1482                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1483                     (const_int 0)))
1484    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1485         (mult:SI (lshiftrt:SI
1486                   (match_dup 2)
1487                   (const_int 16))
1488                  (zero_extend:SI
1489                   (match_dup 1))))]
1490   "TARGET_MULHW"
1491   "mulchwu. %0,%1,%2"
1492   [(set_attr "type" "imul3")])
1493
1494 (define_insn "*mulchwu"
1495   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1496         (mult:SI (lshiftrt:SI
1497                   (match_operand:SI 2 "gpc_reg_operand" "r")
1498                   (const_int 16))
1499                  (zero_extend:SI
1500                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1501   "TARGET_MULHW"
1502   "mulchwu %0,%1,%2"
1503   [(set_attr "type" "imul3")])
1504
1505 (define_insn "*mulhhwc"
1506   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1507         (compare:CC (mult:SI (ashiftrt:SI
1508                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1509                               (const_int 16))
1510                              (ashiftrt:SI
1511                               (match_operand:SI 2 "gpc_reg_operand" "r")
1512                               (const_int 16)))
1513                     (const_int 0)))
1514    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1515         (mult:SI (ashiftrt:SI
1516                   (match_dup 1)
1517                   (const_int 16))
1518                  (ashiftrt:SI
1519                   (match_dup 2)
1520                   (const_int 16))))]
1521   "TARGET_MULHW"
1522   "mulhhw. %0,%1,%2"
1523   [(set_attr "type" "imul3")])
1524
1525 (define_insn "*mulhhw"
1526   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1527         (mult:SI (ashiftrt:SI
1528                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1529                   (const_int 16))
1530                  (ashiftrt:SI
1531                   (match_operand:SI 2 "gpc_reg_operand" "r")
1532                   (const_int 16))))]
1533   "TARGET_MULHW"
1534   "mulhhw %0,%1,%2"
1535   [(set_attr "type" "imul3")])
1536
1537 (define_insn "*mulhhwuc"
1538   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1539         (compare:CC (mult:SI (lshiftrt:SI
1540                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1541                               (const_int 16))
1542                              (lshiftrt:SI
1543                               (match_operand:SI 2 "gpc_reg_operand" "r")
1544                               (const_int 16)))
1545                     (const_int 0)))
1546    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1547         (mult:SI (lshiftrt:SI
1548                   (match_dup 1)
1549                   (const_int 16))
1550                  (lshiftrt:SI
1551                   (match_dup 2)
1552                   (const_int 16))))]
1553   "TARGET_MULHW"
1554   "mulhhwu. %0,%1,%2"
1555   [(set_attr "type" "imul3")])
1556
1557 (define_insn "*mulhhwu"
1558   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1559         (mult:SI (lshiftrt:SI
1560                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1561                   (const_int 16))
1562                  (lshiftrt:SI
1563                   (match_operand:SI 2 "gpc_reg_operand" "r")
1564                   (const_int 16))))]
1565   "TARGET_MULHW"
1566   "mulhhwu %0,%1,%2"
1567   [(set_attr "type" "imul3")])
1568
1569 (define_insn "*mullhwc"
1570   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1571         (compare:CC (mult:SI (sign_extend:SI
1572                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1573                              (sign_extend:SI
1574                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1575                     (const_int 0)))
1576    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1577         (mult:SI (sign_extend:SI
1578                   (match_dup 1))
1579                  (sign_extend:SI
1580                   (match_dup 2))))]
1581   "TARGET_MULHW"
1582   "mullhw. %0,%1,%2"
1583   [(set_attr "type" "imul3")])
1584
1585 (define_insn "*mullhw"
1586   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1587         (mult:SI (sign_extend:SI
1588                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1589                  (sign_extend:SI
1590                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1591   "TARGET_MULHW"
1592   "mullhw %0,%1,%2"
1593   [(set_attr "type" "imul3")])
1594
1595 (define_insn "*mullhwuc"
1596   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1597         (compare:CC (mult:SI (zero_extend:SI
1598                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1599                              (zero_extend:SI
1600                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1601                     (const_int 0)))
1602    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1603         (mult:SI (zero_extend:SI
1604                   (match_dup 1))
1605                  (zero_extend:SI
1606                   (match_dup 2))))]
1607   "TARGET_MULHW"
1608   "mullhwu. %0,%1,%2"
1609   [(set_attr "type" "imul3")])
1610
1611 (define_insn "*mullhwu"
1612   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1613         (mult:SI (zero_extend:SI
1614                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1615                  (zero_extend:SI
1616                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1617   "TARGET_MULHW"
1618   "mullhwu %0,%1,%2"
1619   [(set_attr "type" "imul3")])
1620 \f
1621 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1622 (define_insn "dlmzb"
1623   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1624         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1625                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1626                    UNSPEC_DLMZB_CR))
1627    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1628         (unspec:SI [(match_dup 1)
1629                     (match_dup 2)]
1630                    UNSPEC_DLMZB))]
1631   "TARGET_DLMZB"
1632   "dlmzb. %0,%1,%2")
1633
1634 (define_expand "strlensi"
1635   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1636         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1637                     (match_operand:QI 2 "const_int_operand" "")
1638                     (match_operand 3 "const_int_operand" "")]
1639                    UNSPEC_DLMZB_STRLEN))
1640    (clobber (match_scratch:CC 4 "=x"))]
1641   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1642 {
1643   rtx result = operands[0];
1644   rtx src = operands[1];
1645   rtx search_char = operands[2];
1646   rtx align = operands[3];
1647   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1648   rtx loop_label, end_label, mem, cr0, cond;
1649   if (search_char != const0_rtx
1650       || GET_CODE (align) != CONST_INT
1651       || INTVAL (align) < 8)
1652         FAIL;
1653   word1 = gen_reg_rtx (SImode);
1654   word2 = gen_reg_rtx (SImode);
1655   scratch_dlmzb = gen_reg_rtx (SImode);
1656   scratch_string = gen_reg_rtx (Pmode);
1657   loop_label = gen_label_rtx ();
1658   end_label = gen_label_rtx ();
1659   addr = force_reg (Pmode, XEXP (src, 0));
1660   emit_move_insn (scratch_string, addr);
1661   emit_label (loop_label);
1662   mem = change_address (src, SImode, scratch_string);
1663   emit_move_insn (word1, mem);
1664   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1665   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1666   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1667   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1668   emit_jump_insn (gen_rtx_SET (VOIDmode,
1669                                pc_rtx,
1670                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1671                                                      cond,
1672                                                      gen_rtx_LABEL_REF
1673                                                        (VOIDmode,
1674                                                         end_label),
1675                                                      pc_rtx)));
1676   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1677   emit_jump_insn (gen_rtx_SET (VOIDmode,
1678                                pc_rtx,
1679                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1680   emit_barrier ();
1681   emit_label (end_label);
1682   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1683   emit_insn (gen_subsi3 (result, scratch_string, addr));
1684   emit_insn (gen_subsi3 (result, result, const1_rtx));
1685   DONE;
1686 })
1687 \f
1688 ;; Fixed-point arithmetic insns.
1689
1690 (define_expand "add<mode>3"
1691   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1692         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1693                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1694   ""
1695 {
1696   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1697     {
1698       if (non_short_cint_operand (operands[2], DImode))
1699         FAIL;
1700     }
1701   else if (GET_CODE (operands[2]) == CONST_INT
1702            && ! add_operand (operands[2], <MODE>mode))
1703     {
1704       rtx tmp = ((!can_create_pseudo_p ()
1705                   || rtx_equal_p (operands[0], operands[1]))
1706                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1707
1708       HOST_WIDE_INT val = INTVAL (operands[2]);
1709       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1710       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1711
1712       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1713         FAIL;
1714
1715       /* The ordering here is important for the prolog expander.
1716          When space is allocated from the stack, adding 'low' first may
1717          produce a temporary deallocation (which would be bad).  */
1718       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1719       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1720       DONE;
1721     }
1722 })
1723
1724 ;; Discourage ai/addic because of carry but provide it in an alternative
1725 ;; allowing register zero as source.
1726 (define_insn "*add<mode>3_internal1"
1727   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1728         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1729                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1730   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1731   "@
1732    add %0,%1,%2
1733    addi %0,%1,%2
1734    addic %0,%1,%2
1735    addis %0,%1,%v2"
1736   [(set_attr "length" "4,4,4,4")])
1737
1738 (define_insn "addsi3_high"
1739   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1740         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1741                  (high:SI (match_operand 2 "" ""))))]
1742   "TARGET_MACHO && !TARGET_64BIT"
1743   "addis %0,%1,ha16(%2)"
1744   [(set_attr "length" "4")])
1745
1746 (define_insn "*add<mode>3_internal2"
1747   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1748         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1749                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1750                     (const_int 0)))
1751    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1752   ""
1753   "@
1754    add. %3,%1,%2
1755    addic. %3,%1,%2
1756    #
1757    #"
1758   [(set_attr "type" "fast_compare,compare,compare,compare")
1759    (set_attr "length" "4,4,8,8")])
1760
1761 (define_split
1762   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1763         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1764                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1765                     (const_int 0)))
1766    (clobber (match_scratch:GPR 3 ""))]
1767   "reload_completed"
1768   [(set (match_dup 3)
1769         (plus:GPR (match_dup 1)
1770                  (match_dup 2)))
1771    (set (match_dup 0)
1772         (compare:CC (match_dup 3)
1773                     (const_int 0)))]
1774   "")
1775
1776 (define_insn "*add<mode>3_internal3"
1777   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1778         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1779                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1780                     (const_int 0)))
1781    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1782         (plus:P (match_dup 1)
1783                 (match_dup 2)))]
1784   ""
1785   "@
1786    add. %0,%1,%2
1787    addic. %0,%1,%2
1788    #
1789    #"
1790   [(set_attr "type" "fast_compare,compare,compare,compare")
1791    (set_attr "length" "4,4,8,8")])
1792
1793 (define_split
1794   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1795         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1796                             (match_operand:P 2 "reg_or_short_operand" ""))
1797                     (const_int 0)))
1798    (set (match_operand:P 0 "gpc_reg_operand" "")
1799         (plus:P (match_dup 1) (match_dup 2)))]
1800   "reload_completed"
1801   [(set (match_dup 0)
1802         (plus:P (match_dup 1)
1803                 (match_dup 2)))
1804    (set (match_dup 3)
1805         (compare:CC (match_dup 0)
1806                     (const_int 0)))]
1807   "")
1808
1809 ;; Split an add that we can't do in one insn into two insns, each of which
1810 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1811 ;; add should be last in case the result gets used in an address.
1812
1813 (define_split
1814   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1815         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1816                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1817   ""
1818   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1819    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1820 {
1821   HOST_WIDE_INT val = INTVAL (operands[2]);
1822   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1823   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1824
1825   operands[4] = GEN_INT (low);
1826   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1827     operands[3] = GEN_INT (rest);
1828   else if (can_create_pseudo_p ())
1829     {
1830       operands[3] = gen_reg_rtx (DImode);
1831       emit_move_insn (operands[3], operands[2]);
1832       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1833       DONE;
1834     }
1835   else
1836     FAIL;
1837 })
1838
1839 (define_insn "one_cmpl<mode>2"
1840   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1841         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1842   ""
1843   "nor %0,%1,%1")
1844
1845 (define_insn ""
1846   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1847         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1848                     (const_int 0)))
1849    (clobber (match_scratch:P 2 "=r,r"))]
1850   ""
1851   "@
1852    nor. %2,%1,%1
1853    #"
1854   [(set_attr "type" "fast_compare,compare")
1855    (set_attr "length" "4,8")])
1856
1857 (define_split
1858   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1859         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1860                     (const_int 0)))
1861    (clobber (match_scratch:P 2 ""))]
1862   "reload_completed"
1863   [(set (match_dup 2)
1864         (not:P (match_dup 1)))
1865    (set (match_dup 0)
1866         (compare:CC (match_dup 2)
1867                     (const_int 0)))]
1868   "")
1869
1870 (define_insn ""
1871   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1872         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1873                     (const_int 0)))
1874    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1875         (not:P (match_dup 1)))]
1876   ""
1877   "@
1878    nor. %0,%1,%1
1879    #"
1880   [(set_attr "type" "fast_compare,compare")
1881    (set_attr "length" "4,8")])
1882
1883 (define_split
1884   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1885         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1886                     (const_int 0)))
1887    (set (match_operand:P 0 "gpc_reg_operand" "")
1888         (not:P (match_dup 1)))]
1889   "reload_completed"
1890   [(set (match_dup 0)
1891         (not:P (match_dup 1)))
1892    (set (match_dup 2)
1893         (compare:CC (match_dup 0)
1894                     (const_int 0)))]
1895   "")
1896
1897 (define_insn ""
1898   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1899         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1900                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1901   ""
1902   "@
1903    subf %0,%2,%1
1904    subfic %0,%2,%1")
1905
1906 (define_insn ""
1907   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1908         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1909                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1910                     (const_int 0)))
1911    (clobber (match_scratch:P 3 "=r,r"))]
1912   ""
1913   "@
1914    subf. %3,%2,%1
1915    #"
1916   [(set_attr "type" "fast_compare")
1917    (set_attr "length" "4,8")])
1918
1919 (define_split
1920   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1921         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1922                              (match_operand:P 2 "gpc_reg_operand" ""))
1923                     (const_int 0)))
1924    (clobber (match_scratch:P 3 ""))]
1925   "reload_completed"
1926   [(set (match_dup 3)
1927         (minus:P (match_dup 1)
1928                   (match_dup 2)))
1929    (set (match_dup 0)
1930         (compare:CC (match_dup 3)
1931                     (const_int 0)))]
1932   "")
1933
1934 (define_insn ""
1935   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1936         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1937                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1938                     (const_int 0)))
1939    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1940         (minus:P (match_dup 1)
1941                   (match_dup 2)))]
1942   ""
1943   "@
1944    subf. %0,%2,%1
1945    #"
1946   [(set_attr "type" "fast_compare")
1947    (set_attr "length" "4,8")])
1948
1949 (define_split
1950   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1951         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1952                              (match_operand:P 2 "gpc_reg_operand" ""))
1953                     (const_int 0)))
1954    (set (match_operand:P 0 "gpc_reg_operand" "")
1955         (minus:P (match_dup 1)
1956                   (match_dup 2)))]
1957   "reload_completed"
1958   [(set (match_dup 0)
1959         (minus:P (match_dup 1)
1960                   (match_dup 2)))
1961    (set (match_dup 3)
1962         (compare:CC (match_dup 0)
1963                     (const_int 0)))]
1964   "")
1965
1966 (define_expand "sub<mode>3"
1967   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1968         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1969                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1970   ""
1971   "
1972 {
1973   if (GET_CODE (operands[2]) == CONST_INT)
1974     {
1975       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1976                                  negate_rtx (<MODE>mode, operands[2])));
1977       DONE;
1978     }
1979 }")
1980
1981 (define_expand "neg<mode>2"
1982   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1983         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1984   ""
1985   "")
1986
1987 (define_insn "*neg<mode>2_internal"
1988   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1989         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1990   ""
1991   "neg %0,%1")
1992
1993 (define_insn ""
1994   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1995         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1996                     (const_int 0)))
1997    (clobber (match_scratch:P 2 "=r,r"))]
1998   ""
1999   "@
2000    neg. %2,%1
2001    #"
2002   [(set_attr "type" "fast_compare")
2003    (set_attr "length" "4,8")])
2004
2005 (define_split
2006   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2007         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2008                     (const_int 0)))
2009    (clobber (match_scratch:P 2 ""))]
2010   "reload_completed"
2011   [(set (match_dup 2)
2012         (neg:P (match_dup 1)))
2013    (set (match_dup 0)
2014         (compare:CC (match_dup 2)
2015                     (const_int 0)))]
2016   "")
2017
2018 (define_insn ""
2019   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2020         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2021                     (const_int 0)))
2022    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2023         (neg:P (match_dup 1)))]
2024   ""
2025   "@
2026    neg. %0,%1
2027    #"
2028   [(set_attr "type" "fast_compare")
2029    (set_attr "length" "4,8")])
2030
2031 (define_split
2032   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2033         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2034                     (const_int 0)))
2035    (set (match_operand:P 0 "gpc_reg_operand" "")
2036         (neg:P (match_dup 1)))]
2037   "reload_completed"
2038   [(set (match_dup 0)
2039         (neg:P (match_dup 1)))
2040    (set (match_dup 2)
2041         (compare:CC (match_dup 0)
2042                     (const_int 0)))]
2043   "")
2044
2045 (define_insn "clz<mode>2"
2046   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2047         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2048   ""
2049   "cntlz<wd> %0,%1"
2050   [(set_attr "type" "cntlz")])
2051
2052 (define_expand "ctz<mode>2"
2053   [(set (match_dup 2)
2054         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2055    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2056                                           (match_dup 2)))
2057               (clobber (scratch:CC))])
2058    (set (match_dup 4) (clz:GPR (match_dup 3)))
2059    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2060         (minus:GPR (match_dup 5) (match_dup 4)))]
2061   ""
2062   {
2063      operands[2] = gen_reg_rtx (<MODE>mode);
2064      operands[3] = gen_reg_rtx (<MODE>mode);
2065      operands[4] = gen_reg_rtx (<MODE>mode);
2066      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2067   })
2068
2069 (define_expand "ffs<mode>2"
2070   [(set (match_dup 2)
2071         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2072    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2073                                           (match_dup 2)))
2074               (clobber (scratch:CC))])
2075    (set (match_dup 4) (clz:GPR (match_dup 3)))
2076    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2077         (minus:GPR (match_dup 5) (match_dup 4)))]
2078   ""
2079   {
2080      operands[2] = gen_reg_rtx (<MODE>mode);
2081      operands[3] = gen_reg_rtx (<MODE>mode);
2082      operands[4] = gen_reg_rtx (<MODE>mode);
2083      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2084   })
2085
2086 (define_insn "popcntb<mode>2"
2087   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2088         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2089                      UNSPEC_POPCNTB))]
2090   "TARGET_POPCNTB"
2091   "popcntb %0,%1"
2092   [(set_attr "length" "4")
2093    (set_attr "type" "popcnt")])
2094
2095 (define_insn "popcntd<mode>2"
2096   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2097         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2098   "TARGET_POPCNTD"
2099   "popcnt<wd> %0,%1"
2100   [(set_attr "length" "4")
2101    (set_attr "type" "popcnt")])
2102
2103 (define_expand "popcount<mode>2"
2104   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2105         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2106   "TARGET_POPCNTB || TARGET_POPCNTD"
2107   {
2108     rs6000_emit_popcount (operands[0], operands[1]);
2109     DONE;
2110   })
2111
2112 (define_insn "parity<mode>2_cmpb"
2113   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2114         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
2115   "TARGET_CMPB && TARGET_POPCNTB"
2116   "prty<wd> %0,%1"
2117   [(set_attr "length" "4")
2118    (set_attr "type" "popcnt")])
2119
2120 (define_expand "parity<mode>2"
2121   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2122         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2123   "TARGET_POPCNTB"
2124   {
2125     rs6000_emit_parity (operands[0], operands[1]);
2126     DONE;
2127   })
2128
2129 ;; Since the hardware zeros the upper part of the register, save generating the
2130 ;; AND immediate if we are converting to unsigned
2131 (define_insn "*bswaphi2_extenddi"
2132   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2133         (zero_extend:DI
2134          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2135   "TARGET_POWERPC64"
2136   "lhbrx %0,%y1"
2137   [(set_attr "length" "4")
2138    (set_attr "type" "load")])
2139
2140 (define_insn "*bswaphi2_extendsi"
2141   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2142         (zero_extend:SI
2143          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2144   ""
2145   "lhbrx %0,%y1"
2146   [(set_attr "length" "4")
2147    (set_attr "type" "load")])
2148
2149 (define_expand "bswaphi2"
2150   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
2151                    (bswap:HI
2152                     (match_operand:HI 1 "reg_or_mem_operand" "")))
2153               (clobber (match_scratch:SI 2 ""))])]
2154   ""
2155 {
2156   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2157     operands[1] = force_reg (HImode, operands[1]);
2158 })
2159
2160 (define_insn "bswaphi2_internal"
2161   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
2162         (bswap:HI
2163          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
2164    (clobber (match_scratch:SI 2 "=X,X,&r"))]
2165   ""
2166   "@
2167    lhbrx %0,%y1
2168    sthbrx %1,%y0
2169    #"
2170   [(set_attr "length" "4,4,12")
2171    (set_attr "type" "load,store,*")])
2172
2173 ;; We are always BITS_BIG_ENDIAN, so the (const_int 16) below is
2174 ;; correct for -mlittle as well as -mbig.
2175 (define_split
2176   [(set (match_operand:HI 0 "gpc_reg_operand" "")
2177         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
2178    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2179   "reload_completed"
2180   [(set (match_dup 3)
2181         (zero_extract:SI (match_dup 4)
2182                          (const_int 8)
2183                          (const_int 16)))
2184    (set (match_dup 2)
2185         (and:SI (ashift:SI (match_dup 4)
2186                            (const_int 8))
2187                 (const_int 65280)))             ;; 0xff00
2188    (set (match_dup 3)
2189         (ior:SI (match_dup 3)
2190                 (match_dup 2)))]
2191   "
2192 {
2193   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2194   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2195 }")
2196
2197 (define_insn "*bswapsi2_extenddi"
2198   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2199         (zero_extend:DI
2200          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2201   "TARGET_POWERPC64"
2202   "lwbrx %0,%y1"
2203   [(set_attr "length" "4")
2204    (set_attr "type" "load")])
2205
2206 (define_expand "bswapsi2"
2207   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2208         (bswap:SI
2209          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2210   ""
2211 {
2212   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2213     operands[1] = force_reg (SImode, operands[1]);
2214 })
2215
2216 (define_insn "*bswapsi2_internal"
2217   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2218         (bswap:SI
2219          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2220   ""
2221   "@
2222    lwbrx %0,%y1
2223    stwbrx %1,%y0
2224    #"
2225   [(set_attr "length" "4,4,12")
2226    (set_attr "type" "load,store,*")])
2227
2228 ;; We are always BITS_BIG_ENDIAN, so the bit positions below in
2229 ;; zero_extract insns do not change for -mlittle.
2230 (define_split
2231   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2232         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2233   "reload_completed"
2234   [(set (match_dup 0)
2235         (rotate:SI (match_dup 1) (const_int 8)))
2236    (set (zero_extract:SI (match_dup 0)
2237                          (const_int 8)
2238                          (const_int 0))
2239         (match_dup 1))
2240    (set (zero_extract:SI (match_dup 0)
2241                          (const_int 8)
2242                          (const_int 16))
2243         (rotate:SI (match_dup 1)
2244                    (const_int 16)))]
2245   "")
2246
2247 (define_expand "bswapdi2"
2248   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2249                    (bswap:DI
2250                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2251               (clobber (match_scratch:DI 2 ""))
2252               (clobber (match_scratch:DI 3 ""))
2253               (clobber (match_scratch:DI 4 ""))])]
2254   ""
2255 {
2256   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2257     operands[1] = force_reg (DImode, operands[1]);
2258
2259   if (!TARGET_POWERPC64)
2260     {
2261       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2262          that uses 64-bit registers needs the same scratch registers as 64-bit
2263          mode.  */
2264       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2265       DONE;
2266     }
2267 })
2268
2269 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2270 (define_insn "*bswapdi2_ldbrx"
2271   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2272         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2273    (clobber (match_scratch:DI 2 "=X,X,&r"))
2274    (clobber (match_scratch:DI 3 "=X,X,&r"))
2275    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2276   "TARGET_POWERPC64 && TARGET_LDBRX
2277    && (REG_P (operands[0]) || REG_P (operands[1]))"
2278   "@
2279    ldbrx %0,%y1
2280    stdbrx %1,%y0
2281    #"
2282   [(set_attr "length" "4,4,36")
2283    (set_attr "type" "load,store,*")])
2284
2285 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2286 (define_insn "*bswapdi2_64bit"
2287   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2288         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2289    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2290    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2291    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2292   "TARGET_POWERPC64 && !TARGET_LDBRX
2293    && (REG_P (operands[0]) || REG_P (operands[1]))"
2294   "#"
2295   [(set_attr "length" "16,12,36")])
2296
2297 (define_split
2298   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2299         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2300    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2301    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2302    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2303   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2304   [(const_int 0)]
2305   "
2306 {
2307   rtx dest   = operands[0];
2308   rtx src    = operands[1];
2309   rtx op2    = operands[2];
2310   rtx op3    = operands[3];
2311   rtx op4    = operands[4];
2312   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode,
2313                                     BYTES_BIG_ENDIAN ? 4 : 0);
2314   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode,
2315                                     BYTES_BIG_ENDIAN ? 4 : 0);
2316   rtx addr1;
2317   rtx addr2;
2318   rtx word_high;
2319   rtx word_low;
2320
2321   addr1 = XEXP (src, 0);
2322   if (GET_CODE (addr1) == PLUS)
2323     {
2324       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2325       if (TARGET_AVOID_XFORM)
2326         {
2327           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2328           addr2 = op2;
2329         }
2330       else
2331         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2332     }
2333   else if (TARGET_AVOID_XFORM)
2334     {
2335       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2336       addr2 = op2;
2337     }
2338   else
2339     {
2340       emit_move_insn (op2, GEN_INT (4));
2341       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2342     }
2343
2344   if (BYTES_BIG_ENDIAN)
2345     {
2346       word_high = change_address (src, SImode, addr1);
2347       word_low  = change_address (src, SImode, addr2);
2348     }
2349   else
2350     {
2351       word_high = change_address (src, SImode, addr2);
2352       word_low  = change_address (src, SImode, addr1);
2353     }
2354
2355   emit_insn (gen_bswapsi2 (op3_32, word_low));
2356   emit_insn (gen_bswapsi2 (op4_32, word_high));
2357   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2358   emit_insn (gen_iordi3 (dest, dest, op4));
2359 }")
2360
2361 (define_split
2362   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2363         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2364    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2365    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2366    (clobber (match_operand:DI 4 "" ""))]
2367   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2368   [(const_int 0)]
2369   "
2370 {
2371   rtx dest   = operands[0];
2372   rtx src    = operands[1];
2373   rtx op2    = operands[2];
2374   rtx op3    = operands[3];
2375   rtx src_si = simplify_gen_subreg (SImode, src, DImode,
2376                                     BYTES_BIG_ENDIAN ? 4 : 0);
2377   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode,
2378                                     BYTES_BIG_ENDIAN ? 4 : 0);
2379   rtx addr1;
2380   rtx addr2;
2381   rtx word_high;
2382   rtx word_low;
2383
2384   addr1 = XEXP (dest, 0);
2385   if (GET_CODE (addr1) == PLUS)
2386     {
2387       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2388       if (TARGET_AVOID_XFORM)
2389         {
2390           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2391           addr2 = op2;
2392         }
2393       else
2394         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2395     }
2396   else if (TARGET_AVOID_XFORM)
2397     {
2398       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2399       addr2 = op2;
2400     }
2401   else
2402     {
2403       emit_move_insn (op2, GEN_INT (4));
2404       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2405     }
2406
2407   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2408   if (BYTES_BIG_ENDIAN)
2409     {
2410       word_high = change_address (dest, SImode, addr1);
2411       word_low  = change_address (dest, SImode, addr2);
2412     }
2413   else
2414     {
2415       word_high = change_address (dest, SImode, addr2);
2416       word_low  = change_address (dest, SImode, addr1);
2417     }
2418   emit_insn (gen_bswapsi2 (word_high, src_si));
2419   emit_insn (gen_bswapsi2 (word_low, op3_si));
2420 }")
2421
2422 (define_split
2423   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2424         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2425    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2426    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2427    (clobber (match_operand:DI 4 "" ""))]
2428   "TARGET_POWERPC64 && reload_completed"
2429   [(const_int 0)]
2430   "
2431 {
2432   rtx dest    = operands[0];
2433   rtx src     = operands[1];
2434   rtx op2     = operands[2];
2435   rtx op3     = operands[3];
2436   int lo_off  = BYTES_BIG_ENDIAN ? 4 : 0;
2437   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, lo_off);
2438   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, lo_off);
2439   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, lo_off);
2440   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, lo_off);
2441
2442   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2443   emit_insn (gen_bswapsi2 (dest_si, src_si));
2444   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2445   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2446   emit_insn (gen_iordi3 (dest, dest, op3));
2447 }")
2448
2449 (define_insn "bswapdi2_32bit"
2450   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2451         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2452    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2453   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2454   "#"
2455   [(set_attr "length" "16,12,36")])
2456
2457 (define_split
2458   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2459         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2460    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2461   "!TARGET_POWERPC64 && reload_completed"
2462   [(const_int 0)]
2463   "
2464 {
2465   rtx dest  = operands[0];
2466   rtx src   = operands[1];
2467   rtx op2   = operands[2];
2468   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2469   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2470   rtx addr1;
2471   rtx addr2;
2472   rtx word1;
2473   rtx word2;
2474
2475   addr1 = XEXP (src, 0);
2476   if (GET_CODE (addr1) == PLUS)
2477     {
2478       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2479       if (TARGET_AVOID_XFORM)
2480         {
2481           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2482           addr2 = op2;
2483         }
2484       else
2485         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2486     }
2487   else if (TARGET_AVOID_XFORM)
2488     {
2489       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2490       addr2 = op2;
2491     }
2492   else
2493     {
2494       emit_move_insn (op2, GEN_INT (4));
2495       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2496     }
2497
2498   word1 = change_address (src, SImode, addr1);
2499   word2 = change_address (src, SImode, addr2);
2500
2501   emit_insn (gen_bswapsi2 (dest2, word1));
2502   emit_insn (gen_bswapsi2 (dest1, word2));
2503 }")
2504
2505 (define_split
2506   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2507         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2508    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2509   "!TARGET_POWERPC64 && reload_completed"
2510   [(const_int 0)]
2511   "
2512 {
2513   rtx dest = operands[0];
2514   rtx src  = operands[1];
2515   rtx op2  = operands[2];
2516   rtx src1 = simplify_gen_subreg (SImode, src, DImode, 0);
2517   rtx src2 = simplify_gen_subreg (SImode, src, DImode, 4);
2518   rtx addr1;
2519   rtx addr2;
2520   rtx word1;
2521   rtx word2;
2522
2523   addr1 = XEXP (dest, 0);
2524   if (GET_CODE (addr1) == PLUS)
2525     {
2526       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2527       if (TARGET_AVOID_XFORM)
2528         {
2529           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2530           addr2 = op2;
2531         }
2532       else
2533         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2534     }
2535   else if (TARGET_AVOID_XFORM)
2536     {
2537       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2538       addr2 = op2;
2539     }
2540   else
2541     {
2542       emit_move_insn (op2, GEN_INT (4));
2543       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2544     }
2545
2546   word1 = change_address (dest, SImode, addr1);
2547   word2 = change_address (dest, SImode, addr2);
2548
2549   emit_insn (gen_bswapsi2 (word2, src1));
2550   emit_insn (gen_bswapsi2 (word1, src2));
2551 }")
2552
2553 (define_split
2554   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2555         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2556    (clobber (match_operand:SI 2 "" ""))]
2557   "!TARGET_POWERPC64 && reload_completed"
2558   [(const_int 0)]
2559   "
2560 {
2561   rtx dest  = operands[0];
2562   rtx src   = operands[1];
2563   rtx src1  = simplify_gen_subreg (SImode, src, DImode, 0);
2564   rtx src2  = simplify_gen_subreg (SImode, src, DImode, 4);
2565   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2566   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2567
2568   emit_insn (gen_bswapsi2 (dest1, src2));
2569   emit_insn (gen_bswapsi2 (dest2, src1));
2570 }")
2571
2572 (define_insn "mulsi3"
2573   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2574         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2575                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2576   ""
2577   "@
2578    mullw %0,%1,%2
2579    mulli %0,%1,%2"
2580    [(set (attr "type")
2581       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2582                 (const_string "imul3")
2583              (match_operand:SI 2 "short_cint_operand" "")
2584                 (const_string "imul2")]
2585         (const_string "imul")))])
2586
2587 (define_insn "*mulsi3_internal1"
2588   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2589         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2590                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2591                     (const_int 0)))
2592    (clobber (match_scratch:SI 3 "=r,r"))]
2593   ""
2594   "@
2595    mullw. %3,%1,%2
2596    #"
2597   [(set_attr "type" "imul_compare")
2598    (set_attr "length" "4,8")])
2599
2600 (define_split
2601   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2602         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2603                              (match_operand:SI 2 "gpc_reg_operand" ""))
2604                     (const_int 0)))
2605    (clobber (match_scratch:SI 3 ""))]
2606   "reload_completed"
2607   [(set (match_dup 3)
2608         (mult:SI (match_dup 1) (match_dup 2)))
2609    (set (match_dup 0)
2610         (compare:CC (match_dup 3)
2611                     (const_int 0)))]
2612   "")
2613
2614 (define_insn "*mulsi3_internal2"
2615   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2616         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2617                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2618                     (const_int 0)))
2619    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2620         (mult:SI (match_dup 1) (match_dup 2)))]
2621   ""
2622   "@
2623    mullw. %0,%1,%2
2624    #"
2625   [(set_attr "type" "imul_compare")
2626    (set_attr "length" "4,8")])
2627
2628 (define_split
2629   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2630         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2631                              (match_operand:SI 2 "gpc_reg_operand" ""))
2632                     (const_int 0)))
2633    (set (match_operand:SI 0 "gpc_reg_operand" "")
2634         (mult:SI (match_dup 1) (match_dup 2)))]
2635   "reload_completed"
2636   [(set (match_dup 0)
2637         (mult:SI (match_dup 1) (match_dup 2)))
2638    (set (match_dup 3)
2639         (compare:CC (match_dup 0)
2640                     (const_int 0)))]
2641   "")
2642
2643
2644 (define_insn "udiv<mode>3"
2645   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2646         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2647                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2648   ""
2649   "div<wd>u %0,%1,%2"
2650    [(set (attr "type")
2651       (cond [(match_operand:SI 0 "" "")
2652                 (const_string "idiv")]
2653         (const_string "ldiv")))])
2654
2655
2656 ;; For powers of two we can do srai/aze for divide and then adjust for
2657 ;; modulus.  If it isn't a power of two, force operands into register and do
2658 ;; a normal divide.
2659 (define_expand "div<mode>3"
2660   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2661         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2662                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2663   ""
2664 {
2665   if (GET_CODE (operands[2]) != CONST_INT
2666       || INTVAL (operands[2]) <= 0
2667       || exact_log2 (INTVAL (operands[2])) < 0)
2668     operands[2] = force_reg (<MODE>mode, operands[2]);
2669 })
2670
2671 (define_insn "*div<mode>3"
2672   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2673         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2674                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2675   ""
2676   "div<wd> %0,%1,%2"
2677   [(set (attr "type")
2678      (cond [(match_operand:SI 0 "" "")
2679                 (const_string "idiv")]
2680         (const_string "ldiv")))])
2681
2682 (define_expand "mod<mode>3"
2683   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2684    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2685    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2686   ""
2687   "
2688 {
2689   int i;
2690   rtx temp1;
2691   rtx temp2;
2692
2693   if (GET_CODE (operands[2]) != CONST_INT
2694       || INTVAL (operands[2]) <= 0
2695       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2696     FAIL;
2697
2698   temp1 = gen_reg_rtx (<MODE>mode);
2699   temp2 = gen_reg_rtx (<MODE>mode);
2700
2701   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2702   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2703   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2704   DONE;
2705 }")
2706
2707 (define_insn ""
2708   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2709         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2710                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2711   ""
2712   "sra<wd>i %0,%1,%p2\;addze %0,%0"
2713   [(set_attr "type" "two")
2714    (set_attr "length" "8")])
2715
2716 (define_insn ""
2717   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2718         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2719                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2720                     (const_int 0)))
2721    (clobber (match_scratch:P 3 "=r,r"))]
2722   ""
2723   "@
2724    sra<wd>i %3,%1,%p2\;addze. %3,%3
2725    #"
2726   [(set_attr "type" "compare")
2727    (set_attr "length" "8,12")
2728    (set_attr "cell_micro" "not")])
2729
2730 (define_split
2731   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2732         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2733                              (match_operand:GPR 2 "exact_log2_cint_operand"
2734                               ""))
2735                     (const_int 0)))
2736    (clobber (match_scratch:GPR 3 ""))]
2737   "reload_completed"
2738   [(set (match_dup 3)
2739         (div:<MODE> (match_dup 1) (match_dup 2)))
2740    (set (match_dup 0)
2741         (compare:CC (match_dup 3)
2742                     (const_int 0)))]
2743   "")
2744
2745 (define_insn ""
2746   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2747         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2748                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2749                     (const_int 0)))
2750    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2751         (div:P (match_dup 1) (match_dup 2)))]
2752   ""
2753   "@
2754    sra<wd>i %0,%1,%p2\;addze. %0,%0
2755    #"
2756   [(set_attr "type" "compare")
2757    (set_attr "length" "8,12")
2758    (set_attr "cell_micro" "not")])
2759
2760 (define_split
2761   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2762         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2763                              (match_operand:GPR 2 "exact_log2_cint_operand"
2764                               ""))
2765                     (const_int 0)))
2766    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2767         (div:GPR (match_dup 1) (match_dup 2)))]
2768   "reload_completed"
2769   [(set (match_dup 0)
2770         (div:<MODE> (match_dup 1) (match_dup 2)))
2771    (set (match_dup 3)
2772         (compare:CC (match_dup 0)
2773                     (const_int 0)))]
2774   "")
2775 \f
2776 ;; Logical instructions
2777 ;; The logical instructions are mostly combined by using match_operator,
2778 ;; but the plain AND insns are somewhat different because there is no
2779 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2780 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2781
2782 (define_expand "andsi3"
2783   [(parallel
2784     [(set (match_operand:SI 0 "gpc_reg_operand" "")
2785           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2786                   (match_operand:SI 2 "and_operand" "")))
2787      (clobber (match_scratch:CC 3 ""))])]
2788   ""
2789   "")
2790
2791 (define_insn "andsi3_mc"
2792   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2793         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2794                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2795    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2796   "rs6000_gen_cell_microcode"
2797   "@
2798    and %0,%1,%2
2799    rlwinm %0,%1,0,%m2,%M2
2800    andi. %0,%1,%b2
2801    andis. %0,%1,%u2"
2802   [(set_attr "type" "*,*,fast_compare,fast_compare")])
2803
2804 (define_insn "andsi3_nomc"
2805   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2806         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2807                 (match_operand:SI 2 "and_operand" "?r,T")))
2808    (clobber (match_scratch:CC 3 "=X,X"))]
2809   "!rs6000_gen_cell_microcode"
2810   "@
2811    and %0,%1,%2
2812    rlwinm %0,%1,0,%m2,%M2")
2813
2814 (define_insn "andsi3_internal0_nomc"
2815   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2816         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2817                 (match_operand:SI 2 "and_operand" "?r,T")))]
2818   "!rs6000_gen_cell_microcode"
2819   "@
2820    and %0,%1,%2
2821    rlwinm %0,%1,0,%m2,%M2")
2822
2823
2824 ;; Note to set cr's other than cr0 we do the and immediate and then
2825 ;; the test again -- this avoids a mfcr which on the higher end
2826 ;; machines causes an execution serialization
2827
2828 (define_insn "*andsi3_internal2_mc"
2829   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2830         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2831                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2832                     (const_int 0)))
2833    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2834    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2835   "TARGET_32BIT && rs6000_gen_cell_microcode"
2836   "@
2837    and. %3,%1,%2
2838    andi. %3,%1,%b2
2839    andis. %3,%1,%u2
2840    rlwinm. %3,%1,0,%m2,%M2
2841    #
2842    #
2843    #
2844    #"
2845   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
2846                      compare,compare,compare,compare")
2847    (set_attr "length" "4,4,4,4,8,8,8,8")])
2848
2849 (define_insn "*andsi3_internal3_mc"
2850   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2851         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2852                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2853                     (const_int 0)))
2854    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2855    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2856   "TARGET_64BIT && rs6000_gen_cell_microcode"
2857   "@
2858    #
2859    andi. %3,%1,%b2
2860    andis. %3,%1,%u2
2861    rlwinm. %3,%1,0,%m2,%M2
2862    #
2863    #
2864    #
2865    #"
2866   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
2867                      compare,compare,compare")
2868    (set_attr "length" "8,4,4,4,8,8,8,8")])
2869
2870 (define_split
2871   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2872         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2873                              (match_operand:GPR 2 "and_operand" ""))
2874                     (const_int 0)))
2875    (clobber (match_scratch:GPR 3 ""))
2876    (clobber (match_scratch:CC 4 ""))]
2877   "reload_completed"
2878   [(parallel [(set (match_dup 3)
2879                    (and:<MODE> (match_dup 1)
2880                                (match_dup 2)))
2881               (clobber (match_dup 4))])
2882    (set (match_dup 0)
2883         (compare:CC (match_dup 3)
2884                     (const_int 0)))]
2885   "")
2886
2887 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2888 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2889
2890 (define_split
2891   [(set (match_operand:CC 0 "cc_reg_operand" "")
2892         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2893                             (match_operand:SI 2 "gpc_reg_operand" ""))
2894                     (const_int 0)))
2895    (clobber (match_scratch:SI 3 ""))
2896    (clobber (match_scratch:CC 4 ""))]
2897   "TARGET_POWERPC64 && reload_completed"
2898   [(parallel [(set (match_dup 3)
2899                    (and:SI (match_dup 1)
2900                            (match_dup 2)))
2901               (clobber (match_dup 4))])
2902    (set (match_dup 0)
2903         (compare:CC (match_dup 3)
2904                     (const_int 0)))]
2905   "")
2906
2907 (define_insn "*andsi3_internal4"
2908   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2909         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2910                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2911                     (const_int 0)))
2912    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2913         (and:SI (match_dup 1)
2914                 (match_dup 2)))
2915    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2916   "TARGET_32BIT && rs6000_gen_cell_microcode"
2917   "@
2918    and. %0,%1,%2
2919    andi. %0,%1,%b2
2920    andis. %0,%1,%u2
2921    rlwinm. %0,%1,0,%m2,%M2
2922    #
2923    #
2924    #
2925    #"
2926   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
2927                      compare,compare,compare,compare")
2928    (set_attr "length" "4,4,4,4,8,8,8,8")])
2929
2930 (define_insn "*andsi3_internal5_mc"
2931   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2932         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2933                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2934                     (const_int 0)))
2935    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2936         (and:SI (match_dup 1)
2937                 (match_dup 2)))
2938    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2939   "TARGET_64BIT && rs6000_gen_cell_microcode"
2940   "@
2941    #
2942    andi. %0,%1,%b2
2943    andis. %0,%1,%u2
2944    rlwinm. %0,%1,0,%m2,%M2
2945    #
2946    #
2947    #
2948    #"
2949   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
2950                      compare,compare,compare")
2951    (set_attr "length" "8,4,4,4,8,8,8,8")])
2952
2953 (define_split
2954   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2955         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2956                             (match_operand:SI 2 "and_operand" ""))
2957                     (const_int 0)))
2958    (set (match_operand:SI 0 "gpc_reg_operand" "")
2959         (and:SI (match_dup 1)
2960                 (match_dup 2)))
2961    (clobber (match_scratch:CC 4 ""))]
2962   "reload_completed"
2963   [(parallel [(set (match_dup 0)
2964                    (and:SI (match_dup 1)
2965                            (match_dup 2)))
2966               (clobber (match_dup 4))])
2967    (set (match_dup 3)
2968         (compare:CC (match_dup 0)
2969                     (const_int 0)))]
2970   "")
2971
2972 (define_split
2973   [(set (match_operand:CC 3 "cc_reg_operand" "")
2974         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2975                             (match_operand:SI 2 "gpc_reg_operand" ""))
2976                     (const_int 0)))
2977    (set (match_operand:SI 0 "gpc_reg_operand" "")
2978         (and:SI (match_dup 1)
2979                 (match_dup 2)))
2980    (clobber (match_scratch:CC 4 ""))]
2981   "TARGET_POWERPC64 && reload_completed"
2982   [(parallel [(set (match_dup 0)
2983                    (and:SI (match_dup 1)
2984                            (match_dup 2)))
2985               (clobber (match_dup 4))])
2986    (set (match_dup 3)
2987         (compare:CC (match_dup 0)
2988                     (const_int 0)))]
2989   "")
2990
2991 ;; Handle the PowerPC64 rlwinm corner case
2992
2993 (define_insn_and_split "*andsi3_internal6"
2994   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2995         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2996                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2997   "TARGET_POWERPC64"
2998   "#"
2999   "TARGET_POWERPC64"
3000   [(set (match_dup 0)
3001         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3002                 (match_dup 4)))
3003    (set (match_dup 0)
3004         (rotate:SI (match_dup 0) (match_dup 5)))]
3005   "
3006 {
3007   int mb = extract_MB (operands[2]);
3008   int me = extract_ME (operands[2]);
3009   operands[3] = GEN_INT (me + 1);
3010   operands[5] = GEN_INT (32 - (me + 1));
3011   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3012 }"
3013   [(set_attr "length" "8")])
3014
3015 (define_expand "iorsi3"
3016   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3017         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3018                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3019   ""
3020   "
3021 {
3022   if (GET_CODE (operands[2]) == CONST_INT
3023       && ! logical_operand (operands[2], SImode))
3024     {
3025       HOST_WIDE_INT value = INTVAL (operands[2]);
3026       rtx tmp = ((!can_create_pseudo_p ()
3027                   || rtx_equal_p (operands[0], operands[1]))
3028                  ? operands[0] : gen_reg_rtx (SImode));
3029
3030       emit_insn (gen_iorsi3 (tmp, operands[1],
3031                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3032       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3033       DONE;
3034     }
3035 }")
3036
3037 (define_expand "xorsi3"
3038   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3039         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3040                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3041   ""
3042   "
3043 {
3044   if (GET_CODE (operands[2]) == CONST_INT
3045       && ! logical_operand (operands[2], SImode))
3046     {
3047       HOST_WIDE_INT value = INTVAL (operands[2]);
3048       rtx tmp = ((!can_create_pseudo_p ()
3049                   || rtx_equal_p (operands[0], operands[1]))
3050                  ? operands[0] : gen_reg_rtx (SImode));
3051
3052       emit_insn (gen_xorsi3 (tmp, operands[1],
3053                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3054       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3055       DONE;
3056     }
3057 }")
3058
3059 (define_insn "*boolsi3_internal1"
3060   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3061         (match_operator:SI 3 "boolean_or_operator"
3062          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3063           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3064   ""
3065   "@
3066    %q3 %0,%1,%2
3067    %q3i %0,%1,%b2
3068    %q3is %0,%1,%u2")
3069
3070 (define_insn "*boolsi3_internal2"
3071   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3072         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3073          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3074           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3075          (const_int 0)))
3076    (clobber (match_scratch:SI 3 "=r,r"))]
3077   "TARGET_32BIT"
3078   "@
3079    %q4. %3,%1,%2
3080    #"
3081   [(set_attr "type" "fast_compare,compare")
3082    (set_attr "length" "4,8")])
3083
3084 (define_split
3085   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3086         (compare:CC (match_operator:SI 4 "boolean_operator"
3087          [(match_operand:SI 1 "gpc_reg_operand" "")
3088           (match_operand:SI 2 "gpc_reg_operand" "")])
3089          (const_int 0)))
3090    (clobber (match_scratch:SI 3 ""))]
3091   "TARGET_32BIT && reload_completed"
3092   [(set (match_dup 3) (match_dup 4))
3093    (set (match_dup 0)
3094         (compare:CC (match_dup 3)
3095                     (const_int 0)))]
3096   "")
3097
3098 (define_insn "*boolsi3_internal3"
3099   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3100         (compare:CC (match_operator:SI 4 "boolean_operator"
3101          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3102           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3103          (const_int 0)))
3104    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3105         (match_dup 4))]
3106   "TARGET_32BIT"
3107   "@
3108    %q4. %0,%1,%2
3109    #"
3110   [(set_attr "type" "fast_compare,compare")
3111    (set_attr "length" "4,8")])
3112
3113 (define_split
3114   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3115         (compare:CC (match_operator:SI 4 "boolean_operator"
3116          [(match_operand:SI 1 "gpc_reg_operand" "")
3117           (match_operand:SI 2 "gpc_reg_operand" "")])
3118          (const_int 0)))
3119    (set (match_operand:SI 0 "gpc_reg_operand" "")
3120         (match_dup 4))]
3121   "TARGET_32BIT && reload_completed"
3122   [(set (match_dup 0) (match_dup 4))
3123    (set (match_dup 3)
3124         (compare:CC (match_dup 0)
3125                     (const_int 0)))]
3126   "")
3127
3128 ;; Split a logical operation that we can't do in one insn into two insns,
3129 ;; each of which does one 16-bit part.  This is used by combine.
3130
3131 (define_split
3132   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3133         (match_operator:SI 3 "boolean_or_operator"
3134          [(match_operand:SI 1 "gpc_reg_operand" "")
3135           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3136   ""
3137   [(set (match_dup 0) (match_dup 4))
3138    (set (match_dup 0) (match_dup 5))]
3139 "
3140 {
3141   rtx i;
3142   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3143   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3144                                 operands[1], i);
3145   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3146   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3147                                 operands[0], i);
3148 }")
3149
3150 (define_insn "*boolcsi3_internal1"
3151   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3152         (match_operator:SI 3 "boolean_operator"
3153          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3154           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3155   ""
3156   "%q3 %0,%2,%1")
3157
3158 (define_insn "*boolcsi3_internal2"
3159   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3160         (compare:CC (match_operator:SI 4 "boolean_operator"
3161          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3162           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3163          (const_int 0)))
3164    (clobber (match_scratch:SI 3 "=r,r"))]
3165   "TARGET_32BIT"
3166   "@
3167    %q4. %3,%2,%1
3168    #"
3169   [(set_attr "type" "compare")
3170    (set_attr "length" "4,8")])
3171
3172 (define_split
3173   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3174         (compare:CC (match_operator:SI 4 "boolean_operator"
3175          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3176           (match_operand:SI 2 "gpc_reg_operand" "")])
3177          (const_int 0)))
3178    (clobber (match_scratch:SI 3 ""))]
3179   "TARGET_32BIT && reload_completed"
3180   [(set (match_dup 3) (match_dup 4))
3181    (set (match_dup 0)
3182         (compare:CC (match_dup 3)
3183                     (const_int 0)))]
3184   "")
3185
3186 (define_insn "*boolcsi3_internal3"
3187   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3188         (compare:CC (match_operator:SI 4 "boolean_operator"
3189          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3190           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3191          (const_int 0)))
3192    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3193         (match_dup 4))]
3194   "TARGET_32BIT"
3195   "@
3196    %q4. %0,%2,%1
3197    #"
3198   [(set_attr "type" "compare")
3199    (set_attr "length" "4,8")])
3200
3201 (define_split
3202   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3203         (compare:CC (match_operator:SI 4 "boolean_operator"
3204          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3205           (match_operand:SI 2 "gpc_reg_operand" "")])
3206          (const_int 0)))
3207    (set (match_operand:SI 0 "gpc_reg_operand" "")
3208         (match_dup 4))]
3209   "TARGET_32BIT && reload_completed"
3210   [(set (match_dup 0) (match_dup 4))
3211    (set (match_dup 3)
3212         (compare:CC (match_dup 0)
3213                     (const_int 0)))]
3214   "")
3215
3216 (define_insn "*boolccsi3_internal1"
3217   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3218         (match_operator:SI 3 "boolean_operator"
3219          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3220           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3221   ""
3222   "%q3 %0,%1,%2")
3223
3224 (define_insn "*boolccsi3_internal2"
3225   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3226         (compare:CC (match_operator:SI 4 "boolean_operator"
3227          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3228           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3229          (const_int 0)))
3230    (clobber (match_scratch:SI 3 "=r,r"))]
3231   "TARGET_32BIT"
3232   "@
3233    %q4. %3,%1,%2
3234    #"
3235   [(set_attr "type" "fast_compare,compare")
3236    (set_attr "length" "4,8")])
3237
3238 (define_split
3239   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3240         (compare:CC (match_operator:SI 4 "boolean_operator"
3241          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3242           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3243          (const_int 0)))
3244    (clobber (match_scratch:SI 3 ""))]
3245   "TARGET_32BIT && reload_completed"
3246   [(set (match_dup 3) (match_dup 4))
3247    (set (match_dup 0)
3248         (compare:CC (match_dup 3)
3249                     (const_int 0)))]
3250   "")
3251
3252 (define_insn "*boolccsi3_internal3"
3253   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3254         (compare:CC (match_operator:SI 4 "boolean_operator"
3255          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3256           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3257          (const_int 0)))
3258    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3259         (match_dup 4))]
3260   "TARGET_32BIT"
3261   "@
3262    %q4. %0,%1,%2
3263    #"
3264   [(set_attr "type" "fast_compare,compare")
3265    (set_attr "length" "4,8")])
3266
3267 (define_split
3268   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3269         (compare:CC (match_operator:SI 4 "boolean_operator"
3270          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3271           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3272          (const_int 0)))
3273    (set (match_operand:SI 0 "gpc_reg_operand" "")
3274         (match_dup 4))]
3275   "TARGET_32BIT && reload_completed"
3276   [(set (match_dup 0) (match_dup 4))
3277    (set (match_dup 3)
3278         (compare:CC (match_dup 0)
3279                     (const_int 0)))]
3280   "")
3281 \f
3282 ;; Rotate and shift insns, in all their variants.  These support shifts,
3283 ;; field inserts and extracts, and various combinations thereof.
3284 (define_expand "insv"
3285   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3286                        (match_operand:SI 1 "const_int_operand" "")
3287                        (match_operand:SI 2 "const_int_operand" ""))
3288         (match_operand 3 "gpc_reg_operand" ""))]
3289   ""
3290   "
3291 {
3292   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3293      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3294      compiler if the address of the structure is taken later.  Likewise, do
3295      not handle invalid E500 subregs.  */
3296   if (GET_CODE (operands[0]) == SUBREG
3297       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3298           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3299               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3300     FAIL;
3301
3302   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3303     emit_insn (gen_insvdi_internal (operands[0], operands[1], operands[2],
3304                                     operands[3]));
3305   else
3306     emit_insn (gen_insvsi_internal (operands[0], operands[1], operands[2],
3307                                     operands[3]));
3308   DONE;
3309 }")
3310
3311 (define_insn "insvsi_internal"
3312   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3313                          (match_operand:SI 1 "const_int_operand" "i")
3314                          (match_operand:SI 2 "const_int_operand" "i"))
3315         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3316   ""
3317   "*
3318 {
3319   int start = INTVAL (operands[2]) & 31;
3320   int size = INTVAL (operands[1]) & 31;
3321
3322   operands[4] = GEN_INT (32 - start - size);
3323   operands[1] = GEN_INT (start + size - 1);
3324   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3325 }"
3326   [(set_attr "type" "insert_word")])
3327
3328 (define_insn "*insvsi_internal1"
3329   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3330                          (match_operand:SI 1 "const_int_operand" "i")
3331                          (match_operand:SI 2 "const_int_operand" "i"))
3332         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3333                    (match_operand:SI 4 "const_int_operand" "i")))]
3334   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3335   "*
3336 {
3337   int shift = INTVAL (operands[4]) & 31;
3338   int start = INTVAL (operands[2]) & 31;
3339   int size = INTVAL (operands[1]) & 31;
3340
3341   operands[4] = GEN_INT (shift - start - size);
3342   operands[1] = GEN_INT (start + size - 1);
3343   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3344 }"
3345   [(set_attr "type" "insert_word")])
3346
3347 (define_insn "*insvsi_internal2"
3348   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3349                          (match_operand:SI 1 "const_int_operand" "i")
3350                          (match_operand:SI 2 "const_int_operand" "i"))
3351         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3352                      (match_operand:SI 4 "const_int_operand" "i")))]
3353   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3354   "*
3355 {
3356   int shift = INTVAL (operands[4]) & 31;
3357   int start = INTVAL (operands[2]) & 31;
3358   int size = INTVAL (operands[1]) & 31;
3359
3360   operands[4] = GEN_INT (32 - shift - start - size);
3361   operands[1] = GEN_INT (start + size - 1);
3362   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3363 }"
3364   [(set_attr "type" "insert_word")])
3365
3366 (define_insn "*insvsi_internal3"
3367   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3368                          (match_operand:SI 1 "const_int_operand" "i")
3369                          (match_operand:SI 2 "const_int_operand" "i"))
3370         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3371                      (match_operand:SI 4 "const_int_operand" "i")))]
3372   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3373   "*
3374 {
3375   int shift = INTVAL (operands[4]) & 31;
3376   int start = INTVAL (operands[2]) & 31;
3377   int size = INTVAL (operands[1]) & 31;
3378
3379   operands[4] = GEN_INT (32 - shift - start - size);
3380   operands[1] = GEN_INT (start + size - 1);
3381   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3382 }"
3383   [(set_attr "type" "insert_word")])
3384
3385 (define_insn "*insvsi_internal4"
3386   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3387                          (match_operand:SI 1 "const_int_operand" "i")
3388                          (match_operand:SI 2 "const_int_operand" "i"))
3389         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3390                          (match_operand:SI 4 "const_int_operand" "i")
3391                          (match_operand:SI 5 "const_int_operand" "i")))]
3392   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3393   "*
3394 {
3395   int extract_start = INTVAL (operands[5]) & 31;
3396   int extract_size = INTVAL (operands[4]) & 31;
3397   int insert_start = INTVAL (operands[2]) & 31;
3398   int insert_size = INTVAL (operands[1]) & 31;
3399
3400 /* Align extract field with insert field */
3401   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3402   operands[1] = GEN_INT (insert_start + insert_size - 1);
3403   return \"rlwimi %0,%3,%h5,%h2,%h1\";
3404 }"
3405   [(set_attr "type" "insert_word")])
3406
3407 ;; combine patterns for rlwimi
3408 (define_insn "*insvsi_internal5"
3409   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3410         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3411                         (match_operand:SI 1 "mask_operand" "i"))
3412                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3413                                      (match_operand:SI 2 "const_int_operand" "i"))
3414                         (match_operand:SI 5 "mask_operand" "i"))))]
3415   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3416   "*
3417 {
3418  int me = extract_ME(operands[5]);
3419  int mb = extract_MB(operands[5]);
3420  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3421  operands[2] = GEN_INT(mb);
3422  operands[1] = GEN_INT(me);
3423  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3424 }"
3425   [(set_attr "type" "insert_word")])
3426
3427 (define_insn "*insvsi_internal6"
3428   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3429         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3430                                      (match_operand:SI 2 "const_int_operand" "i"))
3431                         (match_operand:SI 5 "mask_operand" "i"))
3432                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3433                         (match_operand:SI 1 "mask_operand" "i"))))]
3434   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3435   "*
3436 {
3437  int me = extract_ME(operands[5]);
3438  int mb = extract_MB(operands[5]);
3439  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3440  operands[2] = GEN_INT(mb);
3441  operands[1] = GEN_INT(me);
3442  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3443 }"
3444   [(set_attr "type" "insert_word")])
3445
3446 (define_insn "insvdi_internal"
3447   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3448                          (match_operand:SI 1 "const_int_operand" "i")
3449                          (match_operand:SI 2 "const_int_operand" "i"))
3450         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3451   "TARGET_POWERPC64"
3452   "*
3453 {
3454   int start = INTVAL (operands[2]) & 63;
3455   int size = INTVAL (operands[1]) & 63;
3456
3457   operands[1] = GEN_INT (64 - start - size);
3458   return \"rldimi %0,%3,%H1,%H2\";
3459 }"
3460   [(set_attr "type" "insert_dword")])
3461
3462 (define_insn "*insvdi_internal2"
3463   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3464                          (match_operand:SI 1 "const_int_operand" "i")
3465                          (match_operand:SI 2 "const_int_operand" "i"))
3466         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3467                      (match_operand:SI 4 "const_int_operand" "i")))]
3468   "TARGET_POWERPC64
3469    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3470   "*
3471 {
3472   int shift = INTVAL (operands[4]) & 63;
3473   int start = (INTVAL (operands[2]) & 63) - 32;
3474   int size = INTVAL (operands[1]) & 63;
3475
3476   operands[4] = GEN_INT (64 - shift - start - size);
3477   operands[2] = GEN_INT (start);
3478   operands[1] = GEN_INT (start + size - 1);
3479   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3480 }")
3481
3482 (define_insn "*insvdi_internal3"
3483   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3484                          (match_operand:SI 1 "const_int_operand" "i")
3485                          (match_operand:SI 2 "const_int_operand" "i"))
3486         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3487                      (match_operand:SI 4 "const_int_operand" "i")))]
3488   "TARGET_POWERPC64
3489    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3490   "*
3491 {
3492   int shift = INTVAL (operands[4]) & 63;
3493   int start = (INTVAL (operands[2]) & 63) - 32;
3494   int size = INTVAL (operands[1]) & 63;
3495
3496   operands[4] = GEN_INT (64 - shift - start - size);
3497   operands[2] = GEN_INT (start);
3498   operands[1] = GEN_INT (start + size - 1);
3499   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3500 }")
3501
3502 (define_expand "extzv"
3503   [(set (match_operand 0 "gpc_reg_operand" "")
3504         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3505                        (match_operand:SI 2 "const_int_operand" "")
3506                        (match_operand:SI 3 "const_int_operand" "")))]
3507   ""
3508   "
3509 {
3510   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3511      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3512      compiler if the address of the structure is taken later.  */
3513   if (GET_CODE (operands[0]) == SUBREG
3514       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3515     FAIL;
3516
3517   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3518     emit_insn (gen_extzvdi_internal (operands[0], operands[1], operands[2],
3519                                      operands[3]));
3520   else
3521     emit_insn (gen_extzvsi_internal (operands[0], operands[1], operands[2],
3522                                      operands[3]));
3523   DONE;
3524 }")
3525
3526 (define_insn "extzvsi_internal"
3527   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3528         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3529                          (match_operand:SI 2 "const_int_operand" "i")
3530                          (match_operand:SI 3 "const_int_operand" "i")))]
3531   ""
3532   "*
3533 {
3534   int start = INTVAL (operands[3]) & 31;
3535   int size = INTVAL (operands[2]) & 31;
3536
3537   if (start + size >= 32)
3538     operands[3] = const0_rtx;
3539   else
3540     operands[3] = GEN_INT (start + size);
3541   return \"rlwinm %0,%1,%3,%s2,31\";
3542 }")
3543
3544 (define_insn "*extzvsi_internal1"
3545   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3546         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3547                          (match_operand:SI 2 "const_int_operand" "i,i")
3548                          (match_operand:SI 3 "const_int_operand" "i,i"))
3549                     (const_int 0)))
3550    (clobber (match_scratch:SI 4 "=r,r"))]
3551   ""
3552   "*
3553 {
3554   int start = INTVAL (operands[3]) & 31;
3555   int size = INTVAL (operands[2]) & 31;
3556
3557   /* Force split for non-cc0 compare.  */
3558   if (which_alternative == 1)
3559      return \"#\";
3560
3561   /* If the bit-field being tested fits in the upper or lower half of a
3562      word, it is possible to use andiu. or andil. to test it.  This is
3563      useful because the condition register set-use delay is smaller for
3564      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3565      position is 0 because the LT and GT bits may be set wrong.  */
3566
3567   if ((start > 0 && start + size <= 16) || start >= 16)
3568     {
3569       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3570                               - (1 << (16 - (start & 15) - size))));
3571       if (start < 16)
3572         return \"andis. %4,%1,%3\";
3573       else
3574         return \"andi. %4,%1,%3\";
3575     }
3576
3577   if (start + size >= 32)
3578     operands[3] = const0_rtx;
3579   else
3580     operands[3] = GEN_INT (start + size);
3581   return \"rlwinm. %4,%1,%3,%s2,31\";
3582 }"
3583   [(set_attr "type" "delayed_compare")
3584    (set_attr "length" "4,8")])
3585
3586 (define_split
3587   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3588         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3589                          (match_operand:SI 2 "const_int_operand" "")
3590                          (match_operand:SI 3 "const_int_operand" ""))
3591                     (const_int 0)))
3592    (clobber (match_scratch:SI 4 ""))]
3593   "reload_completed"
3594   [(set (match_dup 4)
3595         (zero_extract:SI (match_dup 1) (match_dup 2)
3596                          (match_dup 3)))
3597    (set (match_dup 0)
3598         (compare:CC (match_dup 4)
3599                     (const_int 0)))]
3600   "")
3601
3602 (define_insn "*extzvsi_internal2"
3603   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3604         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3605                          (match_operand:SI 2 "const_int_operand" "i,i")
3606                          (match_operand:SI 3 "const_int_operand" "i,i"))
3607                     (const_int 0)))
3608    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3609         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3610   ""
3611   "*
3612 {
3613   int start = INTVAL (operands[3]) & 31;
3614   int size = INTVAL (operands[2]) & 31;
3615
3616   /* Force split for non-cc0 compare.  */
3617   if (which_alternative == 1)
3618      return \"#\";
3619
3620   /* Since we are using the output value, we can't ignore any need for
3621      a shift.  The bit-field must end at the LSB.  */
3622   if (start >= 16 && start + size == 32)
3623     {
3624       operands[3] = GEN_INT ((1 << size) - 1);
3625       return \"andi. %0,%1,%3\";
3626     }
3627
3628   if (start + size >= 32)
3629     operands[3] = const0_rtx;
3630   else
3631     operands[3] = GEN_INT (start + size);
3632   return \"rlwinm. %0,%1,%3,%s2,31\";
3633 }"
3634   [(set_attr "type" "delayed_compare")
3635    (set_attr "length" "4,8")])
3636
3637 (define_split
3638   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3639         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3640                          (match_operand:SI 2 "const_int_operand" "")
3641                          (match_operand:SI 3 "const_int_operand" ""))
3642                     (const_int 0)))
3643    (set (match_operand:SI 0 "gpc_reg_operand" "")
3644         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3645   "reload_completed"
3646   [(set (match_dup 0)
3647         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3648    (set (match_dup 4)
3649         (compare:CC (match_dup 0)
3650                     (const_int 0)))]
3651   "")
3652
3653 (define_insn "extzvdi_internal"
3654   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3655         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3656                          (match_operand:SI 2 "const_int_operand" "i")
3657                          (match_operand:SI 3 "const_int_operand" "i")))]
3658   "TARGET_POWERPC64"
3659   "*
3660 {
3661   int start = INTVAL (operands[3]) & 63;
3662   int size = INTVAL (operands[2]) & 63;
3663
3664   if (start + size >= 64)
3665     operands[3] = const0_rtx;
3666   else
3667     operands[3] = GEN_INT (start + size);
3668   operands[2] = GEN_INT (64 - size);
3669   return \"rldicl %0,%1,%3,%2\";
3670 }")
3671
3672 (define_insn "*extzvdi_internal1"
3673   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3674         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3675                          (match_operand:SI 2 "const_int_operand" "i")
3676                          (match_operand:SI 3 "const_int_operand" "i"))
3677                     (const_int 0)))
3678    (clobber (match_scratch:DI 4 "=r"))]
3679   "TARGET_64BIT && rs6000_gen_cell_microcode"
3680   "*
3681 {
3682   int start = INTVAL (operands[3]) & 63;
3683   int size = INTVAL (operands[2]) & 63;
3684
3685   if (start + size >= 64)
3686     operands[3] = const0_rtx;
3687   else
3688     operands[3] = GEN_INT (start + size);
3689   operands[2] = GEN_INT (64 - size);
3690   return \"rldicl. %4,%1,%3,%2\";
3691 }"
3692   [(set_attr "type" "compare")])
3693
3694 (define_insn "*extzvdi_internal2"
3695   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3696         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3697                          (match_operand:SI 2 "const_int_operand" "i")
3698                          (match_operand:SI 3 "const_int_operand" "i"))
3699                     (const_int 0)))
3700    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3701         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3702   "TARGET_64BIT && rs6000_gen_cell_microcode"
3703   "*
3704 {
3705   int start = INTVAL (operands[3]) & 63;
3706   int size = INTVAL (operands[2]) & 63;
3707
3708   if (start + size >= 64)
3709     operands[3] = const0_rtx;
3710   else
3711     operands[3] = GEN_INT (start + size);
3712   operands[2] = GEN_INT (64 - size);
3713   return \"rldicl. %0,%1,%3,%2\";
3714 }"
3715   [(set_attr "type" "compare")])
3716
3717 (define_insn "rotlsi3"
3718   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3719         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3720                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3721   ""
3722   "@
3723    rlwnm %0,%1,%2,0xffffffff
3724    rlwinm %0,%1,%h2,0xffffffff"
3725   [(set_attr "type" "var_shift_rotate,integer")])
3726
3727 (define_insn "*rotlsi3_64"
3728   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3729         (zero_extend:DI
3730             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3731                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
3732   "TARGET_64BIT"
3733   "@
3734    rlwnm %0,%1,%2,0xffffffff
3735    rlwinm %0,%1,%h2,0xffffffff"
3736   [(set_attr "type" "var_shift_rotate,integer")])
3737
3738 (define_insn "*rotlsi3_internal2"
3739   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3740         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3741                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3742                     (const_int 0)))
3743    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3744   ""
3745   "@
3746    rlwnm. %3,%1,%2,0xffffffff
3747    rlwinm. %3,%1,%h2,0xffffffff
3748    #
3749    #"
3750   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3751    (set_attr "length" "4,4,8,8")])
3752
3753 (define_split
3754   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3755         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3756                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3757                     (const_int 0)))
3758    (clobber (match_scratch:SI 3 ""))]
3759   "reload_completed"
3760   [(set (match_dup 3)
3761         (rotate:SI (match_dup 1) (match_dup 2)))
3762    (set (match_dup 0)
3763         (compare:CC (match_dup 3)
3764                     (const_int 0)))]
3765   "")
3766
3767 (define_insn "*rotlsi3_internal3"
3768   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3769         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3770                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3771                     (const_int 0)))
3772    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3773         (rotate:SI (match_dup 1) (match_dup 2)))]
3774   ""
3775   "@
3776    rlwnm. %0,%1,%2,0xffffffff
3777    rlwinm. %0,%1,%h2,0xffffffff
3778    #
3779    #"
3780   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3781    (set_attr "length" "4,4,8,8")])
3782
3783 (define_split
3784   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3785         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3786                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3787                     (const_int 0)))
3788    (set (match_operand:SI 0 "gpc_reg_operand" "")
3789         (rotate:SI (match_dup 1) (match_dup 2)))]
3790   "reload_completed"
3791   [(set (match_dup 0)
3792         (rotate:SI (match_dup 1) (match_dup 2)))
3793    (set (match_dup 3)
3794         (compare:CC (match_dup 0)
3795                     (const_int 0)))]
3796   "")
3797
3798 (define_insn "*rotlsi3_internal4"
3799   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3800         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3801                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
3802                 (match_operand:SI 3 "mask_operand" "n,n")))]
3803   ""
3804   "@
3805    rlwnm %0,%1,%2,%m3,%M3
3806    rlwinm %0,%1,%h2,%m3,%M3"
3807   [(set_attr "type" "var_shift_rotate,integer")])
3808
3809 (define_insn "*rotlsi3_internal5"
3810   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3811         (compare:CC (and:SI
3812                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3813                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3814                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3815                     (const_int 0)))
3816    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
3817   ""
3818   "@
3819    rlwnm. %4,%1,%2,%m3,%M3
3820    rlwinm. %4,%1,%h2,%m3,%M3
3821    #
3822    #"
3823   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3824    (set_attr "length" "4,4,8,8")])
3825
3826 (define_split
3827   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3828         (compare:CC (and:SI
3829                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3830                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3831                      (match_operand:SI 3 "mask_operand" ""))
3832                     (const_int 0)))
3833    (clobber (match_scratch:SI 4 ""))]
3834   "reload_completed"
3835   [(set (match_dup 4)
3836         (and:SI (rotate:SI (match_dup 1)
3837                                 (match_dup 2))
3838                      (match_dup 3)))
3839    (set (match_dup 0)
3840         (compare:CC (match_dup 4)
3841                     (const_int 0)))]
3842   "")
3843
3844 (define_insn "*rotlsi3_internal6"
3845   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
3846         (compare:CC (and:SI
3847                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3848                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3849                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3850                     (const_int 0)))
3851    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3852         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3853   ""
3854   "@
3855    rlwnm. %0,%1,%2,%m3,%M3
3856    rlwinm. %0,%1,%h2,%m3,%M3
3857    #
3858    #"
3859   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3860    (set_attr "length" "4,4,8,8")])
3861
3862 (define_split
3863   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3864         (compare:CC (and:SI
3865                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3866                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3867                      (match_operand:SI 3 "mask_operand" ""))
3868                     (const_int 0)))
3869    (set (match_operand:SI 0 "gpc_reg_operand" "")
3870         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3871   "reload_completed"
3872   [(set (match_dup 0)
3873         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3874    (set (match_dup 4)
3875         (compare:CC (match_dup 0)
3876                     (const_int 0)))]
3877   "")
3878
3879 (define_insn "*rotlsi3_internal7le"
3880   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3881         (zero_extend:SI
3882          (subreg:QI
3883           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3884                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3885   "!BYTES_BIG_ENDIAN"
3886   "rlw%I2nm %0,%1,%h2,0xff"
3887   [(set (attr "cell_micro")
3888      (if_then_else (match_operand:SI 2 "const_int_operand" "")
3889         (const_string "not")
3890         (const_string "always")))])
3891
3892 (define_insn "*rotlsi3_internal7be"
3893   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3894         (zero_extend:SI
3895          (subreg:QI
3896           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3897                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 3)))]
3898   "BYTES_BIG_ENDIAN"
3899   "rlw%I2nm %0,%1,%h2,0xff"
3900   [(set (attr "cell_micro")
3901      (if_then_else (match_operand:SI 2 "const_int_operand" "")
3902         (const_string "not")
3903         (const_string "always")))])
3904
3905 (define_insn "*rotlsi3_internal8le"
3906   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3907         (compare:CC (zero_extend:SI
3908                      (subreg:QI
3909                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3910                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3911                     (const_int 0)))
3912    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3913   "!BYTES_BIG_ENDIAN"
3914   "@
3915    rlwnm. %3,%1,%2,0xff
3916    rlwinm. %3,%1,%h2,0xff
3917    #
3918    #"
3919   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3920    (set_attr "length" "4,4,8,8")])
3921
3922 (define_insn "*rotlsi3_internal8be"
3923   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3924         (compare:CC (zero_extend:SI
3925                      (subreg:QI
3926                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3927                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 3))
3928                     (const_int 0)))
3929    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3930   "BYTES_BIG_ENDIAN"
3931   "@
3932    rlwnm. %3,%1,%2,0xff
3933    rlwinm. %3,%1,%h2,0xff
3934    #
3935    #"
3936   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3937    (set_attr "length" "4,4,8,8")])
3938
3939 (define_split
3940   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3941         (compare:CC (zero_extend:SI
3942                      (subreg:QI
3943                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3944                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3945                     (const_int 0)))
3946    (clobber (match_scratch:SI 3 ""))]
3947   "!BYTES_BIG_ENDIAN && reload_completed"
3948   [(set (match_dup 3)
3949         (zero_extend:SI (subreg:QI
3950                       (rotate:SI (match_dup 1)
3951                                  (match_dup 2)) 0)))
3952    (set (match_dup 0)
3953         (compare:CC (match_dup 3)
3954                     (const_int 0)))]
3955   "")
3956
3957 (define_split
3958   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3959         (compare:CC (zero_extend:SI
3960                      (subreg:QI
3961                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3962                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 3))
3963                     (const_int 0)))
3964    (clobber (match_scratch:SI 3 ""))]
3965   "BYTES_BIG_ENDIAN && reload_completed"
3966   [(set (match_dup 3)
3967         (zero_extend:SI (subreg:QI
3968                       (rotate:SI (match_dup 1)
3969                                  (match_dup 2)) 3)))
3970    (set (match_dup 0)
3971         (compare:CC (match_dup 3)
3972                     (const_int 0)))]
3973   "")
3974
3975 (define_insn "*rotlsi3_internal9le"
3976   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3977         (compare:CC (zero_extend:SI
3978                      (subreg:QI
3979                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3980                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3981                     (const_int 0)))
3982    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3983         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3984   "!BYTES_BIG_ENDIAN"
3985   "@
3986    rlwnm. %0,%1,%2,0xff
3987    rlwinm. %0,%1,%h2,0xff
3988    #
3989    #"
3990   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3991    (set_attr "length" "4,4,8,8")])
3992
3993 (define_insn "*rotlsi3_internal9be"
3994   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3995         (compare:CC (zero_extend:SI
3996                      (subreg:QI
3997                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3998                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 3))
3999                     (const_int 0)))
4000    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4001         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))]
4002   "BYTES_BIG_ENDIAN"
4003   "@
4004    rlwnm. %0,%1,%2,0xff
4005    rlwinm. %0,%1,%h2,0xff
4006    #
4007    #"
4008   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4009    (set_attr "length" "4,4,8,8")])
4010
4011 (define_split
4012   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4013         (compare:CC (zero_extend:SI
4014                      (subreg:QI
4015                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4016                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4017                     (const_int 0)))
4018    (set (match_operand:SI 0 "gpc_reg_operand" "")
4019         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4020   "!BYTES_BIG_ENDIAN && reload_completed"
4021   [(set (match_dup 0)
4022         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4023    (set (match_dup 3)
4024         (compare:CC (match_dup 0)
4025                     (const_int 0)))]
4026   "")
4027
4028 (define_split
4029   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4030         (compare:CC (zero_extend:SI
4031                      (subreg:QI
4032                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4033                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 3))
4034                     (const_int 0)))
4035    (set (match_operand:SI 0 "gpc_reg_operand" "")
4036         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))]
4037   "BYTES_BIG_ENDIAN && reload_completed"
4038   [(set (match_dup 0)
4039         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))
4040    (set (match_dup 3)
4041         (compare:CC (match_dup 0)
4042                     (const_int 0)))]
4043   "")
4044
4045 (define_insn "*rotlsi3_internal10le"
4046   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4047         (zero_extend:SI
4048          (subreg:HI
4049           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4050                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4051   "!BYTES_BIG_ENDIAN"
4052   "@
4053    rlwnm %0,%1,%2,0xffff
4054    rlwinm %0,%1,%h2,0xffff"
4055   [(set_attr "type" "var_shift_rotate,integer")])
4056
4057 (define_insn "*rotlsi3_internal10be"
4058   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4059         (zero_extend:SI
4060          (subreg:HI
4061           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4062                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 2)))]
4063   "BYTES_BIG_ENDIAN"
4064   "@
4065    rlwnm %0,%1,%2,0xffff
4066    rlwinm %0,%1,%h2,0xffff"
4067   [(set_attr "type" "var_shift_rotate,integer")])
4068
4069 (define_insn "*rotlsi3_internal11le"
4070   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4071         (compare:CC (zero_extend:SI
4072                      (subreg:HI
4073                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4074                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4075                     (const_int 0)))
4076    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4077   "!BYTES_BIG_ENDIAN"
4078   "@
4079    rlwnm. %3,%1,%2,0xffff
4080    rlwinm. %3,%1,%h2,0xffff
4081    #
4082    #"
4083   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4084    (set_attr "length" "4,4,8,8")])
4085
4086 (define_insn "*rotlsi3_internal11be"
4087   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4088         (compare:CC (zero_extend:SI
4089                      (subreg:HI
4090                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4091                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 2))
4092                     (const_int 0)))
4093    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4094   "BYTES_BIG_ENDIAN"
4095   "@
4096    rlwnm. %3,%1,%2,0xffff
4097    rlwinm. %3,%1,%h2,0xffff
4098    #
4099    #"
4100   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4101    (set_attr "length" "4,4,8,8")])
4102
4103 (define_split
4104   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4105         (compare:CC (zero_extend:SI
4106                      (subreg:HI
4107                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4108                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4109                     (const_int 0)))
4110    (clobber (match_scratch:SI 3 ""))]
4111   "!BYTES_BIG_ENDIAN && reload_completed"
4112   [(set (match_dup 3)
4113         (zero_extend:SI (subreg:HI
4114                       (rotate:SI (match_dup 1)
4115                                  (match_dup 2)) 0)))
4116    (set (match_dup 0)
4117         (compare:CC (match_dup 3)
4118                     (const_int 0)))]
4119   "")
4120
4121 (define_split
4122   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4123         (compare:CC (zero_extend:SI
4124                      (subreg:HI
4125                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4126                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 2))
4127                     (const_int 0)))
4128    (clobber (match_scratch:SI 3 ""))]
4129   "BYTES_BIG_ENDIAN && reload_completed"
4130   [(set (match_dup 3)
4131         (zero_extend:SI (subreg:HI
4132                       (rotate:SI (match_dup 1)
4133                                  (match_dup 2)) 2)))
4134    (set (match_dup 0)
4135         (compare:CC (match_dup 3)
4136                     (const_int 0)))]
4137   "")
4138
4139 (define_insn "*rotlsi3_internal12le"
4140   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4141         (compare:CC (zero_extend:SI
4142                      (subreg:HI
4143                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4144                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4145                     (const_int 0)))
4146    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4147         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4148   "!BYTES_BIG_ENDIAN"
4149   "@
4150    rlwnm. %0,%1,%2,0xffff
4151    rlwinm. %0,%1,%h2,0xffff
4152    #
4153    #"
4154   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4155    (set_attr "length" "4,4,8,8")])
4156
4157 (define_insn "*rotlsi3_internal12be"
4158   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4159         (compare:CC (zero_extend:SI
4160                      (subreg:HI
4161                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4162                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 2))
4163                     (const_int 0)))
4164    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4165         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))]
4166   "BYTES_BIG_ENDIAN"
4167   "@
4168    rlwnm. %0,%1,%2,0xffff
4169    rlwinm. %0,%1,%h2,0xffff
4170    #
4171    #"
4172   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4173    (set_attr "length" "4,4,8,8")])
4174
4175 (define_split
4176   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4177         (compare:CC (zero_extend:SI
4178                      (subreg:HI
4179                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4180                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4181                     (const_int 0)))
4182    (set (match_operand:SI 0 "gpc_reg_operand" "")
4183         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4184   "!BYTES_BIG_ENDIAN && reload_completed"
4185   [(set (match_dup 0)
4186         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4187    (set (match_dup 3)
4188         (compare:CC (match_dup 0)
4189                     (const_int 0)))]
4190   "")
4191
4192 (define_split
4193   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4194         (compare:CC (zero_extend:SI
4195                      (subreg:HI
4196                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4197                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 2))
4198                     (const_int 0)))
4199    (set (match_operand:SI 0 "gpc_reg_operand" "")
4200         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))]
4201   "BYTES_BIG_ENDIAN && reload_completed"
4202   [(set (match_dup 0)
4203         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))
4204    (set (match_dup 3)
4205         (compare:CC (match_dup 0)
4206                     (const_int 0)))]
4207   "")
4208
4209 (define_insn "ashlsi3"
4210   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4211         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4212                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4213   ""
4214   "@
4215    slw %0,%1,%2
4216    slwi %0,%1,%h2"
4217   [(set_attr "type" "var_shift_rotate,shift")])
4218
4219 (define_insn "*ashlsi3_64"
4220   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4221         (zero_extend:DI
4222             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4223                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4224   "TARGET_POWERPC64"
4225   "@
4226    slw %0,%1,%2
4227    slwi %0,%1,%h2"
4228   [(set_attr "type" "var_shift_rotate,shift")])
4229
4230 (define_insn ""
4231   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4232         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4233                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4234                     (const_int 0)))
4235    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4236   "TARGET_32BIT"
4237   "@
4238    slw. %3,%1,%2
4239    slwi. %3,%1,%h2
4240    #
4241    #"
4242   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4243    (set_attr "length" "4,4,8,8")])
4244
4245 (define_split
4246   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4247         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4248                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4249                     (const_int 0)))
4250    (clobber (match_scratch:SI 3 ""))]
4251   "TARGET_32BIT && reload_completed"
4252   [(set (match_dup 3)
4253         (ashift:SI (match_dup 1) (match_dup 2)))
4254    (set (match_dup 0)
4255         (compare:CC (match_dup 3)
4256                     (const_int 0)))]
4257   "")
4258
4259 (define_insn ""
4260   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4261         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4262                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4263                     (const_int 0)))
4264    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4265         (ashift:SI (match_dup 1) (match_dup 2)))]
4266   "TARGET_32BIT"
4267   "@
4268    slw. %0,%1,%2
4269    slwi. %0,%1,%h2
4270    #
4271    #"
4272   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4273    (set_attr "length" "4,4,8,8")])
4274
4275 (define_split
4276   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4277         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4278                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4279                     (const_int 0)))
4280    (set (match_operand:SI 0 "gpc_reg_operand" "")
4281         (ashift:SI (match_dup 1) (match_dup 2)))]
4282   "TARGET_32BIT && reload_completed"
4283   [(set (match_dup 0)
4284         (ashift:SI (match_dup 1) (match_dup 2)))
4285    (set (match_dup 3)
4286         (compare:CC (match_dup 0)
4287                     (const_int 0)))]
4288   "")
4289
4290 (define_insn "rlwinm"
4291   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4292         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4293                            (match_operand:SI 2 "const_int_operand" "i"))
4294                 (match_operand:SI 3 "mask_operand" "n")))]
4295   "includes_lshift_p (operands[2], operands[3])"
4296   "rlwinm %0,%1,%h2,%m3,%M3")
4297
4298 (define_insn ""
4299   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4300         (compare:CC
4301          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4302                             (match_operand:SI 2 "const_int_operand" "i,i"))
4303                  (match_operand:SI 3 "mask_operand" "n,n"))
4304          (const_int 0)))
4305    (clobber (match_scratch:SI 4 "=r,r"))]
4306   "includes_lshift_p (operands[2], operands[3])"
4307   "@
4308    rlwinm. %4,%1,%h2,%m3,%M3
4309    #"
4310   [(set_attr "type" "delayed_compare")
4311    (set_attr "length" "4,8")])
4312
4313 (define_split
4314   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4315         (compare:CC
4316          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4317                             (match_operand:SI 2 "const_int_operand" ""))
4318                  (match_operand:SI 3 "mask_operand" ""))
4319          (const_int 0)))
4320    (clobber (match_scratch:SI 4 ""))]
4321   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4322   [(set (match_dup 4)
4323         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4324                  (match_dup 3)))
4325    (set (match_dup 0)
4326         (compare:CC (match_dup 4)
4327                     (const_int 0)))]
4328   "")
4329
4330 (define_insn ""
4331   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4332         (compare:CC
4333          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4334                             (match_operand:SI 2 "const_int_operand" "i,i"))
4335                  (match_operand:SI 3 "mask_operand" "n,n"))
4336          (const_int 0)))
4337    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4338         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4339   "includes_lshift_p (operands[2], operands[3])"
4340   "@
4341    rlwinm. %0,%1,%h2,%m3,%M3
4342    #"
4343   [(set_attr "type" "delayed_compare")
4344    (set_attr "length" "4,8")])
4345
4346 (define_split
4347   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4348         (compare:CC
4349          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4350                             (match_operand:SI 2 "const_int_operand" ""))
4351                  (match_operand:SI 3 "mask_operand" ""))
4352          (const_int 0)))
4353    (set (match_operand:SI 0 "gpc_reg_operand" "")
4354         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4355   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4356   [(set (match_dup 0)
4357         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4358    (set (match_dup 4)
4359         (compare:CC (match_dup 0)
4360                     (const_int 0)))]
4361   "")
4362
4363 (define_insn "lshrsi3"
4364   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4365         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4366                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
4367   ""
4368   "@
4369   mr %0,%1
4370   srw %0,%1,%2
4371   srwi %0,%1,%h2"
4372   [(set_attr "type" "integer,var_shift_rotate,shift")])
4373
4374 (define_insn "*lshrsi3_64"
4375   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4376         (zero_extend:DI
4377             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4378                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4379   "TARGET_POWERPC64"
4380   "@
4381   srw %0,%1,%2
4382   srwi %0,%1,%h2"
4383   [(set_attr "type" "var_shift_rotate,shift")])
4384
4385 (define_insn ""
4386   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4387         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4388                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4389                     (const_int 0)))
4390    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
4391   "TARGET_32BIT"
4392   "@
4393    mr. %1,%1
4394    srw. %3,%1,%2
4395    srwi. %3,%1,%h2
4396    #
4397    #
4398    #"
4399   [(set_attr "type" "fast_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4400    (set_attr "length" "4,4,4,8,8,8")])
4401
4402 (define_split
4403   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4404         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4405                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4406                     (const_int 0)))
4407    (clobber (match_scratch:SI 3 ""))]
4408   "TARGET_32BIT && reload_completed"
4409   [(set (match_dup 3)
4410         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4411    (set (match_dup 0)
4412         (compare:CC (match_dup 3)
4413                     (const_int 0)))]
4414   "")
4415
4416 (define_insn ""
4417   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4418         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4419                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4420                     (const_int 0)))
4421    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4422         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4423   "TARGET_32BIT"
4424   "@
4425    mr. %0,%1
4426    srw. %0,%1,%2
4427    srwi. %0,%1,%h2
4428    #
4429    #
4430    #"
4431   [(set_attr "type" "fast_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4432    (set_attr "length" "4,4,4,8,8,8")])
4433
4434 (define_split
4435   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4436         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4437                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4438                     (const_int 0)))
4439    (set (match_operand:SI 0 "gpc_reg_operand" "")
4440         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4441   "TARGET_32BIT && reload_completed"
4442   [(set (match_dup 0)
4443         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4444    (set (match_dup 3)
4445         (compare:CC (match_dup 0)
4446                     (const_int 0)))]
4447   "")
4448
4449 (define_insn ""
4450   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4451         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4452                              (match_operand:SI 2 "const_int_operand" "i"))
4453                 (match_operand:SI 3 "mask_operand" "n")))]
4454   "includes_rshift_p (operands[2], operands[3])"
4455   "rlwinm %0,%1,%s2,%m3,%M3")
4456
4457 (define_insn ""
4458   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4459         (compare:CC
4460          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4461                               (match_operand:SI 2 "const_int_operand" "i,i"))
4462                  (match_operand:SI 3 "mask_operand" "n,n"))
4463          (const_int 0)))
4464    (clobber (match_scratch:SI 4 "=r,r"))]
4465   "includes_rshift_p (operands[2], operands[3])"
4466   "@
4467    rlwinm. %4,%1,%s2,%m3,%M3
4468    #"
4469   [(set_attr "type" "delayed_compare")
4470    (set_attr "length" "4,8")])
4471
4472 (define_split
4473   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4474         (compare:CC
4475          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4476                               (match_operand:SI 2 "const_int_operand" ""))
4477                  (match_operand:SI 3 "mask_operand" ""))
4478          (const_int 0)))
4479    (clobber (match_scratch:SI 4 ""))]
4480   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4481   [(set (match_dup 4)
4482         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4483                  (match_dup 3)))
4484    (set (match_dup 0)
4485         (compare:CC (match_dup 4)
4486                     (const_int 0)))]
4487   "")
4488
4489 (define_insn ""
4490   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4491         (compare:CC
4492          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4493                               (match_operand:SI 2 "const_int_operand" "i,i"))
4494                  (match_operand:SI 3 "mask_operand" "n,n"))
4495          (const_int 0)))
4496    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4497         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4498   "includes_rshift_p (operands[2], operands[3])"
4499   "@
4500    rlwinm. %0,%1,%s2,%m3,%M3
4501    #"
4502   [(set_attr "type" "delayed_compare")
4503    (set_attr "length" "4,8")])
4504
4505 (define_split
4506   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4507         (compare:CC
4508          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4509                               (match_operand:SI 2 "const_int_operand" ""))
4510                  (match_operand:SI 3 "mask_operand" ""))
4511          (const_int 0)))
4512    (set (match_operand:SI 0 "gpc_reg_operand" "")
4513         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4514   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4515   [(set (match_dup 0)
4516         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4517    (set (match_dup 4)
4518         (compare:CC (match_dup 0)
4519                     (const_int 0)))]
4520   "")
4521
4522 (define_insn "*lshiftrt_internal1le"
4523   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4524         (zero_extend:SI
4525          (subreg:QI
4526           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4527                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4528   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4529   "rlwinm %0,%1,%s2,0xff")
4530
4531 (define_insn "*lshiftrt_internal1be"
4532   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4533         (zero_extend:SI
4534          (subreg:QI
4535           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4536                        (match_operand:SI 2 "const_int_operand" "i")) 3)))]
4537   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4538   "rlwinm %0,%1,%s2,0xff")
4539
4540 (define_insn "*lshiftrt_internal2le"
4541   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4542         (compare:CC
4543          (zero_extend:SI
4544           (subreg:QI
4545            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4546                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4547          (const_int 0)))
4548    (clobber (match_scratch:SI 3 "=r,r"))]
4549   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4550   "@
4551    rlwinm. %3,%1,%s2,0xff
4552    #"
4553   [(set_attr "type" "delayed_compare")
4554    (set_attr "length" "4,8")])
4555
4556 (define_insn "*lshiftrt_internal2be"
4557   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4558         (compare:CC
4559          (zero_extend:SI
4560           (subreg:QI
4561            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4562                         (match_operand:SI 2 "const_int_operand" "i,i")) 3))
4563          (const_int 0)))
4564    (clobber (match_scratch:SI 3 "=r,r"))]
4565   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4566   "@
4567    rlwinm. %3,%1,%s2,0xff
4568    #"
4569   [(set_attr "type" "delayed_compare")
4570    (set_attr "length" "4,8")])
4571
4572 (define_split
4573   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4574         (compare:CC
4575          (zero_extend:SI
4576           (subreg:QI
4577            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4578                         (match_operand:SI 2 "const_int_operand" "")) 0))
4579          (const_int 0)))
4580    (clobber (match_scratch:SI 3 ""))]
4581   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4582   [(set (match_dup 3)
4583         (zero_extend:SI (subreg:QI
4584            (lshiftrt:SI (match_dup 1)
4585                         (match_dup 2)) 0)))
4586    (set (match_dup 0)
4587         (compare:CC (match_dup 3)
4588                     (const_int 0)))]
4589   "")
4590
4591 (define_split
4592   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4593         (compare:CC
4594          (zero_extend:SI
4595           (subreg:QI
4596            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4597                         (match_operand:SI 2 "const_int_operand" "")) 3))
4598          (const_int 0)))
4599    (clobber (match_scratch:SI 3 ""))]
4600   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4601   [(set (match_dup 3)
4602         (zero_extend:SI (subreg:QI
4603            (lshiftrt:SI (match_dup 1)
4604                         (match_dup 2)) 3)))
4605    (set (match_dup 0)
4606         (compare:CC (match_dup 3)
4607                     (const_int 0)))]
4608   "")
4609
4610 (define_insn "*lshiftrt_internal3le"
4611   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4612         (compare:CC
4613          (zero_extend:SI
4614           (subreg:QI
4615            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4616                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4617          (const_int 0)))
4618    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4619         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4620   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4621   "@
4622    rlwinm. %0,%1,%s2,0xff
4623    #"
4624   [(set_attr "type" "delayed_compare")
4625    (set_attr "length" "4,8")])
4626
4627 (define_insn "*lshiftrt_internal3be"
4628   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4629         (compare:CC
4630          (zero_extend:SI
4631           (subreg:QI
4632            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4633                         (match_operand:SI 2 "const_int_operand" "i,i")) 3))
4634          (const_int 0)))
4635    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4636         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))]
4637   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4638   "@
4639    rlwinm. %0,%1,%s2,0xff
4640    #"
4641   [(set_attr "type" "delayed_compare")
4642    (set_attr "length" "4,8")])
4643
4644 (define_split
4645   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4646         (compare:CC
4647          (zero_extend:SI
4648           (subreg:QI
4649            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4650                         (match_operand:SI 2 "const_int_operand" "")) 0))
4651          (const_int 0)))
4652    (set (match_operand:SI 0 "gpc_reg_operand" "")
4653         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4654   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4655   [(set (match_dup 0)
4656         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4657    (set (match_dup 3)
4658         (compare:CC (match_dup 0)
4659                     (const_int 0)))]
4660   "")
4661
4662 (define_split
4663   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4664         (compare:CC
4665          (zero_extend:SI
4666           (subreg:QI
4667            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4668                         (match_operand:SI 2 "const_int_operand" "")) 3))
4669          (const_int 0)))
4670    (set (match_operand:SI 0 "gpc_reg_operand" "")
4671         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))]
4672   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4673   [(set (match_dup 0)
4674         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))
4675    (set (match_dup 3)
4676         (compare:CC (match_dup 0)
4677                     (const_int 0)))]
4678   "")
4679
4680 (define_insn "*lshiftrt_internal4le"
4681   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4682         (zero_extend:SI
4683          (subreg:HI
4684           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4685                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4686   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4687   "rlwinm %0,%1,%s2,0xffff")
4688
4689 (define_insn "*lshiftrt_internal4be"
4690   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4691         (zero_extend:SI
4692          (subreg:HI
4693           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4694                        (match_operand:SI 2 "const_int_operand" "i")) 2)))]
4695   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4696   "rlwinm %0,%1,%s2,0xffff")
4697
4698 (define_insn "*lshiftrt_internal5le"
4699   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4700         (compare:CC
4701          (zero_extend:SI
4702           (subreg:HI
4703            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4704                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4705          (const_int 0)))
4706    (clobber (match_scratch:SI 3 "=r,r"))]
4707   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4708   "@
4709    rlwinm. %3,%1,%s2,0xffff
4710    #"
4711   [(set_attr "type" "delayed_compare")
4712    (set_attr "length" "4,8")])
4713
4714 (define_insn "*lshiftrt_internal5be"
4715   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4716         (compare:CC
4717          (zero_extend:SI
4718           (subreg:HI
4719            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4720                         (match_operand:SI 2 "const_int_operand" "i,i")) 2))
4721          (const_int 0)))
4722    (clobber (match_scratch:SI 3 "=r,r"))]
4723   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4724   "@
4725    rlwinm. %3,%1,%s2,0xffff
4726    #"
4727   [(set_attr "type" "delayed_compare")
4728    (set_attr "length" "4,8")])
4729
4730 (define_split
4731   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4732         (compare:CC
4733          (zero_extend:SI
4734           (subreg:HI
4735            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4736                         (match_operand:SI 2 "const_int_operand" "")) 0))
4737          (const_int 0)))
4738    (clobber (match_scratch:SI 3 ""))]
4739   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4740   [(set (match_dup 3)
4741         (zero_extend:SI (subreg:HI
4742            (lshiftrt:SI (match_dup 1)
4743                         (match_dup 2)) 0)))
4744    (set (match_dup 0)
4745         (compare:CC (match_dup 3)
4746                     (const_int 0)))]
4747   "")
4748
4749 (define_split
4750   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4751         (compare:CC
4752          (zero_extend:SI
4753           (subreg:HI
4754            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4755                         (match_operand:SI 2 "const_int_operand" "")) 2))
4756          (const_int 0)))
4757    (clobber (match_scratch:SI 3 ""))]
4758   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4759   [(set (match_dup 3)
4760         (zero_extend:SI (subreg:HI
4761            (lshiftrt:SI (match_dup 1)
4762                         (match_dup 2)) 2)))
4763    (set (match_dup 0)
4764         (compare:CC (match_dup 3)
4765                     (const_int 0)))]
4766   "")
4767
4768 (define_insn "*lshiftrt_internal5le"
4769   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4770         (compare:CC
4771          (zero_extend:SI
4772           (subreg:HI
4773            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4774                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4775          (const_int 0)))
4776    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4777         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4778   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4779   "@
4780    rlwinm. %0,%1,%s2,0xffff
4781    #"
4782   [(set_attr "type" "delayed_compare")
4783    (set_attr "length" "4,8")])
4784
4785 (define_insn "*lshiftrt_internal5be"
4786   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4787         (compare:CC
4788          (zero_extend:SI
4789           (subreg:HI
4790            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4791                         (match_operand:SI 2 "const_int_operand" "i,i")) 2))
4792          (const_int 0)))
4793    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4794         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))]
4795   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4796   "@
4797    rlwinm. %0,%1,%s2,0xffff
4798    #"
4799   [(set_attr "type" "delayed_compare")
4800    (set_attr "length" "4,8")])
4801
4802 (define_split
4803   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4804         (compare:CC
4805          (zero_extend:SI
4806           (subreg:HI
4807            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4808                         (match_operand:SI 2 "const_int_operand" "")) 0))
4809          (const_int 0)))
4810    (set (match_operand:SI 0 "gpc_reg_operand" "")
4811         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4812   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4813   [(set (match_dup 0)
4814         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4815    (set (match_dup 3)
4816         (compare:CC (match_dup 0)
4817                     (const_int 0)))]
4818   "")
4819
4820 (define_split
4821   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4822         (compare:CC
4823          (zero_extend:SI
4824           (subreg:HI
4825            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4826                         (match_operand:SI 2 "const_int_operand" "")) 2))
4827          (const_int 0)))
4828    (set (match_operand:SI 0 "gpc_reg_operand" "")
4829         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))]
4830   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4831   [(set (match_dup 0)
4832         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))
4833    (set (match_dup 3)
4834         (compare:CC (match_dup 0)
4835                     (const_int 0)))]
4836   "")
4837
4838 (define_insn "ashrsi3"
4839   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4840         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4841                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4842   ""
4843   "@
4844    sraw %0,%1,%2
4845    srawi %0,%1,%h2"
4846   [(set_attr "type" "var_shift_rotate,shift")])
4847
4848 (define_insn "*ashrsi3_64"
4849   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4850         (sign_extend:DI
4851             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4852                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4853   "TARGET_POWERPC64"
4854   "@
4855    sraw %0,%1,%2
4856    srawi %0,%1,%h2"
4857   [(set_attr "type" "var_shift_rotate,shift")])
4858
4859 (define_insn ""
4860   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4861         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4862                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4863                     (const_int 0)))
4864    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4865   ""
4866   "@
4867    sraw. %3,%1,%2
4868    srawi. %3,%1,%h2
4869    #
4870    #"
4871   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4872    (set_attr "length" "4,4,8,8")])
4873
4874 (define_split
4875   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4876         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4877                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4878                     (const_int 0)))
4879    (clobber (match_scratch:SI 3 ""))]
4880   "reload_completed"
4881   [(set (match_dup 3)
4882         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4883    (set (match_dup 0)
4884         (compare:CC (match_dup 3)
4885                     (const_int 0)))]
4886   "")
4887
4888 (define_insn ""
4889   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4890         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4891                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4892                     (const_int 0)))
4893    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4894         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4895   ""
4896   "@
4897    sraw. %0,%1,%2
4898    srawi. %0,%1,%h2
4899    #
4900    #"
4901   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4902    (set_attr "length" "4,4,8,8")])
4903 \f
4904 ;; Builtins to replace a division to generate FRE reciprocal estimate
4905 ;; instructions and the necessary fixup instructions
4906 (define_expand "recip<mode>3"
4907   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
4908    (match_operand:RECIPF 1 "gpc_reg_operand" "")
4909    (match_operand:RECIPF 2 "gpc_reg_operand" "")]
4910   "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
4911 {
4912    rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
4913    DONE;
4914 })
4915
4916 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
4917 ;; hardware division.  This is only done before register allocation and with
4918 ;; -ffast-math.  This must appear before the divsf3/divdf3 insns.
4919 (define_split
4920   [(set (match_operand:RECIPF 0 "gpc_reg_operand" "")
4921         (div:RECIPF (match_operand 1 "gpc_reg_operand" "")
4922                     (match_operand 2 "gpc_reg_operand" "")))]
4923   "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
4924    && can_create_pseudo_p () && optimize_insn_for_speed_p ()
4925    && flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math"
4926   [(const_int 0)]
4927 {
4928   rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
4929   DONE;
4930 })
4931
4932 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
4933 ;; appropriate fixup.
4934 (define_expand "rsqrt<mode>2"
4935   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
4936    (match_operand:RECIPF 1 "gpc_reg_operand" "")]
4937   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
4938 {
4939   rs6000_emit_swrsqrt (operands[0], operands[1]);
4940   DONE;
4941 })
4942 \f
4943 (define_split
4944   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4945         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4946                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4947                     (const_int 0)))
4948    (set (match_operand:SI 0 "gpc_reg_operand" "")
4949         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4950   "reload_completed"
4951   [(set (match_dup 0)
4952         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4953    (set (match_dup 3)
4954         (compare:CC (match_dup 0)
4955                     (const_int 0)))]
4956   "")
4957
4958 ;; Floating-point insns, excluding normal data motion.
4959 ;;
4960 ;; PowerPC has a full set of single-precision floating point instructions.
4961 ;;
4962 ;; For the POWER architecture, we pretend that we have both SFmode and
4963 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4964 ;; The only conversions we will do will be when storing to memory.  In that
4965 ;; case, we will use the "frsp" instruction before storing.
4966 ;;
4967 ;; Note that when we store into a single-precision memory location, we need to
4968 ;; use the frsp insn first.  If the register being stored isn't dead, we
4969 ;; need a scratch register for the frsp.  But this is difficult when the store
4970 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4971 ;; this case, we just lose precision that we would have otherwise gotten but
4972 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4973
4974 (define_expand "extendsfdf2"
4975   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4976         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
4977   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4978   "")
4979
4980 (define_insn_and_split "*extendsfdf2_fpr"
4981   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d")
4982         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
4983   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
4984   "@
4985    #
4986    fmr %0,%1
4987    lfs%U1%X1 %0,%1"
4988   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
4989   [(const_int 0)]
4990 {
4991   emit_note (NOTE_INSN_DELETED);
4992   DONE;
4993 }
4994   [(set_attr_alternative "type"
4995       [(const_string "fp")
4996        (const_string "fp")
4997        (if_then_else
4998          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
4999          (const_string "fpload_ux")
5000          (if_then_else
5001            (match_test "update_address_mem (operands[1], VOIDmode)")
5002            (const_string "fpload_u")
5003            (const_string "fpload")))])])
5004
5005 (define_expand "truncdfsf2"
5006   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5007         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5008   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5009   "")
5010
5011 (define_insn "*truncdfsf2_fpr"
5012   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5013         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5014   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5015   "frsp %0,%1"
5016   [(set_attr "type" "fp")])
5017
5018 (define_expand "negsf2"
5019   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5020         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5021   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5022   "")
5023
5024 (define_insn "*negsf2"
5025   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5026         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5027   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5028   "fneg %0,%1"
5029   [(set_attr "type" "fp")])
5030
5031 (define_expand "abssf2"
5032   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5033         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5034   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5035   "")
5036
5037 (define_insn "*abssf2"
5038   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5039         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5040   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5041   "fabs %0,%1"
5042   [(set_attr "type" "fp")])
5043
5044 (define_insn ""
5045   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5046         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
5047   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5048   "fnabs %0,%1"
5049   [(set_attr "type" "fp")])
5050
5051 (define_expand "addsf3"
5052   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5053         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5054                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5055   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5056   "")
5057
5058 (define_insn ""
5059   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5060         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5061                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5062   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5063   "fadds %0,%1,%2"
5064   [(set_attr "type" "fp")
5065    (set_attr "fp_type" "fp_addsub_s")])
5066
5067 (define_expand "subsf3"
5068   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5069         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5070                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5071   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5072   "")
5073
5074 (define_insn ""
5075   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5076         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5077                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5078   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5079   "fsubs %0,%1,%2"
5080   [(set_attr "type" "fp")
5081    (set_attr "fp_type" "fp_addsub_s")])
5082
5083 (define_expand "mulsf3"
5084   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5085         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5086                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5087   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
5088   "")
5089
5090 (define_insn ""
5091   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5092         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5093                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5094   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5095   "fmuls %0,%1,%2"
5096   [(set_attr "type" "fp")
5097    (set_attr "fp_type" "fp_mul_s")])
5098
5099 (define_expand "divsf3"
5100   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5101         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5102                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5103   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5104   "")
5105
5106 (define_insn ""
5107   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5108         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5109                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5110   "TARGET_HARD_FLOAT && TARGET_FPRS
5111    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5112   "fdivs %0,%1,%2"
5113   [(set_attr "type" "sdiv")])
5114
5115 (define_insn "fres"
5116   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5117         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5118   "TARGET_FRES"
5119   "fres %0,%1"
5120   [(set_attr "type" "fp")])
5121
5122 ; builtin fmaf support
5123 (define_insn "*fmasf4_fpr"
5124   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5125         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5126                 (match_operand:SF 2 "gpc_reg_operand" "f")
5127                 (match_operand:SF 3 "gpc_reg_operand" "f")))]
5128   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5129   "fmadds %0,%1,%2,%3"
5130   [(set_attr "type" "fp")
5131    (set_attr "fp_type" "fp_maddsub_s")])
5132
5133 (define_insn "*fmssf4_fpr"
5134   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5135         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5136                 (match_operand:SF 2 "gpc_reg_operand" "f")
5137                 (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5138   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5139   "fmsubs %0,%1,%2,%3"
5140   [(set_attr "type" "fp")
5141    (set_attr "fp_type" "fp_maddsub_s")])
5142
5143 (define_insn "*nfmasf4_fpr"
5144   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5145         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5146                         (match_operand:SF 2 "gpc_reg_operand" "f")
5147                         (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5148   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5149   "fnmadds %0,%1,%2,%3"
5150   [(set_attr "type" "fp")
5151    (set_attr "fp_type" "fp_maddsub_s")])
5152
5153 (define_insn "*nfmssf4_fpr"
5154   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5155         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5156                         (match_operand:SF 2 "gpc_reg_operand" "f")
5157                         (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f")))))]
5158   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5159   "fnmsubs %0,%1,%2,%3"
5160   [(set_attr "type" "fp")
5161    (set_attr "fp_type" "fp_maddsub_s")])
5162
5163 (define_expand "sqrtsf2"
5164   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5165         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5166   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU)
5167    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5168    && !TARGET_SIMPLE_FPU"
5169   "")
5170
5171 (define_insn ""
5172   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5173         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5174   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU) && TARGET_HARD_FLOAT
5175    && TARGET_FPRS && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
5176   "fsqrts %0,%1"
5177   [(set_attr "type" "ssqrt")])
5178
5179 (define_insn "*rsqrtsf_internal1"
5180   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5181         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
5182                    UNSPEC_RSQRT))]
5183   "TARGET_FRSQRTES"
5184   "frsqrtes %0,%1"
5185   [(set_attr "type" "fp")])
5186
5187 ;; This expander is here to avoid FLOAT_WORDS_BIGENDIAN tests in
5188 ;; builtins.c and optabs.c that are not correct for IBM long double
5189 ;; when little-endian.
5190 (define_expand "signbittf2"
5191   [(set (match_dup 2)
5192         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))
5193    (set (match_dup 3)
5194         (subreg:DI (match_dup 2) 0))
5195    (set (match_dup 4)
5196         (match_dup 5))
5197    (set (match_operand:SI 0 "gpc_reg_operand" "")
5198         (match_dup 6))]
5199   "!TARGET_IEEEQUAD
5200    && TARGET_HARD_FLOAT
5201    && (TARGET_FPRS || TARGET_E500_DOUBLE)
5202    && TARGET_LONG_DOUBLE_128"
5203 {
5204   operands[2] = gen_reg_rtx (DFmode);
5205   operands[3] = gen_reg_rtx (DImode);
5206   if (TARGET_POWERPC64)
5207     {
5208       operands[4] = gen_reg_rtx (DImode);
5209       operands[5] = gen_rtx_LSHIFTRT (DImode, operands[3], GEN_INT (63));
5210       operands[6] = gen_rtx_SUBREG (SImode, operands[4],
5211                                     WORDS_BIG_ENDIAN ? 4 : 0);
5212     }
5213   else
5214     {
5215       operands[4] = gen_reg_rtx (SImode);
5216       operands[5] = gen_rtx_SUBREG (SImode, operands[3],
5217                                     WORDS_BIG_ENDIAN ? 0 : 4);
5218       operands[6] = gen_rtx_LSHIFTRT (SImode, operands[4], GEN_INT (31));
5219     }
5220 })
5221
5222 (define_expand "copysign<mode>3"
5223   [(set (match_dup 3)
5224         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))
5225    (set (match_dup 4)
5226         (neg:SFDF (abs:SFDF (match_dup 1))))
5227    (set (match_operand:SFDF 0 "gpc_reg_operand" "")
5228         (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand" "")
5229                                (match_dup 5))
5230                          (match_dup 3)
5231                          (match_dup 4)))]
5232   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5233    && ((TARGET_PPC_GFXOPT
5234         && !HONOR_NANS (<MODE>mode)
5235         && !HONOR_SIGNED_ZEROS (<MODE>mode))
5236        || TARGET_CMPB
5237        || VECTOR_UNIT_VSX_P (<MODE>mode))"
5238 {
5239   if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
5240     {
5241       emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
5242                                              operands[2]));
5243       DONE;
5244     }
5245
5246    operands[3] = gen_reg_rtx (<MODE>mode);
5247    operands[4] = gen_reg_rtx (<MODE>mode);
5248    operands[5] = CONST0_RTX (<MODE>mode);
5249   })
5250
5251 ;; Use an unspec rather providing an if-then-else in RTL, to prevent the
5252 ;; compiler from optimizing -0.0
5253 (define_insn "copysign<mode>3_fcpsgn"
5254   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5255         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")
5256                       (match_operand:SFDF 2 "gpc_reg_operand" "<rreg2>")]
5257                      UNSPEC_COPYSIGN))]
5258   "TARGET_CMPB && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5259   "fcpsgn %0,%2,%1"
5260   [(set_attr "type" "fp")])
5261
5262 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5263 ;; fsel instruction and some auxiliary computations.  Then we just have a
5264 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5265 ;; combine.
5266 (define_expand "smaxsf3"
5267   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5268         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5269                              (match_operand:SF 2 "gpc_reg_operand" ""))
5270                          (match_dup 1)
5271                          (match_dup 2)))]
5272   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
5273    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
5274   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5275
5276 (define_expand "sminsf3"
5277   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5278         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5279                              (match_operand:SF 2 "gpc_reg_operand" ""))
5280                          (match_dup 2)
5281                          (match_dup 1)))]
5282   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
5283    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
5284   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5285
5286 (define_split
5287   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5288         (match_operator:SF 3 "min_max_operator"
5289          [(match_operand:SF 1 "gpc_reg_operand" "")
5290           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5291   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
5292    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
5293   [(const_int 0)]
5294   "
5295 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5296                       operands[1], operands[2]);
5297   DONE;
5298 }")
5299
5300 (define_expand "mov<mode>cc"
5301    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
5302          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
5303                            (match_operand:GPR 2 "gpc_reg_operand" "")
5304                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
5305   "TARGET_ISEL<sel>"
5306   "
5307 {
5308   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5309     DONE;
5310   else
5311     FAIL;
5312 }")
5313
5314 ;; We use the BASE_REGS for the isel input operands because, if rA is
5315 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5316 ;; because we may switch the operands and rB may end up being rA.
5317 ;;
5318 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5319 ;; leave out the mode in operand 4 and use one pattern, but reload can
5320 ;; change the mode underneath our feet and then gets confused trying
5321 ;; to reload the value.
5322 (define_insn "isel_signed_<mode>"
5323   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5324         (if_then_else:GPR
5325          (match_operator 1 "scc_comparison_operator"
5326                          [(match_operand:CC 4 "cc_reg_operand" "y,y")
5327                           (const_int 0)])
5328          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
5329          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5330   "TARGET_ISEL<sel>"
5331   "*
5332 { return output_isel (operands); }"
5333   [(set_attr "type" "isel")
5334    (set_attr "length" "4")])
5335
5336 (define_insn "isel_unsigned_<mode>"
5337   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5338         (if_then_else:GPR
5339          (match_operator 1 "scc_comparison_operator"
5340                          [(match_operand:CCUNS 4 "cc_reg_operand" "y,y")
5341                           (const_int 0)])
5342          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
5343          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5344   "TARGET_ISEL<sel>"
5345   "*
5346 { return output_isel (operands); }"
5347   [(set_attr "type" "isel")
5348    (set_attr "length" "4")])
5349
5350 ;; These patterns can be useful for combine; they let combine know that
5351 ;; isel can handle reversed comparisons so long as the operands are
5352 ;; registers.
5353
5354 (define_insn "*isel_reversed_signed_<mode>"
5355   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5356         (if_then_else:GPR
5357          (match_operator 1 "scc_rev_comparison_operator"
5358                          [(match_operand:CC 4 "cc_reg_operand" "y")
5359                           (const_int 0)])
5360          (match_operand:GPR 2 "gpc_reg_operand" "b")
5361          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
5362   "TARGET_ISEL<sel>"
5363   "*
5364 { return output_isel (operands); }"
5365   [(set_attr "type" "isel")
5366    (set_attr "length" "4")])
5367
5368 (define_insn "*isel_reversed_unsigned_<mode>"
5369   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5370         (if_then_else:GPR
5371          (match_operator 1 "scc_rev_comparison_operator"
5372                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5373                           (const_int 0)])
5374          (match_operand:GPR 2 "gpc_reg_operand" "b")
5375          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
5376   "TARGET_ISEL<sel>"
5377   "*
5378 { return output_isel (operands); }"
5379   [(set_attr "type" "isel")
5380    (set_attr "length" "4")])
5381
5382 (define_expand "movsfcc"
5383    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5384          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5385                           (match_operand:SF 2 "gpc_reg_operand" "")
5386                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5387   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5388   "
5389 {
5390   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5391     DONE;
5392   else
5393     FAIL;
5394 }")
5395
5396 (define_insn "*fselsfsf4"
5397   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5398         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5399                              (match_operand:SF 4 "zero_fp_constant" "F"))
5400                          (match_operand:SF 2 "gpc_reg_operand" "f")
5401                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5402   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5403   "fsel %0,%1,%2,%3"
5404   [(set_attr "type" "fp")])
5405
5406 (define_insn "*fseldfsf4"
5407   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5408         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5409                              (match_operand:DF 4 "zero_fp_constant" "F"))
5410                          (match_operand:SF 2 "gpc_reg_operand" "f")
5411                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5412   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5413   "fsel %0,%1,%2,%3"
5414   [(set_attr "type" "fp")])
5415
5416 (define_expand "negdf2"
5417   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5418         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5419   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5420   "")
5421
5422 (define_insn "*negdf2_fpr"
5423   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5424         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5425   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5426    && !VECTOR_UNIT_VSX_P (DFmode)"
5427   "fneg %0,%1"
5428   [(set_attr "type" "fp")])
5429
5430 (define_expand "absdf2"
5431   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5432         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5433   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5434   "")
5435
5436 (define_insn "*absdf2_fpr"
5437   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5438         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5439   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5440    && !VECTOR_UNIT_VSX_P (DFmode)"
5441   "fabs %0,%1"
5442   [(set_attr "type" "fp")])
5443
5444 (define_insn "*nabsdf2_fpr"
5445   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5446         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d"))))]
5447   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5448    && !VECTOR_UNIT_VSX_P (DFmode)"
5449   "fnabs %0,%1"
5450   [(set_attr "type" "fp")])
5451
5452 (define_expand "adddf3"
5453   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5454         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5455                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5456   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5457   "")
5458
5459 (define_insn "*adddf3_fpr"
5460   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5461         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
5462                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
5463   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5464    && !VECTOR_UNIT_VSX_P (DFmode)"
5465   "fadd %0,%1,%2"
5466   [(set_attr "type" "fp")
5467    (set_attr "fp_type" "fp_addsub_d")])
5468
5469 (define_expand "subdf3"
5470   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5471         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5472                   (match_operand:DF 2 "gpc_reg_operand" "")))]
5473   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5474   "")
5475
5476 (define_insn "*subdf3_fpr"
5477   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5478         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "d")
5479                   (match_operand:DF 2 "gpc_reg_operand" "d")))]
5480   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5481    && !VECTOR_UNIT_VSX_P (DFmode)"
5482   "fsub %0,%1,%2"
5483   [(set_attr "type" "fp")
5484    (set_attr "fp_type" "fp_addsub_d")])
5485
5486 (define_expand "muldf3"
5487   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5488         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
5489                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5490   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5491   "")
5492
5493 (define_insn "*muldf3_fpr"
5494   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5495         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
5496                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
5497   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5498    && !VECTOR_UNIT_VSX_P (DFmode)"
5499   "fmul %0,%1,%2"
5500   [(set_attr "type" "dmul")
5501    (set_attr "fp_type" "fp_mul_d")])
5502
5503 (define_expand "divdf3"
5504   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5505         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
5506                 (match_operand:DF 2 "gpc_reg_operand" "")))]
5507   "TARGET_HARD_FLOAT
5508    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)
5509    && !TARGET_SIMPLE_FPU"
5510   "")
5511
5512 (define_insn "*divdf3_fpr"
5513   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5514         (div:DF (match_operand:DF 1 "gpc_reg_operand" "d")
5515                 (match_operand:DF 2 "gpc_reg_operand" "d")))]
5516   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && !TARGET_SIMPLE_FPU
5517    && !VECTOR_UNIT_VSX_P (DFmode)"
5518   "fdiv %0,%1,%2"
5519   [(set_attr "type" "ddiv")])
5520
5521 (define_insn "*fred_fpr"
5522   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5523         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5524   "TARGET_FRE && !VECTOR_UNIT_VSX_P (DFmode)"
5525   "fre %0,%1"
5526   [(set_attr "type" "fp")])
5527
5528 (define_insn "*rsqrtdf_internal1"
5529   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5530         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")]
5531                    UNSPEC_RSQRT))]
5532   "TARGET_FRSQRTE && !VECTOR_UNIT_VSX_P (DFmode)"
5533   "frsqrte %0,%1"
5534   [(set_attr "type" "fp")])
5535
5536 ; builtin fma support
5537 (define_insn "*fmadf4_fpr"
5538   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5539         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5540                 (match_operand:DF 2 "gpc_reg_operand" "f")
5541                 (match_operand:DF 3 "gpc_reg_operand" "f")))]
5542   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5543    && VECTOR_UNIT_NONE_P (DFmode)"
5544   "fmadd %0,%1,%2,%3"
5545   [(set_attr "type" "fp")
5546    (set_attr "fp_type" "fp_maddsub_d")])
5547
5548 (define_insn "*fmsdf4_fpr"
5549   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5550         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5551                 (match_operand:DF 2 "gpc_reg_operand" "f")
5552                 (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5553   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5554    && VECTOR_UNIT_NONE_P (DFmode)"
5555   "fmsub %0,%1,%2,%3"
5556   [(set_attr "type" "fp")
5557    (set_attr "fp_type" "fp_maddsub_d")])
5558
5559 (define_insn "*nfmadf4_fpr"
5560   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5561         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5562                         (match_operand:DF 2 "gpc_reg_operand" "f")
5563                         (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5564   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5565    && VECTOR_UNIT_NONE_P (DFmode)"
5566   "fnmadd %0,%1,%2,%3"
5567   [(set_attr "type" "fp")
5568    (set_attr "fp_type" "fp_maddsub_d")])
5569
5570 (define_insn "*nfmsdf4_fpr"
5571   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5572         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5573                         (match_operand:DF 2 "gpc_reg_operand" "f")
5574                         (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f")))))]
5575   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5576    && VECTOR_UNIT_NONE_P (DFmode)"
5577   "fnmsub %0,%1,%2,%3"
5578   [(set_attr "type" "fp")
5579    (set_attr "fp_type" "fp_maddsub_d")])
5580
5581 (define_expand "sqrtdf2"
5582   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5583         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5584   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5585   "")
5586
5587 (define_insn "*sqrtdf2_fpr"
5588   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5589         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5590   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5591    && !VECTOR_UNIT_VSX_P (DFmode)"
5592   "fsqrt %0,%1"
5593   [(set_attr "type" "dsqrt")])
5594
5595 ;; The conditional move instructions allow us to perform max and min
5596 ;; operations even when
5597
5598 (define_expand "smaxdf3"
5599   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5600         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5601                              (match_operand:DF 2 "gpc_reg_operand" ""))
5602                          (match_dup 1)
5603                          (match_dup 2)))]
5604   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5605    && !flag_trapping_math"
5606   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5607
5608 (define_expand "smindf3"
5609   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5610         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5611                              (match_operand:DF 2 "gpc_reg_operand" ""))
5612                          (match_dup 2)
5613                          (match_dup 1)))]
5614   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5615    && !flag_trapping_math"
5616   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5617
5618 (define_split
5619   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5620         (match_operator:DF 3 "min_max_operator"
5621          [(match_operand:DF 1 "gpc_reg_operand" "")
5622           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5623   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5624    && !flag_trapping_math"
5625   [(const_int 0)]
5626   "
5627 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5628                       operands[1], operands[2]);
5629   DONE;
5630 }")
5631
5632 (define_expand "movdfcc"
5633    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5634          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5635                           (match_operand:DF 2 "gpc_reg_operand" "")
5636                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5637   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5638   "
5639 {
5640   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5641     DONE;
5642   else
5643     FAIL;
5644 }")
5645
5646 (define_insn "*fseldfdf4"
5647   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5648         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5649                              (match_operand:DF 4 "zero_fp_constant" "F"))
5650                          (match_operand:DF 2 "gpc_reg_operand" "d")
5651                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5652   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5653   "fsel %0,%1,%2,%3"
5654   [(set_attr "type" "fp")])
5655
5656 (define_insn "*fselsfdf4"
5657   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5658         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5659                              (match_operand:SF 4 "zero_fp_constant" "F"))
5660                          (match_operand:DF 2 "gpc_reg_operand" "d")
5661                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5662   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5663   "fsel %0,%1,%2,%3"
5664   [(set_attr "type" "fp")])
5665 \f
5666 ;; Conversions to and from floating-point.
5667
5668 ; We don't define lfiwax/lfiwzx with the normal definition, because we
5669 ; don't want to support putting SImode in FPR registers.
5670 (define_insn "lfiwax"
5671   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wm,!wm")
5672         (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r")]
5673                    UNSPEC_LFIWAX))]
5674   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX"
5675   "@
5676    lfiwax %0,%y1
5677    lxsiwax %x0,%y1
5678    mtvsrwa %x0,%1"
5679   [(set_attr "type" "fpload,fpload,mffgpr")])
5680
5681 ; This split must be run before register allocation because it allocates the
5682 ; memory slot that is needed to move values to/from the FPR.  We don't allocate
5683 ; it earlier to allow for the combiner to merge insns together where it might
5684 ; not be needed and also in case the insns are deleted as dead code.
5685
5686 (define_insn_and_split "floatsi<mode>2_lfiwax"
5687   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5688         (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5689    (clobber (match_scratch:DI 2 "=d"))]
5690   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5691    && <SI_CONVERT_FP> && can_create_pseudo_p ()"
5692   "#"
5693   ""
5694   [(pc)]
5695   "
5696 {
5697   rtx dest = operands[0];
5698   rtx src = operands[1];
5699   rtx tmp;
5700
5701   if (!MEM_P (src) && TARGET_POWERPC64
5702       && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
5703     tmp = convert_to_mode (DImode, src, false);
5704   else
5705     {
5706       tmp = operands[2];
5707       if (GET_CODE (tmp) == SCRATCH)
5708         tmp = gen_reg_rtx (DImode);
5709       if (MEM_P (src))
5710         {
5711           src = rs6000_address_for_fpconvert (src);
5712           emit_insn (gen_lfiwax (tmp, src));
5713         }
5714       else
5715         {
5716           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5717           emit_move_insn (stack, src);
5718           emit_insn (gen_lfiwax (tmp, stack));
5719         }
5720     }
5721   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5722   DONE;
5723 }"
5724   [(set_attr "length" "12")
5725    (set_attr "type" "fpload")])
5726
5727 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
5728   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5729         (float:SFDF
5730          (sign_extend:DI
5731           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5732    (clobber (match_scratch:DI 2 "=0,d"))]
5733   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5734    && <SI_CONVERT_FP>"
5735   "#"
5736   ""
5737   [(pc)]
5738   "
5739 {
5740   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5741   if (GET_CODE (operands[2]) == SCRATCH)
5742     operands[2] = gen_reg_rtx (DImode);
5743   emit_insn (gen_lfiwax (operands[2], operands[1]));
5744   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5745   DONE;
5746 }"
5747   [(set_attr "length" "8")
5748    (set_attr "type" "fpload")])
5749
5750 (define_insn "lfiwzx"
5751   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wm,!wm")
5752         (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r")]
5753                    UNSPEC_LFIWZX))]
5754   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX"
5755   "@
5756    lfiwzx %0,%y1
5757    lxsiwzx %x0,%y1
5758    mtvsrwz %x0,%1"
5759   [(set_attr "type" "fpload,fpload,mftgpr")])
5760
5761 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
5762   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5763         (unsigned_float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5764    (clobber (match_scratch:DI 2 "=d"))]
5765   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5766    && <SI_CONVERT_FP>"
5767   "#"
5768   ""
5769   [(pc)]
5770   "
5771 {
5772   rtx dest = operands[0];
5773   rtx src = operands[1];
5774   rtx tmp;
5775
5776   if (!MEM_P (src) && TARGET_POWERPC64
5777       && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
5778     tmp = convert_to_mode (DImode, src, true);
5779   else
5780     {
5781       tmp = operands[2];
5782       if (GET_CODE (tmp) == SCRATCH)
5783         tmp = gen_reg_rtx (DImode);
5784       if (MEM_P (src))
5785         {
5786           src = rs6000_address_for_fpconvert (src);
5787           emit_insn (gen_lfiwzx (tmp, src));
5788         }
5789       else
5790         {
5791           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5792           emit_move_insn (stack, src);
5793           emit_insn (gen_lfiwzx (tmp, stack));
5794         }
5795     }
5796   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5797   DONE;
5798 }"
5799   [(set_attr "length" "12")
5800    (set_attr "type" "fpload")])
5801
5802 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
5803   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5804         (unsigned_float:SFDF
5805          (zero_extend:DI
5806           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5807    (clobber (match_scratch:DI 2 "=0,d"))]
5808   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5809    && <SI_CONVERT_FP>"
5810   "#"
5811   ""
5812   [(pc)]
5813   "
5814 {
5815   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5816   if (GET_CODE (operands[2]) == SCRATCH)
5817     operands[2] = gen_reg_rtx (DImode);
5818   emit_insn (gen_lfiwzx (operands[2], operands[1]));
5819   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5820   DONE;
5821 }"
5822   [(set_attr "length" "8")
5823    (set_attr "type" "fpload")])
5824
5825 ; For each of these conversions, there is a define_expand, a define_insn
5826 ; with a '#' template, and a define_split (with C code).  The idea is
5827 ; to allow constant folding with the template of the define_insn,
5828 ; then to have the insns split later (between sched1 and final).
5829
5830 (define_expand "floatsidf2"
5831   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5832                    (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5833               (use (match_dup 2))
5834               (use (match_dup 3))
5835               (clobber (match_dup 4))
5836               (clobber (match_dup 5))
5837               (clobber (match_dup 6))])]
5838   "TARGET_HARD_FLOAT 
5839    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5840   "
5841 {
5842   if (TARGET_E500_DOUBLE)
5843     {
5844       if (!REG_P (operands[1]))
5845         operands[1] = force_reg (SImode, operands[1]);
5846       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5847       DONE;
5848     }
5849   else if (TARGET_LFIWAX && TARGET_FCFID)
5850     {
5851       emit_insn (gen_floatsidf2_lfiwax (operands[0], operands[1]));
5852       DONE;
5853     }
5854   else if (TARGET_FCFID)
5855     {
5856       rtx dreg = operands[1];
5857       if (!REG_P (dreg))
5858         dreg = force_reg (SImode, dreg);
5859       dreg = convert_to_mode (DImode, dreg, false);
5860       emit_insn (gen_floatdidf2 (operands[0], dreg));
5861       DONE;
5862     }
5863
5864   if (!REG_P (operands[1]))
5865     operands[1] = force_reg (SImode, operands[1]);
5866   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5867   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5868   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5869   operands[5] = gen_reg_rtx (DFmode);
5870   operands[6] = gen_reg_rtx (SImode);
5871 }")
5872
5873 (define_insn_and_split "*floatsidf2_internal"
5874   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5875         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5876    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5877    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5878    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5879    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
5880    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5881   "! TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5882   "#"
5883   ""
5884   [(pc)]
5885   "
5886 {
5887   rtx lowword, highword;
5888   gcc_assert (MEM_P (operands[4]));
5889   highword = adjust_address (operands[4], SImode, 0);
5890   lowword = adjust_address (operands[4], SImode, 4);
5891   if (! WORDS_BIG_ENDIAN)
5892     {
5893       rtx tmp;
5894       tmp = highword; highword = lowword; lowword = tmp;
5895     }
5896
5897   emit_insn (gen_xorsi3 (operands[6], operands[1],
5898                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5899   emit_move_insn (lowword, operands[6]);
5900   emit_move_insn (highword, operands[2]);
5901   emit_move_insn (operands[5], operands[4]);
5902   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5903   DONE;
5904 }"
5905   [(set_attr "length" "24")
5906    (set_attr "type" "fp")])
5907
5908 ;; If we don't have a direct conversion to single precision, don't enable this
5909 ;; conversion for 32-bit without fast math, because we don't have the insn to
5910 ;; generate the fixup swizzle to avoid double rounding problems.
5911 (define_expand "floatunssisf2"
5912   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5913         (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5914   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
5915    && (!TARGET_FPRS
5916        || (TARGET_FPRS
5917            && ((TARGET_FCFIDUS && TARGET_LFIWZX)
5918                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
5919                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
5920   "
5921 {
5922   if (!TARGET_FPRS)
5923     {
5924       if (!REG_P (operands[1]))
5925         operands[1] = force_reg (SImode, operands[1]);
5926     }
5927   else if (TARGET_LFIWZX && TARGET_FCFIDUS)
5928     {
5929       emit_insn (gen_floatunssisf2_lfiwzx (operands[0], operands[1]));
5930       DONE;
5931     }
5932   else
5933     {
5934       rtx dreg = operands[1];
5935       if (!REG_P (dreg))
5936         dreg = force_reg (SImode, dreg);
5937       dreg = convert_to_mode (DImode, dreg, true);
5938       emit_insn (gen_floatdisf2 (operands[0], dreg));
5939       DONE;
5940     }
5941 }")
5942
5943 (define_expand "floatunssidf2"
5944   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5945                    (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5946               (use (match_dup 2))
5947               (use (match_dup 3))
5948               (clobber (match_dup 4))
5949               (clobber (match_dup 5))])]
5950   "TARGET_HARD_FLOAT
5951    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5952   "
5953 {
5954   if (TARGET_E500_DOUBLE)
5955     {
5956       if (!REG_P (operands[1]))
5957         operands[1] = force_reg (SImode, operands[1]);
5958       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5959       DONE;
5960     }
5961   else if (TARGET_LFIWZX && TARGET_FCFID)
5962     {
5963       emit_insn (gen_floatunssidf2_lfiwzx (operands[0], operands[1]));
5964       DONE;
5965     }
5966   else if (TARGET_FCFID)
5967     {
5968       rtx dreg = operands[1];
5969       if (!REG_P (dreg))
5970         dreg = force_reg (SImode, dreg);
5971       dreg = convert_to_mode (DImode, dreg, true);
5972       emit_insn (gen_floatdidf2 (operands[0], dreg));
5973       DONE;
5974     }
5975
5976   if (!REG_P (operands[1]))
5977     operands[1] = force_reg (SImode, operands[1]);
5978   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5979   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5980   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5981   operands[5] = gen_reg_rtx (DFmode);
5982 }")
5983
5984 (define_insn_and_split "*floatunssidf2_internal"
5985   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5986         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5987    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5988    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5989    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5990    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
5991   "! TARGET_FCFIDU && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5992    && !(TARGET_FCFID && TARGET_POWERPC64)"
5993   "#"
5994   ""
5995   [(pc)]
5996   "
5997 {
5998   rtx lowword, highword;
5999   gcc_assert (MEM_P (operands[4]));
6000   highword = adjust_address (operands[4], SImode, 0);
6001   lowword = adjust_address (operands[4], SImode, 4);
6002   if (! WORDS_BIG_ENDIAN)
6003     {
6004       rtx tmp;
6005       tmp = highword; highword = lowword; lowword = tmp;
6006     }
6007
6008   emit_move_insn (lowword, operands[1]);
6009   emit_move_insn (highword, operands[2]);
6010   emit_move_insn (operands[5], operands[4]);
6011   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6012   DONE;
6013 }"
6014   [(set_attr "length" "20")
6015    (set_attr "type" "fp")])
6016
6017 (define_expand "fix_trunc<mode>si2"
6018   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6019         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6020   "TARGET_HARD_FLOAT && ((TARGET_FPRS && <TARGET_FLOAT>) || <E500_CONVERT>)"
6021   "
6022 {
6023   if (!<E500_CONVERT>)
6024     {
6025       rtx tmp, stack;
6026
6027       if (TARGET_STFIWX)
6028         emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6029       else
6030         {
6031           tmp = gen_reg_rtx (DImode);
6032           stack = rs6000_allocate_stack_temp (DImode, true, false);
6033           emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], operands[1],
6034                                                       tmp, stack));
6035         }
6036       DONE;
6037     }
6038 }")
6039
6040 ; Like the convert to float patterns, this insn must be split before
6041 ; register allocation so that it can allocate the memory slot if it
6042 ; needed
6043 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
6044   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6045         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6046    (clobber (match_scratch:DI 2 "=d"))]
6047   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6048    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
6049    && TARGET_STFIWX && can_create_pseudo_p ()"
6050   "#"
6051   ""
6052   [(pc)]
6053 {
6054   rtx dest = operands[0];
6055   rtx src = operands[1];
6056   rtx tmp = operands[2];
6057
6058   if (GET_CODE (tmp) == SCRATCH)
6059     tmp = gen_reg_rtx (DImode);
6060
6061   emit_insn (gen_fctiwz_<mode> (tmp, src));
6062   if (MEM_P (dest))
6063     {
6064       dest = rs6000_address_for_fpconvert (dest);
6065       emit_insn (gen_stfiwx (dest, tmp));
6066       DONE;
6067     }
6068   else if (TARGET_POWERPC64 && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
6069     {
6070       dest = gen_lowpart (DImode, dest);
6071       emit_move_insn (dest, tmp);
6072       DONE;
6073     }
6074   else
6075     {
6076       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6077       emit_insn (gen_stfiwx (stack, tmp));
6078       emit_move_insn (dest, stack);
6079       DONE;
6080     }
6081 }
6082   [(set_attr "length" "12")
6083    (set_attr "type" "fp")])
6084
6085 (define_insn_and_split "fix_trunc<mode>si2_internal"
6086   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,?r")
6087         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,<rreg>")))
6088    (clobber (match_operand:DI 2 "gpc_reg_operand" "=1,d"))
6089    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o,o"))]
6090   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6091   "#"
6092   ""
6093   [(pc)]
6094   "
6095 {
6096   rtx lowword;
6097   gcc_assert (MEM_P (operands[3]));
6098   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6099
6100   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
6101   emit_move_insn (operands[3], operands[2]);
6102   emit_move_insn (operands[0], lowword);
6103   DONE;
6104 }"
6105   [(set_attr "length" "16")
6106    (set_attr "type" "fp")])
6107
6108 (define_expand "fix_trunc<mode>di2"
6109   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6110         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6111   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6112    && TARGET_FCFID"
6113   "")
6114
6115 (define_insn "*fix_trunc<mode>di2_fctidz"
6116   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6117         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6118   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6119     && TARGET_FCFID && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6120   "fctidz %0,%1"
6121   [(set_attr "type" "fp")])
6122
6123 (define_expand "fixuns_trunc<mode>si2"
6124   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6125         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6126   "TARGET_HARD_FLOAT
6127    && ((TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ && TARGET_STFIWX)
6128        || <E500_CONVERT>)"
6129   "
6130 {
6131   if (!<E500_CONVERT>)
6132     {
6133       emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6134       DONE;
6135     }
6136 }")
6137
6138 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
6139   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6140         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6141    (clobber (match_scratch:DI 2 "=d"))]
6142   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
6143    && TARGET_STFIWX && can_create_pseudo_p ()"
6144   "#"
6145   ""
6146   [(pc)]
6147 {
6148   rtx dest = operands[0];
6149   rtx src = operands[1];
6150   rtx tmp = operands[2];
6151
6152   if (GET_CODE (tmp) == SCRATCH)
6153     tmp = gen_reg_rtx (DImode);
6154
6155   emit_insn (gen_fctiwuz_<mode> (tmp, src));
6156   if (MEM_P (dest))
6157     {
6158       dest = rs6000_address_for_fpconvert (dest);
6159       emit_insn (gen_stfiwx (dest, tmp));
6160       DONE;
6161     }
6162   else if (TARGET_POWERPC64 && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
6163     {
6164       dest = gen_lowpart (DImode, dest);
6165       emit_move_insn (dest, tmp);
6166       DONE;
6167     }
6168   else
6169     {
6170       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6171       emit_insn (gen_stfiwx (stack, tmp));
6172       emit_move_insn (dest, stack);
6173       DONE;
6174     }
6175 }
6176   [(set_attr "length" "12")
6177    (set_attr "type" "fp")])
6178
6179 (define_expand "fixuns_trunc<mode>di2"
6180   [(set (match_operand:DI 0 "register_operand" "")
6181         (unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
6182   "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
6183   "")
6184
6185 (define_insn "*fixuns_trunc<mode>di2_fctiduz"
6186   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6187         (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6188   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6189     && TARGET_FCTIDUZ && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6190   "fctiduz %0,%1"
6191   [(set_attr "type" "fp")])
6192
6193 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6194 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
6195 ; because the first makes it clear that operand 0 is not live
6196 ; before the instruction.
6197 (define_insn "fctiwz_<mode>"
6198   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6199         (unspec:DI [(fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))]
6200                    UNSPEC_FCTIWZ))]
6201   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6202   "fctiwz %0,%1"
6203   [(set_attr "type" "fp")])
6204
6205 (define_insn "fctiwuz_<mode>"
6206   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6207         (unspec:DI [(unsigned_fix:SI
6208                      (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>"))]
6209                    UNSPEC_FCTIWUZ))]
6210   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ"
6211   "fctiwuz %0,%1"
6212   [(set_attr "type" "fp")])
6213
6214 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
6215 ;; since the friz instruction does not truncate the value if the floating
6216 ;; point value is < LONG_MIN or > LONG_MAX.
6217 (define_insn "*friz"
6218   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6219         (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d"))))]
6220   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_FPRND
6221    && !VECTOR_UNIT_VSX_P (DFmode) && flag_unsafe_math_optimizations
6222    && !flag_trapping_math && TARGET_FRIZ"
6223   "friz %0,%1"
6224   [(set_attr "type" "fp")])
6225
6226 ;; Since FCTIWZ doesn't sign extend the upper bits, we have to do a store and a
6227 ;; load to properly sign extend the value, but at least doing a store, load
6228 ;; into a GPR to sign extend, a store from the GPR and a load back into the FPR
6229 ;; if we have 32-bit memory ops
6230 (define_insn_and_split "*round32<mode>2_fprs"
6231   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6232         (float:SFDF
6233          (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6234    (clobber (match_scratch:DI 2 "=d"))
6235    (clobber (match_scratch:DI 3 "=d"))]
6236   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6237    && <SI_CONVERT_FP> && TARGET_LFIWAX && TARGET_STFIWX && TARGET_FCFID
6238    && can_create_pseudo_p ()"
6239   "#"
6240   ""
6241   [(pc)]
6242 {
6243   rtx dest = operands[0];
6244   rtx src = operands[1];
6245   rtx tmp1 = operands[2];
6246   rtx tmp2 = operands[3];
6247   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6248
6249   if (GET_CODE (tmp1) == SCRATCH)
6250     tmp1 = gen_reg_rtx (DImode);
6251   if (GET_CODE (tmp2) == SCRATCH)
6252     tmp2 = gen_reg_rtx (DImode);
6253
6254   emit_insn (gen_fctiwz_<mode> (tmp1, src));
6255   emit_insn (gen_stfiwx (stack, tmp1));
6256   emit_insn (gen_lfiwax (tmp2, stack));
6257   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6258   DONE;
6259 }
6260   [(set_attr "type" "fpload")
6261    (set_attr "length" "16")])
6262
6263 (define_insn_and_split "*roundu32<mode>2_fprs"
6264   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6265         (unsigned_float:SFDF
6266          (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6267    (clobber (match_scratch:DI 2 "=d"))
6268    (clobber (match_scratch:DI 3 "=d"))]
6269   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6270    && TARGET_LFIWZX && TARGET_STFIWX && TARGET_FCFIDU
6271    && can_create_pseudo_p ()"
6272   "#"
6273   ""
6274   [(pc)]
6275 {
6276   rtx dest = operands[0];
6277   rtx src = operands[1];
6278   rtx tmp1 = operands[2];
6279   rtx tmp2 = operands[3];
6280   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6281
6282   if (GET_CODE (tmp1) == SCRATCH)
6283     tmp1 = gen_reg_rtx (DImode);
6284   if (GET_CODE (tmp2) == SCRATCH)
6285     tmp2 = gen_reg_rtx (DImode);
6286
6287   emit_insn (gen_fctiwuz_<mode> (tmp1, src));
6288   emit_insn (gen_stfiwx (stack, tmp1));
6289   emit_insn (gen_lfiwzx (tmp2, stack));
6290   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6291   DONE;
6292 }
6293   [(set_attr "type" "fpload")
6294    (set_attr "length" "16")])
6295
6296 ;; No VSX equivalent to fctid
6297 (define_insn "lrint<mode>di2"
6298   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6299         (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6300                    UNSPEC_FCTID))]
6301   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
6302   "fctid %0,%1"
6303   [(set_attr "type" "fp")])
6304
6305 (define_expand "btrunc<mode>2"
6306   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
6307         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
6308                      UNSPEC_FRIZ))]
6309   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
6310   "")
6311
6312 (define_insn "*btrunc<mode>2_fpr"
6313   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6314         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6315                      UNSPEC_FRIZ))]
6316   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
6317    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6318   "friz %0,%1"
6319   [(set_attr "type" "fp")])
6320
6321 (define_expand "ceil<mode>2"
6322   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
6323         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
6324                      UNSPEC_FRIP))]
6325   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
6326   "")
6327
6328 (define_insn "*ceil<mode>2_fpr"
6329   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6330         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6331                      UNSPEC_FRIP))]
6332   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
6333    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6334   "frip %0,%1"
6335   [(set_attr "type" "fp")])
6336
6337 (define_expand "floor<mode>2"
6338   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
6339         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
6340                      UNSPEC_FRIM))]
6341   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
6342   "")
6343
6344 (define_insn "*floor<mode>2_fpr"
6345   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6346         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6347                      UNSPEC_FRIM))]
6348   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
6349    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6350   "frim %0,%1"
6351   [(set_attr "type" "fp")])
6352
6353 ;; No VSX equivalent to frin
6354 (define_insn "round<mode>2"
6355   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6356         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6357                      UNSPEC_FRIN))]
6358   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
6359   "frin %0,%1"
6360   [(set_attr "type" "fp")])
6361
6362 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6363 (define_insn "stfiwx"
6364   [(set (match_operand:SI 0 "memory_operand" "=Z")
6365         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
6366                    UNSPEC_STFIWX))]
6367   "TARGET_PPC_GFXOPT"
6368   "stfiwx %1,%y0"
6369   [(set_attr "type" "fpstore")])
6370
6371 ;; If we don't have a direct conversion to single precision, don't enable this
6372 ;; conversion for 32-bit without fast math, because we don't have the insn to
6373 ;; generate the fixup swizzle to avoid double rounding problems.
6374 (define_expand "floatsisf2"
6375   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6376         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
6377   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
6378    && (!TARGET_FPRS
6379        || (TARGET_FPRS
6380            && ((TARGET_FCFIDS && TARGET_LFIWAX)
6381                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
6382                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
6383   "
6384 {
6385   if (!TARGET_FPRS)
6386     {
6387       if (!REG_P (operands[1]))
6388         operands[1] = force_reg (SImode, operands[1]);
6389     }
6390   else if (TARGET_FCFIDS && TARGET_LFIWAX)
6391     {
6392       emit_insn (gen_floatsisf2_lfiwax (operands[0], operands[1]));
6393       DONE;
6394     }
6395   else if (TARGET_FCFID && TARGET_LFIWAX)
6396     {
6397       rtx dfreg = gen_reg_rtx (DFmode);
6398       emit_insn (gen_floatsidf2_lfiwax (dfreg, operands[1]));
6399       emit_insn (gen_truncdfsf2 (operands[0], dfreg));
6400       DONE;
6401     }
6402   else
6403     {
6404       rtx dreg = operands[1];
6405       if (!REG_P (dreg))
6406         dreg = force_reg (SImode, dreg);
6407       dreg = convert_to_mode (DImode, dreg, false);
6408       emit_insn (gen_floatdisf2 (operands[0], dreg));
6409       DONE;
6410     }
6411 }")
6412
6413 (define_expand "floatdidf2"
6414   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6415         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
6416   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
6417   "")
6418
6419 (define_insn "*floatdidf2_fpr"
6420   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6421         (float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6422   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6423    && !VECTOR_UNIT_VSX_P (DFmode)"
6424   "fcfid %0,%1"
6425   [(set_attr "type" "fp")])
6426
6427 ; Allow the combiner to merge source memory operands to the conversion so that
6428 ; the optimizer/register allocator doesn't try to load the value too early in a
6429 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
6430 ; hit.  We will split after reload to avoid the trip through the GPRs
6431
6432 (define_insn_and_split "*floatdidf2_mem"
6433   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6434         (float:DF (match_operand:DI 1 "memory_operand" "m")))
6435    (clobber (match_scratch:DI 2 "=d"))]
6436   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCFID"
6437   "#"
6438   "&& reload_completed"
6439   [(set (match_dup 2) (match_dup 1))
6440    (set (match_dup 0) (float:DF (match_dup 2)))]
6441   ""
6442   [(set_attr "length" "8")
6443    (set_attr "type" "fpload")])
6444
6445 (define_expand "floatunsdidf2"
6446   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6447         (unsigned_float:DF
6448          (match_operand:DI 1 "gpc_reg_operand" "")))]
6449   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
6450   "")
6451
6452 (define_insn "*floatunsdidf2_fcfidu"
6453   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6454         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6455   "TARGET_HARD_FLOAT && TARGET_FCFIDU && !VECTOR_UNIT_VSX_P (DFmode)"
6456   "fcfidu %0,%1"
6457   [(set_attr "type" "fp")
6458    (set_attr "length" "4")])
6459
6460 (define_insn_and_split "*floatunsdidf2_mem"
6461   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6462         (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m")))
6463    (clobber (match_scratch:DI 2 "=d"))]
6464   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
6465   "#"
6466   "&& reload_completed"
6467   [(set (match_dup 2) (match_dup 1))
6468    (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
6469   ""
6470   [(set_attr "length" "8")
6471    (set_attr "type" "fpload")])
6472
6473 (define_expand "floatdisf2"
6474   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6475         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6476   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6477    && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
6478   "
6479 {
6480   if (!TARGET_FCFIDS)
6481     {
6482       rtx val = operands[1];
6483       if (!flag_unsafe_math_optimizations)
6484         {
6485           rtx label = gen_label_rtx ();
6486           val = gen_reg_rtx (DImode);
6487           emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
6488           emit_label (label);
6489         }
6490       emit_insn (gen_floatdisf2_internal1 (operands[0], val));
6491       DONE;
6492     }
6493 }")
6494
6495 (define_insn "floatdisf2_fcfids"
6496   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6497         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6498   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6499    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
6500   "fcfids %0,%1"
6501   [(set_attr "type" "fp")])
6502
6503 (define_insn_and_split "*floatdisf2_mem"
6504   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6505         (float:SF (match_operand:DI 1 "memory_operand" "m")))
6506    (clobber (match_scratch:DI 2 "=f"))]
6507   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6508    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
6509   "#"
6510   "&& reload_completed"
6511   [(pc)]
6512   "
6513 {
6514   emit_move_insn (operands[2], operands[1]);
6515   emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
6516   DONE;
6517 }"
6518   [(set_attr "length" "8")])
6519
6520 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6521 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6522 ;; from double rounding.
6523 ;; Instead of creating a new cpu type for two FP operations, just use fp
6524 (define_insn_and_split "floatdisf2_internal1"
6525   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6526         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
6527    (clobber (match_scratch:DF 2 "=d"))]
6528   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6529   "#"
6530   "&& reload_completed"
6531   [(set (match_dup 2)
6532         (float:DF (match_dup 1)))
6533    (set (match_dup 0)
6534         (float_truncate:SF (match_dup 2)))]
6535   ""
6536   [(set_attr "length" "8")
6537    (set_attr "type" "fp")])
6538
6539 ;; Twiddles bits to avoid double rounding.
6540 ;; Bits that might be truncated when converting to DFmode are replaced
6541 ;; by a bit that won't be lost at that stage, but is below the SFmode
6542 ;; rounding position.
6543 (define_expand "floatdisf2_internal2"
6544   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6545                                    (const_int 53)))
6546    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6547                                                       (const_int 2047)))
6548               (clobber (scratch:CC))])
6549    (set (match_dup 3) (plus:DI (match_dup 3)
6550                                (const_int 1)))
6551    (set (match_dup 0) (plus:DI (match_dup 0)
6552                                (const_int 2047)))
6553    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6554                                      (const_int 2)))
6555    (set (match_dup 0) (ior:DI (match_dup 0)
6556                               (match_dup 1)))
6557    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6558                                          (const_int -2048)))
6559               (clobber (scratch:CC))])
6560    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6561                            (label_ref (match_operand:DI 2 "" ""))
6562                            (pc)))
6563    (set (match_dup 0) (match_dup 1))]
6564   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6565   "
6566 {
6567   operands[3] = gen_reg_rtx (DImode);
6568   operands[4] = gen_reg_rtx (CCUNSmode);
6569 }")
6570
6571 (define_expand "floatunsdisf2"
6572   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6573         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6574   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6575    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6576   "")
6577
6578 (define_insn "floatunsdisf2_fcfidus"
6579   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6580         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6581   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6582    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6583   "fcfidus %0,%1"
6584   [(set_attr "type" "fp")])
6585
6586 (define_insn_and_split "*floatunsdisf2_mem"
6587   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6588         (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m")))
6589    (clobber (match_scratch:DI 2 "=f"))]
6590   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6591    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6592   "#"
6593   "&& reload_completed"
6594   [(pc)]
6595   "
6596 {
6597   emit_move_insn (operands[2], operands[1]);
6598   emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
6599   DONE;
6600 }"
6601   [(set_attr "length" "8")
6602    (set_attr "type" "fpload")])
6603 \f
6604 ;; Define the DImode operations that can be done in a small number
6605 ;; of instructions.  The & constraints are to prevent the register
6606 ;; allocator from allocating registers that overlap with the inputs
6607 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6608 ;; also allow for the output being the same as one of the inputs.
6609
6610 (define_insn "*adddi3_noppc64"
6611   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6612         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6613                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6614   "! TARGET_POWERPC64"
6615   "*
6616 {
6617   if (WORDS_BIG_ENDIAN)
6618     return (GET_CODE (operands[2])) != CONST_INT
6619             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6620             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6621   else
6622     return (GET_CODE (operands[2])) != CONST_INT
6623             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6624             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6625 }"
6626   [(set_attr "type" "two")
6627    (set_attr "length" "8")])
6628
6629 (define_insn "*subdi3_noppc64"
6630   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6631         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6632                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6633   "! TARGET_POWERPC64"
6634   "*
6635 {
6636   if (WORDS_BIG_ENDIAN)
6637     return (GET_CODE (operands[1]) != CONST_INT)
6638             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6639             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6640   else
6641     return (GET_CODE (operands[1]) != CONST_INT)
6642             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6643             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6644 }"
6645   [(set_attr "type" "two")
6646    (set_attr "length" "8")])
6647
6648 (define_insn "*negdi2_noppc64"
6649   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6650         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6651   "! TARGET_POWERPC64"
6652   "*
6653 {
6654   return (WORDS_BIG_ENDIAN)
6655     ? \"subfic %L0,%L1,0\;subfze %0,%1\"
6656     : \"subfic %0,%1,0\;subfze %L0,%L1\";
6657 }"
6658   [(set_attr "type" "two")
6659    (set_attr "length" "8")])
6660
6661 (define_insn "mulsidi3"
6662   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6663         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6664                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6665   "! TARGET_POWERPC64"
6666 {
6667   return (WORDS_BIG_ENDIAN)
6668     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6669     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6670 }
6671   [(set_attr "type" "imul")
6672    (set_attr "length" "8")])
6673
6674 (define_split
6675   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6676         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6677                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6678   "! TARGET_POWERPC64 && reload_completed"
6679   [(set (match_dup 3)
6680         (truncate:SI
6681          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6682                                (sign_extend:DI (match_dup 2)))
6683                       (const_int 32))))
6684    (set (match_dup 4)
6685         (mult:SI (match_dup 1)
6686                  (match_dup 2)))]
6687   "
6688 {
6689   int endian = (WORDS_BIG_ENDIAN == 0);
6690   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6691   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6692 }")
6693
6694 (define_insn "umulsidi3"
6695   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6696         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6697                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6698   "! TARGET_POWERPC64"
6699   "*
6700 {
6701   return (WORDS_BIG_ENDIAN)
6702     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6703     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6704 }"
6705   [(set_attr "type" "imul")
6706    (set_attr "length" "8")])
6707
6708 (define_split
6709   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6710         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6711                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6712   "! TARGET_POWERPC64 && reload_completed"
6713   [(set (match_dup 3)
6714         (truncate:SI
6715          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6716                                (zero_extend:DI (match_dup 2)))
6717                       (const_int 32))))
6718    (set (match_dup 4)
6719         (mult:SI (match_dup 1)
6720                  (match_dup 2)))]
6721   "
6722 {
6723   int endian = (WORDS_BIG_ENDIAN == 0);
6724   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6725   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6726 }")
6727
6728 (define_insn "smulsi3_highpart"
6729   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6730         (truncate:SI
6731          (lshiftrt:DI (mult:DI (sign_extend:DI
6732                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6733                                (sign_extend:DI
6734                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6735                       (const_int 32))))]
6736   ""
6737   "mulhw %0,%1,%2"
6738   [(set_attr "type" "imul")])
6739
6740 (define_insn "umulsi3_highpart"
6741   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6742         (truncate:SI
6743          (lshiftrt:DI (mult:DI (zero_extend:DI
6744                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6745                                (zero_extend:DI
6746                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6747                       (const_int 32))))]
6748   ""
6749   "mulhwu %0,%1,%2"
6750   [(set_attr "type" "imul")])
6751
6752 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6753 ;; just handle shifts by constants.
6754 (define_insn "ashrdi3_no_power"
6755   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6756         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6757                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6758   "!TARGET_POWERPC64"
6759   "*
6760 {
6761   switch (which_alternative)
6762     {
6763     default:
6764       gcc_unreachable ();
6765     case 0:
6766       if (WORDS_BIG_ENDIAN)
6767         return \"srawi %0,%1,31\;srawi %L0,%1,%h2\";
6768       else
6769         return \"srawi %L0,%L1,31\;srawi %0,%L1,%h2\";
6770     case 1:
6771       if (WORDS_BIG_ENDIAN)
6772         return \"srwi %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;srawi %0,%1,%h2\";
6773       else
6774         return \"srwi %0,%1,%h2\;insrwi %0,%L1,%h2,0\;srawi %L0,%L1,%h2\";
6775     }
6776 }"
6777   [(set_attr "type" "two,three")
6778    (set_attr "length" "8,12")])
6779
6780 (define_insn "*ashrdisi3_noppc64be"
6781   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6782         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6783                                 (const_int 32)) 4))]
6784   "TARGET_32BIT && !TARGET_POWERPC64 && WORDS_BIG_ENDIAN"
6785   "*
6786 {
6787   if (REGNO (operands[0]) == REGNO (operands[1]))
6788     return \"\";
6789   else
6790     return \"mr %0,%1\";
6791 }"
6792    [(set_attr "length" "4")])
6793
6794 \f
6795 ;; PowerPC64 DImode operations.
6796
6797 (define_insn "muldi3"
6798   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6799         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6800                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6801   "TARGET_POWERPC64"
6802   "@
6803    mulld %0,%1,%2
6804    mulli %0,%1,%2"
6805    [(set (attr "type")
6806       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6807                 (const_string "imul3")
6808              (match_operand:SI 2 "short_cint_operand" "")
6809                 (const_string "imul2")]
6810         (const_string "lmul")))])
6811
6812 (define_insn "*muldi3_internal1"
6813   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6814         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6815                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6816                     (const_int 0)))
6817    (clobber (match_scratch:DI 3 "=r,r"))]
6818   "TARGET_POWERPC64"
6819   "@
6820    mulld. %3,%1,%2
6821    #"
6822   [(set_attr "type" "lmul_compare")
6823    (set_attr "length" "4,8")])
6824
6825 (define_split
6826   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6827         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6828                              (match_operand:DI 2 "gpc_reg_operand" ""))
6829                     (const_int 0)))
6830    (clobber (match_scratch:DI 3 ""))]
6831   "TARGET_POWERPC64 && reload_completed"
6832   [(set (match_dup 3)
6833         (mult:DI (match_dup 1) (match_dup 2)))
6834    (set (match_dup 0)
6835         (compare:CC (match_dup 3)
6836                     (const_int 0)))]
6837   "")
6838
6839 (define_insn "*muldi3_internal2"
6840   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6841         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6842                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6843                     (const_int 0)))
6844    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6845         (mult:DI (match_dup 1) (match_dup 2)))]
6846   "TARGET_POWERPC64"
6847   "@
6848    mulld. %0,%1,%2
6849    #"
6850   [(set_attr "type" "lmul_compare")
6851    (set_attr "length" "4,8")])
6852
6853 (define_split
6854   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6855         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6856                              (match_operand:DI 2 "gpc_reg_operand" ""))
6857                     (const_int 0)))
6858    (set (match_operand:DI 0 "gpc_reg_operand" "")
6859         (mult:DI (match_dup 1) (match_dup 2)))]
6860   "TARGET_POWERPC64 && reload_completed"
6861   [(set (match_dup 0)
6862         (mult:DI (match_dup 1) (match_dup 2)))
6863    (set (match_dup 3)
6864         (compare:CC (match_dup 0)
6865                     (const_int 0)))]
6866   "")
6867
6868 (define_insn "smuldi3_highpart"
6869   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6870         (truncate:DI
6871          (lshiftrt:TI (mult:TI (sign_extend:TI
6872                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6873                                (sign_extend:TI
6874                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6875                       (const_int 64))))]
6876   "TARGET_POWERPC64"
6877   "mulhd %0,%1,%2"
6878   [(set_attr "type" "lmul")])
6879
6880 (define_insn "umuldi3_highpart"
6881   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6882         (truncate:DI
6883          (lshiftrt:TI (mult:TI (zero_extend:TI
6884                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6885                                (zero_extend:TI
6886                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6887                       (const_int 64))))]
6888   "TARGET_POWERPC64"
6889   "mulhdu %0,%1,%2"
6890   [(set_attr "type" "lmul")])
6891
6892 (define_expand "mulditi3"
6893   [(set (match_operand:TI 0 "gpc_reg_operand")
6894         (mult:TI (sign_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6895                  (sign_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6896   "TARGET_POWERPC64"
6897 {
6898   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6899   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6900   emit_insn (gen_smuldi3_highpart (h, operands[1], operands[2]));
6901   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6902   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6903   DONE;
6904 })
6905
6906 (define_expand "umulditi3"
6907   [(set (match_operand:TI 0 "gpc_reg_operand")
6908         (mult:TI (zero_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6909                  (zero_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6910   "TARGET_POWERPC64"
6911 {
6912   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6913   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6914   emit_insn (gen_umuldi3_highpart (h, operands[1], operands[2]));
6915   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6916   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6917   DONE;
6918 })
6919
6920 (define_insn "rotldi3"
6921   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6922         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6923                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
6924   "TARGET_POWERPC64"
6925   "@
6926    rldcl %0,%1,%2,0
6927    rldicl %0,%1,%H2,0"
6928   [(set_attr "type" "var_shift_rotate,integer")])
6929
6930 (define_insn "*rotldi3_internal2"
6931   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6932         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6933                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6934                     (const_int 0)))
6935    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6936   "TARGET_64BIT"
6937   "@
6938    rldcl. %3,%1,%2,0
6939    rldicl. %3,%1,%H2,0
6940    #
6941    #"
6942   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6943    (set_attr "length" "4,4,8,8")])
6944
6945 (define_split
6946   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6947         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6948                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6949                     (const_int 0)))
6950    (clobber (match_scratch:DI 3 ""))]
6951   "TARGET_POWERPC64 && reload_completed"
6952   [(set (match_dup 3)
6953         (rotate:DI (match_dup 1) (match_dup 2)))
6954    (set (match_dup 0)
6955         (compare:CC (match_dup 3)
6956                     (const_int 0)))]
6957   "")
6958
6959 (define_insn "*rotldi3_internal3"
6960   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6961         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6962                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6963                     (const_int 0)))
6964    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6965         (rotate:DI (match_dup 1) (match_dup 2)))]
6966   "TARGET_64BIT"
6967   "@
6968    rldcl. %0,%1,%2,0
6969    rldicl. %0,%1,%H2,0
6970    #
6971    #"
6972   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6973    (set_attr "length" "4,4,8,8")])
6974
6975 (define_split
6976   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6977         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6978                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6979                     (const_int 0)))
6980    (set (match_operand:DI 0 "gpc_reg_operand" "")
6981         (rotate:DI (match_dup 1) (match_dup 2)))]
6982   "TARGET_POWERPC64 && reload_completed"
6983   [(set (match_dup 0)
6984         (rotate:DI (match_dup 1) (match_dup 2)))
6985    (set (match_dup 3)
6986         (compare:CC (match_dup 0)
6987                     (const_int 0)))]
6988   "")
6989
6990 (define_insn "*rotldi3_internal4"
6991   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6992         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6993                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
6994                 (match_operand:DI 3 "mask64_operand" "n,n")))]
6995   "TARGET_POWERPC64"
6996   "@
6997    rldc%B3 %0,%1,%2,%S3
6998    rldic%B3 %0,%1,%H2,%S3"
6999   [(set_attr "type" "var_shift_rotate,integer")])
7000
7001 (define_insn "*rotldi3_internal5"
7002   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7003         (compare:CC (and:DI
7004                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7005                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7006                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7007                     (const_int 0)))
7008    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
7009   "TARGET_64BIT"
7010   "@
7011    rldc%B3. %4,%1,%2,%S3
7012    rldic%B3. %4,%1,%H2,%S3
7013    #
7014    #"
7015   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7016    (set_attr "length" "4,4,8,8")])
7017
7018 (define_split
7019   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7020         (compare:CC (and:DI
7021                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7022                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7023                      (match_operand:DI 3 "mask64_operand" ""))
7024                     (const_int 0)))
7025    (clobber (match_scratch:DI 4 ""))]
7026   "TARGET_POWERPC64 && reload_completed"
7027   [(set (match_dup 4)
7028         (and:DI (rotate:DI (match_dup 1)
7029                                 (match_dup 2))
7030                      (match_dup 3)))
7031    (set (match_dup 0)
7032         (compare:CC (match_dup 4)
7033                     (const_int 0)))]
7034   "")
7035
7036 (define_insn "*rotldi3_internal6"
7037   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
7038         (compare:CC (and:DI
7039                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7040                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7041                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7042                     (const_int 0)))
7043    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7044         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7045   "TARGET_64BIT"
7046   "@
7047    rldc%B3. %0,%1,%2,%S3
7048    rldic%B3. %0,%1,%H2,%S3
7049    #
7050    #"
7051   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7052    (set_attr "length" "4,4,8,8")])
7053
7054 (define_split
7055   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7056         (compare:CC (and:DI
7057                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7058                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7059                      (match_operand:DI 3 "mask64_operand" ""))
7060                     (const_int 0)))
7061    (set (match_operand:DI 0 "gpc_reg_operand" "")
7062         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7063   "TARGET_POWERPC64 && reload_completed"
7064   [(set (match_dup 0)
7065         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
7066    (set (match_dup 4)
7067         (compare:CC (match_dup 0)
7068                     (const_int 0)))]
7069   "")
7070
7071 (define_insn "*rotldi3_internal7le"
7072   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7073         (zero_extend:DI
7074          (subreg:QI
7075           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7076                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7077   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7078   "@
7079    rldcl %0,%1,%2,56
7080    rldicl %0,%1,%H2,56"
7081   [(set_attr "type" "var_shift_rotate,integer")])
7082
7083 (define_insn "*rotldi3_internal7be"
7084   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7085         (zero_extend:DI
7086          (subreg:QI
7087           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7088                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 7)))]
7089   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7090   "@
7091    rldcl %0,%1,%2,56
7092    rldicl %0,%1,%H2,56"
7093   [(set_attr "type" "var_shift_rotate,integer")])
7094
7095 (define_insn "*rotldi3_internal8le"
7096   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7097         (compare:CC (zero_extend:DI
7098                      (subreg:QI
7099                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7100                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7101                     (const_int 0)))
7102    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7103   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7104   "@
7105    rldcl. %3,%1,%2,56
7106    rldicl. %3,%1,%H2,56
7107    #
7108    #"
7109   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7110    (set_attr "length" "4,4,8,8")])
7111
7112 (define_insn "*rotldi3_internal8be"
7113   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7114         (compare:CC (zero_extend:DI
7115                      (subreg:QI
7116                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7117                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 7))
7118                     (const_int 0)))
7119    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7120   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7121   "@
7122    rldcl. %3,%1,%2,56
7123    rldicl. %3,%1,%H2,56
7124    #
7125    #"
7126   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7127    (set_attr "length" "4,4,8,8")])
7128
7129 (define_split
7130   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7131         (compare:CC (zero_extend:DI
7132                      (subreg:QI
7133                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7134                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7135                     (const_int 0)))
7136    (clobber (match_scratch:DI 3 ""))]
7137   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7138   [(set (match_dup 3)
7139         (zero_extend:DI (subreg:QI
7140                       (rotate:DI (match_dup 1)
7141                                  (match_dup 2)) 0)))
7142    (set (match_dup 0)
7143         (compare:CC (match_dup 3)
7144                     (const_int 0)))]
7145   "")
7146
7147 (define_split
7148   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7149         (compare:CC (zero_extend:DI
7150                      (subreg:QI
7151                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7152                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 7))
7153                     (const_int 0)))
7154    (clobber (match_scratch:DI 3 ""))]
7155   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7156   [(set (match_dup 3)
7157         (zero_extend:DI (subreg:QI
7158                       (rotate:DI (match_dup 1)
7159                                  (match_dup 2)) 7)))
7160    (set (match_dup 0)
7161         (compare:CC (match_dup 3)
7162                     (const_int 0)))]
7163   "")
7164
7165 (define_insn "*rotldi3_internal9le"
7166   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7167         (compare:CC (zero_extend:DI
7168                      (subreg:QI
7169                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7170                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7171                     (const_int 0)))
7172    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7173         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7174   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7175   "@
7176    rldcl. %0,%1,%2,56
7177    rldicl. %0,%1,%H2,56
7178    #
7179    #"
7180   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7181    (set_attr "length" "4,4,8,8")])
7182
7183 (define_insn "*rotldi3_internal9be"
7184   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7185         (compare:CC (zero_extend:DI
7186                      (subreg:QI
7187                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7188                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 7))
7189                     (const_int 0)))
7190    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7191         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))]
7192   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7193   "@
7194    rldcl. %0,%1,%2,56
7195    rldicl. %0,%1,%H2,56
7196    #
7197    #"
7198   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7199    (set_attr "length" "4,4,8,8")])
7200
7201 (define_split
7202   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7203         (compare:CC (zero_extend:DI
7204                      (subreg:QI
7205                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7206                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7207                     (const_int 0)))
7208    (set (match_operand:DI 0 "gpc_reg_operand" "")
7209         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7210   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7211   [(set (match_dup 0)
7212         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7213    (set (match_dup 3)
7214         (compare:CC (match_dup 0)
7215                     (const_int 0)))]
7216   "")
7217
7218 (define_split
7219   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7220         (compare:CC (zero_extend:DI
7221                      (subreg:QI
7222                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7223                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 7))
7224                     (const_int 0)))
7225    (set (match_operand:DI 0 "gpc_reg_operand" "")
7226         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))]
7227   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7228   [(set (match_dup 0)
7229         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))
7230    (set (match_dup 3)
7231         (compare:CC (match_dup 0)
7232                     (const_int 0)))]
7233   "")
7234
7235 (define_insn "*rotldi3_internal10le"
7236   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7237         (zero_extend:DI
7238          (subreg:HI
7239           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7240                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7241   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7242   "@
7243    rldcl %0,%1,%2,48
7244    rldicl %0,%1,%H2,48"
7245   [(set_attr "type" "var_shift_rotate,integer")])
7246
7247 (define_insn "*rotldi3_internal10be"
7248   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7249         (zero_extend:DI
7250          (subreg:HI
7251           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7252                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 6)))]
7253   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7254   "@
7255    rldcl %0,%1,%2,48
7256    rldicl %0,%1,%H2,48"
7257   [(set_attr "type" "var_shift_rotate,integer")])
7258
7259 (define_insn "*rotldi3_internal11le"
7260   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7261         (compare:CC (zero_extend:DI
7262                      (subreg:HI
7263                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7264                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7265                     (const_int 0)))
7266    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7267   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7268   "@
7269    rldcl. %3,%1,%2,48
7270    rldicl. %3,%1,%H2,48
7271    #
7272    #"
7273   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7274    (set_attr "length" "4,4,8,8")])
7275
7276 (define_insn "*rotldi3_internal11be"
7277   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7278         (compare:CC (zero_extend:DI
7279                      (subreg:HI
7280                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7281                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 6))
7282                     (const_int 0)))
7283    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7284   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7285   "@
7286    rldcl. %3,%1,%2,48
7287    rldicl. %3,%1,%H2,48
7288    #
7289    #"
7290   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7291    (set_attr "length" "4,4,8,8")])
7292
7293 (define_split
7294   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7295         (compare:CC (zero_extend:DI
7296                      (subreg:HI
7297                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7298                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7299                     (const_int 0)))
7300    (clobber (match_scratch:DI 3 ""))]
7301   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7302   [(set (match_dup 3)
7303         (zero_extend:DI (subreg:HI
7304                       (rotate:DI (match_dup 1)
7305                                  (match_dup 2)) 0)))
7306    (set (match_dup 0)
7307         (compare:CC (match_dup 3)
7308                     (const_int 0)))]
7309   "")
7310
7311 (define_split
7312   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7313         (compare:CC (zero_extend:DI
7314                      (subreg:HI
7315                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7316                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 6))
7317                     (const_int 0)))
7318    (clobber (match_scratch:DI 3 ""))]
7319   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7320   [(set (match_dup 3)
7321         (zero_extend:DI (subreg:HI
7322                       (rotate:DI (match_dup 1)
7323                                  (match_dup 2)) 6)))
7324    (set (match_dup 0)
7325         (compare:CC (match_dup 3)
7326                     (const_int 0)))]
7327   "")
7328
7329 (define_insn "*rotldi3_internal12le"
7330   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7331         (compare:CC (zero_extend:DI
7332                      (subreg:HI
7333                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7334                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7335                     (const_int 0)))
7336    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7337         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7338   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7339   "@
7340    rldcl. %0,%1,%2,48
7341    rldicl. %0,%1,%H2,48
7342    #
7343    #"
7344   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7345    (set_attr "length" "4,4,8,8")])
7346
7347 (define_insn "*rotldi3_internal12be"
7348   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7349         (compare:CC (zero_extend:DI
7350                      (subreg:HI
7351                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7352                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 6))
7353                     (const_int 0)))
7354    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7355         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))]
7356   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7357   "@
7358    rldcl. %0,%1,%2,48
7359    rldicl. %0,%1,%H2,48
7360    #
7361    #"
7362   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7363    (set_attr "length" "4,4,8,8")])
7364
7365 (define_split
7366   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7367         (compare:CC (zero_extend:DI
7368                      (subreg:HI
7369                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7370                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7371                     (const_int 0)))
7372    (set (match_operand:DI 0 "gpc_reg_operand" "")
7373         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7374   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7375   [(set (match_dup 0)
7376         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7377    (set (match_dup 3)
7378         (compare:CC (match_dup 0)
7379                     (const_int 0)))]
7380   "")
7381
7382 (define_split
7383   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7384         (compare:CC (zero_extend:DI
7385                      (subreg:HI
7386                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7387                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 6))
7388                     (const_int 0)))
7389    (set (match_operand:DI 0 "gpc_reg_operand" "")
7390         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))]
7391   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7392   [(set (match_dup 0)
7393         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))
7394    (set (match_dup 3)
7395         (compare:CC (match_dup 0)
7396                     (const_int 0)))]
7397   "")
7398
7399 (define_insn "*rotldi3_internal13le"
7400   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7401         (zero_extend:DI
7402          (subreg:SI
7403           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7404                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7405   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7406   "@
7407    rldcl %0,%1,%2,32
7408    rldicl %0,%1,%H2,32"
7409   [(set_attr "type" "var_shift_rotate,integer")])
7410
7411 (define_insn "*rotldi3_internal13be"
7412   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7413         (zero_extend:DI
7414          (subreg:SI
7415           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7416                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 4)))]
7417   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7418   "@
7419    rldcl %0,%1,%2,32
7420    rldicl %0,%1,%H2,32"
7421   [(set_attr "type" "var_shift_rotate,integer")])
7422
7423 (define_insn "*rotldi3_internal14le"
7424   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7425         (compare:CC (zero_extend:DI
7426                      (subreg:SI
7427                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7428                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7429                     (const_int 0)))
7430    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7431   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7432   "@
7433    rldcl. %3,%1,%2,32
7434    rldicl. %3,%1,%H2,32
7435    #
7436    #"
7437   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7438    (set_attr "length" "4,4,8,8")])
7439
7440 (define_insn "*rotldi3_internal14be"
7441   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7442         (compare:CC (zero_extend:DI
7443                      (subreg:SI
7444                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7445                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 4))
7446                     (const_int 0)))
7447    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7448   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7449   "@
7450    rldcl. %3,%1,%2,32
7451    rldicl. %3,%1,%H2,32
7452    #
7453    #"
7454   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7455    (set_attr "length" "4,4,8,8")])
7456
7457 (define_split
7458   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7459         (compare:CC (zero_extend:DI
7460                      (subreg:SI
7461                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7462                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7463                     (const_int 0)))
7464    (clobber (match_scratch:DI 3 ""))]
7465   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7466   [(set (match_dup 3)
7467         (zero_extend:DI (subreg:SI
7468                       (rotate:DI (match_dup 1)
7469                                  (match_dup 2)) 0)))
7470    (set (match_dup 0)
7471         (compare:CC (match_dup 3)
7472                     (const_int 0)))]
7473   "")
7474
7475 (define_split
7476   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7477         (compare:CC (zero_extend:DI
7478                      (subreg:SI
7479                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7480                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 4))
7481                     (const_int 0)))
7482    (clobber (match_scratch:DI 3 ""))]
7483   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7484   [(set (match_dup 3)
7485         (zero_extend:DI (subreg:SI
7486                       (rotate:DI (match_dup 1)
7487                                  (match_dup 2)) 4)))
7488    (set (match_dup 0)
7489         (compare:CC (match_dup 3)
7490                     (const_int 0)))]
7491   "")
7492
7493 (define_insn "*rotldi3_internal15le"
7494   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7495         (compare:CC (zero_extend:DI
7496                      (subreg:SI
7497                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7498                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7499                     (const_int 0)))
7500    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7501         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7502   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7503   "@
7504    rldcl. %0,%1,%2,32
7505    rldicl. %0,%1,%H2,32
7506    #
7507    #"
7508   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7509    (set_attr "length" "4,4,8,8")])
7510
7511 (define_insn "*rotldi3_internal15be"
7512   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7513         (compare:CC (zero_extend:DI
7514                      (subreg:SI
7515                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7516                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 4))
7517                     (const_int 0)))
7518    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7519         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))]
7520   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7521   "@
7522    rldcl. %0,%1,%2,32
7523    rldicl. %0,%1,%H2,32
7524    #
7525    #"
7526   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7527    (set_attr "length" "4,4,8,8")])
7528
7529 (define_split
7530   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7531         (compare:CC (zero_extend:DI
7532                      (subreg:SI
7533                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7534                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7535                     (const_int 0)))
7536    (set (match_operand:DI 0 "gpc_reg_operand" "")
7537         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7538   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7539   [(set (match_dup 0)
7540         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7541    (set (match_dup 3)
7542         (compare:CC (match_dup 0)
7543                     (const_int 0)))]
7544   "")
7545
7546 (define_split
7547   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7548         (compare:CC (zero_extend:DI
7549                      (subreg:SI
7550                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7551                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 4))
7552                     (const_int 0)))
7553    (set (match_operand:DI 0 "gpc_reg_operand" "")
7554         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))]
7555   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7556   [(set (match_dup 0)
7557         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))
7558    (set (match_dup 3)
7559         (compare:CC (match_dup 0)
7560                     (const_int 0)))]
7561   "")
7562
7563 (define_expand "ashldi3"
7564   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7565         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7566                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
7567   "TARGET_POWERPC64"
7568   "")
7569
7570 (define_insn "*ashldi3_internal1"
7571   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7572         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7573                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7574   "TARGET_POWERPC64"
7575   "@
7576    sld %0,%1,%2
7577    sldi %0,%1,%H2"
7578   [(set_attr "type" "var_shift_rotate,shift")])
7579
7580 (define_insn "*ashldi3_internal2"
7581   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7582         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7583                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7584                     (const_int 0)))
7585    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7586   "TARGET_64BIT"
7587   "@
7588    sld. %3,%1,%2
7589    sldi. %3,%1,%H2
7590    #
7591    #"
7592   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7593    (set_attr "length" "4,4,8,8")])
7594
7595 (define_split
7596   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7597         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7598                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7599                     (const_int 0)))
7600    (clobber (match_scratch:DI 3 ""))]
7601   "TARGET_POWERPC64 && reload_completed"
7602   [(set (match_dup 3)
7603         (ashift:DI (match_dup 1) (match_dup 2)))
7604    (set (match_dup 0)
7605         (compare:CC (match_dup 3)
7606                     (const_int 0)))]
7607   "")
7608
7609 (define_insn "*ashldi3_internal3"
7610   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7611         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7612                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7613                     (const_int 0)))
7614    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7615         (ashift:DI (match_dup 1) (match_dup 2)))]
7616   "TARGET_64BIT"
7617   "@
7618    sld. %0,%1,%2
7619    sldi. %0,%1,%H2
7620    #
7621    #"
7622   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7623    (set_attr "length" "4,4,8,8")])
7624
7625 (define_split
7626   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7627         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7628                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7629                     (const_int 0)))
7630    (set (match_operand:DI 0 "gpc_reg_operand" "")
7631         (ashift:DI (match_dup 1) (match_dup 2)))]
7632   "TARGET_POWERPC64 && reload_completed"
7633   [(set (match_dup 0)
7634         (ashift:DI (match_dup 1) (match_dup 2)))
7635    (set (match_dup 3)
7636         (compare:CC (match_dup 0)
7637                     (const_int 0)))]
7638   "")
7639
7640 (define_insn "*ashldi3_internal4"
7641   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7642         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7643                            (match_operand:SI 2 "const_int_operand" "i"))
7644                 (match_operand:DI 3 "const_int_operand" "n")))]
7645   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7646   "rldic %0,%1,%H2,%W3")
7647
7648 (define_insn "ashldi3_internal5"
7649   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7650         (compare:CC
7651          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7652                             (match_operand:SI 2 "const_int_operand" "i,i"))
7653                  (match_operand:DI 3 "const_int_operand" "n,n"))
7654          (const_int 0)))
7655    (clobber (match_scratch:DI 4 "=r,r"))]
7656   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7657   "@
7658    rldic. %4,%1,%H2,%W3
7659    #"
7660   [(set_attr "type" "compare")
7661    (set_attr "length" "4,8")])
7662
7663 (define_split
7664   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7665         (compare:CC
7666          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7667                             (match_operand:SI 2 "const_int_operand" ""))
7668                  (match_operand:DI 3 "const_int_operand" ""))
7669          (const_int 0)))
7670    (clobber (match_scratch:DI 4 ""))]
7671   "TARGET_POWERPC64 && reload_completed
7672    && includes_rldic_lshift_p (operands[2], operands[3])"
7673   [(set (match_dup 4)
7674         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7675                 (match_dup 3)))
7676    (set (match_dup 0)
7677         (compare:CC (match_dup 4)
7678                     (const_int 0)))]
7679   "")
7680
7681 (define_insn "*ashldi3_internal6"
7682   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7683         (compare:CC
7684          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7685                             (match_operand:SI 2 "const_int_operand" "i,i"))
7686                     (match_operand:DI 3 "const_int_operand" "n,n"))
7687          (const_int 0)))
7688    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7689         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7690   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7691   "@
7692    rldic. %0,%1,%H2,%W3
7693    #"
7694   [(set_attr "type" "compare")
7695    (set_attr "length" "4,8")])
7696
7697 (define_split
7698   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7699         (compare:CC
7700          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7701                             (match_operand:SI 2 "const_int_operand" ""))
7702                  (match_operand:DI 3 "const_int_operand" ""))
7703          (const_int 0)))
7704    (set (match_operand:DI 0 "gpc_reg_operand" "")
7705         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7706   "TARGET_POWERPC64 && reload_completed
7707    && includes_rldic_lshift_p (operands[2], operands[3])"
7708   [(set (match_dup 0)
7709         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7710                 (match_dup 3)))
7711    (set (match_dup 4)
7712         (compare:CC (match_dup 0)
7713                     (const_int 0)))]
7714   "")
7715
7716 (define_insn "*ashldi3_internal7"
7717   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7718         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7719                            (match_operand:SI 2 "const_int_operand" "i"))
7720                 (match_operand:DI 3 "mask64_operand" "n")))]
7721   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7722   "rldicr %0,%1,%H2,%S3")
7723
7724 (define_insn "ashldi3_internal8"
7725   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7726         (compare:CC
7727          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7728                             (match_operand:SI 2 "const_int_operand" "i,i"))
7729                  (match_operand:DI 3 "mask64_operand" "n,n"))
7730          (const_int 0)))
7731    (clobber (match_scratch:DI 4 "=r,r"))]
7732   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7733   "@
7734    rldicr. %4,%1,%H2,%S3
7735    #"
7736   [(set_attr "type" "compare")
7737    (set_attr "length" "4,8")])
7738
7739 (define_split
7740   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7741         (compare:CC
7742          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7743                             (match_operand:SI 2 "const_int_operand" ""))
7744                  (match_operand:DI 3 "mask64_operand" ""))
7745          (const_int 0)))
7746    (clobber (match_scratch:DI 4 ""))]
7747   "TARGET_POWERPC64 && reload_completed
7748    && includes_rldicr_lshift_p (operands[2], operands[3])"
7749   [(set (match_dup 4)
7750         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7751                 (match_dup 3)))
7752    (set (match_dup 0)
7753         (compare:CC (match_dup 4)
7754                     (const_int 0)))]
7755   "")
7756
7757 (define_insn "*ashldi3_internal9"
7758   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7759         (compare:CC
7760          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7761                             (match_operand:SI 2 "const_int_operand" "i,i"))
7762                     (match_operand:DI 3 "mask64_operand" "n,n"))
7763          (const_int 0)))
7764    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7765         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7766   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7767   "@
7768    rldicr. %0,%1,%H2,%S3
7769    #"
7770   [(set_attr "type" "compare")
7771    (set_attr "length" "4,8")])
7772
7773 (define_split
7774   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7775         (compare:CC
7776          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7777                             (match_operand:SI 2 "const_int_operand" ""))
7778                  (match_operand:DI 3 "mask64_operand" ""))
7779          (const_int 0)))
7780    (set (match_operand:DI 0 "gpc_reg_operand" "")
7781         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7782   "TARGET_POWERPC64 && reload_completed
7783    && includes_rldicr_lshift_p (operands[2], operands[3])"
7784   [(set (match_dup 0)
7785         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7786                 (match_dup 3)))
7787    (set (match_dup 4)
7788         (compare:CC (match_dup 0)
7789                     (const_int 0)))]
7790   "")
7791
7792 (define_expand "lshrdi3"
7793   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7794         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7795                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7796   "TARGET_POWERPC64"
7797   "")
7798
7799 (define_insn "*lshrdi3_internal1"
7800   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7801         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7802                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7803   "TARGET_POWERPC64"
7804   "@
7805    srd %0,%1,%2
7806    srdi %0,%1,%H2"
7807   [(set_attr "type" "var_shift_rotate,shift")])
7808
7809 (define_insn "*lshrdi3_internal2"
7810   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7811         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7812                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7813                     (const_int 0)))
7814    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7815   "TARGET_64BIT "
7816   "@
7817    srd. %3,%1,%2
7818    srdi. %3,%1,%H2
7819    #
7820    #"
7821   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7822    (set_attr "length" "4,4,8,8")])
7823
7824 (define_split
7825   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7826         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7827                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7828                     (const_int 0)))
7829    (clobber (match_scratch:DI 3 ""))]
7830   "TARGET_POWERPC64 && reload_completed"
7831   [(set (match_dup 3)
7832         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7833    (set (match_dup 0)
7834         (compare:CC (match_dup 3)
7835                     (const_int 0)))]
7836   "")
7837
7838 (define_insn "*lshrdi3_internal3"
7839   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7840         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7841                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7842                     (const_int 0)))
7843    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7844         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7845   "TARGET_64BIT"
7846   "@
7847    srd. %0,%1,%2
7848    srdi. %0,%1,%H2
7849    #
7850    #"
7851   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7852    (set_attr "length" "4,4,8,8")])
7853
7854 (define_split
7855   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7856         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7857                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7858                     (const_int 0)))
7859    (set (match_operand:DI 0 "gpc_reg_operand" "")
7860         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7861   "TARGET_POWERPC64 && reload_completed"
7862   [(set (match_dup 0)
7863         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7864    (set (match_dup 3)
7865         (compare:CC (match_dup 0)
7866                     (const_int 0)))]
7867   "")
7868
7869 (define_expand "ashrdi3"
7870   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7871         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7872                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7873   ""
7874   "
7875 {
7876   if (TARGET_POWERPC64)
7877     ;
7878   else if (GET_CODE (operands[2]) == CONST_INT)
7879     {
7880       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7881       DONE;
7882     }
7883   else
7884     FAIL;
7885 }")
7886
7887 (define_insn "*ashrdi3_internal1"
7888   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7889         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7890                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7891   "TARGET_POWERPC64"
7892   "@
7893    srad %0,%1,%2
7894    sradi %0,%1,%H2"
7895   [(set_attr "type" "var_shift_rotate,shift")])
7896
7897 (define_insn "*ashrdi3_internal2"
7898   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7899         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7900                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7901                     (const_int 0)))
7902    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7903   "TARGET_64BIT"
7904   "@
7905    srad. %3,%1,%2
7906    sradi. %3,%1,%H2
7907    #
7908    #"
7909   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7910    (set_attr "length" "4,4,8,8")])
7911
7912 (define_split
7913   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7914         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7915                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7916                     (const_int 0)))
7917    (clobber (match_scratch:DI 3 ""))]
7918   "TARGET_POWERPC64 && reload_completed"
7919   [(set (match_dup 3)
7920         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7921    (set (match_dup 0)
7922         (compare:CC (match_dup 3)
7923                     (const_int 0)))]
7924   "")
7925
7926 (define_insn "*ashrdi3_internal3"
7927   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7928         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7929                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7930                     (const_int 0)))
7931    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7932         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7933   "TARGET_64BIT"
7934   "@
7935    srad. %0,%1,%2
7936    sradi. %0,%1,%H2
7937    #
7938    #"
7939   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7940    (set_attr "length" "4,4,8,8")])
7941
7942 (define_split
7943   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7944         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7945                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7946                     (const_int 0)))
7947    (set (match_operand:DI 0 "gpc_reg_operand" "")
7948         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7949   "TARGET_POWERPC64 && reload_completed"
7950   [(set (match_dup 0)
7951         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7952    (set (match_dup 3)
7953         (compare:CC (match_dup 0)
7954                     (const_int 0)))]
7955   "")
7956
7957 (define_expand "anddi3"
7958   [(parallel
7959     [(set (match_operand:DI 0 "gpc_reg_operand" "")
7960           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7961                   (match_operand:DI 2 "and64_2_operand" "")))
7962      (clobber (match_scratch:CC 3 ""))])]
7963   "TARGET_POWERPC64"
7964   "")
7965
7966 (define_insn "anddi3_mc"
7967   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7968         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7969                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7970    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7971   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
7972   "@
7973    and %0,%1,%2
7974    rldic%B2 %0,%1,0,%S2
7975    rlwinm %0,%1,0,%m2,%M2
7976    andi. %0,%1,%b2
7977    andis. %0,%1,%u2
7978    #"
7979   [(set_attr "type" "*,*,*,fast_compare,fast_compare,*")
7980    (set_attr "length" "4,4,4,4,4,8")])
7981
7982 (define_insn "anddi3_nomc"
7983   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7984         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
7985                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
7986    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
7987   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
7988   "@
7989    and %0,%1,%2
7990    rldic%B2 %0,%1,0,%S2
7991    rlwinm %0,%1,0,%m2,%M2
7992    #"
7993   [(set_attr "length" "4,4,4,8")])
7994
7995 (define_split
7996   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7997         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7998                 (match_operand:DI 2 "mask64_2_operand" "")))
7999    (clobber (match_scratch:CC 3 ""))]
8000   "TARGET_POWERPC64
8001     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8002     && !mask_operand (operands[2], DImode)
8003     && !mask64_operand (operands[2], DImode)"
8004   [(set (match_dup 0)
8005         (and:DI (rotate:DI (match_dup 1)
8006                            (match_dup 4))
8007                 (match_dup 5)))
8008    (set (match_dup 0)
8009         (and:DI (rotate:DI (match_dup 0)
8010                            (match_dup 6))
8011                 (match_dup 7)))]
8012 {
8013   build_mask64_2_operands (operands[2], &operands[4]);
8014 })
8015
8016 (define_insn "*anddi3_internal2_mc"
8017   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8018         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8019                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8020                     (const_int 0)))
8021    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
8022    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8023   "TARGET_64BIT && rs6000_gen_cell_microcode"
8024   "@
8025    and. %3,%1,%2
8026    rldic%B2. %3,%1,0,%S2
8027    rlwinm. %3,%1,0,%m2,%M2
8028    andi. %3,%1,%b2
8029    andis. %3,%1,%u2
8030    #
8031    #
8032    #
8033    #
8034    #
8035    #
8036    #"
8037   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8038                      fast_compare,compare,compare,compare,compare,compare,\
8039                      compare,compare")
8040    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8041
8042 (define_split
8043   [(set (match_operand:CC 0 "cc_reg_operand" "")
8044         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8045                             (match_operand:DI 2 "mask64_2_operand" ""))
8046                     (const_int 0)))
8047    (clobber (match_scratch:DI 3 ""))
8048    (clobber (match_scratch:CC 4 ""))]
8049   "TARGET_64BIT && reload_completed
8050     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8051     && !mask_operand (operands[2], DImode)
8052     && !mask64_operand (operands[2], DImode)"
8053   [(set (match_dup 3)
8054         (and:DI (rotate:DI (match_dup 1)
8055                            (match_dup 5))
8056                 (match_dup 6)))
8057    (parallel [(set (match_dup 0)
8058                    (compare:CC (and:DI (rotate:DI (match_dup 3)
8059                                                   (match_dup 7))
8060                                        (match_dup 8))
8061                                (const_int 0)))
8062               (clobber (match_dup 3))])]
8063   "
8064 {
8065   build_mask64_2_operands (operands[2], &operands[5]);
8066 }")
8067
8068 (define_insn "*anddi3_internal3_mc"
8069   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8070         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8071                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8072                     (const_int 0)))
8073    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
8074         (and:DI (match_dup 1) (match_dup 2)))
8075    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8076   "TARGET_64BIT && rs6000_gen_cell_microcode"
8077   "@
8078    and. %0,%1,%2
8079    rldic%B2. %0,%1,0,%S2
8080    rlwinm. %0,%1,0,%m2,%M2
8081    andi. %0,%1,%b2
8082    andis. %0,%1,%u2
8083    #
8084    #
8085    #
8086    #
8087    #
8088    #
8089    #"
8090   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
8091                      fast_compare,compare,compare,compare,compare,compare,\
8092                      compare,compare")
8093    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8094
8095 (define_split
8096   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8097         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8098                             (match_operand:DI 2 "and64_2_operand" ""))
8099                     (const_int 0)))
8100    (set (match_operand:DI 0 "gpc_reg_operand" "")
8101         (and:DI (match_dup 1) (match_dup 2)))
8102    (clobber (match_scratch:CC 4 ""))]
8103   "TARGET_64BIT && reload_completed"
8104   [(parallel [(set (match_dup 0)
8105                     (and:DI (match_dup 1) (match_dup 2)))
8106                (clobber (match_dup 4))])
8107    (set (match_dup 3)
8108         (compare:CC (match_dup 0)
8109                     (const_int 0)))]
8110   "")
8111
8112 (define_split
8113   [(set (match_operand:CC 3 "cc_reg_operand" "")
8114         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8115                             (match_operand:DI 2 "mask64_2_operand" ""))
8116                     (const_int 0)))
8117    (set (match_operand:DI 0 "gpc_reg_operand" "")
8118         (and:DI (match_dup 1) (match_dup 2)))
8119    (clobber (match_scratch:CC 4 ""))]
8120   "TARGET_64BIT && reload_completed
8121     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8122     && !mask_operand (operands[2], DImode)
8123     && !mask64_operand (operands[2], DImode)"
8124   [(set (match_dup 0)
8125         (and:DI (rotate:DI (match_dup 1)
8126                            (match_dup 5))
8127                 (match_dup 6)))
8128    (parallel [(set (match_dup 3)
8129                    (compare:CC (and:DI (rotate:DI (match_dup 0)
8130                                                   (match_dup 7))
8131                                        (match_dup 8))
8132                                (const_int 0)))
8133               (set (match_dup 0)
8134                    (and:DI (rotate:DI (match_dup 0)
8135                                       (match_dup 7))
8136                            (match_dup 8)))])]
8137   "
8138 {
8139   build_mask64_2_operands (operands[2], &operands[5]);
8140 }")
8141
8142 (define_expand "iordi3"
8143   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8144         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
8145                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8146   "TARGET_POWERPC64"
8147   "
8148 {
8149   if (non_logical_cint_operand (operands[2], DImode))
8150     {
8151       HOST_WIDE_INT value;
8152       rtx tmp = ((!can_create_pseudo_p ()
8153                   || rtx_equal_p (operands[0], operands[1]))
8154                  ? operands[0] : gen_reg_rtx (DImode));
8155
8156       value = INTVAL (operands[2]);
8157       emit_insn (gen_iordi3 (tmp, operands[1],
8158                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8159
8160       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8161       DONE;
8162     }
8163 }")
8164
8165 (define_expand "xordi3"
8166   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8167         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
8168                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
8169   "TARGET_POWERPC64"
8170   "
8171 {
8172   if (non_logical_cint_operand (operands[2], DImode))
8173     {
8174       HOST_WIDE_INT value;
8175       rtx tmp = ((!can_create_pseudo_p ()
8176                   || rtx_equal_p (operands[0], operands[1]))
8177                  ? operands[0] : gen_reg_rtx (DImode));
8178
8179       value = INTVAL (operands[2]);
8180       emit_insn (gen_xordi3 (tmp, operands[1],
8181                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8182
8183       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8184       DONE;
8185     }
8186 }")
8187
8188 (define_insn "*booldi3_internal1"
8189   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
8190         (match_operator:DI 3 "boolean_or_operator"
8191          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
8192           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
8193   "TARGET_POWERPC64"
8194   "@
8195    %q3 %0,%1,%2
8196    %q3i %0,%1,%b2
8197    %q3is %0,%1,%u2")
8198
8199 (define_insn "*booldi3_internal2"
8200   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8201         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8202          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8203           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8204          (const_int 0)))
8205    (clobber (match_scratch:DI 3 "=r,r"))]
8206   "TARGET_64BIT"
8207   "@
8208    %q4. %3,%1,%2
8209    #"
8210   [(set_attr "type" "fast_compare,compare")
8211    (set_attr "length" "4,8")])
8212
8213 (define_split
8214   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8215         (compare:CC (match_operator:DI 4 "boolean_operator"
8216          [(match_operand:DI 1 "gpc_reg_operand" "")
8217           (match_operand:DI 2 "gpc_reg_operand" "")])
8218          (const_int 0)))
8219    (clobber (match_scratch:DI 3 ""))]
8220   "TARGET_POWERPC64 && reload_completed"
8221   [(set (match_dup 3) (match_dup 4))
8222    (set (match_dup 0)
8223         (compare:CC (match_dup 3)
8224                     (const_int 0)))]
8225   "")
8226
8227 (define_insn "*booldi3_internal3"
8228   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8229         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8230          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8231           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8232          (const_int 0)))
8233    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8234         (match_dup 4))]
8235   "TARGET_64BIT"
8236   "@
8237    %q4. %0,%1,%2
8238    #"
8239   [(set_attr "type" "fast_compare,compare")
8240    (set_attr "length" "4,8")])
8241
8242 (define_split
8243   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8244         (compare:CC (match_operator:DI 4 "boolean_operator"
8245          [(match_operand:DI 1 "gpc_reg_operand" "")
8246           (match_operand:DI 2 "gpc_reg_operand" "")])
8247          (const_int 0)))
8248    (set (match_operand:DI 0 "gpc_reg_operand" "")
8249         (match_dup 4))]
8250   "TARGET_POWERPC64 && reload_completed"
8251   [(set (match_dup 0) (match_dup 4))
8252    (set (match_dup 3)
8253         (compare:CC (match_dup 0)
8254                     (const_int 0)))]
8255   "")
8256
8257 ;; Split a logical operation that we can't do in one insn into two insns,
8258 ;; each of which does one 16-bit part.  This is used by combine.
8259
8260 (define_split
8261   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8262         (match_operator:DI 3 "boolean_or_operator"
8263          [(match_operand:DI 1 "gpc_reg_operand" "")
8264           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
8265   "TARGET_POWERPC64"
8266   [(set (match_dup 0) (match_dup 4))
8267    (set (match_dup 0) (match_dup 5))]
8268 "
8269 {
8270   rtx i3,i4;
8271
8272   i3 = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
8273   i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
8274   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8275                                 operands[1], i3);
8276   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8277                                 operands[0], i4);
8278 }")
8279
8280 (define_insn "*boolcdi3_internal1"
8281   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8282         (match_operator:DI 3 "boolean_operator"
8283          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8284           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
8285   "TARGET_POWERPC64"
8286   "%q3 %0,%2,%1")
8287
8288 (define_insn "*boolcdi3_internal2"
8289   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8290         (compare:CC (match_operator:DI 4 "boolean_operator"
8291          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8292           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8293          (const_int 0)))
8294    (clobber (match_scratch:DI 3 "=r,r"))]
8295   "TARGET_64BIT"
8296   "@
8297    %q4. %3,%2,%1
8298    #"
8299   [(set_attr "type" "fast_compare,compare")
8300    (set_attr "length" "4,8")])
8301
8302 (define_split
8303   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8304         (compare:CC (match_operator:DI 4 "boolean_operator"
8305          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8306           (match_operand:DI 2 "gpc_reg_operand" "")])
8307          (const_int 0)))
8308    (clobber (match_scratch:DI 3 ""))]
8309   "TARGET_POWERPC64 && reload_completed"
8310   [(set (match_dup 3) (match_dup 4))
8311    (set (match_dup 0)
8312         (compare:CC (match_dup 3)
8313                     (const_int 0)))]
8314   "")
8315
8316 (define_insn "*boolcdi3_internal3"
8317   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8318         (compare:CC (match_operator:DI 4 "boolean_operator"
8319          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8320           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8321          (const_int 0)))
8322    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8323         (match_dup 4))]
8324   "TARGET_64BIT"
8325   "@
8326    %q4. %0,%2,%1
8327    #"
8328   [(set_attr "type" "fast_compare,compare")
8329    (set_attr "length" "4,8")])
8330
8331 (define_split
8332   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8333         (compare:CC (match_operator:DI 4 "boolean_operator"
8334          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8335           (match_operand:DI 2 "gpc_reg_operand" "")])
8336          (const_int 0)))
8337    (set (match_operand:DI 0 "gpc_reg_operand" "")
8338         (match_dup 4))]
8339   "TARGET_POWERPC64 && reload_completed"
8340   [(set (match_dup 0) (match_dup 4))
8341    (set (match_dup 3)
8342         (compare:CC (match_dup 0)
8343                     (const_int 0)))]
8344   "")
8345
8346 (define_insn "*boolccdi3_internal1"
8347   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8348         (match_operator:DI 3 "boolean_operator"
8349          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8350           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
8351   "TARGET_POWERPC64"
8352   "%q3 %0,%1,%2")
8353
8354 (define_insn "*boolccdi3_internal2"
8355   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8356         (compare:CC (match_operator:DI 4 "boolean_operator"
8357          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8358           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8359          (const_int 0)))
8360    (clobber (match_scratch:DI 3 "=r,r"))]
8361   "TARGET_64BIT"
8362   "@
8363    %q4. %3,%1,%2
8364    #"
8365   [(set_attr "type" "fast_compare,compare")
8366    (set_attr "length" "4,8")])
8367
8368 (define_split
8369   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8370         (compare:CC (match_operator:DI 4 "boolean_operator"
8371          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8372           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8373          (const_int 0)))
8374    (clobber (match_scratch:DI 3 ""))]
8375   "TARGET_POWERPC64 && reload_completed"
8376   [(set (match_dup 3) (match_dup 4))
8377    (set (match_dup 0)
8378         (compare:CC (match_dup 3)
8379                     (const_int 0)))]
8380   "")
8381
8382 (define_insn "*boolccdi3_internal3"
8383   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8384         (compare:CC (match_operator:DI 4 "boolean_operator"
8385          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8386           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8387          (const_int 0)))
8388    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8389         (match_dup 4))]
8390   "TARGET_64BIT"
8391   "@
8392    %q4. %0,%1,%2
8393    #"
8394   [(set_attr "type" "fast_compare,compare")
8395    (set_attr "length" "4,8")])
8396
8397 (define_split
8398   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8399         (compare:CC (match_operator:DI 4 "boolean_operator"
8400          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8401           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8402          (const_int 0)))
8403    (set (match_operand:DI 0 "gpc_reg_operand" "")
8404         (match_dup 4))]
8405   "TARGET_POWERPC64 && reload_completed"
8406   [(set (match_dup 0) (match_dup 4))
8407    (set (match_dup 3)
8408         (compare:CC (match_dup 0)
8409                     (const_int 0)))]
8410   "")
8411
8412 ;; Eqv operation.
8413 (define_insn "*eqv<mode>3"
8414   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
8415         (not:GPR
8416          (xor:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
8417                   (match_operand:GPR 2 "gpc_reg_operand" "r"))))]
8418   ""
8419   "eqv %0,%1,%2"
8420   [(set_attr "type" "integer")
8421    (set_attr "length" "4")])
8422
8423 \f
8424 ;; Now define ways of moving data around.
8425
8426 ;; Set up a register with a value from the GOT table
8427
8428 (define_expand "movsi_got"
8429   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8430         (unspec:SI [(match_operand:SI 1 "got_operand" "")
8431                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
8432   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8433   "
8434 {
8435   if (GET_CODE (operands[1]) == CONST)
8436     {
8437       rtx offset = const0_rtx;
8438       HOST_WIDE_INT value;
8439
8440       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
8441       value = INTVAL (offset);
8442       if (value != 0)
8443         {
8444           rtx tmp = (!can_create_pseudo_p ()
8445                      ? operands[0]
8446                      : gen_reg_rtx (Pmode));
8447           emit_insn (gen_movsi_got (tmp, operands[1]));
8448           emit_insn (gen_addsi3 (operands[0], tmp, offset));
8449           DONE;
8450         }
8451     }
8452
8453   operands[2] = rs6000_got_register (operands[1]);
8454 }")
8455
8456 (define_insn "*movsi_got_internal"
8457   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8458         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8459                     (match_operand:SI 2 "gpc_reg_operand" "b")]
8460                    UNSPEC_MOVSI_GOT))]
8461   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8462   "lwz %0,%a1@got(%2)"
8463   [(set_attr "type" "load")])
8464
8465 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
8466 ;; didn't get allocated to a hard register.
8467 (define_split
8468   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8469         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8470                     (match_operand:SI 2 "memory_operand" "")]
8471                    UNSPEC_MOVSI_GOT))]
8472   "DEFAULT_ABI == ABI_V4
8473     && flag_pic == 1
8474     && (reload_in_progress || reload_completed)"
8475   [(set (match_dup 0) (match_dup 2))
8476    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
8477                                  UNSPEC_MOVSI_GOT))]
8478   "")
8479
8480 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8481 ;; do the load 16-bits at a time.  We could do this by loading from memory,
8482 ;; and this is even supposed to be faster, but it is simpler not to get
8483 ;; integers in the TOC.
8484 (define_insn "movsi_low"
8485   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8486         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8487                            (match_operand 2 "" ""))))]
8488   "TARGET_MACHO && ! TARGET_64BIT"
8489   "lwz %0,lo16(%2)(%1)"
8490   [(set_attr "type" "load")
8491    (set_attr "length" "4")])
8492
8493 (define_insn "*movsi_internal1"
8494   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h")
8495         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0"))]
8496   "!TARGET_SINGLE_FPU &&
8497    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8498   "@
8499    mr %0,%1
8500    la %0,%a1
8501    lwz%U1%X1 %0,%1
8502    stw%U0%X0 %1,%0
8503    li %0,%1
8504    lis %0,%v1
8505    #
8506    mf%1 %0
8507    mt%0 %1
8508    mt%0 %1
8509    nop"
8510   [(set_attr_alternative "type"
8511       [(const_string "*")
8512        (const_string "*")
8513        (if_then_else
8514          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
8515          (const_string "load_ux")
8516          (if_then_else
8517            (match_test "update_address_mem (operands[1], VOIDmode)")
8518            (const_string "load_u")
8519            (const_string "load")))
8520        (if_then_else
8521          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
8522          (const_string "store_ux")
8523          (if_then_else
8524            (match_test "update_address_mem (operands[0], VOIDmode)")
8525            (const_string "store_u")
8526            (const_string "store")))
8527        (const_string "*")
8528        (const_string "*")
8529        (const_string "*")
8530        (const_string "mfjmpr")
8531        (const_string "mtjmpr")
8532        (const_string "*")
8533        (const_string "*")])
8534
8535    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4")])
8536
8537 (define_insn "*movsi_internal1_single"
8538   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h,m,*f")
8539         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0,f,m"))]
8540   "TARGET_SINGLE_FPU &&
8541    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8542   "@
8543    mr %0,%1
8544    la %0,%a1
8545    lwz%U1%X1 %0,%1
8546    stw%U0%X0 %1,%0
8547    li %0,%1
8548    lis %0,%v1
8549    #
8550    mf%1 %0
8551    mt%0 %1
8552    mt%0 %1
8553    nop
8554    stfs%U0%X0 %1,%0
8555    lfs%U1%X1 %0,%1"
8556   [(set_attr_alternative "type"
8557       [(const_string "*")
8558        (const_string "*")
8559        (if_then_else
8560          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
8561          (const_string "load_ux")
8562          (if_then_else
8563            (match_test "update_address_mem (operands[1], VOIDmode)")
8564            (const_string "load_u")
8565            (const_string "load")))
8566        (if_then_else
8567          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
8568          (const_string "store_ux")
8569          (if_then_else
8570            (match_test "update_address_mem (operands[0], VOIDmode)")
8571            (const_string "store_u")
8572            (const_string "store")))
8573        (const_string "*")
8574        (const_string "*")
8575        (const_string "*")
8576        (const_string "mfjmpr")
8577        (const_string "mtjmpr")
8578        (const_string "*")
8579        (const_string "*")
8580        (if_then_else
8581          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
8582          (const_string "fpstore_ux")
8583          (if_then_else
8584            (match_test "update_address_mem (operands[0], VOIDmode)")
8585            (const_string "fpstore_u")
8586            (const_string "fpstore")))
8587        (if_then_else
8588          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
8589          (const_string "fpload_ux")
8590          (if_then_else
8591            (match_test "update_address_mem (operands[1], VOIDmode)")
8592            (const_string "fpload_u")
8593            (const_string "fpload")))])
8594    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
8595
8596 ;; Split a load of a large constant into the appropriate two-insn
8597 ;; sequence.
8598
8599 (define_split
8600   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8601         (match_operand:SI 1 "const_int_operand" ""))]
8602   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
8603    && (INTVAL (operands[1]) & 0xffff) != 0"
8604   [(set (match_dup 0)
8605         (match_dup 2))
8606    (set (match_dup 0)
8607         (ior:SI (match_dup 0)
8608                 (match_dup 3)))]
8609   "
8610 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
8611
8612   if (tem == operands[0])
8613     DONE;
8614   else
8615     FAIL;
8616 }")
8617
8618 (define_insn "*mov<mode>_internal2"
8619   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8620         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
8621                     (const_int 0)))
8622    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8623   ""
8624   "@
8625    cmp<wd>i %2,%0,0
8626    mr. %0,%1
8627    #"
8628   [(set_attr "type" "cmp,fast_compare,cmp")
8629    (set_attr "length" "4,4,8")])
8630
8631 (define_split
8632   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
8633         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
8634                     (const_int 0)))
8635    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
8636   "reload_completed"
8637   [(set (match_dup 0) (match_dup 1))
8638    (set (match_dup 2)
8639         (compare:CC (match_dup 0)
8640                     (const_int 0)))]
8641   "")
8642 \f
8643 (define_insn "*movhi_internal"
8644   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
8645         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,0"))]
8646   "gpc_reg_operand (operands[0], HImode)
8647    || gpc_reg_operand (operands[1], HImode)"
8648   "@
8649    mr %0,%1
8650    lhz%U1%X1 %0,%1
8651    sth%U0%X0 %1,%0
8652    li %0,%w1
8653    mf%1 %0
8654    mt%0 %1
8655    nop"
8656   [(set_attr_alternative "type"
8657       [(const_string "*")
8658        (if_then_else
8659          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
8660          (const_string "load_ux")
8661          (if_then_else
8662            (match_test "update_address_mem (operands[1], VOIDmode)")
8663            (const_string "load_u")
8664            (const_string "load")))
8665        (if_then_else
8666          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
8667          (const_string "store_ux")
8668          (if_then_else
8669            (match_test "update_address_mem (operands[0], VOIDmode)")
8670            (const_string "store_u")
8671            (const_string "store")))
8672        (const_string "*")
8673        (const_string "mfjmpr")
8674        (const_string "mtjmpr")
8675        (const_string "*")])])
8676
8677 (define_expand "mov<mode>"
8678   [(set (match_operand:INT 0 "general_operand" "")
8679         (match_operand:INT 1 "any_operand" ""))]
8680   ""
8681   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8682
8683 (define_insn "*movqi_internal"
8684   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
8685         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,0"))]
8686   "gpc_reg_operand (operands[0], QImode)
8687    || gpc_reg_operand (operands[1], QImode)"
8688   "@
8689    mr %0,%1
8690    lbz%U1%X1 %0,%1
8691    stb%U0%X0 %1,%0
8692    li %0,%1
8693    mf%1 %0
8694    mt%0 %1
8695    nop"
8696   [(set_attr_alternative "type"
8697       [(const_string "*")
8698        (if_then_else
8699          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
8700          (const_string "load_ux")
8701          (if_then_else
8702            (match_test "update_address_mem (operands[1], VOIDmode)")
8703            (const_string "load_u")
8704            (const_string "load")))
8705        (if_then_else
8706          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
8707          (const_string "store_ux")
8708          (if_then_else
8709            (match_test "update_address_mem (operands[0], VOIDmode)")
8710            (const_string "store_u")
8711            (const_string "store")))
8712        (const_string "*")
8713        (const_string "mfjmpr")
8714        (const_string "mtjmpr")
8715        (const_string "*")])])
8716 \f
8717 ;; Here is how to move condition codes around.  When we store CC data in
8718 ;; an integer register or memory, we store just the high-order 4 bits.
8719 ;; This lets us not shift in the most common case of CR0.
8720 (define_expand "movcc"
8721   [(set (match_operand:CC 0 "nonimmediate_operand" "")
8722         (match_operand:CC 1 "nonimmediate_operand" ""))]
8723   ""
8724   "")
8725
8726 (define_insn "*movcc_internal1"
8727   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,cl,r,m")
8728         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,m,r"))]
8729   "register_operand (operands[0], CCmode)
8730    || register_operand (operands[1], CCmode)"
8731   "@
8732    mcrf %0,%1
8733    mtcrf 128,%1
8734    rlwinm %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;rlwinm %1,%1,%f0,0xffffffff
8735    crxor %0,%0,%0
8736    mfcr %0%Q1
8737    mfcr %0%Q1\;rlwinm %0,%0,%f1,0xf0000000
8738    mr %0,%1
8739    li %0,%1
8740    mf%1 %0
8741    mt%0 %1
8742    lwz%U1%X1 %0,%1
8743    stw%U0%X0 %1,%0"
8744   [(set (attr "type")
8745      (cond [(eq_attr "alternative" "0,3")
8746                 (const_string "cr_logical")
8747             (eq_attr "alternative" "1,2")
8748                 (const_string "mtcr")
8749             (eq_attr "alternative" "6,7")
8750                 (const_string "integer")
8751             (eq_attr "alternative" "8")
8752                 (const_string "mfjmpr")
8753             (eq_attr "alternative" "9")
8754                 (const_string "mtjmpr")
8755             (eq_attr "alternative" "10")
8756                 (if_then_else
8757                   (match_test "update_indexed_address_mem (operands[1],
8758                                                            VOIDmode)")
8759                   (const_string "load_ux")
8760                   (if_then_else
8761                     (match_test "update_address_mem (operands[1], VOIDmode)")
8762                     (const_string "load_u")
8763                     (const_string "load")))
8764             (eq_attr "alternative" "11")
8765                 (if_then_else
8766                   (match_test "update_indexed_address_mem (operands[0],
8767                                                            VOIDmode)")
8768                   (const_string "store_ux")
8769                   (if_then_else
8770                     (match_test "update_address_mem (operands[0], VOIDmode)")
8771                     (const_string "store_u")
8772                     (const_string "store")))
8773             (match_test "TARGET_MFCRF")
8774                 (const_string "mfcrf")
8775            ]
8776         (const_string "mfcr")))
8777    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4")])
8778 \f
8779 ;; For floating-point, we normally deal with the floating-point registers
8780 ;; unless -msoft-float is used.  The sole exception is that parameter passing
8781 ;; can produce floating-point values in fixed-point registers.  Unless the
8782 ;; value is a simple constant or already in memory, we deal with this by
8783 ;; allocating memory and copying the value explicitly via that memory location.
8784
8785 ;; Move 32-bit binary/decimal floating point
8786 (define_expand "mov<mode>"
8787   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "")
8788         (match_operand:FMOVE32 1 "any_operand" ""))]
8789   "<fmove_ok>"
8790   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8791
8792 (define_split
8793   [(set (match_operand:FMOVE32 0 "gpc_reg_operand" "")
8794         (match_operand:FMOVE32 1 "const_double_operand" ""))]
8795   "reload_completed
8796    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8797        || (GET_CODE (operands[0]) == SUBREG
8798            && GET_CODE (SUBREG_REG (operands[0])) == REG
8799            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8800   [(set (match_dup 2) (match_dup 3))]
8801   "
8802 {
8803   long l;
8804   REAL_VALUE_TYPE rv;
8805
8806   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8807   <real_value_to_target> (rv, l);
8808
8809   if (! TARGET_POWERPC64)
8810     operands[2] = operand_subword (operands[0], 0, 0, <MODE>mode);
8811   else
8812     operands[2] = gen_lowpart (SImode, operands[0]);
8813
8814   operands[3] = gen_int_mode (l, SImode);
8815 }")
8816
8817 (define_insn "mov<mode>_hardfloat"
8818   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "=!r,!r,m,f,wa,wa,<f32_lr>,<f32_sm>,wm,Z,?<f32_dm>,?r,*c*l,!r,*h,!r,!r")
8819         (match_operand:FMOVE32 1 "input_operand" "r,m,r,f,wa,j,<f32_lm>,<f32_sr>,Z,wm,r,<f32_dm>,r,h,0,G,Fn"))]
8820   "(gpc_reg_operand (operands[0], <MODE>mode)
8821    || gpc_reg_operand (operands[1], <MODE>mode))
8822    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
8823   "@
8824    mr %0,%1
8825    lwz%U1%X1 %0,%1
8826    stw%U0%X0 %1,%0
8827    fmr %0,%1
8828    xxlor %x0,%x1,%x1
8829    xxlxor %x0,%x0,%x0
8830    <f32_li>
8831    <f32_si>
8832    <f32_lv>
8833    <f32_sv>
8834    mtvsrwz %x0,%1
8835    mfvsrwz %0,%x1
8836    mt%0 %1
8837    mf%1 %0
8838    nop
8839    #
8840    #"
8841   [(set_attr_alternative "type"
8842       [(const_string "*")
8843        (if_then_else
8844          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
8845          (const_string "load_ux")
8846          (if_then_else
8847            (match_test "update_address_mem (operands[1], VOIDmode)")
8848            (const_string "load_u")
8849            (const_string "load")))
8850        (if_then_else
8851          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
8852          (const_string "store_ux")
8853          (if_then_else
8854            (match_test "update_address_mem (operands[0], VOIDmode)")
8855            (const_string "store_u")
8856            (const_string "store")))
8857        (const_string "fp")
8858        (const_string "vecsimple")
8859        (const_string "vecsimple")
8860        (if_then_else
8861          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
8862          (const_string "fpload_ux")
8863          (if_then_else
8864            (match_test "update_address_mem (operands[1], VOIDmode)")
8865            (const_string "fpload_u")
8866            (const_string "fpload")))
8867        (if_then_else
8868          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
8869          (const_string "fpstore_ux")
8870          (if_then_else
8871            (match_test "update_address_mem (operands[0], VOIDmode)")
8872            (const_string "fpstore_u")
8873            (const_string "fpstore")))
8874        (const_string "fpload")
8875        (const_string "fpstore")
8876        (const_string "mftgpr")
8877        (const_string "mffgpr")
8878        (const_string "mtjmpr")
8879        (const_string "mfjmpr")
8880        (const_string "*")
8881        (const_string "*")
8882        (const_string "*")])
8883    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8")])
8884
8885 (define_insn "*mov<mode>_softfloat"
8886   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "=r,cl,r,r,m,r,r,r,r,*h")
8887         (match_operand:FMOVE32 1 "input_operand" "r,r,h,m,r,I,L,G,Fn,0"))]
8888   "(gpc_reg_operand (operands[0], <MODE>mode)
8889    || gpc_reg_operand (operands[1], <MODE>mode))
8890    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
8891   "@
8892    mr %0,%1
8893    mt%0 %1
8894    mf%1 %0
8895    lwz%U1%X1 %0,%1
8896    stw%U0%X0 %1,%0
8897    li %0,%1
8898    lis %0,%v1
8899    #
8900    #
8901    nop"
8902   [(set_attr_alternative "type"
8903       [(const_string "*")
8904        (const_string "mtjmpr")
8905        (const_string "mfjmpr")
8906        (if_then_else
8907          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
8908          (const_string "load_ux")
8909          (if_then_else
8910            (match_test "update_address_mem (operands[1], VOIDmode)")
8911            (const_string "load_u")
8912            (const_string "load")))
8913        (if_then_else
8914          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
8915          (const_string "store_ux")
8916          (if_then_else
8917            (match_test "update_address_mem (operands[0], VOIDmode)")
8918            (const_string "store_u")
8919            (const_string "store")))
8920        (const_string "*")
8921        (const_string "*")
8922        (const_string "*")
8923        (const_string "*")
8924        (const_string "*")])
8925    (set_attr "length" "4,4,4,4,4,4,4,4,8,4")])
8926
8927 \f
8928 ;; Move 64-bit binary/decimal floating point
8929 (define_expand "mov<mode>"
8930   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "")
8931         (match_operand:FMOVE64 1 "any_operand" ""))]
8932   ""
8933   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8934
8935 (define_split
8936   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
8937         (match_operand:FMOVE64 1 "const_int_operand" ""))]
8938   "! TARGET_POWERPC64 && reload_completed
8939    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8940        || (GET_CODE (operands[0]) == SUBREG
8941            && GET_CODE (SUBREG_REG (operands[0])) == REG
8942            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8943   [(set (match_dup 2) (match_dup 4))
8944    (set (match_dup 3) (match_dup 1))]
8945   "
8946 {
8947   int endian = (WORDS_BIG_ENDIAN == 0);
8948   HOST_WIDE_INT value = INTVAL (operands[1]);
8949
8950   operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
8951   operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
8952   operands[4] = GEN_INT (value >> 32);
8953   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8954 }")
8955
8956 (define_split
8957   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
8958         (match_operand:FMOVE64 1 "const_double_operand" ""))]
8959   "! TARGET_POWERPC64 && reload_completed
8960    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8961        || (GET_CODE (operands[0]) == SUBREG
8962            && GET_CODE (SUBREG_REG (operands[0])) == REG
8963            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8964   [(set (match_dup 2) (match_dup 4))
8965    (set (match_dup 3) (match_dup 5))]
8966   "
8967 {
8968   int endian = (WORDS_BIG_ENDIAN == 0);
8969   long l[2];
8970   REAL_VALUE_TYPE rv;
8971
8972   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8973   <real_value_to_target> (rv, l);
8974
8975   operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
8976   operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
8977   operands[4] = gen_int_mode (l[endian], SImode);
8978   operands[5] = gen_int_mode (l[1 - endian], SImode);
8979 }")
8980
8981 (define_split
8982   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
8983         (match_operand:FMOVE64 1 "const_double_operand" ""))]
8984   "TARGET_POWERPC64 && reload_completed
8985    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8986        || (GET_CODE (operands[0]) == SUBREG
8987            && GET_CODE (SUBREG_REG (operands[0])) == REG
8988            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8989   [(set (match_dup 2) (match_dup 3))]
8990   "
8991 {
8992   int endian = (WORDS_BIG_ENDIAN == 0);
8993   long l[2];
8994   REAL_VALUE_TYPE rv;
8995   HOST_WIDE_INT val;
8996
8997   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8998   <real_value_to_target> (rv, l);
8999
9000   operands[2] = gen_lowpart (DImode, operands[0]);
9001   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
9002   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
9003          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
9004
9005   operands[3] = gen_int_mode (val, DImode);
9006 }")
9007
9008 ;; Don't have reload use general registers to load a constant.  It is
9009 ;; less efficient than loading the constant into an FP register, since
9010 ;; it will probably be used there.
9011
9012 ;; The move constraints are ordered to prefer floating point registers before
9013 ;; general purpose registers to avoid doing a store and a load to get the value
9014 ;; into a floating point register when it is needed for a floating point
9015 ;; operation.  Prefer traditional floating point registers over VSX registers,
9016 ;; since the D-form version of the memory instructions does not need a GPR for
9017 ;; reloading.
9018
9019 (define_insn "*mov<mode>_hardfloat32"
9020   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=m,d,d,ws,?wa,Z,?Z,ws,?wa,wa,Y,r,!r,!r,!r,!r")
9021         (match_operand:FMOVE64 1 "input_operand" "d,m,d,Z,Z,ws,wa,ws,wa,j,r,Y,r,G,H,F"))]
9022   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9023    && (gpc_reg_operand (operands[0], <MODE>mode)
9024        || gpc_reg_operand (operands[1], <MODE>mode))"
9025   "@
9026    stfd%U0%X0 %1,%0
9027    lfd%U1%X1 %0,%1
9028    fmr %0,%1
9029    lxsd%U1x %x0,%y1
9030    lxsd%U1x %x0,%y1
9031    stxsd%U0x %x1,%y0
9032    stxsd%U0x %x1,%y0
9033    xxlor %x0,%x1,%x1
9034    xxlor %x0,%x1,%x1
9035    xxlxor %x0,%x0,%x0
9036    #
9037    #
9038    #
9039    #
9040    #
9041    #"
9042   [(set_attr_alternative "type"
9043       [(if_then_else
9044          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9045          (const_string "fpstore_ux")
9046          (if_then_else
9047            (match_test "update_address_mem (operands[0], VOIDmode)")
9048            (const_string "fpstore_u")
9049            (const_string "fpstore")))
9050        (if_then_else
9051          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9052          (const_string "fpload_ux")
9053          (if_then_else
9054            (match_test "update_address_mem (operands[1], VOIDmode)")
9055            (const_string "fpload_u")
9056            (const_string "fpload")))
9057        (const_string "fp")
9058        (if_then_else
9059          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9060          (const_string "fpload_ux")
9061          (const_string "fpload"))
9062        (if_then_else
9063          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9064          (const_string "fpload_ux")
9065          (const_string "fpload"))
9066        (if_then_else
9067          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9068          (const_string "fpstore_ux")
9069          (const_string "fpstore"))
9070        (if_then_else
9071          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9072          (const_string "fpstore_ux")
9073          (const_string "fpstore"))
9074        (const_string "vecsimple")
9075        (const_string "vecsimple")
9076        (const_string "vecsimple")
9077        (const_string "store")
9078        (const_string "load")
9079        (const_string "two")
9080        (const_string "fp")
9081        (const_string "fp")
9082        (const_string "*")])
9083    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,8,8,8,12,16")])
9084
9085 (define_insn "*mov<mode>_softfloat32"
9086   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=Y,r,r,r,r,r")
9087         (match_operand:FMOVE64 1 "input_operand" "r,Y,r,G,H,F"))]
9088   "! TARGET_POWERPC64 
9089    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
9090        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
9091    && (gpc_reg_operand (operands[0], <MODE>mode)
9092        || gpc_reg_operand (operands[1], <MODE>mode))"
9093   "#"
9094   [(set_attr "type" "store,load,two,*,*,*")
9095    (set_attr "length" "8,8,8,8,12,16")])
9096
9097 ; ld/std require word-aligned displacements -> 'Y' constraint.
9098 ; List Y->r and r->Y before r->r for reload.
9099 (define_insn "*mov<mode>_hardfloat64"
9100   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=m,d,d,ws,?wa,Z,?Z,ws,?wa,wa,Y,r,!r,*c*l,!r,*h,!r,!r,!r,r,wg,r,wm")
9101         (match_operand:FMOVE64 1 "input_operand" "d,m,d,Z,Z,ws,wa,ws,wa,j,r,Y,r,r,h,0,G,H,F,wg,r,wm,r"))]
9102   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
9103    && (gpc_reg_operand (operands[0], <MODE>mode)
9104        || gpc_reg_operand (operands[1], <MODE>mode))"
9105   "@
9106    stfd%U0%X0 %1,%0
9107    lfd%U1%X1 %0,%1
9108    fmr %0,%1
9109    lxsd%U1x %x0,%y1
9110    lxsd%U1x %x0,%y1
9111    stxsd%U0x %x1,%y0
9112    stxsd%U0x %x1,%y0
9113    xxlor %x0,%x1,%x1
9114    xxlor %x0,%x1,%x1
9115    xxlxor %x0,%x0,%x0
9116    std%U0%X0 %1,%0
9117    ld%U1%X1 %0,%1
9118    mr %0,%1
9119    mt%0 %1
9120    mf%1 %0
9121    nop
9122    #
9123    #
9124    #
9125    mftgpr %0,%1
9126    mffgpr %0,%1
9127    mfvsrd %0,%x1
9128    mtvsrd %x0,%1"
9129   [(set_attr_alternative "type"
9130       [(if_then_else
9131          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9132          (const_string "fpstore_ux")
9133          (if_then_else
9134            (match_test "update_address_mem (operands[0], VOIDmode)")
9135            (const_string "fpstore_u")
9136            (const_string "fpstore")))
9137        (if_then_else
9138          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9139          (const_string "fpload_ux")
9140          (if_then_else
9141            (match_test "update_address_mem (operands[1], VOIDmode)")
9142            (const_string "fpload_u")
9143            (const_string "fpload")))
9144        (const_string "fp")
9145        (if_then_else
9146          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9147          (const_string "fpload_ux")
9148          (const_string "fpload"))
9149        (if_then_else
9150          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9151          (const_string "fpload_ux")
9152          (const_string "fpload"))
9153        (if_then_else
9154          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9155          (const_string "fpstore_ux")
9156          (const_string "fpstore"))
9157        (if_then_else
9158          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9159          (const_string "fpstore_ux")
9160          (const_string "fpstore"))
9161        (const_string "vecsimple")
9162        (const_string "vecsimple")
9163        (const_string "vecsimple")
9164        (if_then_else
9165          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9166          (const_string "store_ux")
9167          (if_then_else
9168            (match_test "update_address_mem (operands[0], VOIDmode)")
9169            (const_string "store_u")
9170            (const_string "store")))
9171        (if_then_else
9172          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9173          (const_string "load_ux")
9174          (if_then_else
9175            (match_test "update_address_mem (operands[1], VOIDmode)")
9176            (const_string "load_u")
9177            (const_string "load")))
9178        (const_string "*")
9179        (const_string "mtjmpr")
9180        (const_string "mfjmpr")
9181        (const_string "*")
9182        (const_string "*")
9183        (const_string "*")
9184        (const_string "*")
9185        (const_string "mftgpr")
9186        (const_string "mffgpr")
9187        (const_string "mftgpr")
9188        (const_string "mffgpr")])
9189    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4,4,4")])
9190
9191 (define_insn "*mov<mode>_softfloat64"
9192   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=Y,r,r,cl,r,r,r,r,*h")
9193         (match_operand:FMOVE64 1 "input_operand" "r,Y,r,r,h,G,H,F,0"))]
9194   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
9195    && (gpc_reg_operand (operands[0], <MODE>mode)
9196        || gpc_reg_operand (operands[1], <MODE>mode))"
9197   "@
9198    std%U0%X0 %1,%0
9199    ld%U1%X1 %0,%1
9200    mr %0,%1
9201    mt%0 %1
9202    mf%1 %0
9203    #
9204    #
9205    #
9206    nop"
9207   [(set_attr_alternative "type"
9208       [(if_then_else
9209          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9210          (const_string "store_ux")
9211          (if_then_else
9212            (match_test "update_address_mem (operands[0], VOIDmode)")
9213            (const_string "store_u")
9214            (const_string "store")))
9215        (if_then_else
9216          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9217          (const_string "load_ux")
9218          (if_then_else
9219            (match_test "update_address_mem (operands[1], VOIDmode)")
9220            (const_string "load_u")
9221            (const_string "load")))
9222        (const_string "*")
9223        (const_string "mtjmpr")
9224        (const_string "mfjmpr")
9225        (const_string "*")
9226        (const_string "*")
9227        (const_string "*")
9228        (const_string "*")])
9229    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
9230 \f
9231 (define_expand "mov<mode>"
9232   [(set (match_operand:FMOVE128 0 "general_operand" "")
9233         (match_operand:FMOVE128 1 "any_operand" ""))]
9234   ""
9235   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9236
9237 ;; It's important to list Y->r and r->Y before r->r because otherwise
9238 ;; reload, given m->r, will try to pick r->r and reload it, which
9239 ;; doesn't make progress.
9240 (define_insn_and_split "*mov<mode>_internal"
9241   [(set (match_operand:FMOVE128 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
9242         (match_operand:FMOVE128 1 "input_operand" "d,m,d,r,YGHF,r"))]
9243   "TARGET_HARD_FLOAT && TARGET_FPRS
9244    && (gpc_reg_operand (operands[0], <MODE>mode)
9245        || gpc_reg_operand (operands[1], <MODE>mode))"
9246   "#"
9247   "&& reload_completed"
9248   [(pc)]
9249 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9250   [(set_attr "length" "8,8,8,20,20,16")])
9251
9252 (define_insn_and_split "*mov<mode>_softfloat"
9253   [(set (match_operand:FMOVE128 0 "rs6000_nonimmediate_operand" "=Y,r,r")
9254         (match_operand:FMOVE128 1 "input_operand" "r,YGHF,r"))]
9255   "(TARGET_SOFT_FLOAT || !TARGET_FPRS)
9256    && (gpc_reg_operand (operands[0], <MODE>mode)
9257        || gpc_reg_operand (operands[1], <MODE>mode))"
9258   "#"
9259   "&& reload_completed"
9260   [(pc)]
9261 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9262   [(set_attr "length" "20,20,16")])
9263
9264 (define_expand "extenddftf2"
9265   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9266         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
9267   "!TARGET_IEEEQUAD
9268    && TARGET_HARD_FLOAT
9269    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9270    && TARGET_LONG_DOUBLE_128"
9271 {
9272   if (TARGET_E500_DOUBLE)
9273     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
9274   else
9275     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
9276   DONE;
9277 })
9278
9279 (define_expand "extenddftf2_fprs"
9280   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9281                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
9282               (use (match_dup 2))])]
9283   "!TARGET_IEEEQUAD
9284    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9285    && TARGET_LONG_DOUBLE_128"
9286 {
9287   operands[2] = CONST0_RTX (DFmode);
9288   /* Generate GOT reference early for SVR4 PIC.  */
9289   if (DEFAULT_ABI == ABI_V4 && flag_pic)
9290     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
9291 })
9292
9293 (define_insn_and_split "*extenddftf2_internal"
9294   [(set (match_operand:TF 0 "nonimmediate_operand" "=m,Y,d,&d,r")
9295        (float_extend:TF (match_operand:DF 1 "input_operand" "d,r,md,md,rmGHF")))
9296    (use (match_operand:DF 2 "zero_reg_mem_operand" "d,r,m,d,n"))]
9297   "!TARGET_IEEEQUAD
9298    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9299    && TARGET_LONG_DOUBLE_128"
9300   "#"
9301   "&& reload_completed"
9302   [(pc)]
9303 {
9304   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9305   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9306   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
9307                   operands[1]);
9308   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
9309                   operands[2]);
9310   DONE;
9311 })
9312
9313 (define_expand "extendsftf2"
9314   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9315         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
9316   "!TARGET_IEEEQUAD
9317    && TARGET_HARD_FLOAT
9318    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9319    && TARGET_LONG_DOUBLE_128"
9320 {
9321   rtx tmp = gen_reg_rtx (DFmode);
9322   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
9323   emit_insn (gen_extenddftf2 (operands[0], tmp));
9324   DONE;
9325 })
9326
9327 (define_expand "trunctfdf2"
9328   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9329         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
9330   "!TARGET_IEEEQUAD
9331    && TARGET_HARD_FLOAT
9332    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9333    && TARGET_LONG_DOUBLE_128"
9334   "")
9335
9336 (define_insn_and_split "trunctfdf2_internal1"
9337   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
9338         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
9339   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
9340    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9341   "@
9342    #
9343    fmr %0,%1"
9344   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
9345   [(const_int 0)]
9346 {
9347   emit_note (NOTE_INSN_DELETED);
9348   DONE;
9349 }
9350   [(set_attr "type" "fp")])
9351
9352 (define_insn "trunctfdf2_internal2"
9353   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9354         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9355   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
9356    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9357    && TARGET_LONG_DOUBLE_128"
9358   "fadd %0,%1,%L1"
9359   [(set_attr "type" "fp")
9360    (set_attr "fp_type" "fp_addsub_d")])
9361
9362 (define_expand "trunctfsf2"
9363   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9364         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
9365   "!TARGET_IEEEQUAD
9366    && TARGET_HARD_FLOAT
9367    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9368    && TARGET_LONG_DOUBLE_128"
9369 {
9370   if (TARGET_E500_DOUBLE)
9371     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
9372   else
9373     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
9374   DONE;
9375 })
9376
9377 (define_insn_and_split "trunctfsf2_fprs"
9378   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
9379         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
9380    (clobber (match_scratch:DF 2 "=d"))]
9381   "!TARGET_IEEEQUAD
9382    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
9383    && TARGET_LONG_DOUBLE_128"
9384   "#"
9385   "&& reload_completed"
9386   [(set (match_dup 2)
9387         (float_truncate:DF (match_dup 1)))
9388    (set (match_dup 0)
9389         (float_truncate:SF (match_dup 2)))]
9390   "")
9391
9392 (define_expand "floatsitf2"
9393   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9394         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
9395   "!TARGET_IEEEQUAD
9396    && TARGET_HARD_FLOAT
9397    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9398    && TARGET_LONG_DOUBLE_128"
9399 {
9400   rtx tmp = gen_reg_rtx (DFmode);
9401   expand_float (tmp, operands[1], false);
9402   emit_insn (gen_extenddftf2 (operands[0], tmp));
9403   DONE;
9404 })
9405
9406 ; fadd, but rounding towards zero.
9407 ; This is probably not the optimal code sequence.
9408 (define_insn "fix_trunc_helper"
9409   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9410         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
9411                    UNSPEC_FIX_TRUNC_TF))
9412    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
9413   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
9414   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
9415   [(set_attr "type" "fp")
9416    (set_attr "length" "20")])
9417
9418 (define_expand "fix_trunctfsi2"
9419   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9420         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
9421   "!TARGET_IEEEQUAD && TARGET_HARD_FLOAT
9422    && (TARGET_FPRS || TARGET_E500_DOUBLE) && TARGET_LONG_DOUBLE_128"
9423 {
9424   if (TARGET_E500_DOUBLE)
9425     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
9426   else
9427     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
9428   DONE;
9429 })
9430
9431 (define_expand "fix_trunctfsi2_fprs"
9432   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
9433                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
9434               (clobber (match_dup 2))
9435               (clobber (match_dup 3))
9436               (clobber (match_dup 4))
9437               (clobber (match_dup 5))])]
9438   "!TARGET_IEEEQUAD
9439    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9440 {
9441   operands[2] = gen_reg_rtx (DFmode);
9442   operands[3] = gen_reg_rtx (DFmode);
9443   operands[4] = gen_reg_rtx (DImode);
9444   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode));
9445 })
9446
9447 (define_insn_and_split "*fix_trunctfsi2_internal"
9448   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9449         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
9450    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
9451    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
9452    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
9453    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
9454   "!TARGET_IEEEQUAD
9455    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9456   "#"
9457   ""
9458   [(pc)]
9459 {
9460   rtx lowword;
9461   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
9462
9463   gcc_assert (MEM_P (operands[5]));
9464   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
9465
9466   emit_insn (gen_fctiwz_df (operands[4], operands[2]));
9467   emit_move_insn (operands[5], operands[4]);
9468   emit_move_insn (operands[0], lowword);
9469   DONE;
9470 })
9471
9472 (define_expand "negtf2"
9473   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9474         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9475   "!TARGET_IEEEQUAD
9476    && TARGET_HARD_FLOAT
9477    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9478    && TARGET_LONG_DOUBLE_128"
9479   "")
9480
9481 (define_insn "negtf2_internal"
9482   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
9483         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9484   "!TARGET_IEEEQUAD
9485    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9486   "*
9487 {
9488   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9489     return \"fneg %L0,%L1\;fneg %0,%1\";
9490   else
9491     return \"fneg %0,%1\;fneg %L0,%L1\";
9492 }"
9493   [(set_attr "type" "fp")
9494    (set_attr "length" "8")])
9495
9496 (define_expand "abstf2"
9497   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9498         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9499   "!TARGET_IEEEQUAD
9500    && TARGET_HARD_FLOAT
9501    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9502    && TARGET_LONG_DOUBLE_128"
9503   "
9504 {
9505   rtx label = gen_label_rtx ();
9506   if (TARGET_E500_DOUBLE)
9507     {
9508       if (flag_finite_math_only && !flag_trapping_math)
9509         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
9510       else
9511         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
9512     }
9513   else
9514     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
9515   emit_label (label);
9516   DONE;
9517 }")
9518
9519 (define_expand "abstf2_internal"
9520   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9521         (match_operand:TF 1 "gpc_reg_operand" ""))
9522    (set (match_dup 3) (match_dup 5))
9523    (set (match_dup 5) (abs:DF (match_dup 5)))
9524    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
9525    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
9526                            (label_ref (match_operand 2 "" ""))
9527                            (pc)))
9528    (set (match_dup 6) (neg:DF (match_dup 6)))]
9529   "!TARGET_IEEEQUAD
9530    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9531    && TARGET_LONG_DOUBLE_128"
9532   "
9533 {
9534   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9535   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9536   operands[3] = gen_reg_rtx (DFmode);
9537   operands[4] = gen_reg_rtx (CCFPmode);
9538   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
9539   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
9540 }")
9541 \f
9542 ;; Reload helper functions used by rs6000_secondary_reload.  The patterns all
9543 ;; must have 3 arguments, and scratch register constraint must be a single
9544 ;; constraint.
9545
9546 ;; Reload patterns to support gpr load/store with misaligned mem.
9547 ;; and multiple gpr load/store at offset >= 0xfffc
9548 (define_expand "reload_<mode>_store"
9549   [(parallel [(match_operand 0 "memory_operand" "=m")
9550               (match_operand 1 "gpc_reg_operand" "r")
9551               (match_operand:GPR 2 "register_operand" "=&b")])]
9552   ""
9553 {
9554   rs6000_secondary_reload_gpr (operands[1], operands[0], operands[2], true);
9555   DONE;
9556 })
9557
9558 (define_expand "reload_<mode>_load"
9559   [(parallel [(match_operand 0 "gpc_reg_operand" "=r")
9560               (match_operand 1 "memory_operand" "m")
9561               (match_operand:GPR 2 "register_operand" "=b")])]
9562   ""
9563 {
9564   rs6000_secondary_reload_gpr (operands[0], operands[1], operands[2], false);
9565   DONE;
9566 })
9567
9568 \f
9569 ;; Power8 merge instructions to allow direct move to/from floating point
9570 ;; registers in 32-bit mode.  We use TF mode to get two registers to move the
9571 ;; individual 32-bit parts across.  Subreg doesn't work too well on the TF
9572 ;; value, since it is allocated in reload and not all of the flow information
9573 ;; is setup for it.  We have two patterns to do the two moves between gprs and
9574 ;; fprs.  There isn't a dependancy between the two, but we could potentially
9575 ;; schedule other instructions between the two instructions.  TFmode is
9576 ;; currently limited to traditional FPR registers.  If/when this is changed, we
9577 ;; will need to revist %L to make sure it works with VSX registers, or add an
9578 ;; %x version of %L.
9579
9580 (define_insn "p8_fmrgow_<mode>"
9581   [(set (match_operand:FMOVE64X 0 "register_operand" "=d")
9582         (unspec:FMOVE64X [(match_operand:TF 1 "register_operand" "d")]
9583                          UNSPEC_P8V_FMRGOW))]
9584   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9585   "fmrgow %0,%1,%L1"
9586   [(set_attr "type" "vecperm")])
9587
9588 (define_insn "p8_mtvsrwz_1"
9589   [(set (match_operand:TF 0 "register_operand" "=d")
9590         (unspec:TF [(match_operand:SI 1 "register_operand" "r")]
9591                    UNSPEC_P8V_MTVSRWZ))]
9592   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9593   "mtvsrwz %x0,%1"
9594   [(set_attr "type" "mftgpr")])
9595
9596 (define_insn "p8_mtvsrwz_2"
9597   [(set (match_operand:TF 0 "register_operand" "+d")
9598         (unspec:TF [(match_dup 0)
9599                     (match_operand:SI 1 "register_operand" "r")]
9600                    UNSPEC_P8V_MTVSRWZ))]
9601   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9602   "mtvsrwz %L0,%1"
9603   [(set_attr "type" "mftgpr")])
9604
9605 (define_insn_and_split "reload_fpr_from_gpr<mode>"
9606   [(set (match_operand:FMOVE64X 0 "register_operand" "=ws")
9607         (unspec:FMOVE64X [(match_operand:FMOVE64X 1 "register_operand" "r")]
9608                          UNSPEC_P8V_RELOAD_FROM_GPR))
9609    (clobber (match_operand:TF 2 "register_operand" "=d"))]
9610   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9611   "#"
9612   "&& reload_completed"
9613   [(const_int 0)]
9614 {
9615   rtx dest = operands[0];
9616   rtx src = operands[1];
9617   rtx tmp = operands[2];
9618   rtx gpr_hi_reg = gen_highpart (SImode, src);
9619   rtx gpr_lo_reg = gen_lowpart (SImode, src);
9620
9621   emit_insn (gen_p8_mtvsrwz_1 (tmp, gpr_hi_reg));
9622   emit_insn (gen_p8_mtvsrwz_2 (tmp, gpr_lo_reg));
9623   emit_insn (gen_p8_fmrgow_<mode> (dest, tmp));
9624   DONE;
9625 }
9626   [(set_attr "length" "12")
9627    (set_attr "type" "three")])
9628
9629 ;; Move 128 bit values from GPRs to VSX registers in 64-bit mode
9630 (define_insn "p8_mtvsrd_1"
9631   [(set (match_operand:TF 0 "register_operand" "=ws")
9632         (unspec:TF [(match_operand:DI 1 "register_operand" "r")]
9633                    UNSPEC_P8V_MTVSRD))]
9634   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9635   "mtvsrd %0,%1"
9636   [(set_attr "type" "mftgpr")])
9637
9638 (define_insn "p8_mtvsrd_2"
9639   [(set (match_operand:TF 0 "register_operand" "+ws")
9640         (unspec:TF [(match_dup 0)
9641                     (match_operand:DI 1 "register_operand" "r")]
9642                    UNSPEC_P8V_MTVSRD))]
9643   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9644   "mtvsrd %L0,%1"
9645   [(set_attr "type" "mftgpr")])
9646
9647 (define_insn "p8_xxpermdi_<mode>"
9648   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9649         (unspec:FMOVE128_GPR [(match_operand:TF 1 "register_operand" "ws")]
9650                              UNSPEC_P8V_XXPERMDI))]
9651   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9652   "xxpermdi %x0,%1,%L1,0"
9653   [(set_attr "type" "vecperm")])
9654
9655 (define_insn_and_split "reload_vsx_from_gpr<mode>"
9656   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9657         (unspec:FMOVE128_GPR
9658          [(match_operand:FMOVE128_GPR 1 "register_operand" "r")]
9659          UNSPEC_P8V_RELOAD_FROM_GPR))
9660    (clobber (match_operand:TF 2 "register_operand" "=ws"))]
9661   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9662   "#"
9663   "&& reload_completed"
9664   [(const_int 0)]
9665 {
9666   rtx dest = operands[0];
9667   rtx src = operands[1];
9668   rtx tmp = operands[2];
9669   rtx gpr_hi_reg = gen_highpart (DImode, src);
9670   rtx gpr_lo_reg = gen_lowpart (DImode, src);
9671
9672   emit_insn (gen_p8_mtvsrd_1 (tmp, gpr_hi_reg));
9673   emit_insn (gen_p8_mtvsrd_2 (tmp, gpr_lo_reg));
9674   emit_insn (gen_p8_xxpermdi_<mode> (dest, tmp));
9675 }
9676   [(set_attr "length" "12")
9677    (set_attr "type" "three")])
9678
9679 ;; Move SFmode to a VSX from a GPR register.  Because scalar floating point
9680 ;; type is stored internally as double precision in the VSX registers, we have
9681 ;; to convert it from the vector format.
9682
9683 (define_insn_and_split "reload_vsx_from_gprsf"
9684   [(set (match_operand:SF 0 "register_operand" "=wa")
9685         (unspec:SF [(match_operand:SF 1 "register_operand" "r")]
9686                    UNSPEC_P8V_RELOAD_FROM_GPR))
9687    (clobber (match_operand:DI 2 "register_operand" "=r"))]
9688   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE && WORDS_BIG_ENDIAN"
9689   "#"
9690   "&& reload_completed"
9691   [(const_int 0)]
9692 {
9693   rtx op0 = operands[0];
9694   rtx op1 = operands[1];
9695   rtx op2 = operands[2];
9696   rtx op0_di = simplify_gen_subreg (DImode, op0, SFmode, 0);
9697   rtx op1_di = simplify_gen_subreg (DImode, op1, SFmode, 0);
9698
9699   /* Move SF value to upper 32-bits for xscvspdpn.  */
9700   emit_insn (gen_ashldi3 (op2, op1_di, GEN_INT (32)));
9701   emit_move_insn (op0_di, op2);
9702   emit_insn (gen_vsx_xscvspdpn_directmove (op0, op0));
9703   DONE;
9704 }
9705   [(set_attr "length" "8")
9706    (set_attr "type" "two")])
9707
9708 ;; Move 128 bit values from VSX registers to GPRs in 64-bit mode by doing a
9709 ;; normal 64-bit move, followed by an xxpermdi to get the bottom 64-bit value,
9710 ;; and then doing a move of that.
9711 (define_insn "p8_mfvsrd_3_<mode>"
9712   [(set (match_operand:DF 0 "register_operand" "=r")
9713         (unspec:DF [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9714                    UNSPEC_P8V_RELOAD_FROM_VSX))]
9715   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE && WORDS_BIG_ENDIAN"
9716   "mfvsrd %0,%x1"
9717   [(set_attr "type" "mftgpr")])
9718
9719 (define_insn_and_split "reload_gpr_from_vsx<mode>"
9720   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=r")
9721         (unspec:FMOVE128_GPR
9722          [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9723          UNSPEC_P8V_RELOAD_FROM_VSX))
9724    (clobber (match_operand:FMOVE128_GPR 2 "register_operand" "=wa"))]
9725   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE && WORDS_BIG_ENDIAN"
9726   "#"
9727   "&& reload_completed"
9728   [(const_int 0)]
9729 {
9730   rtx dest = operands[0];
9731   rtx src = operands[1];
9732   rtx tmp = operands[2];
9733   rtx gpr_hi_reg = gen_highpart (DFmode, dest);
9734   rtx gpr_lo_reg = gen_lowpart (DFmode, dest);
9735
9736   emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_hi_reg, src));
9737   emit_insn (gen_vsx_xxpermdi_<mode> (tmp, src, src, GEN_INT (3)));
9738   emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_lo_reg, tmp));
9739 }
9740   [(set_attr "length" "12")
9741    (set_attr "type" "three")])
9742
9743 ;; Move SFmode to a GPR from a VSX register.  Because scalar floating point
9744 ;; type is stored internally as double precision, we have to convert it to the
9745 ;; vector format.
9746
9747 (define_insn_and_split "reload_gpr_from_vsxsf"
9748   [(set (match_operand:SF 0 "register_operand" "=r")
9749         (unspec:SF [(match_operand:SF 1 "register_operand" "wa")]
9750                    UNSPEC_P8V_RELOAD_FROM_VSX))
9751    (clobber (match_operand:V4SF 2 "register_operand" "=wa"))]
9752   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE && WORDS_BIG_ENDIAN"
9753   "#"
9754   "&& reload_completed"
9755   [(const_int 0)]
9756 {
9757   rtx op0 = operands[0];
9758   rtx op1 = operands[1];
9759   rtx op2 = operands[2];
9760   rtx diop0 = simplify_gen_subreg (DImode, op0, SFmode, 0);
9761
9762   emit_insn (gen_vsx_xscvdpspn_scalar (op2, op1));
9763   emit_insn (gen_p8_mfvsrd_4_disf (diop0, op2));
9764   emit_insn (gen_lshrdi3 (diop0, diop0, GEN_INT (32)));
9765   DONE;
9766 }
9767   [(set_attr "length" "12")
9768    (set_attr "type" "three")])
9769
9770 (define_insn "p8_mfvsrd_4_disf"
9771   [(set (match_operand:DI 0 "register_operand" "=r")
9772         (unspec:DI [(match_operand:V4SF 1 "register_operand" "wa")]
9773                    UNSPEC_P8V_RELOAD_FROM_VSX))]
9774   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE && WORDS_BIG_ENDIAN"
9775   "mfvsrd %0,%x1"
9776   [(set_attr "type" "mftgpr")])
9777
9778 \f
9779 ;; Next come the multi-word integer load and store and the load and store
9780 ;; multiple insns.
9781
9782 ;; List r->r after r->Y, otherwise reload will try to reload a
9783 ;; non-offsettable address by using r->r which won't make progress.
9784 ;; Use of fprs is disparaged slightly otherwise reload prefers to reload
9785 ;; a gpr into a fpr instead of reloading an invalid 'Y' address
9786 (define_insn "*movdi_internal32"
9787   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=Y,r,r,?m,?*d,?*d,r,?wa")
9788         (match_operand:DI 1 "input_operand" "r,Y,r,d,m,d,IJKnGHF,O"))]
9789   "! TARGET_POWERPC64
9790    && (gpc_reg_operand (operands[0], DImode)
9791        || gpc_reg_operand (operands[1], DImode))"
9792   "@
9793    #
9794    #
9795    #
9796    stfd%U0%X0 %1,%0
9797    lfd%U1%X1 %0,%1
9798    fmr %0,%1
9799    #
9800    xxlxor %x0,%x0,%x0"
9801   [(set_attr_alternative "type"
9802       [(const_string "store")
9803        (const_string "load")
9804        (const_string "*")
9805        (if_then_else
9806          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9807          (const_string "fpstore_ux")
9808          (if_then_else
9809            (match_test "update_address_mem (operands[0], VOIDmode)")
9810            (const_string "fpstore_u")
9811            (const_string "fpstore")))
9812        (if_then_else
9813          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9814          (const_string "fpload_ux")
9815          (if_then_else
9816            (match_test "update_address_mem (operands[1], VOIDmode)")
9817            (const_string "fpload_u")
9818            (const_string "fpload")))
9819        (const_string "fp")
9820        (const_string "*")
9821        (const_string "vecsimple")])])
9822
9823 (define_split
9824   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9825         (match_operand:DI 1 "const_int_operand" ""))]
9826   "! TARGET_POWERPC64 && reload_completed
9827    && gpr_or_gpr_p (operands[0], operands[1])
9828    && !direct_move_p (operands[0], operands[1])"
9829   [(set (match_dup 2) (match_dup 4))
9830    (set (match_dup 3) (match_dup 1))]
9831   "
9832 {
9833   HOST_WIDE_INT value = INTVAL (operands[1]);
9834   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9835                                        DImode);
9836   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9837                                        DImode);
9838   operands[4] = GEN_INT (value >> 32);
9839   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9840 }")
9841
9842 (define_split
9843   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
9844         (match_operand:DIFD 1 "input_operand" ""))]
9845   "reload_completed && !TARGET_POWERPC64
9846    && gpr_or_gpr_p (operands[0], operands[1])
9847    && !direct_move_p (operands[0], operands[1])"
9848   [(pc)]
9849 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9850
9851 (define_insn "*movdi_internal64"
9852   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,r,r,r,r,?m,?*d,?*d,?Z,?wa,?wa,r,*h,*h,?wa,r,?*wg,r,?*wm")
9853         (match_operand:DI 1 "input_operand" "r,Y,r,I,L,nF,d,m,d,wa,Z,wa,*h,r,0,O,*wg,r,*wm,r"))]
9854   "TARGET_POWERPC64
9855    && (gpc_reg_operand (operands[0], DImode)
9856        || gpc_reg_operand (operands[1], DImode))"
9857   "@
9858    std%U0%X0 %1,%0
9859    ld%U1%X1 %0,%1
9860    mr %0,%1
9861    li %0,%1
9862    lis %0,%v1
9863    #
9864    stfd%U0%X0 %1,%0
9865    lfd%U1%X1 %0,%1
9866    fmr %0,%1
9867    stxsd%U0x %x1,%y0
9868    lxsd%U1x %x0,%y1
9869    xxlor %x0,%x1,%x1
9870    mf%1 %0
9871    mt%0 %1
9872    nop
9873    xxlxor %x0,%x0,%x0
9874    mftgpr %0,%1
9875    mffgpr %0,%1
9876    mfvsrd %0,%x1
9877    mtvsrd %x0,%1"
9878   [(set_attr_alternative "type"
9879       [(if_then_else
9880          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9881          (const_string "store_ux")
9882          (if_then_else
9883            (match_test "update_address_mem (operands[0], VOIDmode)")
9884            (const_string "store_u")
9885            (const_string "store")))
9886        (if_then_else
9887          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9888          (const_string "load_ux")
9889          (if_then_else
9890            (match_test "update_address_mem (operands[1], VOIDmode)")
9891            (const_string "load_u")
9892            (const_string "load")))
9893        (const_string "*")
9894        (const_string "*")
9895        (const_string "*")
9896        (const_string "*")
9897        (if_then_else
9898          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9899          (const_string "fpstore_ux")
9900          (if_then_else
9901            (match_test "update_address_mem (operands[0], VOIDmode)")
9902            (const_string "fpstore_u")
9903            (const_string "fpstore")))
9904        (if_then_else
9905          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9906          (const_string "fpload_ux")
9907          (if_then_else
9908            (match_test "update_address_mem (operands[1], VOIDmode)")
9909            (const_string "fpload_u")
9910            (const_string "fpload")))
9911        (const_string "fp")
9912        (if_then_else
9913          (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
9914          (const_string "fpstore_ux")
9915          (const_string "fpstore"))
9916        (if_then_else
9917          (match_test "update_indexed_address_mem (operands[1], VOIDmode)")
9918          (const_string "fpload_ux")
9919          (const_string "fpload"))
9920        (const_string "vecsimple")
9921        (const_string "mfjmpr")
9922        (const_string "mtjmpr")
9923        (const_string "*")
9924        (const_string "vecsimple")
9925        (const_string "mftgpr")
9926        (const_string "mffgpr")
9927        (const_string "mftgpr")
9928        (const_string "mffgpr")])
9929    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4,4,4,4,4,4")])
9930
9931 ;; Generate all one-bits and clear left or right.
9932 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
9933 (define_split
9934   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9935         (match_operand:DI 1 "mask64_operand" ""))]
9936   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9937   [(set (match_dup 0) (const_int -1))
9938    (set (match_dup 0)
9939         (and:DI (rotate:DI (match_dup 0)
9940                            (const_int 0))
9941                 (match_dup 1)))]
9942   "")
9943
9944 ;; Split a load of a large constant into the appropriate five-instruction
9945 ;; sequence.  Handle anything in a constant number of insns.
9946 ;; When non-easy constants can go in the TOC, this should use
9947 ;; easy_fp_constant predicate.
9948 (define_split
9949   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9950         (match_operand:DI 1 "const_int_operand" ""))]
9951   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9952   [(set (match_dup 0) (match_dup 2))
9953    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9954   "
9955 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9956
9957   if (tem == operands[0])
9958     DONE;
9959   else
9960     FAIL;
9961 }")
9962
9963 (define_split
9964   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9965         (match_operand:DI 1 "const_double_operand" ""))]
9966   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9967   [(set (match_dup 0) (match_dup 2))
9968    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9969   "
9970 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9971
9972   if (tem == operands[0])
9973     DONE;
9974   else
9975     FAIL;
9976 }")
9977 \f
9978 ;; TImode/PTImode is similar, except that we usually want to compute the
9979 ;; address into a register and use lsi/stsi (the exception is during reload).
9980
9981 (define_insn "*mov<mode>_string"
9982   [(set (match_operand:TI2 0 "reg_or_mem_operand" "=Q,Y,????r,????r,????r,r")
9983         (match_operand:TI2 1 "input_operand" "r,r,Q,Y,r,n"))]
9984   "! TARGET_POWERPC64
9985    && (<MODE>mode != TImode || VECTOR_MEM_NONE_P (TImode))
9986    && (gpc_reg_operand (operands[0], <MODE>mode)
9987        || gpc_reg_operand (operands[1], <MODE>mode))"
9988   "*
9989 {
9990   switch (which_alternative)
9991     {
9992     default:
9993       gcc_unreachable ();
9994     case 0:
9995       if (TARGET_STRING)
9996         return \"stswi %1,%P0,16\";
9997     case 1:
9998       return \"#\";
9999     case 2:
10000       /* If the address is not used in the output, we can use lsi.  Otherwise,
10001          fall through to generating four loads.  */
10002       if (TARGET_STRING
10003           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
10004         return \"lswi %0,%P1,16\";
10005       /* ... fall through ...  */
10006     case 3:
10007     case 4:
10008     case 5:
10009       return \"#\";
10010     }
10011 }"
10012   [(set_attr "type" "store_ux,store_ux,load_ux,load_ux,*,*")
10013    (set (attr "cell_micro") (if_then_else (match_test "TARGET_STRING")
10014                                           (const_string "always")
10015                                           (const_string "conditional")))])
10016
10017 (define_insn "*mov<mode>_ppc64"
10018   [(set (match_operand:TI2 0 "nonimmediate_operand" "=Y,r,r,r")
10019         (match_operand:TI2 1 "input_operand" "r,Y,r,F"))]
10020   "(TARGET_POWERPC64 && VECTOR_MEM_NONE_P (<MODE>mode)
10021    && (gpc_reg_operand (operands[0], <MODE>mode)
10022        || gpc_reg_operand (operands[1], <MODE>mode)))"
10023   "#"
10024   [(set_attr "type" "store,load,*,*")])
10025
10026 (define_split
10027   [(set (match_operand:TI2 0 "int_reg_operand" "")
10028         (match_operand:TI2 1 "const_double_operand" ""))]
10029   "TARGET_POWERPC64
10030    && (VECTOR_MEM_NONE_P (<MODE>mode)
10031        || (reload_completed && INT_REGNO_P (REGNO (operands[0]))))"
10032   [(set (match_dup 2) (match_dup 4))
10033    (set (match_dup 3) (match_dup 5))]
10034   "
10035 {
10036   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10037                                        <MODE>mode);
10038   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10039                                        <MODE>mode);
10040   if (GET_CODE (operands[1]) == CONST_DOUBLE)
10041     {
10042       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
10043       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
10044     }
10045   else if (GET_CODE (operands[1]) == CONST_INT)
10046     {
10047       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
10048       operands[5] = operands[1];
10049     }
10050   else
10051     FAIL;
10052 }")
10053
10054 (define_split
10055   [(set (match_operand:TI2 0 "nonimmediate_operand" "")
10056         (match_operand:TI2 1 "input_operand" ""))]
10057   "reload_completed
10058    && gpr_or_gpr_p (operands[0], operands[1])
10059    && !direct_move_p (operands[0], operands[1])
10060    && !quad_load_store_p (operands[0], operands[1])"
10061   [(pc)]
10062 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10063 \f
10064 (define_expand "load_multiple"
10065   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10066                           (match_operand:SI 1 "" ""))
10067                      (use (match_operand:SI 2 "" ""))])]
10068   "TARGET_STRING && !TARGET_POWERPC64"
10069   "
10070 {
10071   int regno;
10072   int count;
10073   rtx op1;
10074   int i;
10075
10076   /* Support only loading a constant number of fixed-point registers from
10077      memory and only bother with this if more than two; the machine
10078      doesn't support more than eight.  */
10079   if (GET_CODE (operands[2]) != CONST_INT
10080       || INTVAL (operands[2]) <= 2
10081       || INTVAL (operands[2]) > 8
10082       || GET_CODE (operands[1]) != MEM
10083       || GET_CODE (operands[0]) != REG
10084       || REGNO (operands[0]) >= 32)
10085     FAIL;
10086
10087   count = INTVAL (operands[2]);
10088   regno = REGNO (operands[0]);
10089
10090   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
10091   op1 = replace_equiv_address (operands[1],
10092                                force_reg (SImode, XEXP (operands[1], 0)));
10093
10094   for (i = 0; i < count; i++)
10095     XVECEXP (operands[3], 0, i)
10096       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
10097                      adjust_address_nv (op1, SImode, i * 4));
10098 }")
10099
10100 (define_insn "*ldmsi8"
10101   [(match_parallel 0 "load_multiple_operation"
10102     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10103           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10104      (set (match_operand:SI 3 "gpc_reg_operand" "")
10105           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10106      (set (match_operand:SI 4 "gpc_reg_operand" "")
10107           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10108      (set (match_operand:SI 5 "gpc_reg_operand" "")
10109           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10110      (set (match_operand:SI 6 "gpc_reg_operand" "")
10111           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10112      (set (match_operand:SI 7 "gpc_reg_operand" "")
10113           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10114      (set (match_operand:SI 8 "gpc_reg_operand" "")
10115           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
10116      (set (match_operand:SI 9 "gpc_reg_operand" "")
10117           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
10118   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10119   "*
10120 { return rs6000_output_load_multiple (operands); }"
10121   [(set_attr "type" "load_ux")
10122    (set_attr "length" "32")])
10123
10124 (define_insn "*ldmsi7"
10125   [(match_parallel 0 "load_multiple_operation"
10126     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10127           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10128      (set (match_operand:SI 3 "gpc_reg_operand" "")
10129           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10130      (set (match_operand:SI 4 "gpc_reg_operand" "")
10131           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10132      (set (match_operand:SI 5 "gpc_reg_operand" "")
10133           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10134      (set (match_operand:SI 6 "gpc_reg_operand" "")
10135           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10136      (set (match_operand:SI 7 "gpc_reg_operand" "")
10137           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10138      (set (match_operand:SI 8 "gpc_reg_operand" "")
10139           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
10140   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10141   "*
10142 { return rs6000_output_load_multiple (operands); }"
10143   [(set_attr "type" "load_ux")
10144    (set_attr "length" "32")])
10145
10146 (define_insn "*ldmsi6"
10147   [(match_parallel 0 "load_multiple_operation"
10148     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10149           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10150      (set (match_operand:SI 3 "gpc_reg_operand" "")
10151           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10152      (set (match_operand:SI 4 "gpc_reg_operand" "")
10153           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10154      (set (match_operand:SI 5 "gpc_reg_operand" "")
10155           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10156      (set (match_operand:SI 6 "gpc_reg_operand" "")
10157           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10158      (set (match_operand:SI 7 "gpc_reg_operand" "")
10159           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
10160   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10161   "*
10162 { return rs6000_output_load_multiple (operands); }"
10163   [(set_attr "type" "load_ux")
10164    (set_attr "length" "32")])
10165
10166 (define_insn "*ldmsi5"
10167   [(match_parallel 0 "load_multiple_operation"
10168     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10169           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10170      (set (match_operand:SI 3 "gpc_reg_operand" "")
10171           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10172      (set (match_operand:SI 4 "gpc_reg_operand" "")
10173           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10174      (set (match_operand:SI 5 "gpc_reg_operand" "")
10175           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10176      (set (match_operand:SI 6 "gpc_reg_operand" "")
10177           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
10178   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10179   "*
10180 { return rs6000_output_load_multiple (operands); }"
10181   [(set_attr "type" "load_ux")
10182    (set_attr "length" "32")])
10183
10184 (define_insn "*ldmsi4"
10185   [(match_parallel 0 "load_multiple_operation"
10186     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10187           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10188      (set (match_operand:SI 3 "gpc_reg_operand" "")
10189           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10190      (set (match_operand:SI 4 "gpc_reg_operand" "")
10191           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10192      (set (match_operand:SI 5 "gpc_reg_operand" "")
10193           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
10194   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10195   "*
10196 { return rs6000_output_load_multiple (operands); }"
10197   [(set_attr "type" "load_ux")
10198    (set_attr "length" "32")])
10199
10200 (define_insn "*ldmsi3"
10201   [(match_parallel 0 "load_multiple_operation"
10202     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10203           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10204      (set (match_operand:SI 3 "gpc_reg_operand" "")
10205           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10206      (set (match_operand:SI 4 "gpc_reg_operand" "")
10207           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
10208   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
10209   "*
10210 { return rs6000_output_load_multiple (operands); }"
10211   [(set_attr "type" "load_ux")
10212    (set_attr "length" "32")])
10213
10214 (define_expand "store_multiple"
10215   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10216                           (match_operand:SI 1 "" ""))
10217                      (clobber (scratch:SI))
10218                      (use (match_operand:SI 2 "" ""))])]
10219   "TARGET_STRING && !TARGET_POWERPC64"
10220   "
10221 {
10222   int regno;
10223   int count;
10224   rtx to;
10225   rtx op0;
10226   int i;
10227
10228   /* Support only storing a constant number of fixed-point registers to
10229      memory and only bother with this if more than two; the machine
10230      doesn't support more than eight.  */
10231   if (GET_CODE (operands[2]) != CONST_INT
10232       || INTVAL (operands[2]) <= 2
10233       || INTVAL (operands[2]) > 8
10234       || GET_CODE (operands[0]) != MEM
10235       || GET_CODE (operands[1]) != REG
10236       || REGNO (operands[1]) >= 32)
10237     FAIL;
10238
10239   count = INTVAL (operands[2]);
10240   regno = REGNO (operands[1]);
10241
10242   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
10243   to = force_reg (SImode, XEXP (operands[0], 0));
10244   op0 = replace_equiv_address (operands[0], to);
10245
10246   XVECEXP (operands[3], 0, 0)
10247     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
10248   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
10249                                                  gen_rtx_SCRATCH (SImode));
10250
10251   for (i = 1; i < count; i++)
10252     XVECEXP (operands[3], 0, i + 1)
10253       = gen_rtx_SET (VOIDmode,
10254                      adjust_address_nv (op0, SImode, i * 4),
10255                      gen_rtx_REG (SImode, regno + i));
10256 }")
10257
10258 (define_insn "*stmsi8"
10259   [(match_parallel 0 "store_multiple_operation"
10260     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10261           (match_operand:SI 2 "gpc_reg_operand" "r"))
10262      (clobber (match_scratch:SI 3 "=X"))
10263      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10264           (match_operand:SI 4 "gpc_reg_operand" "r"))
10265      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10266           (match_operand:SI 5 "gpc_reg_operand" "r"))
10267      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10268           (match_operand:SI 6 "gpc_reg_operand" "r"))
10269      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10270           (match_operand:SI 7 "gpc_reg_operand" "r"))
10271      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10272           (match_operand:SI 8 "gpc_reg_operand" "r"))
10273      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10274           (match_operand:SI 9 "gpc_reg_operand" "r"))
10275      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10276           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10277   "TARGET_STRING && XVECLEN (operands[0], 0) == 9"
10278   "stswi %2,%1,%O0"
10279   [(set_attr "type" "store_ux")
10280    (set_attr "cell_micro" "always")])
10281
10282 (define_insn "*stmsi7"
10283   [(match_parallel 0 "store_multiple_operation"
10284     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10285           (match_operand:SI 2 "gpc_reg_operand" "r"))
10286      (clobber (match_scratch:SI 3 "=X"))
10287      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10288           (match_operand:SI 4 "gpc_reg_operand" "r"))
10289      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10290           (match_operand:SI 5 "gpc_reg_operand" "r"))
10291      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10292           (match_operand:SI 6 "gpc_reg_operand" "r"))
10293      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10294           (match_operand:SI 7 "gpc_reg_operand" "r"))
10295      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10296           (match_operand:SI 8 "gpc_reg_operand" "r"))
10297      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10298           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10299   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10300   "stswi %2,%1,%O0"
10301   [(set_attr "type" "store_ux")
10302    (set_attr "cell_micro" "always")])
10303
10304 (define_insn "*stmsi6"
10305   [(match_parallel 0 "store_multiple_operation"
10306     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10307           (match_operand:SI 2 "gpc_reg_operand" "r"))
10308      (clobber (match_scratch:SI 3 "=X"))
10309      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10310           (match_operand:SI 4 "gpc_reg_operand" "r"))
10311      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10312           (match_operand:SI 5 "gpc_reg_operand" "r"))
10313      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10314           (match_operand:SI 6 "gpc_reg_operand" "r"))
10315      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10316           (match_operand:SI 7 "gpc_reg_operand" "r"))
10317      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10318           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10319   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10320   "stswi %2,%1,%O0"
10321   [(set_attr "type" "store_ux")
10322    (set_attr "cell_micro" "always")])
10323
10324 (define_insn "*stmsi5"
10325   [(match_parallel 0 "store_multiple_operation"
10326     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10327           (match_operand:SI 2 "gpc_reg_operand" "r"))
10328      (clobber (match_scratch:SI 3 "=X"))
10329      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10330           (match_operand:SI 4 "gpc_reg_operand" "r"))
10331      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10332           (match_operand:SI 5 "gpc_reg_operand" "r"))
10333      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10334           (match_operand:SI 6 "gpc_reg_operand" "r"))
10335      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10336           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10337   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10338   "stswi %2,%1,%O0"
10339   [(set_attr "type" "store_ux")
10340    (set_attr "cell_micro" "always")])
10341
10342 (define_insn "*stmsi4"
10343   [(match_parallel 0 "store_multiple_operation"
10344     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10345           (match_operand:SI 2 "gpc_reg_operand" "r"))
10346      (clobber (match_scratch:SI 3 "=X"))
10347      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10348           (match_operand:SI 4 "gpc_reg_operand" "r"))
10349      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10350           (match_operand:SI 5 "gpc_reg_operand" "r"))
10351      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10352           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10353   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10354   "stswi %2,%1,%O0"
10355   [(set_attr "type" "store_ux")
10356    (set_attr "cell_micro" "always")])
10357
10358 (define_insn "*stmsi3"
10359   [(match_parallel 0 "store_multiple_operation"
10360     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10361           (match_operand:SI 2 "gpc_reg_operand" "r"))
10362      (clobber (match_scratch:SI 3 "=X"))
10363      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10364           (match_operand:SI 4 "gpc_reg_operand" "r"))
10365      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10366           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10367   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10368   "stswi %2,%1,%O0"
10369   [(set_attr "type" "store_ux")
10370    (set_attr "cell_micro" "always")])
10371 \f
10372 (define_expand "setmemsi"
10373   [(parallel [(set (match_operand:BLK 0 "" "")
10374                    (match_operand 2 "const_int_operand" ""))
10375               (use (match_operand:SI 1 "" ""))
10376               (use (match_operand:SI 3 "" ""))])]
10377   ""
10378   "
10379 {
10380   /* If value to set is not zero, use the library routine.  */
10381   if (operands[2] != const0_rtx)
10382     FAIL;
10383
10384   if (expand_block_clear (operands))
10385     DONE;
10386   else
10387     FAIL;
10388 }")
10389
10390 ;; String/block move insn.
10391 ;; Argument 0 is the destination
10392 ;; Argument 1 is the source
10393 ;; Argument 2 is the length
10394 ;; Argument 3 is the alignment
10395
10396 (define_expand "movmemsi"
10397   [(parallel [(set (match_operand:BLK 0 "" "")
10398                    (match_operand:BLK 1 "" ""))
10399               (use (match_operand:SI 2 "" ""))
10400               (use (match_operand:SI 3 "" ""))])]
10401   ""
10402   "
10403 {
10404   if (expand_block_move (operands))
10405     DONE;
10406   else
10407     FAIL;
10408 }")
10409
10410 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
10411 ;; register allocator doesn't have a clue about allocating 8 word registers.
10412 ;; rD/rS = r5 is preferred, efficient form.
10413 (define_expand "movmemsi_8reg"
10414   [(parallel [(set (match_operand 0 "" "")
10415                    (match_operand 1 "" ""))
10416               (use (match_operand 2 "" ""))
10417               (use (match_operand 3 "" ""))
10418               (clobber (reg:SI  5))
10419               (clobber (reg:SI  6))
10420               (clobber (reg:SI  7))
10421               (clobber (reg:SI  8))
10422               (clobber (reg:SI  9))
10423               (clobber (reg:SI 10))
10424               (clobber (reg:SI 11))
10425               (clobber (reg:SI 12))
10426               (clobber (match_scratch:SI 4 ""))])]
10427   "TARGET_STRING"
10428   "")
10429
10430 (define_insn ""
10431   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10432         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10433    (use (match_operand:SI 2 "immediate_operand" "i"))
10434    (use (match_operand:SI 3 "immediate_operand" "i"))
10435    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10436    (clobber (reg:SI  6))
10437    (clobber (reg:SI  7))
10438    (clobber (reg:SI  8))
10439    (clobber (reg:SI  9))
10440    (clobber (reg:SI 10))
10441    (clobber (reg:SI 11))
10442    (clobber (reg:SI 12))
10443    (clobber (match_scratch:SI 5 "=X"))]
10444   "TARGET_STRING
10445    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10446        || INTVAL (operands[2]) == 0)
10447    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10448    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10449    && REGNO (operands[4]) == 5"
10450   "lswi %4,%1,%2\;stswi %4,%0,%2"
10451   [(set_attr "type" "store_ux")
10452    (set_attr "cell_micro" "always")
10453    (set_attr "length" "8")])
10454
10455 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
10456 ;; register allocator doesn't have a clue about allocating 6 word registers.
10457 ;; rD/rS = r5 is preferred, efficient form.
10458 (define_expand "movmemsi_6reg"
10459   [(parallel [(set (match_operand 0 "" "")
10460                    (match_operand 1 "" ""))
10461               (use (match_operand 2 "" ""))
10462               (use (match_operand 3 "" ""))
10463               (clobber (reg:SI  5))
10464               (clobber (reg:SI  6))
10465               (clobber (reg:SI  7))
10466               (clobber (reg:SI  8))
10467               (clobber (reg:SI  9))
10468               (clobber (reg:SI 10))
10469               (clobber (match_scratch:SI 4 ""))])]
10470   "TARGET_STRING"
10471   "")
10472
10473 (define_insn ""
10474   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10475         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10476    (use (match_operand:SI 2 "immediate_operand" "i"))
10477    (use (match_operand:SI 3 "immediate_operand" "i"))
10478    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10479    (clobber (reg:SI  6))
10480    (clobber (reg:SI  7))
10481    (clobber (reg:SI  8))
10482    (clobber (reg:SI  9))
10483    (clobber (reg:SI 10))
10484    (clobber (match_scratch:SI 5 "=X"))]
10485   "TARGET_STRING
10486    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
10487    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10488    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10489    && REGNO (operands[4]) == 5"
10490   "lswi %4,%1,%2\;stswi %4,%0,%2"
10491   [(set_attr "type" "store_ux")
10492    (set_attr "cell_micro" "always")
10493    (set_attr "length" "8")])
10494
10495 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
10496 ;; problems with TImode.
10497 ;; rD/rS = r5 is preferred, efficient form.
10498 (define_expand "movmemsi_4reg"
10499   [(parallel [(set (match_operand 0 "" "")
10500                    (match_operand 1 "" ""))
10501               (use (match_operand 2 "" ""))
10502               (use (match_operand 3 "" ""))
10503               (clobber (reg:SI 5))
10504               (clobber (reg:SI 6))
10505               (clobber (reg:SI 7))
10506               (clobber (reg:SI 8))
10507               (clobber (match_scratch:SI 4 ""))])]
10508   "TARGET_STRING"
10509   "")
10510
10511 (define_insn ""
10512   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10513         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10514    (use (match_operand:SI 2 "immediate_operand" "i"))
10515    (use (match_operand:SI 3 "immediate_operand" "i"))
10516    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10517    (clobber (reg:SI 6))
10518    (clobber (reg:SI 7))
10519    (clobber (reg:SI 8))
10520    (clobber (match_scratch:SI 5 "=X"))]
10521   "TARGET_STRING
10522    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
10523    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
10524    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
10525    && REGNO (operands[4]) == 5"
10526   "lswi %4,%1,%2\;stswi %4,%0,%2"
10527   [(set_attr "type" "store_ux")
10528    (set_attr "cell_micro" "always")
10529    (set_attr "length" "8")])
10530
10531 ;; Move up to 8 bytes at a time.
10532 (define_expand "movmemsi_2reg"
10533   [(parallel [(set (match_operand 0 "" "")
10534                    (match_operand 1 "" ""))
10535               (use (match_operand 2 "" ""))
10536               (use (match_operand 3 "" ""))
10537               (clobber (match_scratch:DI 4 ""))
10538               (clobber (match_scratch:SI 5 ""))])]
10539   "TARGET_STRING && ! TARGET_POWERPC64"
10540   "")
10541
10542 (define_insn ""
10543   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10544         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10545    (use (match_operand:SI 2 "immediate_operand" "i"))
10546    (use (match_operand:SI 3 "immediate_operand" "i"))
10547    (clobber (match_scratch:DI 4 "=&r"))
10548    (clobber (match_scratch:SI 5 "=X"))]
10549   "TARGET_STRING && ! TARGET_POWERPC64
10550    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
10551   "lswi %4,%1,%2\;stswi %4,%0,%2"
10552   [(set_attr "type" "store_ux")
10553    (set_attr "cell_micro" "always")
10554    (set_attr "length" "8")])
10555
10556 ;; Move up to 4 bytes at a time.
10557 (define_expand "movmemsi_1reg"
10558   [(parallel [(set (match_operand 0 "" "")
10559                    (match_operand 1 "" ""))
10560               (use (match_operand 2 "" ""))
10561               (use (match_operand 3 "" ""))
10562               (clobber (match_scratch:SI 4 ""))
10563               (clobber (match_scratch:SI 5 ""))])]
10564   "TARGET_STRING"
10565   "")
10566
10567 (define_insn ""
10568   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10569         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10570    (use (match_operand:SI 2 "immediate_operand" "i"))
10571    (use (match_operand:SI 3 "immediate_operand" "i"))
10572    (clobber (match_scratch:SI 4 "=&r"))
10573    (clobber (match_scratch:SI 5 "=X"))]
10574   "TARGET_STRING && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
10575   "lswi %4,%1,%2\;stswi %4,%0,%2"
10576   [(set_attr "type" "store_ux")
10577    (set_attr "cell_micro" "always")
10578    (set_attr "length" "8")])
10579 \f
10580 ;; Define insns that do load or store with update.  Some of these we can
10581 ;; get by using pre-decrement or pre-increment, but the hardware can also
10582 ;; do cases where the increment is not the size of the object.
10583 ;;
10584 ;; In all these cases, we use operands 0 and 1 for the register being
10585 ;; incremented because those are the operands that local-alloc will
10586 ;; tie and these are the pair most likely to be tieable (and the ones
10587 ;; that will benefit the most).
10588
10589 (define_insn "*movdi_update1"
10590   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
10591         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
10592                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
10593    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
10594         (plus:DI (match_dup 1) (match_dup 2)))]
10595   "TARGET_POWERPC64 && TARGET_UPDATE
10596    && (!avoiding_indexed_address_p (DImode)
10597        || !gpc_reg_operand (operands[2], DImode))"
10598   "@
10599    ldux %3,%0,%2
10600    ldu %3,%2(%0)"
10601   [(set_attr "type" "load_ux,load_u")])
10602
10603 (define_insn "movdi_<mode>_update"
10604   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10605                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10606         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10607    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10608         (plus:P (match_dup 1) (match_dup 2)))]
10609   "TARGET_POWERPC64 && TARGET_UPDATE
10610    && (!avoiding_indexed_address_p (Pmode)
10611        || !gpc_reg_operand (operands[2], Pmode)
10612        || (REG_P (operands[0])
10613            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10614   "@
10615    stdux %3,%0,%2
10616    stdu %3,%2(%0)"
10617   [(set_attr "type" "store_ux,store_u")])
10618
10619 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
10620 ;; needed for stack allocation, even if the user passes -mno-update.
10621 (define_insn "movdi_<mode>_update_stack"
10622   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10623                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10624         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10625    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10626         (plus:P (match_dup 1) (match_dup 2)))]
10627   "TARGET_POWERPC64"
10628   "@
10629    stdux %3,%0,%2
10630    stdu %3,%2(%0)"
10631   [(set_attr "type" "store_ux,store_u")])
10632
10633 (define_insn "*movsi_update1"
10634   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10635         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10636                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10637    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10638         (plus:SI (match_dup 1) (match_dup 2)))]
10639   "TARGET_UPDATE
10640    && (!avoiding_indexed_address_p (SImode)
10641        || !gpc_reg_operand (operands[2], SImode))"
10642   "@
10643    lwzux %3,%0,%2
10644    lwzu %3,%2(%0)"
10645   [(set_attr "type" "load_ux,load_u")])
10646
10647 (define_insn "*movsi_update2"
10648   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
10649         (sign_extend:DI
10650          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
10651                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
10652    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
10653         (plus:DI (match_dup 1) (match_dup 2)))]
10654   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
10655    && !avoiding_indexed_address_p (DImode)"
10656   "lwaux %3,%0,%2"
10657   [(set_attr "type" "load_ext_ux")])
10658
10659 (define_insn "movsi_update"
10660   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10661                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10662         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10663    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10664         (plus:SI (match_dup 1) (match_dup 2)))]
10665   "TARGET_UPDATE
10666    && (!avoiding_indexed_address_p (SImode)
10667        || !gpc_reg_operand (operands[2], SImode)
10668        || (REG_P (operands[0])
10669            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10670   "@
10671    stwux %3,%0,%2
10672    stwu %3,%2(%0)"
10673   [(set_attr "type" "store_ux,store_u")])
10674
10675 ;; This is an unconditional pattern; needed for stack allocation, even
10676 ;; if the user passes -mno-update.
10677 (define_insn "movsi_update_stack"
10678   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10679                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10680         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10681    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10682         (plus:SI (match_dup 1) (match_dup 2)))]
10683   ""
10684   "@
10685    stwux %3,%0,%2
10686    stwu %3,%2(%0)"
10687   [(set_attr "type" "store_ux,store_u")])
10688
10689 (define_insn "*movhi_update1"
10690   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
10691         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10692                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10693    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10694         (plus:SI (match_dup 1) (match_dup 2)))]
10695   "TARGET_UPDATE
10696    && (!avoiding_indexed_address_p (SImode)
10697        || !gpc_reg_operand (operands[2], SImode))"
10698   "@
10699    lhzux %3,%0,%2
10700    lhzu %3,%2(%0)"
10701   [(set_attr "type" "load_ux,load_u")])
10702
10703 (define_insn "*movhi_update2"
10704   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10705         (zero_extend:SI
10706          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10707                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10708    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10709         (plus:SI (match_dup 1) (match_dup 2)))]
10710   "TARGET_UPDATE
10711    && (!avoiding_indexed_address_p (SImode)
10712        || !gpc_reg_operand (operands[2], SImode))"
10713   "@
10714    lhzux %3,%0,%2
10715    lhzu %3,%2(%0)"
10716   [(set_attr "type" "load_ux,load_u")])
10717
10718 (define_insn "*movhi_update3"
10719   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10720         (sign_extend:SI
10721          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10722                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10723    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10724         (plus:SI (match_dup 1) (match_dup 2)))]
10725   "TARGET_UPDATE && rs6000_gen_cell_microcode
10726    && (!avoiding_indexed_address_p (SImode)
10727        || !gpc_reg_operand (operands[2], SImode))"
10728   "@
10729    lhaux %3,%0,%2
10730    lhau %3,%2(%0)"
10731   [(set_attr "type" "load_ext_ux,load_ext_u")])
10732
10733 (define_insn "*movhi_update4"
10734   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10735                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10736         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
10737    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10738         (plus:SI (match_dup 1) (match_dup 2)))]
10739   "TARGET_UPDATE
10740    && (!avoiding_indexed_address_p (SImode)
10741        || !gpc_reg_operand (operands[2], SImode))"
10742   "@
10743    sthux %3,%0,%2
10744    sthu %3,%2(%0)"
10745   [(set_attr "type" "store_ux,store_u")])
10746
10747 (define_insn "*movqi_update1"
10748   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
10749         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10750                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10751    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10752         (plus:SI (match_dup 1) (match_dup 2)))]
10753   "TARGET_UPDATE
10754    && (!avoiding_indexed_address_p (SImode)
10755        || !gpc_reg_operand (operands[2], SImode))"
10756   "@
10757    lbzux %3,%0,%2
10758    lbzu %3,%2(%0)"
10759   [(set_attr "type" "load_ux,load_u")])
10760
10761 (define_insn "*movqi_update2"
10762   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10763         (zero_extend:SI
10764          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10765                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10766    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10767         (plus:SI (match_dup 1) (match_dup 2)))]
10768   "TARGET_UPDATE
10769    && (!avoiding_indexed_address_p (SImode)
10770        || !gpc_reg_operand (operands[2], SImode))"
10771   "@
10772    lbzux %3,%0,%2
10773    lbzu %3,%2(%0)"
10774   [(set_attr "type" "load_ux,load_u")])
10775
10776 (define_insn "*movqi_update3"
10777   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10778                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10779         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
10780    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10781         (plus:SI (match_dup 1) (match_dup 2)))]
10782   "TARGET_UPDATE
10783    && (!avoiding_indexed_address_p (SImode)
10784        || !gpc_reg_operand (operands[2], SImode))"
10785   "@
10786    stbux %3,%0,%2
10787    stbu %3,%2(%0)"
10788   [(set_attr "type" "store_ux,store_u")])
10789
10790 (define_insn "*movsf_update1"
10791   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
10792         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10793                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10794    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10795         (plus:SI (match_dup 1) (match_dup 2)))]
10796   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10797    && (!avoiding_indexed_address_p (SImode)
10798        || !gpc_reg_operand (operands[2], SImode))"
10799   "@
10800    lfsux %3,%0,%2
10801    lfsu %3,%2(%0)"
10802   [(set_attr "type" "fpload_ux,fpload_u")])
10803
10804 (define_insn "*movsf_update2"
10805   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10806                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10807         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
10808    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10809         (plus:SI (match_dup 1) (match_dup 2)))]
10810   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10811    && (!avoiding_indexed_address_p (SImode)
10812        || !gpc_reg_operand (operands[2], SImode))"
10813   "@
10814    stfsux %3,%0,%2
10815    stfsu %3,%2(%0)"
10816   [(set_attr "type" "fpstore_ux,fpstore_u")])
10817
10818 (define_insn "*movsf_update3"
10819   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
10820         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10821                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10822    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10823         (plus:SI (match_dup 1) (match_dup 2)))]
10824   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
10825    && (!avoiding_indexed_address_p (SImode)
10826        || !gpc_reg_operand (operands[2], SImode))"
10827   "@
10828    lwzux %3,%0,%2
10829    lwzu %3,%2(%0)"
10830   [(set_attr "type" "load_ux,load_u")])
10831
10832 (define_insn "*movsf_update4"
10833   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10834                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10835         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
10836    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10837         (plus:SI (match_dup 1) (match_dup 2)))]
10838   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
10839    && (!avoiding_indexed_address_p (SImode)
10840        || !gpc_reg_operand (operands[2], SImode))"
10841   "@
10842    stwux %3,%0,%2
10843    stwu %3,%2(%0)"
10844   [(set_attr "type" "store_ux,store_u")])
10845
10846 (define_insn "*movdf_update1"
10847   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
10848         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10849                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10850    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10851         (plus:SI (match_dup 1) (match_dup 2)))]
10852   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
10853    && (!avoiding_indexed_address_p (SImode)
10854        || !gpc_reg_operand (operands[2], SImode))"
10855   "@
10856    lfdux %3,%0,%2
10857    lfdu %3,%2(%0)"
10858   [(set_attr "type" "fpload_ux,fpload_u")])
10859
10860 (define_insn "*movdf_update2"
10861   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10862                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10863         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
10864    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10865         (plus:SI (match_dup 1) (match_dup 2)))]
10866   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
10867    && (!avoiding_indexed_address_p (SImode)
10868        || !gpc_reg_operand (operands[2], SImode))"
10869   "@
10870    stfdux %3,%0,%2
10871    stfdu %3,%2(%0)"
10872   [(set_attr "type" "fpstore_ux,fpstore_u")])
10873
10874
10875 ;; After inserting conditional returns we can sometimes have
10876 ;; unnecessary register moves.  Unfortunately we cannot have a
10877 ;; modeless peephole here, because some single SImode sets have early
10878 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
10879 ;; sequences, using get_attr_length here will smash the operands
10880 ;; array.  Neither is there an early_cobbler_p predicate.
10881 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
10882 (define_peephole2
10883   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10884         (match_operand:DF 1 "any_operand" ""))
10885    (set (match_operand:DF 2 "gpc_reg_operand" "")
10886         (match_dup 0))]
10887   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
10888    && peep2_reg_dead_p (2, operands[0])"
10889   [(set (match_dup 2) (match_dup 1))])
10890
10891 (define_peephole2
10892   [(set (match_operand:SF 0 "gpc_reg_operand" "")
10893         (match_operand:SF 1 "any_operand" ""))
10894    (set (match_operand:SF 2 "gpc_reg_operand" "")
10895         (match_dup 0))]
10896   "peep2_reg_dead_p (2, operands[0])"
10897   [(set (match_dup 2) (match_dup 1))])
10898
10899 \f
10900 ;; TLS support.
10901
10902 ;; Mode attributes for different ABIs.
10903 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
10904 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
10905 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
10906 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
10907
10908 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
10909   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10910         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
10911               (match_operand 4 "" "g")))
10912    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10913                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10914                    UNSPEC_TLSGD)
10915    (clobber (reg:SI LR_REGNO))]
10916   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
10917 {
10918   if (TARGET_CMODEL != CMODEL_SMALL)
10919     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;"
10920            "bl %z3\;nop";
10921   else
10922     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;nop";
10923 }
10924   "&& TARGET_TLS_MARKERS"
10925   [(set (match_dup 0)
10926         (unspec:TLSmode [(match_dup 1)
10927                          (match_dup 2)]
10928                         UNSPEC_TLSGD))
10929    (parallel [(set (match_dup 0)
10930                    (call (mem:TLSmode (match_dup 3))
10931                          (match_dup 4)))
10932               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
10933               (clobber (reg:SI LR_REGNO))])]
10934   ""
10935   [(set_attr "type" "two")
10936    (set (attr "length")
10937      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10938                    (const_int 16)
10939                    (const_int 12)))])
10940
10941 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
10942   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10943         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
10944               (match_operand 4 "" "g")))
10945    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10946                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10947                    UNSPEC_TLSGD)
10948    (clobber (reg:SI LR_REGNO))]
10949   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
10950 {
10951   if (flag_pic)
10952     {
10953       if (TARGET_SECURE_PLT && flag_pic == 2)
10954         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
10955       else
10956         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
10957     }
10958   else
10959     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
10960 }
10961   "&& TARGET_TLS_MARKERS"
10962   [(set (match_dup 0)
10963         (unspec:TLSmode [(match_dup 1)
10964                          (match_dup 2)]
10965                         UNSPEC_TLSGD))
10966    (parallel [(set (match_dup 0)
10967                    (call (mem:TLSmode (match_dup 3))
10968                          (match_dup 4)))
10969               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
10970               (clobber (reg:SI LR_REGNO))])]
10971   ""
10972   [(set_attr "type" "two")
10973    (set_attr "length" "8")])
10974
10975 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
10976   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10977         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10978                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10979                         UNSPEC_TLSGD))]
10980   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
10981   "addi %0,%1,%2@got@tlsgd"
10982   "&& TARGET_CMODEL != CMODEL_SMALL"
10983   [(set (match_dup 3)
10984         (high:TLSmode
10985             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))
10986    (set (match_dup 0)
10987         (lo_sum:TLSmode (match_dup 3)
10988             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)))]
10989   "
10990 {
10991   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
10992 }"
10993   [(set (attr "length")
10994      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10995                    (const_int 8)
10996                    (const_int 4)))])
10997
10998 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
10999   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11000      (high:TLSmode
11001        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11002                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11003                        UNSPEC_TLSGD)))]
11004   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11005   "addis %0,%1,%2@got@tlsgd@ha"
11006   [(set_attr "length" "4")])
11007
11008 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
11009   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11010      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11011        (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11012                        UNSPEC_TLSGD)))]
11013   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11014   "addi %0,%1,%2@got@tlsgd@l"
11015   [(set_attr "length" "4")])
11016
11017 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
11018   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11019         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11020               (match_operand 2 "" "g")))
11021    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11022                    UNSPEC_TLSGD)
11023    (clobber (reg:SI LR_REGNO))]
11024   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11025   "bl %z1(%3@tlsgd)\;nop"
11026   [(set_attr "type" "branch")
11027    (set_attr "length" "8")])
11028
11029 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
11030   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11031         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11032               (match_operand 2 "" "g")))
11033    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11034                    UNSPEC_TLSGD)
11035    (clobber (reg:SI LR_REGNO))]
11036   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11037 {
11038   if (flag_pic)
11039     {
11040       if (TARGET_SECURE_PLT && flag_pic == 2)
11041         return "bl %z1+32768(%3@tlsgd)@plt";
11042       return "bl %z1(%3@tlsgd)@plt";
11043     }
11044   return "bl %z1(%3@tlsgd)";
11045 }
11046   [(set_attr "type" "branch")
11047    (set_attr "length" "4")])
11048
11049 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
11050   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11051         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11052               (match_operand 3 "" "g")))
11053    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11054                    UNSPEC_TLSLD)
11055    (clobber (reg:SI LR_REGNO))]
11056   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
11057 {
11058   if (TARGET_CMODEL != CMODEL_SMALL)
11059     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;"
11060            "bl %z2\;nop";
11061   else
11062     return "addi %0,%1,%&@got@tlsld\;bl %z2\;nop";
11063 }
11064   "&& TARGET_TLS_MARKERS"
11065   [(set (match_dup 0)
11066         (unspec:TLSmode [(match_dup 1)]
11067                         UNSPEC_TLSLD))
11068    (parallel [(set (match_dup 0)
11069                    (call (mem:TLSmode (match_dup 2))
11070                          (match_dup 3)))
11071               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11072               (clobber (reg:SI LR_REGNO))])]
11073   ""
11074   [(set_attr "type" "two")
11075    (set (attr "length")
11076      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11077                    (const_int 16)
11078                    (const_int 12)))])
11079
11080 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
11081   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11082         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11083               (match_operand 3 "" "g")))
11084    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11085                    UNSPEC_TLSLD)
11086    (clobber (reg:SI LR_REGNO))]
11087   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11088 {
11089   if (flag_pic)
11090     {
11091       if (TARGET_SECURE_PLT && flag_pic == 2)
11092         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11093       else
11094         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11095     }
11096   else
11097     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11098 }
11099   "&& TARGET_TLS_MARKERS"
11100   [(set (match_dup 0)
11101         (unspec:TLSmode [(match_dup 1)]
11102                         UNSPEC_TLSLD))
11103    (parallel [(set (match_dup 0)
11104                    (call (mem:TLSmode (match_dup 2))
11105                          (match_dup 3)))
11106               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11107               (clobber (reg:SI LR_REGNO))])]
11108   ""
11109   [(set_attr "length" "8")])
11110
11111 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
11112   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11113         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11114                         UNSPEC_TLSLD))]
11115   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11116   "addi %0,%1,%&@got@tlsld"
11117   "&& TARGET_CMODEL != CMODEL_SMALL"
11118   [(set (match_dup 2)
11119         (high:TLSmode
11120             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))
11121    (set (match_dup 0)
11122         (lo_sum:TLSmode (match_dup 2)
11123             (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
11124   "
11125 {
11126   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11127 }"
11128   [(set (attr "length")
11129      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11130                    (const_int 8)
11131                    (const_int 4)))])
11132
11133 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
11134   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11135      (high:TLSmode
11136        (unspec:TLSmode [(const_int 0)
11137                         (match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11138                        UNSPEC_TLSLD)))]
11139   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11140   "addis %0,%1,%&@got@tlsld@ha"
11141   [(set_attr "length" "4")])
11142
11143 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
11144   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11145      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11146        (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
11147   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11148   "addi %0,%1,%&@got@tlsld@l"
11149   [(set_attr "length" "4")])
11150
11151 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11152   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11153         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11154               (match_operand 2 "" "g")))
11155    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11156    (clobber (reg:SI LR_REGNO))]
11157   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
11158   "bl %z1(%&@tlsld)\;nop"
11159   [(set_attr "type" "branch")
11160    (set_attr "length" "8")])
11161
11162 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11163   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11164         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11165               (match_operand 2 "" "g")))
11166    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11167    (clobber (reg:SI LR_REGNO))]
11168   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11169 {
11170   if (flag_pic)
11171     {
11172       if (TARGET_SECURE_PLT && flag_pic == 2)
11173         return "bl %z1+32768(%&@tlsld)@plt";
11174       return "bl %z1(%&@tlsld)@plt";
11175     }
11176   return "bl %z1(%&@tlsld)";
11177 }
11178   [(set_attr "type" "branch")
11179    (set_attr "length" "4")])
11180
11181 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11182   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11183         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11184                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11185                         UNSPEC_TLSDTPREL))]
11186   "HAVE_AS_TLS"
11187   "addi %0,%1,%2@dtprel")
11188
11189 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11190   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11191         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11192                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11193                         UNSPEC_TLSDTPRELHA))]
11194   "HAVE_AS_TLS"
11195   "addis %0,%1,%2@dtprel@ha")
11196
11197 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11198   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11199         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11200                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11201                         UNSPEC_TLSDTPRELLO))]
11202   "HAVE_AS_TLS"
11203   "addi %0,%1,%2@dtprel@l")
11204
11205 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11206   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11207         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11208                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11209                         UNSPEC_TLSGOTDTPREL))]
11210   "HAVE_AS_TLS"
11211   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
11212   "&& TARGET_CMODEL != CMODEL_SMALL"
11213   [(set (match_dup 3)
11214         (high:TLSmode
11215             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))
11216    (set (match_dup 0)
11217         (lo_sum:TLSmode (match_dup 3)
11218             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
11219   "
11220 {
11221   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11222 }"
11223   [(set (attr "length")
11224      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11225                    (const_int 8)
11226                    (const_int 4)))])
11227
11228 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
11229   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11230      (high:TLSmode
11231        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11232                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11233                        UNSPEC_TLSGOTDTPREL)))]
11234   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11235   "addis %0,%1,%2@got@dtprel@ha"
11236   [(set_attr "length" "4")])
11237
11238 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
11239   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11240      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11241          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11242                          UNSPEC_TLSGOTDTPREL)))]
11243   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11244   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
11245   [(set_attr "length" "4")])
11246
11247 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11248   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11249         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11250                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11251                         UNSPEC_TLSTPREL))]
11252   "HAVE_AS_TLS"
11253   "addi %0,%1,%2@tprel")
11254
11255 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11256   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11257         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11258                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11259                         UNSPEC_TLSTPRELHA))]
11260   "HAVE_AS_TLS"
11261   "addis %0,%1,%2@tprel@ha")
11262
11263 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11264   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11265         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11266                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11267                         UNSPEC_TLSTPRELLO))]
11268   "HAVE_AS_TLS"
11269   "addi %0,%1,%2@tprel@l")
11270
11271 ;; "b" output constraint here and on tls_tls input to support linker tls
11272 ;; optimization.  The linker may edit the instructions emitted by a
11273 ;; tls_got_tprel/tls_tls pair to addis,addi.
11274 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11275   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11276         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11277                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11278                         UNSPEC_TLSGOTTPREL))]
11279   "HAVE_AS_TLS"
11280   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
11281   "&& TARGET_CMODEL != CMODEL_SMALL"
11282   [(set (match_dup 3)
11283         (high:TLSmode
11284             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))
11285    (set (match_dup 0)
11286         (lo_sum:TLSmode (match_dup 3)
11287             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL)))]
11288   "
11289 {
11290   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11291 }"
11292   [(set (attr "length")
11293      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11294                    (const_int 8)
11295                    (const_int 4)))])
11296
11297 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
11298   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11299      (high:TLSmode
11300        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11301                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11302                        UNSPEC_TLSGOTTPREL)))]
11303   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11304   "addis %0,%1,%2@got@tprel@ha"
11305   [(set_attr "length" "4")])
11306
11307 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
11308   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11309      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11310          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11311                          UNSPEC_TLSGOTTPREL)))]
11312   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11313   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
11314   [(set_attr "length" "4")])
11315
11316 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11317   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11318         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11319                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11320                         UNSPEC_TLSTLS))]
11321   "TARGET_ELF && HAVE_AS_TLS"
11322   "add %0,%1,%2@tls")
11323
11324 (define_expand "tls_get_tpointer"
11325   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11326         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))]
11327   "TARGET_XCOFF && HAVE_AS_TLS"
11328   "
11329 {
11330   emit_insn (gen_tls_get_tpointer_internal ());
11331   emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
11332   DONE;
11333 }")
11334
11335 (define_insn "tls_get_tpointer_internal"
11336   [(set (reg:SI 3)
11337         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))
11338    (clobber (reg:SI LR_REGNO))]
11339   "TARGET_XCOFF && HAVE_AS_TLS"
11340   "bla __get_tpointer")
11341
11342 (define_expand "tls_get_addr<mode>"
11343   [(set (match_operand:P 0 "gpc_reg_operand" "")
11344         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "")
11345                    (match_operand:P 2 "gpc_reg_operand" "")] UNSPEC_TLSTLS))]
11346   "TARGET_XCOFF && HAVE_AS_TLS"
11347   "
11348 {
11349   emit_move_insn (gen_rtx_REG (Pmode, 3), operands[1]);
11350   emit_move_insn (gen_rtx_REG (Pmode, 4), operands[2]);
11351   emit_insn (gen_tls_get_addr_internal<mode> ());
11352   emit_move_insn (operands[0], gen_rtx_REG (Pmode, 3));
11353   DONE;
11354 }")
11355
11356 (define_insn "tls_get_addr_internal<mode>"
11357   [(set (reg:P 3)
11358         (unspec:P [(reg:P 3) (reg:P 4)] UNSPEC_TLSTLS))
11359    (clobber (reg:P 0))
11360    (clobber (reg:P 4))
11361    (clobber (reg:P 5))
11362    (clobber (reg:P 11))
11363    (clobber (reg:CC CR0_REGNO))
11364    (clobber (reg:P LR_REGNO))]
11365   "TARGET_XCOFF && HAVE_AS_TLS"
11366   "bla __tls_get_addr")
11367 \f
11368 ;; Next come insns related to the calling sequence.
11369 ;;
11370 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11371 ;; We move the back-chain and decrement the stack pointer.
11372
11373 (define_expand "allocate_stack"
11374   [(set (match_operand 0 "gpc_reg_operand" "")
11375         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11376    (set (reg 1)
11377         (minus (reg 1) (match_dup 1)))]
11378   ""
11379   "
11380 { rtx chain = gen_reg_rtx (Pmode);
11381   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11382   rtx neg_op0;
11383   rtx insn, par, set, mem;
11384
11385   emit_move_insn (chain, stack_bot);
11386
11387   /* Check stack bounds if necessary.  */
11388   if (crtl->limit_stack)
11389     {
11390       rtx available;
11391       available = expand_binop (Pmode, sub_optab,
11392                                 stack_pointer_rtx, stack_limit_rtx,
11393                                 NULL_RTX, 1, OPTAB_WIDEN);
11394       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11395     }
11396
11397   if (GET_CODE (operands[1]) != CONST_INT
11398       || INTVAL (operands[1]) < -32767
11399       || INTVAL (operands[1]) > 32768)
11400     {
11401       neg_op0 = gen_reg_rtx (Pmode);
11402       if (TARGET_32BIT)
11403         emit_insn (gen_negsi2 (neg_op0, operands[1]));
11404       else
11405         emit_insn (gen_negdi2 (neg_op0, operands[1]));
11406     }
11407   else
11408     neg_op0 = GEN_INT (- INTVAL (operands[1]));
11409
11410   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
11411                                        : gen_movdi_di_update_stack))
11412                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
11413                          chain));
11414   /* Since we didn't use gen_frame_mem to generate the MEM, grab
11415      it now and set the alias set/attributes. The above gen_*_update
11416      calls will generate a PARALLEL with the MEM set being the first
11417      operation. */
11418   par = PATTERN (insn);
11419   gcc_assert (GET_CODE (par) == PARALLEL);
11420   set = XVECEXP (par, 0, 0);
11421   gcc_assert (GET_CODE (set) == SET);
11422   mem = SET_DEST (set);
11423   gcc_assert (MEM_P (mem));
11424   MEM_NOTRAP_P (mem) = 1;
11425   set_mem_alias_set (mem, get_frame_alias_set ());
11426
11427   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
11428   DONE;
11429 }")
11430
11431 ;; These patterns say how to save and restore the stack pointer.  We need not
11432 ;; save the stack pointer at function level since we are careful to
11433 ;; preserve the backchain.  At block level, we have to restore the backchain
11434 ;; when we restore the stack pointer.
11435 ;;
11436 ;; For nonlocal gotos, we must save both the stack pointer and its
11437 ;; backchain and restore both.  Note that in the nonlocal case, the
11438 ;; save area is a memory location.
11439
11440 (define_expand "save_stack_function"
11441   [(match_operand 0 "any_operand" "")
11442    (match_operand 1 "any_operand" "")]
11443   ""
11444   "DONE;")
11445
11446 (define_expand "restore_stack_function"
11447   [(match_operand 0 "any_operand" "")
11448    (match_operand 1 "any_operand" "")]
11449   ""
11450   "DONE;")
11451
11452 ;; Adjust stack pointer (op0) to a new value (op1).
11453 ;; First copy old stack backchain to new location, and ensure that the
11454 ;; scheduler won't reorder the sp assignment before the backchain write.
11455 (define_expand "restore_stack_block"
11456   [(set (match_dup 2) (match_dup 3))
11457    (set (match_dup 4) (match_dup 2))
11458    (match_dup 5)
11459    (set (match_operand 0 "register_operand" "")
11460         (match_operand 1 "register_operand" ""))]
11461   ""
11462   "
11463 {
11464   rtvec p;
11465
11466   operands[1] = force_reg (Pmode, operands[1]);
11467   operands[2] = gen_reg_rtx (Pmode);
11468   operands[3] = gen_frame_mem (Pmode, operands[0]);
11469   operands[4] = gen_frame_mem (Pmode, operands[1]);
11470   p = rtvec_alloc (1);
11471   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
11472                                   gen_frame_mem (BLKmode, operands[0]),
11473                                   const0_rtx);
11474   operands[5] = gen_rtx_PARALLEL (VOIDmode, p);
11475 }")
11476
11477 (define_expand "save_stack_nonlocal"
11478   [(set (match_dup 3) (match_dup 4))
11479    (set (match_operand 0 "memory_operand" "") (match_dup 3))
11480    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
11481   ""
11482   "
11483 {
11484   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11485
11486   /* Copy the backchain to the first word, sp to the second.  */
11487   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
11488   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
11489   operands[3] = gen_reg_rtx (Pmode);
11490   operands[4] = gen_frame_mem (Pmode, operands[1]);
11491 }")
11492
11493 (define_expand "restore_stack_nonlocal"
11494   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
11495    (set (match_dup 3) (match_dup 4))
11496    (set (match_dup 5) (match_dup 2))
11497    (match_dup 6)
11498    (set (match_operand 0 "register_operand" "") (match_dup 3))]
11499   ""
11500   "
11501 {
11502   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11503   rtvec p;
11504
11505   /* Restore the backchain from the first word, sp from the second.  */
11506   operands[2] = gen_reg_rtx (Pmode);
11507   operands[3] = gen_reg_rtx (Pmode);
11508   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
11509   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
11510   operands[5] = gen_frame_mem (Pmode, operands[3]);
11511   p = rtvec_alloc (1);
11512   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
11513                                   gen_frame_mem (BLKmode, operands[0]),
11514                                   const0_rtx);
11515   operands[6] = gen_rtx_PARALLEL (VOIDmode, p);
11516 }")
11517 \f
11518 ;; TOC register handling.
11519
11520 ;; Code to initialize the TOC register...
11521
11522 (define_insn "load_toc_aix_si"
11523   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11524                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
11525               (use (reg:SI 2))])]
11526   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
11527   "*
11528 {
11529   char buf[30];
11530   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11531   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11532   operands[2] = gen_rtx_REG (Pmode, 2);
11533   return \"lwz %0,%1(%2)\";
11534 }"
11535   [(set_attr "type" "load")])
11536
11537 (define_insn "load_toc_aix_di"
11538   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11539                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
11540               (use (reg:DI 2))])]
11541   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
11542   "*
11543 {
11544   char buf[30];
11545 #ifdef TARGET_RELOCATABLE
11546   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
11547                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
11548 #else
11549   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11550 #endif
11551   if (TARGET_ELF)
11552     strcat (buf, \"@toc\");
11553   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11554   operands[2] = gen_rtx_REG (Pmode, 2);
11555   return \"ld %0,%1(%2)\";
11556 }"
11557   [(set_attr "type" "load")])
11558
11559 (define_insn "load_toc_v4_pic_si"
11560   [(set (reg:SI LR_REGNO)
11561         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
11562   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
11563   "bl _GLOBAL_OFFSET_TABLE_@local-4"
11564   [(set_attr "type" "branch")
11565    (set_attr "length" "4")])
11566
11567 (define_expand "load_toc_v4_PIC_1"
11568   [(parallel [(set (reg:SI LR_REGNO)
11569                    (match_operand:SI 0 "immediate_operand" "s"))
11570               (use (unspec [(match_dup 0)] UNSPEC_TOC))])]
11571   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
11572    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11573   "")
11574
11575 (define_insn "load_toc_v4_PIC_1_normal"
11576   [(set (reg:SI LR_REGNO)
11577         (match_operand:SI 0 "immediate_operand" "s"))
11578    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11579   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX
11580    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11581   "bcl 20,31,%0\\n%0:"
11582   [(set_attr "type" "branch")
11583    (set_attr "length" "4")])
11584
11585 (define_insn "load_toc_v4_PIC_1_476"
11586   [(set (reg:SI LR_REGNO)
11587         (match_operand:SI 0 "immediate_operand" "s"))
11588    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11589   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX
11590    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11591   "*
11592 {
11593   char name[32];
11594   static char templ[32];
11595
11596   get_ppc476_thunk_name (name);
11597   sprintf (templ, \"bl %s\\n%%0:\", name);
11598   return templ;
11599 }"
11600   [(set_attr "type" "branch")
11601    (set_attr "length" "4")])
11602
11603 (define_expand "load_toc_v4_PIC_1b"
11604   [(parallel [(set (reg:SI LR_REGNO)
11605                    (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11606                                (label_ref (match_operand 1 "" ""))]
11607                            UNSPEC_TOCPTR))
11608               (match_dup 1)])]
11609   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11610   "")
11611
11612 (define_insn "load_toc_v4_PIC_1b_normal"
11613   [(set (reg:SI LR_REGNO)
11614         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11615                     (label_ref (match_operand 1 "" ""))]
11616                 UNSPEC_TOCPTR))
11617    (match_dup 1)]
11618   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11619   "bcl 20,31,$+8\;.long %0-$"
11620   [(set_attr "type" "branch")
11621    (set_attr "length" "8")])
11622
11623 (define_insn "load_toc_v4_PIC_1b_476"
11624   [(set (reg:SI LR_REGNO)
11625         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11626                     (label_ref (match_operand 1 "" ""))]
11627                 UNSPEC_TOCPTR))
11628    (match_dup 1)]
11629   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11630   "*
11631 {
11632   char name[32];
11633   static char templ[32];
11634
11635   get_ppc476_thunk_name (name);
11636   sprintf (templ, \"bl %s\\n\\tb $+8\\n\\t.long %%0-$\", name);
11637   return templ;
11638 }"
11639   [(set_attr "type" "branch")
11640    (set_attr "length" "16")])
11641
11642 (define_insn "load_toc_v4_PIC_2"
11643   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11644         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11645                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
11646                              (match_operand:SI 3 "immediate_operand" "s")))))]
11647   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
11648   "lwz %0,%2-%3(%1)"
11649   [(set_attr "type" "load")])
11650
11651 (define_insn "load_toc_v4_PIC_3b"
11652   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11653         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11654                  (high:SI
11655                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11656                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
11657   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
11658   "addis %0,%1,%2-%3@ha")
11659
11660 (define_insn "load_toc_v4_PIC_3c"
11661   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11662         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11663                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11664                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
11665   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
11666   "addi %0,%1,%2-%3@l")
11667
11668 ;; If the TOC is shared over a translation unit, as happens with all
11669 ;; the kinds of PIC that we support, we need to restore the TOC
11670 ;; pointer only when jumping over units of translation.
11671 ;; On Darwin, we need to reload the picbase.
11672
11673 (define_expand "builtin_setjmp_receiver"
11674   [(use (label_ref (match_operand 0 "" "")))]
11675   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11676    || (TARGET_TOC && TARGET_MINIMAL_TOC)
11677    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
11678   "
11679 {
11680 #if TARGET_MACHO
11681   if (DEFAULT_ABI == ABI_DARWIN)
11682     {
11683       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
11684       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
11685       rtx tmplabrtx;
11686       char tmplab[20];
11687
11688       crtl->uses_pic_offset_table = 1;
11689       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
11690                                   CODE_LABEL_NUMBER (operands[0]));
11691       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
11692
11693       emit_insn (gen_load_macho_picbase (tmplabrtx));
11694       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
11695       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
11696     }
11697   else
11698 #endif
11699     rs6000_emit_load_toc_table (FALSE);
11700   DONE;
11701 }")
11702
11703 ;; Largetoc support
11704 (define_insn "*largetoc_high"
11705   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11706         (high:DI
11707           (unspec [(match_operand:DI 1 "" "")
11708                    (match_operand:DI 2 "gpc_reg_operand" "b")]
11709                   UNSPEC_TOCREL)))]
11710    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11711    "addis %0,%2,%1@toc@ha")
11712
11713 (define_insn "*largetoc_high_aix<mode>"
11714   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11715         (high:P
11716           (unspec [(match_operand:P 1 "" "")
11717                    (match_operand:P 2 "gpc_reg_operand" "b")]
11718                   UNSPEC_TOCREL)))]
11719    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11720    "addis %0,%1@u(%2)")
11721
11722 (define_insn "*largetoc_high_plus"
11723   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11724         (high:DI
11725           (plus:DI
11726             (unspec [(match_operand:DI 1 "" "")
11727                      (match_operand:DI 2 "gpc_reg_operand" "b")]
11728                     UNSPEC_TOCREL)
11729             (match_operand 3 "const_int_operand" "n"))))]
11730    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11731    "addis %0,%2,%1+%3@toc@ha")
11732
11733 (define_insn "*largetoc_high_plus_aix<mode>"
11734   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11735         (high:P
11736           (plus:P
11737             (unspec [(match_operand:P 1 "" "")
11738                      (match_operand:P 2 "gpc_reg_operand" "b")]
11739                     UNSPEC_TOCREL)
11740             (match_operand 3 "const_int_operand" "n"))))]
11741    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11742    "addis %0,%1+%3@u(%2)")
11743
11744 (define_insn "*largetoc_low"
11745   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11746         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,!*r")
11747                    (match_operand:DI 2 "" "")))]
11748    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11749    "@
11750     addi %0,%1,%2@l
11751     addic %0,%1,%2@l")
11752
11753 (define_insn "*largetoc_low_aix<mode>"
11754   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11755         (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
11756                    (match_operand:P 2 "" "")))]
11757    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11758    "la %0,%2@l(%1)")
11759
11760 (define_insn_and_split "*tocref<mode>"
11761   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11762         (match_operand:P 1 "small_toc_ref" "R"))]
11763    "TARGET_TOC"
11764    "la %0,%a1"
11765    "&& TARGET_CMODEL != CMODEL_SMALL && reload_completed"
11766   [(set (match_dup 0) (high:P (match_dup 1)))
11767    (set (match_dup 0) (lo_sum:P (match_dup 0) (match_dup 1)))])
11768
11769 ;; Elf specific ways of loading addresses for non-PIC code.
11770 ;; The output of this could be r0, but we make a very strong
11771 ;; preference for a base register because it will usually
11772 ;; be needed there.
11773 (define_insn "elf_high"
11774   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
11775         (high:SI (match_operand 1 "" "")))]
11776   "TARGET_ELF && ! TARGET_64BIT"
11777   "lis %0,%1@ha")
11778
11779 (define_insn "elf_low"
11780   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11781         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
11782                    (match_operand 2 "" "")))]
11783    "TARGET_ELF && ! TARGET_64BIT"
11784    "@
11785     la %0,%2@l(%1)
11786     addic %0,%1,%K2")
11787 \f
11788 ;; Call and call_value insns
11789 (define_expand "call"
11790   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11791                     (match_operand 1 "" ""))
11792               (use (match_operand 2 "" ""))
11793               (clobber (reg:SI LR_REGNO))])]
11794   ""
11795   "
11796 {
11797 #if TARGET_MACHO
11798   if (MACHOPIC_INDIRECT)
11799     operands[0] = machopic_indirect_call_target (operands[0]);
11800 #endif
11801
11802   gcc_assert (GET_CODE (operands[0]) == MEM);
11803   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11804
11805   operands[0] = XEXP (operands[0], 0);
11806
11807   if (GET_CODE (operands[0]) != SYMBOL_REF
11808       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
11809       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
11810     {
11811       if (INTVAL (operands[2]) & CALL_LONG)
11812         operands[0] = rs6000_longcall_ref (operands[0]);
11813
11814       switch (DEFAULT_ABI)
11815         {
11816         case ABI_V4:
11817         case ABI_DARWIN:
11818           operands[0] = force_reg (Pmode, operands[0]);
11819           break;
11820
11821         case ABI_AIX:
11822           /* AIX function pointers are really pointers to a three word
11823              area.  */
11824           rs6000_call_indirect_aix (NULL_RTX, operands[0], operands[1]);
11825           DONE;
11826
11827         default:
11828           gcc_unreachable ();
11829         }
11830     }
11831 }")
11832
11833 (define_expand "call_value"
11834   [(parallel [(set (match_operand 0 "" "")
11835                    (call (mem:SI (match_operand 1 "address_operand" ""))
11836                          (match_operand 2 "" "")))
11837               (use (match_operand 3 "" ""))
11838               (clobber (reg:SI LR_REGNO))])]
11839   ""
11840   "
11841 {
11842 #if TARGET_MACHO
11843   if (MACHOPIC_INDIRECT)
11844     operands[1] = machopic_indirect_call_target (operands[1]);
11845 #endif
11846
11847   gcc_assert (GET_CODE (operands[1]) == MEM);
11848   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11849
11850   operands[1] = XEXP (operands[1], 0);
11851
11852   if (GET_CODE (operands[1]) != SYMBOL_REF
11853       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
11854       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
11855     {
11856       if (INTVAL (operands[3]) & CALL_LONG)
11857         operands[1] = rs6000_longcall_ref (operands[1]);
11858
11859       switch (DEFAULT_ABI)
11860         {
11861         case ABI_V4:
11862         case ABI_DARWIN:
11863           operands[1] = force_reg (Pmode, operands[1]);
11864           break;
11865
11866         case ABI_AIX:
11867           /* AIX function pointers are really pointers to a three word
11868              area.  */
11869           rs6000_call_indirect_aix (operands[0], operands[1], operands[2]);
11870           DONE;
11871
11872         default:
11873           gcc_unreachable ();
11874         }
11875     }
11876 }")
11877
11878 ;; Call to function in current module.  No TOC pointer reload needed.
11879 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11880 ;; either the function was not prototyped, or it was prototyped as a
11881 ;; variable argument function.  It is > 0 if FP registers were passed
11882 ;; and < 0 if they were not.
11883
11884 (define_insn "*call_local32"
11885   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11886          (match_operand 1 "" "g,g"))
11887    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11888    (clobber (reg:SI LR_REGNO))]
11889   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11890   "*
11891 {
11892   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11893     output_asm_insn (\"crxor 6,6,6\", operands);
11894
11895   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11896     output_asm_insn (\"creqv 6,6,6\", operands);
11897
11898   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11899 }"
11900   [(set_attr "type" "branch")
11901    (set_attr "length" "4,8")])
11902
11903 (define_insn "*call_local64"
11904   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11905          (match_operand 1 "" "g,g"))
11906    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11907    (clobber (reg:SI LR_REGNO))]
11908   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11909   "*
11910 {
11911   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11912     output_asm_insn (\"crxor 6,6,6\", operands);
11913
11914   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11915     output_asm_insn (\"creqv 6,6,6\", operands);
11916
11917   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11918 }"
11919   [(set_attr "type" "branch")
11920    (set_attr "length" "4,8")])
11921
11922 (define_insn "*call_value_local32"
11923   [(set (match_operand 0 "" "")
11924         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11925               (match_operand 2 "" "g,g")))
11926    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11927    (clobber (reg:SI LR_REGNO))]
11928   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11929   "*
11930 {
11931   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11932     output_asm_insn (\"crxor 6,6,6\", operands);
11933
11934   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11935     output_asm_insn (\"creqv 6,6,6\", operands);
11936
11937   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11938 }"
11939   [(set_attr "type" "branch")
11940    (set_attr "length" "4,8")])
11941
11942
11943 (define_insn "*call_value_local64"
11944   [(set (match_operand 0 "" "")
11945         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11946               (match_operand 2 "" "g,g")))
11947    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11948    (clobber (reg:SI LR_REGNO))]
11949   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11950   "*
11951 {
11952   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11953     output_asm_insn (\"crxor 6,6,6\", operands);
11954
11955   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11956     output_asm_insn (\"creqv 6,6,6\", operands);
11957
11958   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11959 }"
11960   [(set_attr "type" "branch")
11961    (set_attr "length" "4,8")])
11962
11963 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
11964 ;; Operand0 is the addresss of the function to call
11965 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
11966 ;; Operand2 is the location in the function descriptor to load r2 from
11967 ;; Operand3 is the stack location to hold the current TOC pointer
11968
11969 (define_insn "call_indirect_aix<ptrsize>"
11970   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
11971          (match_operand 1 "" "g,g"))
11972    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
11973    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
11974    (use (reg:P STATIC_CHAIN_REGNUM))
11975    (clobber (reg:P LR_REGNO))]
11976   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
11977   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
11978   [(set_attr "type" "jmpreg")
11979    (set_attr "length" "12")])
11980
11981 ;; Like call_indirect_aix<ptrsize>, but no use of the static chain
11982 ;; Operand0 is the addresss of the function to call
11983 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
11984 ;; Operand2 is the location in the function descriptor to load r2 from
11985 ;; Operand3 is the stack location to hold the current TOC pointer
11986
11987 (define_insn "call_indirect_aix<ptrsize>_nor11"
11988   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
11989          (match_operand 1 "" "g,g"))
11990    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
11991    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
11992    (clobber (reg:P LR_REGNO))]
11993   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
11994   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
11995   [(set_attr "type" "jmpreg")
11996    (set_attr "length" "12")])
11997
11998 ;; Operand0 is the return result of the function
11999 ;; Operand1 is the addresss of the function to call
12000 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
12001 ;; Operand3 is the location in the function descriptor to load r2 from
12002 ;; Operand4 is the stack location to hold the current TOC pointer
12003
12004 (define_insn "call_value_indirect_aix<ptrsize>"
12005   [(set (match_operand 0 "" "")
12006         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12007               (match_operand 2 "" "g,g")))
12008    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12009    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
12010    (use (reg:P STATIC_CHAIN_REGNUM))
12011    (clobber (reg:P LR_REGNO))]
12012   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12013   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12014   [(set_attr "type" "jmpreg")
12015    (set_attr "length" "12")])
12016
12017 ;; Like call_value_indirect_aix<ptrsize>, but no use of the static chain
12018 ;; Operand0 is the return result of the function
12019 ;; Operand1 is the addresss of the function to call
12020 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
12021 ;; Operand3 is the location in the function descriptor to load r2 from
12022 ;; Operand4 is the stack location to hold the current TOC pointer
12023
12024 (define_insn "call_value_indirect_aix<ptrsize>_nor11"
12025   [(set (match_operand 0 "" "")
12026         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12027               (match_operand 2 "" "g,g")))
12028    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12029    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
12030    (clobber (reg:P LR_REGNO))]
12031   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
12032   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12033   [(set_attr "type" "jmpreg")
12034    (set_attr "length" "12")])
12035
12036 ;; Call to function which may be in another module.  Restore the TOC
12037 ;; pointer (r2) after the call unless this is System V.
12038 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12039 ;; either the function was not prototyped, or it was prototyped as a
12040 ;; variable argument function.  It is > 0 if FP registers were passed
12041 ;; and < 0 if they were not.
12042
12043 (define_insn "*call_nonlocal_aix32"
12044   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
12045          (match_operand 1 "" "g"))
12046    (use (match_operand:SI 2 "immediate_operand" "O"))
12047    (clobber (reg:SI LR_REGNO))]
12048   "TARGET_32BIT
12049    && DEFAULT_ABI == ABI_AIX
12050    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12051   "bl %z0\;nop"
12052   [(set_attr "type" "branch")
12053    (set_attr "length" "8")])
12054    
12055 (define_insn "*call_nonlocal_aix64"
12056   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
12057          (match_operand 1 "" "g"))
12058    (use (match_operand:SI 2 "immediate_operand" "O"))
12059    (clobber (reg:SI LR_REGNO))]
12060   "TARGET_64BIT
12061    && DEFAULT_ABI == ABI_AIX
12062    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12063   "bl %z0\;nop"
12064   [(set_attr "type" "branch")
12065    (set_attr "length" "8")])
12066
12067 (define_insn "*call_value_nonlocal_aix32"
12068   [(set (match_operand 0 "" "")
12069         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
12070               (match_operand 2 "" "g")))
12071    (use (match_operand:SI 3 "immediate_operand" "O"))
12072    (clobber (reg:SI LR_REGNO))]
12073   "TARGET_32BIT
12074    && DEFAULT_ABI == ABI_AIX
12075    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12076   "bl %z1\;nop"
12077   [(set_attr "type" "branch")
12078    (set_attr "length" "8")])
12079
12080 (define_insn "*call_value_nonlocal_aix64"
12081   [(set (match_operand 0 "" "")
12082         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
12083               (match_operand 2 "" "g")))
12084    (use (match_operand:SI 3 "immediate_operand" "O"))
12085    (clobber (reg:SI LR_REGNO))]
12086   "TARGET_64BIT
12087    && DEFAULT_ABI == ABI_AIX
12088    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12089   "bl %z1\;nop"
12090   [(set_attr "type" "branch")
12091    (set_attr "length" "8")])
12092
12093 ;; A function pointer under System V is just a normal pointer
12094 ;; operands[0] is the function pointer
12095 ;; operands[1] is the stack size to clean up
12096 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12097 ;; which indicates how to set cr1
12098
12099 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12100   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12101          (match_operand 1 "" "g,g,g,g"))
12102    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12103    (clobber (reg:SI LR_REGNO))]
12104   "DEFAULT_ABI == ABI_V4
12105    || DEFAULT_ABI == ABI_DARWIN"
12106 {
12107   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12108     output_asm_insn ("crxor 6,6,6", operands);
12109
12110   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12111     output_asm_insn ("creqv 6,6,6", operands);
12112
12113   return "b%T0l";
12114 }
12115   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12116    (set_attr "length" "4,4,8,8")])
12117
12118 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12119   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12120          (match_operand 1 "" "g,g"))
12121    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12122    (clobber (reg:SI LR_REGNO))]
12123   "(DEFAULT_ABI == ABI_DARWIN
12124    || (DEFAULT_ABI == ABI_V4
12125        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12126 {
12127   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12128     output_asm_insn ("crxor 6,6,6", operands);
12129
12130   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12131     output_asm_insn ("creqv 6,6,6", operands);
12132
12133 #if TARGET_MACHO
12134   return output_call(insn, operands, 0, 2);
12135 #else
12136   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12137     {
12138       gcc_assert (!TARGET_SECURE_PLT);
12139       return "bl %z0@plt";
12140     }
12141   else
12142     return "bl %z0";
12143 #endif
12144 }
12145   "DEFAULT_ABI == ABI_V4
12146    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12147    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12148   [(parallel [(call (mem:SI (match_dup 0))
12149                     (match_dup 1))
12150               (use (match_dup 2))
12151               (use (match_dup 3))
12152               (clobber (reg:SI LR_REGNO))])]
12153 {
12154   operands[3] = pic_offset_table_rtx;
12155 }
12156   [(set_attr "type" "branch,branch")
12157    (set_attr "length" "4,8")])
12158
12159 (define_insn "*call_nonlocal_sysv_secure<mode>"
12160   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12161          (match_operand 1 "" "g,g"))
12162    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12163    (use (match_operand:SI 3 "register_operand" "r,r"))
12164    (clobber (reg:SI LR_REGNO))]
12165   "(DEFAULT_ABI == ABI_V4
12166     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12167     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
12168 {
12169   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12170     output_asm_insn ("crxor 6,6,6", operands);
12171
12172   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12173     output_asm_insn ("creqv 6,6,6", operands);
12174
12175   if (flag_pic == 2)
12176     /* The magic 32768 offset here and in the other sysv call insns
12177        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12178        See sysv4.h:toc_section.  */
12179     return "bl %z0+32768@plt";
12180   else
12181     return "bl %z0@plt";
12182 }
12183   [(set_attr "type" "branch,branch")
12184    (set_attr "length" "4,8")])
12185
12186 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12187   [(set (match_operand 0 "" "")
12188         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12189               (match_operand 2 "" "g,g,g,g")))
12190    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12191    (clobber (reg:SI LR_REGNO))]
12192   "DEFAULT_ABI == ABI_V4
12193    || DEFAULT_ABI == ABI_DARWIN"
12194 {
12195   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12196     output_asm_insn ("crxor 6,6,6", operands);
12197
12198   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12199     output_asm_insn ("creqv 6,6,6", operands);
12200
12201   return "b%T1l";
12202 }
12203   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12204    (set_attr "length" "4,4,8,8")])
12205
12206 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12207   [(set (match_operand 0 "" "")
12208         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12209               (match_operand 2 "" "g,g")))
12210    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12211    (clobber (reg:SI LR_REGNO))]
12212   "(DEFAULT_ABI == ABI_DARWIN
12213    || (DEFAULT_ABI == ABI_V4
12214        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12215 {
12216   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12217     output_asm_insn ("crxor 6,6,6", operands);
12218
12219   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12220     output_asm_insn ("creqv 6,6,6", operands);
12221
12222 #if TARGET_MACHO
12223   return output_call(insn, operands, 1, 3);
12224 #else
12225   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12226     {
12227       gcc_assert (!TARGET_SECURE_PLT);
12228       return "bl %z1@plt";
12229     }
12230   else
12231     return "bl %z1";
12232 #endif
12233 }
12234   "DEFAULT_ABI == ABI_V4
12235    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12236    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12237   [(parallel [(set (match_dup 0)
12238                    (call (mem:SI (match_dup 1))
12239                          (match_dup 2)))
12240               (use (match_dup 3))
12241               (use (match_dup 4))
12242               (clobber (reg:SI LR_REGNO))])]
12243 {
12244   operands[4] = pic_offset_table_rtx;
12245 }
12246   [(set_attr "type" "branch,branch")
12247    (set_attr "length" "4,8")])
12248
12249 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12250   [(set (match_operand 0 "" "")
12251         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12252               (match_operand 2 "" "g,g")))
12253    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12254    (use (match_operand:SI 4 "register_operand" "r,r"))
12255    (clobber (reg:SI LR_REGNO))]
12256   "(DEFAULT_ABI == ABI_V4
12257     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12258     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12259 {
12260   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12261     output_asm_insn ("crxor 6,6,6", operands);
12262
12263   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12264     output_asm_insn ("creqv 6,6,6", operands);
12265
12266   if (flag_pic == 2)
12267     return "bl %z1+32768@plt";
12268   else
12269     return "bl %z1@plt";
12270 }
12271   [(set_attr "type" "branch,branch")
12272    (set_attr "length" "4,8")])
12273
12274 ;; Call subroutine returning any type.
12275 (define_expand "untyped_call"
12276   [(parallel [(call (match_operand 0 "" "")
12277                     (const_int 0))
12278               (match_operand 1 "" "")
12279               (match_operand 2 "" "")])]
12280   ""
12281   "
12282 {
12283   int i;
12284
12285   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12286
12287   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12288     {
12289       rtx set = XVECEXP (operands[2], 0, i);
12290       emit_move_insn (SET_DEST (set), SET_SRC (set));
12291     }
12292
12293   /* The optimizer does not know that the call sets the function value
12294      registers we stored in the result block.  We avoid problems by
12295      claiming that all hard registers are used and clobbered at this
12296      point.  */
12297   emit_insn (gen_blockage ());
12298
12299   DONE;
12300 }")
12301
12302 ;; sibling call patterns
12303 (define_expand "sibcall"
12304   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12305                     (match_operand 1 "" ""))
12306               (use (match_operand 2 "" ""))
12307               (use (reg:SI LR_REGNO))
12308               (simple_return)])]
12309   ""
12310   "
12311 {
12312 #if TARGET_MACHO
12313   if (MACHOPIC_INDIRECT)
12314     operands[0] = machopic_indirect_call_target (operands[0]);
12315 #endif
12316
12317   gcc_assert (GET_CODE (operands[0]) == MEM);
12318   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12319
12320   operands[0] = XEXP (operands[0], 0);
12321 }")
12322
12323 ;; this and similar patterns must be marked as using LR, otherwise
12324 ;; dataflow will try to delete the store into it.  This is true
12325 ;; even when the actual reg to jump to is in CTR, when LR was
12326 ;; saved and restored around the PIC-setting BCL.
12327 (define_insn "*sibcall_local32"
12328   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12329          (match_operand 1 "" "g,g"))
12330    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12331    (use (reg:SI LR_REGNO))
12332    (simple_return)]
12333   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12334   "*
12335 {
12336   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12337     output_asm_insn (\"crxor 6,6,6\", operands);
12338
12339   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12340     output_asm_insn (\"creqv 6,6,6\", operands);
12341
12342   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12343 }"
12344   [(set_attr "type" "branch")
12345    (set_attr "length" "4,8")])
12346
12347 (define_insn "*sibcall_local64"
12348   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12349          (match_operand 1 "" "g,g"))
12350    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12351    (use (reg:SI LR_REGNO))
12352    (simple_return)]
12353   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12354   "*
12355 {
12356   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12357     output_asm_insn (\"crxor 6,6,6\", operands);
12358
12359   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12360     output_asm_insn (\"creqv 6,6,6\", operands);
12361
12362   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12363 }"
12364   [(set_attr "type" "branch")
12365    (set_attr "length" "4,8")])
12366
12367 (define_insn "*sibcall_value_local32"
12368   [(set (match_operand 0 "" "")
12369         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12370               (match_operand 2 "" "g,g")))
12371    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12372    (use (reg:SI LR_REGNO))
12373    (simple_return)]
12374   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12375   "*
12376 {
12377   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12378     output_asm_insn (\"crxor 6,6,6\", operands);
12379
12380   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12381     output_asm_insn (\"creqv 6,6,6\", operands);
12382
12383   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12384 }"
12385   [(set_attr "type" "branch")
12386    (set_attr "length" "4,8")])
12387
12388
12389 (define_insn "*sibcall_value_local64"
12390   [(set (match_operand 0 "" "")
12391         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12392               (match_operand 2 "" "g,g")))
12393    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12394    (use (reg:SI LR_REGNO))
12395    (simple_return)]
12396   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12397   "*
12398 {
12399   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12400     output_asm_insn (\"crxor 6,6,6\", operands);
12401
12402   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12403     output_asm_insn (\"creqv 6,6,6\", operands);
12404
12405   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12406 }"
12407   [(set_attr "type" "branch")
12408    (set_attr "length" "4,8")])
12409
12410 (define_insn "*sibcall_nonlocal_aix<mode>"
12411   [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
12412          (match_operand 1 "" "g,g"))
12413    (use (match_operand:SI 2 "immediate_operand" "O,O"))
12414    (use (reg:SI LR_REGNO))
12415    (simple_return)]
12416   "DEFAULT_ABI == ABI_AIX
12417    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12418   "@
12419    b %z0
12420    b%T0"
12421   [(set_attr "type" "branch")
12422    (set_attr "length" "4")])
12423
12424 (define_insn "*sibcall_value_nonlocal_aix<mode>"
12425   [(set (match_operand 0 "" "")
12426         (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
12427               (match_operand 2 "" "g,g")))
12428    (use (match_operand:SI 3 "immediate_operand" "O,O"))
12429    (use (reg:SI LR_REGNO))
12430    (simple_return)]
12431   "DEFAULT_ABI == ABI_AIX
12432    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12433   "@
12434    b %z1
12435    b%T1"
12436   [(set_attr "type" "branch")
12437    (set_attr "length" "4")])
12438
12439 (define_insn "*sibcall_nonlocal_sysv<mode>"
12440   [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c"))
12441          (match_operand 1 "" ""))
12442    (use (match_operand 2 "immediate_operand" "O,n,O,n"))
12443    (use (reg:SI LR_REGNO))
12444    (simple_return)]
12445   "(DEFAULT_ABI == ABI_DARWIN
12446     || DEFAULT_ABI == ABI_V4)
12447    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12448   "*
12449 {
12450   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12451     output_asm_insn (\"crxor 6,6,6\", operands);
12452
12453   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12454     output_asm_insn (\"creqv 6,6,6\", operands);
12455
12456   if (which_alternative >= 2)
12457     return \"b%T0\";
12458   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12459     {
12460       gcc_assert (!TARGET_SECURE_PLT);
12461       return \"b %z0@plt\";
12462     }
12463   else
12464     return \"b %z0\";
12465 }"
12466   [(set_attr "type" "branch")
12467    (set_attr "length" "4,8,4,8")])
12468
12469 (define_expand "sibcall_value"
12470   [(parallel [(set (match_operand 0 "register_operand" "")
12471                 (call (mem:SI (match_operand 1 "address_operand" ""))
12472                       (match_operand 2 "" "")))
12473               (use (match_operand 3 "" ""))
12474               (use (reg:SI LR_REGNO))
12475               (simple_return)])]
12476   ""
12477   "
12478 {
12479 #if TARGET_MACHO
12480   if (MACHOPIC_INDIRECT)
12481     operands[1] = machopic_indirect_call_target (operands[1]);
12482 #endif
12483
12484   gcc_assert (GET_CODE (operands[1]) == MEM);
12485   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12486
12487   operands[1] = XEXP (operands[1], 0);
12488 }")
12489
12490 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
12491   [(set (match_operand 0 "" "")
12492         (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c"))
12493               (match_operand 2 "" "")))
12494    (use (match_operand:SI 3 "immediate_operand" "O,n,O,n"))
12495    (use (reg:SI LR_REGNO))
12496    (simple_return)]
12497   "(DEFAULT_ABI == ABI_DARWIN
12498     || DEFAULT_ABI == ABI_V4)
12499    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12500   "*
12501 {
12502   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12503     output_asm_insn (\"crxor 6,6,6\", operands);
12504
12505   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12506     output_asm_insn (\"creqv 6,6,6\", operands);
12507
12508   if (which_alternative >= 2)
12509     return \"b%T1\";
12510   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12511     {
12512       gcc_assert (!TARGET_SECURE_PLT);
12513       return \"b %z1@plt\";
12514     }
12515   else
12516     return \"b %z1\";
12517 }"
12518   [(set_attr "type" "branch")
12519    (set_attr "length" "4,8,4,8")])
12520
12521 (define_expand "sibcall_epilogue"
12522   [(use (const_int 0))]
12523   ""
12524 {
12525   if (!TARGET_SCHED_PROLOG)
12526     emit_insn (gen_blockage ());
12527   rs6000_emit_epilogue (TRUE);
12528   DONE;
12529 })
12530
12531 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12532 ;; all of memory.  This blocks insns from being moved across this point.
12533
12534 (define_insn "blockage"
12535   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
12536   ""
12537   "")
12538
12539 (define_expand "probe_stack"
12540   [(set (match_operand 0 "memory_operand" "=m")
12541         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
12542   ""
12543 {
12544   if (TARGET_64BIT)
12545     emit_insn (gen_probe_stack_di (operands[0]));
12546   else
12547     emit_insn (gen_probe_stack_si (operands[0]));
12548   DONE;
12549 })
12550
12551 (define_insn "probe_stack_<mode>"
12552   [(set (match_operand:P 0 "memory_operand" "=m")
12553         (unspec:P [(const_int 0)] UNSPEC_PROBE_STACK))]
12554   ""
12555 {
12556   operands[1] = gen_rtx_REG (Pmode, 0);
12557   return "st<wd>%U0%X0 %1,%0";
12558 }
12559   [(set (attr "type")
12560       (if_then_else
12561         (match_test "update_indexed_address_mem (operands[0], VOIDmode)")
12562         (const_string "store_ux")
12563         (if_then_else
12564           (match_test "update_address_mem (operands[0], VOIDmode)")
12565           (const_string "store_u")
12566           (const_string "store"))))
12567    (set_attr "length" "4")])
12568
12569 (define_insn "probe_stack_range<P:mode>"
12570   [(set (match_operand:P 0 "register_operand" "=r")
12571         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
12572                             (match_operand:P 2 "register_operand" "r")]
12573                            UNSPECV_PROBE_STACK_RANGE))]
12574   ""
12575   "* return output_probe_stack_range (operands[0], operands[2]);"
12576   [(set_attr "type" "three")])
12577 \f
12578 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
12579 ;; signed & unsigned, and one type of branch.
12580 ;;
12581 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
12582 ;; insns, and branches.
12583
12584 (define_expand "cbranch<mode>4"
12585   [(use (match_operator 0 "rs6000_cbranch_operator"
12586          [(match_operand:GPR 1 "gpc_reg_operand" "")
12587           (match_operand:GPR 2 "reg_or_short_operand" "")]))
12588    (use (match_operand 3 ""))]
12589   ""
12590   "
12591 {
12592   /* Take care of the possibility that operands[2] might be negative but
12593      this might be a logical operation.  That insn doesn't exist.  */
12594   if (GET_CODE (operands[2]) == CONST_INT
12595       && INTVAL (operands[2]) < 0)
12596     {
12597       operands[2] = force_reg (<MODE>mode, operands[2]);
12598       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
12599                                     GET_MODE (operands[0]),
12600                                     operands[1], operands[2]);
12601    }
12602
12603   rs6000_emit_cbranch (<MODE>mode, operands);
12604   DONE;
12605 }")
12606
12607 (define_expand "cbranch<mode>4"
12608   [(use (match_operator 0 "rs6000_cbranch_operator"
12609          [(match_operand:FP 1 "gpc_reg_operand" "")
12610           (match_operand:FP 2 "gpc_reg_operand" "")]))
12611    (use (match_operand 3 ""))]
12612   ""
12613   "
12614 {
12615   rs6000_emit_cbranch (<MODE>mode, operands);
12616   DONE;
12617 }")
12618
12619 (define_expand "cstore<mode>4"
12620   [(use (match_operator 1 "rs6000_cbranch_operator"
12621          [(match_operand:GPR 2 "gpc_reg_operand" "")
12622           (match_operand:GPR 3 "reg_or_short_operand" "")]))
12623    (clobber (match_operand:SI 0 "register_operand"))]
12624   ""
12625   "
12626 {
12627   /* Take care of the possibility that operands[3] might be negative but
12628      this might be a logical operation.  That insn doesn't exist.  */
12629   if (GET_CODE (operands[3]) == CONST_INT
12630       && INTVAL (operands[3]) < 0)
12631     {
12632       operands[3] = force_reg (<MODE>mode, operands[3]);
12633       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
12634                                     GET_MODE (operands[1]),
12635                                     operands[2], operands[3]);
12636     }
12637
12638   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
12639      For SEQ, likewise, except that comparisons with zero should be done
12640      with an scc insns.  However, due to the order that combine see the
12641      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
12642      the cases we don't want to handle or are best handled by portable
12643      code.  */
12644   if (GET_CODE (operands[1]) == NE)
12645     FAIL;
12646   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
12647        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
12648       && operands[3] == const0_rtx)
12649     FAIL;
12650   rs6000_emit_sCOND (<MODE>mode, operands);
12651   DONE;
12652 }")
12653
12654 (define_expand "cstore<mode>4"
12655   [(use (match_operator 1 "rs6000_cbranch_operator"
12656          [(match_operand:FP 2 "gpc_reg_operand" "")
12657           (match_operand:FP 3 "gpc_reg_operand" "")]))
12658    (clobber (match_operand:SI 0 "register_operand"))]
12659   ""
12660   "
12661 {
12662   rs6000_emit_sCOND (<MODE>mode, operands);
12663   DONE;
12664 }")
12665
12666
12667 (define_expand "stack_protect_set"
12668   [(match_operand 0 "memory_operand" "")
12669    (match_operand 1 "memory_operand" "")]
12670   ""
12671 {
12672 #ifdef TARGET_THREAD_SSP_OFFSET
12673   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12674   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12675   operands[1] = gen_rtx_MEM (Pmode, addr);
12676 #endif
12677   if (TARGET_64BIT)
12678     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
12679   else
12680     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
12681   DONE;
12682 })
12683
12684 (define_insn "stack_protect_setsi"
12685   [(set (match_operand:SI 0 "memory_operand" "=m")
12686         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12687    (set (match_scratch:SI 2 "=&r") (const_int 0))]
12688   "TARGET_32BIT"
12689   "lwz%U1%X1 %2,%1\;stw%U0%X0 %2,%0\;li %2,0"
12690   [(set_attr "type" "three")
12691    (set_attr "length" "12")])
12692
12693 (define_insn "stack_protect_setdi"
12694   [(set (match_operand:DI 0 "memory_operand" "=Y")
12695         (unspec:DI [(match_operand:DI 1 "memory_operand" "Y")] UNSPEC_SP_SET))
12696    (set (match_scratch:DI 2 "=&r") (const_int 0))]
12697   "TARGET_64BIT"
12698   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;li %2,0"
12699   [(set_attr "type" "three")
12700    (set_attr "length" "12")])
12701
12702 (define_expand "stack_protect_test"
12703   [(match_operand 0 "memory_operand" "")
12704    (match_operand 1 "memory_operand" "")
12705    (match_operand 2 "" "")]
12706   ""
12707 {
12708   rtx test, op0, op1;
12709 #ifdef TARGET_THREAD_SSP_OFFSET
12710   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12711   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12712   operands[1] = gen_rtx_MEM (Pmode, addr);
12713 #endif
12714   op0 = operands[0];
12715   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
12716   test = gen_rtx_EQ (VOIDmode, op0, op1);
12717   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
12718   DONE;
12719 })
12720
12721 (define_insn "stack_protect_testsi"
12722   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12723         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
12724                       (match_operand:SI 2 "memory_operand" "m,m")]
12725                      UNSPEC_SP_TEST))
12726    (set (match_scratch:SI 4 "=r,r") (const_int 0))
12727    (clobber (match_scratch:SI 3 "=&r,&r"))]
12728   "TARGET_32BIT"
12729   "@
12730    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
12731    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;cmplw %0,%3,%4\;li %3,0\;li %4,0"
12732   [(set_attr "length" "16,20")])
12733
12734 (define_insn "stack_protect_testdi"
12735   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12736         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "Y,Y")
12737                       (match_operand:DI 2 "memory_operand" "Y,Y")]
12738                      UNSPEC_SP_TEST))
12739    (set (match_scratch:DI 4 "=r,r") (const_int 0))
12740    (clobber (match_scratch:DI 3 "=&r,&r"))]
12741   "TARGET_64BIT"
12742   "@
12743    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
12744    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;li %3,0\;li %4,0"
12745   [(set_attr "length" "16,20")])
12746
12747 \f
12748 ;; Here are the actual compare insns.
12749 (define_insn "*cmp<mode>_internal1"
12750   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
12751         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
12752                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
12753   ""
12754   "cmp<wd>%I2 %0,%1,%2"
12755   [(set_attr "type" "cmp")])
12756
12757 ;; If we are comparing a register for equality with a large constant,
12758 ;; we can do this with an XOR followed by a compare.  But this is profitable
12759 ;; only if the large constant is only used for the comparison (and in this
12760 ;; case we already have a register to reuse as scratch).
12761 ;;
12762 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
12763 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
12764
12765 (define_peephole2
12766   [(set (match_operand:SI 0 "register_operand")
12767         (match_operand:SI 1 "logical_const_operand" ""))
12768    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
12769                        [(match_dup 0)
12770                         (match_operand:SI 2 "logical_const_operand" "")]))
12771    (set (match_operand:CC 4 "cc_reg_operand" "")
12772         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
12773                     (match_dup 0)))
12774    (set (pc)
12775         (if_then_else (match_operator 6 "equality_operator"
12776                        [(match_dup 4) (const_int 0)])
12777                       (match_operand 7 "" "")
12778                       (match_operand 8 "" "")))]
12779   "peep2_reg_dead_p (3, operands[0])
12780    && peep2_reg_dead_p (4, operands[4])"
12781  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
12782   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
12783   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
12784  
12785 {
12786   /* Get the constant we are comparing against, and see what it looks like
12787      when sign-extended from 16 to 32 bits.  Then see what constant we could
12788      XOR with SEXTC to get the sign-extended value.  */
12789   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
12790                                               SImode,
12791                                               operands[1], operands[2]);
12792   HOST_WIDE_INT c = INTVAL (cnst);
12793   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
12794   HOST_WIDE_INT xorv = c ^ sextc;
12795
12796   operands[9] = GEN_INT (xorv);
12797   operands[10] = GEN_INT (sextc);
12798 })
12799
12800 (define_insn "*cmpsi_internal2"
12801   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12802         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12803                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
12804   ""
12805   "cmplw%I2 %0,%1,%b2"
12806   [(set_attr "type" "cmp")])
12807
12808 (define_insn "*cmpdi_internal2"
12809   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12810         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
12811                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
12812   ""
12813   "cmpld%I2 %0,%1,%b2"
12814   [(set_attr "type" "cmp")])
12815
12816 ;; The following two insns don't exist as single insns, but if we provide
12817 ;; them, we can swap an add and compare, which will enable us to overlap more
12818 ;; of the required delay between a compare and branch.  We generate code for
12819 ;; them by splitting.
12820
12821 (define_insn ""
12822   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
12823         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
12824                     (match_operand:SI 2 "short_cint_operand" "i")))
12825    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12826         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12827   ""
12828   "#"
12829   [(set_attr "length" "8")])
12830
12831 (define_insn ""
12832   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
12833         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12834                        (match_operand:SI 2 "u_short_cint_operand" "i")))
12835    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12836         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12837   ""
12838   "#"
12839   [(set_attr "length" "8")])
12840
12841 (define_split
12842   [(set (match_operand:CC 3 "cc_reg_operand" "")
12843         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
12844                     (match_operand:SI 2 "short_cint_operand" "")))
12845    (set (match_operand:SI 0 "gpc_reg_operand" "")
12846         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12847   ""
12848   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
12849    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12850
12851 (define_split
12852   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
12853         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
12854                        (match_operand:SI 2 "u_short_cint_operand" "")))
12855    (set (match_operand:SI 0 "gpc_reg_operand" "")
12856         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12857   ""
12858   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
12859    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12860
12861 (define_insn "*cmpsf_internal1"
12862   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12863         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
12864                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
12865   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
12866   "fcmpu %0,%1,%2"
12867   [(set_attr "type" "fpcompare")])
12868
12869 (define_insn "*cmpdf_internal1"
12870   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12871         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
12872                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
12873   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
12874    && !VECTOR_UNIT_VSX_P (DFmode)"
12875   "fcmpu %0,%1,%2"
12876   [(set_attr "type" "fpcompare")])
12877
12878 ;; Only need to compare second words if first words equal
12879 (define_insn "*cmptf_internal1"
12880   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12881         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12882                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
12883   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
12884    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12885   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
12886   [(set_attr "type" "fpcompare")
12887    (set_attr "length" "12")])
12888
12889 (define_insn_and_split "*cmptf_internal2"
12890   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12891         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12892                       (match_operand:TF 2 "gpc_reg_operand" "d")))
12893     (clobber (match_scratch:DF 3 "=d"))
12894     (clobber (match_scratch:DF 4 "=d"))
12895     (clobber (match_scratch:DF 5 "=d"))
12896     (clobber (match_scratch:DF 6 "=d"))
12897     (clobber (match_scratch:DF 7 "=d"))
12898     (clobber (match_scratch:DF 8 "=d"))
12899     (clobber (match_scratch:DF 9 "=d"))
12900     (clobber (match_scratch:DF 10 "=d"))
12901     (clobber (match_scratch:GPR 11 "=b"))]
12902   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
12903    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12904   "#"
12905   "&& reload_completed"
12906   [(set (match_dup 3) (match_dup 14))
12907    (set (match_dup 4) (match_dup 15))
12908    (set (match_dup 9) (abs:DF (match_dup 5)))
12909    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
12910    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
12911                            (label_ref (match_dup 12))
12912                            (pc)))
12913    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
12914    (set (pc) (label_ref (match_dup 13)))
12915    (match_dup 12)
12916    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
12917    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
12918    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
12919    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
12920    (match_dup 13)]
12921 {
12922   REAL_VALUE_TYPE rv;
12923   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
12924   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
12925
12926   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
12927   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
12928   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
12929   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
12930   operands[12] = gen_label_rtx ();
12931   operands[13] = gen_label_rtx ();
12932   real_inf (&rv);
12933   operands[14] = force_const_mem (DFmode,
12934                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
12935   operands[15] = force_const_mem (DFmode,
12936                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
12937                                                                 DFmode));
12938   if (TARGET_TOC)
12939     {
12940       rtx tocref;
12941       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
12942       operands[14] = gen_const_mem (DFmode, tocref);
12943       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
12944       operands[15] = gen_const_mem (DFmode, tocref);
12945       set_mem_alias_set (operands[14], get_TOC_alias_set ());
12946       set_mem_alias_set (operands[15], get_TOC_alias_set ());
12947     }
12948 })
12949 \f
12950 ;; Now we have the scc insns.  We can do some combinations because of the
12951 ;; way the machine works.
12952 ;;
12953 ;; Note that this is probably faster if we can put an insn between the
12954 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
12955 ;; cases the insns below which don't use an intermediate CR field will
12956 ;; be used instead.
12957 (define_insn ""
12958   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12959         (match_operator:SI 1 "scc_comparison_operator"
12960                            [(match_operand 2 "cc_reg_operand" "y")
12961                             (const_int 0)]))]
12962   ""
12963   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
12964   [(set (attr "type")
12965      (cond [(match_test "TARGET_MFCRF")
12966                 (const_string "mfcrf")
12967            ]
12968         (const_string "mfcr")))
12969    (set_attr "length" "8")])
12970
12971 ;; Same as above, but get the GT bit.
12972 (define_insn "move_from_CR_gt_bit"
12973   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12974         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
12975   "TARGET_HARD_FLOAT && !TARGET_FPRS"
12976   "mfcr %0\;rlwinm %0,%0,%D1,31,31"
12977   [(set_attr "type" "mfcr")
12978    (set_attr "length" "8")])
12979
12980 ;; Same as above, but get the OV/ORDERED bit.
12981 (define_insn "move_from_CR_ov_bit"
12982   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12983         (unspec:SI [(match_operand:CC 1 "cc_reg_operand" "y")]
12984                    UNSPEC_MV_CR_OV))]
12985   "TARGET_ISEL"
12986   "mfcr %0\;rlwinm %0,%0,%t1,1"
12987   [(set_attr "type" "mfcr")
12988    (set_attr "length" "8")])
12989
12990 (define_insn ""
12991   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12992         (match_operator:DI 1 "scc_comparison_operator"
12993                            [(match_operand 2 "cc_reg_operand" "y")
12994                             (const_int 0)]))]
12995   "TARGET_POWERPC64"
12996   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
12997   [(set (attr "type")
12998      (cond [(match_test "TARGET_MFCRF")
12999                 (const_string "mfcrf")
13000            ]
13001         (const_string "mfcr")))
13002    (set_attr "length" "8")])
13003
13004 (define_insn ""
13005   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13006         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13007                                        [(match_operand 2 "cc_reg_operand" "y,y")
13008                                         (const_int 0)])
13009                     (const_int 0)))
13010    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
13011         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13012   "TARGET_32BIT"
13013   "@
13014    mfcr %3%Q2\;rlwinm. %3,%3,%J1,1
13015    #"
13016   [(set_attr "type" "delayed_compare")
13017    (set_attr "length" "8,16")])
13018
13019 (define_split
13020   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13021         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13022                                        [(match_operand 2 "cc_reg_operand" "")
13023                                         (const_int 0)])
13024                     (const_int 0)))
13025    (set (match_operand:SI 3 "gpc_reg_operand" "")
13026         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13027   "TARGET_32BIT && reload_completed"
13028   [(set (match_dup 3)
13029         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
13030    (set (match_dup 0)
13031         (compare:CC (match_dup 3)
13032                     (const_int 0)))]
13033   "")
13034
13035 (define_insn ""
13036   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13037         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13038                                       [(match_operand 2 "cc_reg_operand" "y")
13039                                        (const_int 0)])
13040                    (match_operand:SI 3 "const_int_operand" "n")))]
13041   ""
13042   "*
13043 {
13044   int is_bit = ccr_bit (operands[1], 1);
13045   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13046   int count;
13047
13048   if (is_bit >= put_bit)
13049     count = is_bit - put_bit;
13050   else
13051     count = 32 - (put_bit - is_bit);
13052
13053   operands[4] = GEN_INT (count);
13054   operands[5] = GEN_INT (put_bit);
13055
13056   return \"mfcr %0%Q2\;rlwinm %0,%0,%4,%5,%5\";
13057 }"
13058   [(set (attr "type")
13059      (cond [(match_test "TARGET_MFCRF")
13060                 (const_string "mfcrf")
13061            ]
13062         (const_string "mfcr")))
13063    (set_attr "length" "8")])
13064
13065 (define_insn ""
13066   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13067         (compare:CC
13068          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13069                                        [(match_operand 2 "cc_reg_operand" "y,y")
13070                                         (const_int 0)])
13071                     (match_operand:SI 3 "const_int_operand" "n,n"))
13072          (const_int 0)))
13073    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
13074         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13075                    (match_dup 3)))]
13076   ""
13077   "*
13078 {
13079   int is_bit = ccr_bit (operands[1], 1);
13080   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13081   int count;
13082
13083   /* Force split for non-cc0 compare.  */
13084   if (which_alternative == 1)
13085      return \"#\";
13086
13087   if (is_bit >= put_bit)
13088     count = is_bit - put_bit;
13089   else
13090     count = 32 - (put_bit - is_bit);
13091
13092   operands[5] = GEN_INT (count);
13093   operands[6] = GEN_INT (put_bit);
13094
13095   return \"mfcr %4%Q2\;rlwinm. %4,%4,%5,%6,%6\";
13096 }"
13097   [(set_attr "type" "delayed_compare")
13098    (set_attr "length" "8,16")])
13099
13100 (define_split
13101   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13102         (compare:CC
13103          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13104                                        [(match_operand 2 "cc_reg_operand" "")
13105                                         (const_int 0)])
13106                     (match_operand:SI 3 "const_int_operand" ""))
13107          (const_int 0)))
13108    (set (match_operand:SI 4 "gpc_reg_operand" "")
13109         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13110                    (match_dup 3)))]
13111   "reload_completed"
13112   [(set (match_dup 4)
13113         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13114                    (match_dup 3)))
13115    (set (match_dup 0)
13116         (compare:CC (match_dup 4)
13117                     (const_int 0)))]
13118   "")
13119
13120 ;; There is a 3 cycle delay between consecutive mfcr instructions
13121 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13122
13123 (define_peephole
13124   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13125         (match_operator:SI 1 "scc_comparison_operator"
13126                            [(match_operand 2 "cc_reg_operand" "y")
13127                             (const_int 0)]))
13128    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13129         (match_operator:SI 4 "scc_comparison_operator"
13130                            [(match_operand 5 "cc_reg_operand" "y")
13131                             (const_int 0)]))]
13132   "REGNO (operands[2]) != REGNO (operands[5])"
13133   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
13134   [(set_attr "type" "mfcr")
13135    (set_attr "length" "12")])
13136
13137 (define_peephole
13138   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13139         (match_operator:DI 1 "scc_comparison_operator"
13140                            [(match_operand 2 "cc_reg_operand" "y")
13141                             (const_int 0)]))
13142    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13143         (match_operator:DI 4 "scc_comparison_operator"
13144                            [(match_operand 5 "cc_reg_operand" "y")
13145                             (const_int 0)]))]
13146   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13147   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
13148   [(set_attr "type" "mfcr")
13149    (set_attr "length" "12")])
13150
13151 ;; There are some scc insns that can be done directly, without a compare.
13152 ;; These are faster because they don't involve the communications between
13153 ;; the FXU and branch units.   In fact, we will be replacing all of the
13154 ;; integer scc insns here or in the portable methods in emit_store_flag.
13155 ;;
13156 ;; Also support (neg (scc ..)) since that construct is used to replace
13157 ;; branches, (plus (scc ..) ..) since that construct is common and
13158 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13159 ;; cases where it is no more expensive than (neg (scc ..)).
13160
13161 ;; Have reload force a constant into a register for the simple insns that
13162 ;; otherwise won't accept constants.  We do this because it is faster than
13163 ;; the cmp/mfcr sequence we would otherwise generate.
13164
13165 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13166                               (DI "rKJI")])
13167
13168 (define_insn_and_split "*eq<mode>"
13169   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13170         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13171                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13172   ""
13173   "#"
13174   ""
13175   [(set (match_dup 0)
13176         (clz:GPR (match_dup 3)))
13177    (set (match_dup 0)
13178         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13179   {
13180     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13181       {
13182         /* Use output operand as intermediate.  */
13183         operands[3] = operands[0];
13184
13185         if (logical_operand (operands[2], <MODE>mode))
13186           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13187                                   gen_rtx_XOR (<MODE>mode,
13188                                                operands[1], operands[2])));
13189         else
13190           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13191                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13192                                                 negate_rtx (<MODE>mode,
13193                                                             operands[2]))));
13194       }
13195     else
13196       operands[3] = operands[1];
13197
13198     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13199   })
13200
13201 (define_insn_and_split "*eq<mode>_compare"
13202   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13203         (compare:CC
13204          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13205                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13206          (const_int 0)))
13207    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13208         (eq:P (match_dup 1) (match_dup 2)))]
13209   "optimize_size"
13210   "#"
13211   "optimize_size"
13212   [(set (match_dup 0)
13213         (clz:P (match_dup 4)))
13214    (parallel [(set (match_dup 3)
13215                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13216                                (const_int 0)))
13217               (set (match_dup 0)
13218                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13219   {
13220     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13221       {
13222         /* Use output operand as intermediate.  */
13223         operands[4] = operands[0];
13224
13225         if (logical_operand (operands[2], <MODE>mode))
13226           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13227                                   gen_rtx_XOR (<MODE>mode,
13228                                                operands[1], operands[2])));
13229         else
13230           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13231                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13232                                                 negate_rtx (<MODE>mode,
13233                                                             operands[2]))));
13234       }
13235     else
13236       operands[4] = operands[1];
13237
13238     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13239   })
13240
13241 ;; We have insns of the form shown by the first define_insn below.  If
13242 ;; there is something inside the comparison operation, we must split it.
13243 (define_split
13244   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13245         (plus:SI (match_operator 1 "comparison_operator"
13246                                  [(match_operand:SI 2 "" "")
13247                                   (match_operand:SI 3
13248                                                     "reg_or_cint_operand" "")])
13249                  (match_operand:SI 4 "gpc_reg_operand" "")))
13250    (clobber (match_operand:SI 5 "register_operand" ""))]
13251   "! gpc_reg_operand (operands[2], SImode)"
13252   [(set (match_dup 5) (match_dup 2))
13253    (set (match_dup 0) (plus:SI (match_op_dup 1 [(match_dup 5) (match_dup 3)])
13254                                (match_dup 4)))])
13255
13256 (define_insn "*plus_eqsi"
13257   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13258         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13259                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13260                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13261   "TARGET_32BIT"
13262   "@
13263    xor %0,%1,%2\;subfic %0,%0,0\;addze %0,%3
13264    subfic %0,%1,0\;addze %0,%3
13265    xori %0,%1,%b2\;subfic %0,%0,0\;addze %0,%3
13266    xoris %0,%1,%u2\;subfic %0,%0,0\;addze %0,%3
13267    subfic %0,%1,%2\;subfic %0,%0,0\;addze %0,%3"
13268   [(set_attr "type" "three,two,three,three,three")
13269    (set_attr "length" "12,8,12,12,12")])
13270
13271 (define_insn "*compare_plus_eqsi"
13272   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13273         (compare:CC
13274          (plus:SI
13275           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13276                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13277           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13278          (const_int 0)))
13279    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13280   "TARGET_32BIT && optimize_size"
13281   "@
13282    xor %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
13283    subfic %4,%1,0\;addze. %4,%3
13284    xori %4,%1,%b2\;subfic %4,%4,0\;addze. %4,%3
13285    xoris %4,%1,%u2\;subfic %4,%4,0\;addze. %4,%3
13286    subfic %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
13287    #
13288    #
13289    #
13290    #
13291    #"
13292   [(set_attr "type" "compare")
13293    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13294
13295 (define_split
13296   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13297         (compare:CC
13298          (plus:SI
13299           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13300                  (match_operand:SI 2 "scc_eq_operand" ""))
13301           (match_operand:SI 3 "gpc_reg_operand" ""))
13302          (const_int 0)))
13303    (clobber (match_scratch:SI 4 ""))]
13304   "TARGET_32BIT && optimize_size && reload_completed"
13305   [(set (match_dup 4)
13306         (plus:SI (eq:SI (match_dup 1)
13307                  (match_dup 2))
13308           (match_dup 3)))
13309    (set (match_dup 0)
13310         (compare:CC (match_dup 4)
13311                     (const_int 0)))]
13312   "")
13313
13314 (define_insn "*plus_eqsi_compare"
13315   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13316         (compare:CC
13317          (plus:SI
13318           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13319                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13320           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13321          (const_int 0)))
13322    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13323         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13324   "TARGET_32BIT && optimize_size"
13325   "@
13326    xor %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
13327    subfic %0,%1,0\;addze. %0,%3
13328    xori %0,%1,%b2\;subfic %0,%0,0\;addze. %0,%3
13329    xoris %0,%1,%u2\;subfic %0,%0,0\;addze. %0,%3
13330    subfic %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
13331    #
13332    #
13333    #
13334    #
13335    #"
13336   [(set_attr "type" "compare")
13337    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13338
13339 (define_split
13340   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13341         (compare:CC
13342          (plus:SI
13343           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13344                  (match_operand:SI 2 "scc_eq_operand" ""))
13345           (match_operand:SI 3 "gpc_reg_operand" ""))
13346          (const_int 0)))
13347    (set (match_operand:SI 0 "gpc_reg_operand" "")
13348         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13349   "TARGET_32BIT && optimize_size && reload_completed"
13350   [(set (match_dup 0)
13351         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13352    (set (match_dup 4)
13353         (compare:CC (match_dup 0)
13354                     (const_int 0)))]
13355   "")
13356
13357 (define_insn "*neg_eq0<mode>"
13358   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13359         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13360                      (const_int 0))))]
13361   ""
13362   "addic %0,%1,-1\;subfe %0,%0,%0"
13363   [(set_attr "type" "two")
13364    (set_attr "length" "8")])
13365
13366 (define_insn_and_split "*neg_eq<mode>"
13367   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13368         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
13369                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
13370   ""
13371   "#"
13372   ""
13373   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
13374   {
13375     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13376       {
13377         /* Use output operand as intermediate.  */
13378         operands[3] = operands[0];
13379
13380         if (logical_operand (operands[2], <MODE>mode))
13381           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13382                                   gen_rtx_XOR (<MODE>mode,
13383                                                operands[1], operands[2])));
13384         else
13385           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13386                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13387                                                 negate_rtx (<MODE>mode,
13388                                                             operands[2]))));
13389       }
13390     else
13391       operands[3] = operands[1];
13392   })
13393
13394 (define_insn "*ne0_<mode>"
13395   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13396         (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13397               (const_int 0)))
13398    (clobber (match_scratch:P 2 "=&r"))]
13399   "!(TARGET_32BIT && TARGET_ISEL)"
13400   "addic %2,%1,-1\;subfe %0,%2,%1"
13401   [(set_attr "type" "two")
13402    (set_attr "length" "8")])
13403
13404 (define_insn "*plus_ne0_<mode>"
13405   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13406         (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13407                       (const_int 0))
13408                 (match_operand:P 2 "gpc_reg_operand" "r")))
13409    (clobber (match_scratch:P 3 "=&r"))]
13410   ""
13411   "addic %3,%1,-1\;addze %0,%2"
13412   [(set_attr "type" "two")
13413    (set_attr "length" "8")])
13414
13415 (define_insn "*compare_plus_ne0_<mode>"
13416   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13417         (compare:CC (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13418                                   (const_int 0))
13419                             (match_operand:P 2 "gpc_reg_operand" "r,r"))
13420                     (const_int 0)))
13421    (clobber (match_scratch:P 3 "=&r,&r"))
13422    (clobber (match_scratch:P 4 "=X,&r"))]
13423   ""
13424   "@
13425    addic %3,%1,-1\;addze. %3,%2
13426    #"
13427   [(set_attr "type" "compare")
13428    (set_attr "length" "8,12")])
13429
13430 (define_split
13431   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13432         (compare:CC (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
13433                           (const_int 0))
13434                     (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
13435    (clobber (match_scratch:P 3 ""))
13436    (clobber (match_scratch:P 4 ""))]
13437   "reload_completed"
13438   [(parallel [(set (match_dup 3)
13439                    (plus:P (ne:P (match_dup 1)
13440                                  (const_int 0))
13441                            (match_dup 2)))
13442               (clobber (match_dup 4))])
13443    (set (match_dup 0)
13444         (compare:CC (match_dup 3)
13445                     (const_int 0)))]
13446   "")
13447
13448 ; For combine.
13449 (define_insn "*compare_plus_ne0_<mode>_1"
13450   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13451         (compare:CCEQ (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13452                             (const_int 0))
13453                       (neg:P (match_operand:P 2 "gpc_reg_operand" "r,r"))))
13454    (clobber (match_scratch:P 3 "=&r,&r"))
13455    (clobber (match_scratch:P 4 "=X,&r"))]
13456   ""
13457   "@
13458    addic %3,%1,-1\;addze. %3,%2
13459    #"
13460   [(set_attr "type" "compare")
13461    (set_attr "length" "8,12")])
13462
13463 (define_split
13464   [(set (match_operand:CCEQ 0 "cc_reg_not_micro_cr0_operand" "")
13465         (compare:CCEQ (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
13466                             (const_int 0))
13467                       (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
13468    (clobber (match_scratch:P 3 ""))
13469    (clobber (match_scratch:P 4 ""))]
13470   "reload_completed"
13471   [(parallel [(set (match_dup 3)
13472                    (plus:P (ne:P (match_dup 1)
13473                                  (const_int 0))
13474                            (match_dup 2)))
13475               (clobber (match_dup 4))])
13476    (set (match_dup 0)
13477         (compare:CC (match_dup 3)
13478                     (const_int 0)))]
13479   "")
13480
13481 (define_insn "*plus_ne0_<mode>_compare"
13482   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13483         (compare:CC
13484          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13485                        (const_int 0))
13486                  (match_operand:P 2 "gpc_reg_operand" "r,r"))
13487          (const_int 0)))
13488    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13489         (plus:P (ne:P (match_dup 1)
13490                       (const_int 0))
13491                 (match_dup 2)))
13492    (clobber (match_scratch:P 3 "=&r,&r"))]
13493   ""
13494   "@
13495    addic %3,%1,-1\;addze. %0,%2
13496    #"
13497   [(set_attr "type" "compare")
13498    (set_attr "length" "8,12")])
13499
13500 (define_split
13501   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
13502         (compare:CC
13503          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "")
13504                        (const_int 0))
13505                  (match_operand:P 2 "gpc_reg_operand" ""))
13506          (const_int 0)))
13507    (set (match_operand:P 0 "gpc_reg_operand" "")
13508         (plus:P (ne:P (match_dup 1)
13509                       (const_int 0))
13510                 (match_dup 2)))
13511    (clobber (match_scratch:P 3 ""))]
13512   "reload_completed"
13513   [(parallel [(set (match_dup 0)
13514                    (plus:P (ne:P (match_dup 1)
13515                                  (const_int 0))
13516                            (match_dup 2)))
13517               (clobber (match_dup 3))])
13518    (set (match_dup 4)
13519         (compare:CC (match_dup 0)
13520                     (const_int 0)))]
13521   "")
13522
13523 (define_insn "*leu<mode>"
13524   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13525         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13526                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13527   ""
13528   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
13529   [(set_attr "type" "three")
13530    (set_attr "length" "12")])
13531
13532 (define_insn "*leu<mode>_compare"
13533   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13534         (compare:CC
13535          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13536                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13537          (const_int 0)))
13538    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13539         (leu:P (match_dup 1) (match_dup 2)))]
13540   ""
13541   "@
13542    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
13543    #"
13544   [(set_attr "type" "compare")
13545    (set_attr "length" "12,16")])
13546
13547 (define_split
13548   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13549         (compare:CC
13550          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
13551                 (match_operand:P 2 "reg_or_short_operand" ""))
13552          (const_int 0)))
13553    (set (match_operand:P 0 "gpc_reg_operand" "")
13554         (leu:P (match_dup 1) (match_dup 2)))]
13555   "reload_completed"
13556   [(set (match_dup 0)
13557         (leu:P (match_dup 1) (match_dup 2)))
13558    (set (match_dup 3)
13559         (compare:CC (match_dup 0)
13560                     (const_int 0)))]
13561   "")
13562
13563 (define_insn "*plus_leu<mode>"
13564   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13565         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13566                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13567                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13568   ""
13569   "subf%I2c %0,%1,%2\;addze %0,%3"
13570   [(set_attr "type" "two")
13571    (set_attr "length" "8")])
13572
13573 (define_insn ""
13574   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13575         (compare:CC
13576          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13577                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13578                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13579          (const_int 0)))
13580    (clobber (match_scratch:SI 4 "=&r,&r"))]
13581   "TARGET_32BIT"
13582   "@
13583    subf%I2c %4,%1,%2\;addze. %4,%3
13584    #"
13585   [(set_attr "type" "compare")
13586    (set_attr "length" "8,12")])
13587
13588 (define_split
13589   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13590         (compare:CC
13591          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13592                           (match_operand:SI 2 "reg_or_short_operand" ""))
13593                   (match_operand:SI 3 "gpc_reg_operand" ""))
13594          (const_int 0)))
13595    (clobber (match_scratch:SI 4 ""))]
13596   "TARGET_32BIT && reload_completed"
13597   [(set (match_dup 4)
13598         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
13599                   (match_dup 3)))
13600    (set (match_dup 0)
13601         (compare:CC (match_dup 4)
13602                     (const_int 0)))]
13603   "")
13604
13605 (define_insn ""
13606   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13607         (compare:CC
13608          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13609                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13610                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13611          (const_int 0)))
13612    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13613         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13614   "TARGET_32BIT"
13615   "@
13616    subf%I2c %0,%1,%2\;addze. %0,%3
13617    #"
13618   [(set_attr "type" "compare")
13619    (set_attr "length" "8,12")])
13620
13621 (define_split
13622   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13623         (compare:CC
13624          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13625                           (match_operand:SI 2 "reg_or_short_operand" ""))
13626                   (match_operand:SI 3 "gpc_reg_operand" ""))
13627          (const_int 0)))
13628    (set (match_operand:SI 0 "gpc_reg_operand" "")
13629         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13630   "TARGET_32BIT && reload_completed"
13631   [(set (match_dup 0)
13632         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13633    (set (match_dup 4)
13634         (compare:CC (match_dup 0)
13635                     (const_int 0)))]
13636   "")
13637
13638 (define_insn "*neg_leu<mode>"
13639   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13640         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13641                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13642   ""
13643   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;nand %0,%0,%0"
13644    [(set_attr "type" "three")
13645     (set_attr "length" "12")])
13646
13647 (define_insn "*and_neg_leu<mode>"
13648   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13649         (and:P (neg:P
13650                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13651                         (match_operand:P 2 "reg_or_short_operand" "rI")))
13652                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13653   ""
13654   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc %0,%3,%0"
13655   [(set_attr "type" "three")
13656    (set_attr "length" "12")])
13657
13658 (define_insn ""
13659   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13660         (compare:CC
13661          (and:SI (neg:SI
13662                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13663                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13664                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13665          (const_int 0)))
13666    (clobber (match_scratch:SI 4 "=&r,&r"))]
13667   "TARGET_32BIT"
13668   "@
13669    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;andc. %4,%3,%4
13670    #"
13671   [(set_attr "type" "compare")
13672    (set_attr "length" "12,16")])
13673
13674 (define_split
13675   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13676         (compare:CC
13677          (and:SI (neg:SI
13678                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13679                           (match_operand:SI 2 "reg_or_short_operand" "")))
13680                  (match_operand:SI 3 "gpc_reg_operand" ""))
13681          (const_int 0)))
13682    (clobber (match_scratch:SI 4 ""))]
13683   "TARGET_32BIT && reload_completed"
13684   [(set (match_dup 4)
13685         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13686                 (match_dup 3)))
13687    (set (match_dup 0)
13688         (compare:CC (match_dup 4)
13689                     (const_int 0)))]
13690   "")
13691
13692 (define_insn ""
13693   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13694         (compare:CC
13695          (and:SI (neg:SI
13696                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13697                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13698                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13699          (const_int 0)))
13700    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13701         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13702   "TARGET_32BIT"
13703   "@
13704    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc. %0,%3,%0
13705    #"
13706   [(set_attr "type" "compare")
13707    (set_attr "length" "12,16")])
13708
13709 (define_split
13710   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13711         (compare:CC
13712          (and:SI (neg:SI
13713                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13714                           (match_operand:SI 2 "reg_or_short_operand" "")))
13715                  (match_operand:SI 3 "gpc_reg_operand" ""))
13716          (const_int 0)))
13717    (set (match_operand:SI 0 "gpc_reg_operand" "")
13718         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13719   "TARGET_32BIT && reload_completed"
13720   [(set (match_dup 0)
13721         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13722                 (match_dup 3)))
13723    (set (match_dup 4)
13724         (compare:CC (match_dup 0)
13725                     (const_int 0)))]
13726   "")
13727
13728 (define_insn_and_split "*ltu<mode>"
13729   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13730         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13731                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13732   ""
13733   "#"
13734   ""
13735   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13736    (set (match_dup 0) (neg:P (match_dup 0)))]
13737   "")
13738
13739 (define_insn_and_split "*ltu<mode>_compare"
13740   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13741         (compare:CC
13742          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13743                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13744          (const_int 0)))
13745    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13746         (ltu:P (match_dup 1) (match_dup 2)))]
13747   ""
13748   "#"
13749   ""
13750   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13751    (parallel [(set (match_dup 3)
13752                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13753               (set (match_dup 0) (neg:P (match_dup 0)))])]
13754   "")
13755
13756 (define_insn_and_split "*plus_ltu<mode>"
13757   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
13758         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13759                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13760                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
13761   ""
13762   "#"
13763   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13764   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13765    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13766   "")
13767
13768 (define_insn_and_split "*plus_ltu<mode>_compare"
13769   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13770         (compare:CC
13771          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13772                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13773                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13774          (const_int 0)))
13775    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13776         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13777   ""
13778   "#"
13779   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13780   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13781    (parallel [(set (match_dup 4)
13782                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13783                                (const_int 0)))
13784               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13785   "")
13786
13787 (define_insn "*neg_ltu<mode>"
13788   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13789         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13790                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
13791   ""
13792   "@
13793    subfc %0,%2,%1\;subfe %0,%0,%0
13794    addic %0,%1,%n2\;subfe %0,%0,%0"
13795   [(set_attr "type" "two")
13796    (set_attr "length" "8")])
13797
13798 (define_insn "*geu<mode>"
13799   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13800         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13801                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13802   ""
13803   "@
13804    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
13805    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
13806   [(set_attr "type" "three")
13807    (set_attr "length" "12")])
13808
13809 (define_insn "*geu<mode>_compare"
13810   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13811         (compare:CC
13812          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13813                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13814          (const_int 0)))
13815    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13816         (geu:P (match_dup 1) (match_dup 2)))]
13817   ""
13818   "@
13819    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
13820    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
13821    #
13822    #"
13823   [(set_attr "type" "compare")
13824    (set_attr "length" "12,12,16,16")])
13825
13826 (define_split
13827   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
13828         (compare:CC
13829          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
13830                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
13831          (const_int 0)))
13832    (set (match_operand:P 0 "gpc_reg_operand" "")
13833         (geu:P (match_dup 1) (match_dup 2)))]
13834   "reload_completed"
13835   [(set (match_dup 0)
13836         (geu:P (match_dup 1) (match_dup 2)))
13837    (set (match_dup 3)
13838         (compare:CC (match_dup 0)
13839                     (const_int 0)))]
13840   "")
13841
13842 (define_insn "*plus_geu<mode>"
13843   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13844         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13845                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13846                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13847   ""
13848   "@
13849    subfc %0,%2,%1\;addze %0,%3
13850    addic %0,%1,%n2\;addze %0,%3"
13851   [(set_attr "type" "two")
13852    (set_attr "length" "8")])
13853
13854 (define_insn ""
13855   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13856         (compare:CC
13857          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13858                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13859                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13860          (const_int 0)))
13861    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13862   "TARGET_32BIT"
13863   "@
13864    subfc %4,%2,%1\;addze. %4,%3
13865    addic %4,%1,%n2\;addze. %4,%3
13866    #
13867    #"
13868   [(set_attr "type" "compare")
13869    (set_attr "length" "8,8,12,12")])
13870
13871 (define_split
13872   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13873         (compare:CC
13874          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13875                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13876                   (match_operand:SI 3 "gpc_reg_operand" ""))
13877          (const_int 0)))
13878    (clobber (match_scratch:SI 4 ""))]
13879   "TARGET_32BIT && reload_completed"
13880   [(set (match_dup 4)
13881         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
13882                   (match_dup 3)))
13883    (set (match_dup 0)
13884         (compare:CC (match_dup 4)
13885                     (const_int 0)))]
13886   "")
13887
13888 (define_insn ""
13889   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13890         (compare:CC
13891          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13892                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13893                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13894          (const_int 0)))
13895    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13896         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13897   "TARGET_32BIT"
13898   "@
13899    subfc %0,%2,%1\;addze. %0,%3
13900    addic %0,%1,%n2\;addze. %0,%3
13901    #
13902    #"
13903   [(set_attr "type" "compare")
13904    (set_attr "length" "8,8,12,12")])
13905
13906 (define_split
13907   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13908         (compare:CC
13909          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13910                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13911                   (match_operand:SI 3 "gpc_reg_operand" ""))
13912          (const_int 0)))
13913    (set (match_operand:SI 0 "gpc_reg_operand" "")
13914         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13915   "TARGET_32BIT && reload_completed"
13916   [(set (match_dup 0)
13917         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13918    (set (match_dup 4)
13919         (compare:CC (match_dup 0)
13920                     (const_int 0)))]
13921   "")
13922
13923 (define_insn "*neg_geu<mode>"
13924   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13925         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13926                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
13927   ""
13928   "@
13929    subfc %0,%2,%1\;subfe %0,%0,%0\;nand %0,%0,%0
13930    subfic %0,%1,-1\;add%I2c %0,%0,%2\;subfe %0,%0,%0"
13931   [(set_attr "type" "three")
13932    (set_attr "length" "12")])
13933
13934 (define_insn "*and_neg_geu<mode>"
13935   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13936         (and:P (neg:P
13937                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13938                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
13939                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13940   ""
13941   "@
13942    subfc %0,%2,%1\;subfe %0,%0,%0\;andc %0,%3,%0
13943    addic %0,%1,%n2\;subfe %0,%0,%0\;andc %0,%3,%0"
13944   [(set_attr "type" "three")
13945    (set_attr "length" "12")])
13946
13947 (define_insn ""
13948   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13949         (compare:CC
13950          (and:SI (neg:SI
13951                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13952                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13953                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13954          (const_int 0)))
13955    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13956   "TARGET_32BIT"
13957   "@
13958    subfc %4,%2,%1\;subfe %4,%4,%4\;andc. %4,%3,%4
13959    addic %4,%1,%n2\;subfe %4,%4,%4\;andc. %4,%3,%4
13960    #
13961    #"
13962   [(set_attr "type" "compare")
13963    (set_attr "length" "12,12,16,16")])
13964
13965 (define_split
13966   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13967         (compare:CC
13968          (and:SI (neg:SI
13969                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13970                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13971                  (match_operand:SI 3 "gpc_reg_operand" ""))
13972          (const_int 0)))
13973    (clobber (match_scratch:SI 4 ""))]
13974   "TARGET_32BIT && reload_completed"
13975   [(set (match_dup 4)
13976         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
13977                 (match_dup 3)))
13978    (set (match_dup 0)
13979         (compare:CC (match_dup 4)
13980                     (const_int 0)))]
13981   "")
13982
13983 (define_insn ""
13984   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13985         (compare:CC
13986          (and:SI (neg:SI
13987                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13988                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13989                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13990          (const_int 0)))
13991    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13992         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13993   "TARGET_32BIT"
13994   "@
13995    subfc %0,%2,%1\;subfe %0,%0,%0\;andc. %0,%3,%0
13996    addic %0,%1,%n2\;subfe %0,%0,%0\;andc. %0,%3,%0
13997    #
13998    #"
13999   [(set_attr "type" "compare")
14000    (set_attr "length" "12,12,16,16")])
14001
14002 (define_split
14003   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14004         (compare:CC
14005          (and:SI (neg:SI
14006                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14007                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14008                  (match_operand:SI 3 "gpc_reg_operand" ""))
14009          (const_int 0)))
14010    (set (match_operand:SI 0 "gpc_reg_operand" "")
14011         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14012   "TARGET_32BIT && reload_completed"
14013   [(set (match_dup 0)
14014         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
14015    (set (match_dup 4)
14016         (compare:CC (match_dup 0)
14017                     (const_int 0)))]
14018   "")
14019
14020 (define_insn "*plus_gt0<mode>"
14021   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14022         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
14023                       (const_int 0))
14024                  (match_operand:P 2 "gpc_reg_operand" "r")))]
14025   ""
14026   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
14027   [(set_attr "type" "three")
14028    (set_attr "length" "12")])
14029
14030 (define_insn ""
14031   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14032         (compare:CC
14033          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14034                          (const_int 0))
14035                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14036          (const_int 0)))
14037    (clobber (match_scratch:SI 3 "=&r,&r"))]
14038   "TARGET_32BIT"
14039   "@
14040    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14041    #"
14042   [(set_attr "type" "compare")
14043    (set_attr "length" "12,16")])
14044
14045 (define_split
14046   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14047         (compare:CC
14048          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14049                          (const_int 0))
14050                   (match_operand:SI 2 "gpc_reg_operand" ""))
14051          (const_int 0)))
14052    (clobber (match_scratch:SI 3 ""))]
14053   "TARGET_32BIT && reload_completed"
14054   [(set (match_dup 3)
14055         (plus:SI (gt:SI (match_dup 1) (const_int 0))
14056                   (match_dup 2)))
14057    (set (match_dup 0)
14058         (compare:CC (match_dup 3)
14059                     (const_int 0)))]
14060   "")
14061
14062 (define_insn ""
14063   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14064         (compare:CC
14065          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14066                          (const_int 0))
14067                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14068          (const_int 0)))
14069    (clobber (match_scratch:DI 3 "=&r,&r"))]
14070   "TARGET_64BIT"
14071   "@
14072    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14073    #"
14074   [(set_attr "type" "compare")
14075    (set_attr "length" "12,16")])
14076
14077 (define_split
14078   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14079         (compare:CC
14080          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14081                          (const_int 0))
14082                   (match_operand:DI 2 "gpc_reg_operand" ""))
14083          (const_int 0)))
14084    (clobber (match_scratch:DI 3 ""))]
14085   "TARGET_64BIT && reload_completed"
14086   [(set (match_dup 3)
14087         (plus:DI (gt:DI (match_dup 1) (const_int 0))
14088                  (match_dup 2)))
14089    (set (match_dup 0)
14090         (compare:CC (match_dup 3)
14091                     (const_int 0)))]
14092   "")
14093
14094 (define_insn ""
14095   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14096         (compare:CC
14097          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14098                          (const_int 0))
14099                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14100          (const_int 0)))
14101    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14102         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14103   "TARGET_32BIT"
14104   "@
14105    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14106    #"
14107   [(set_attr "type" "compare")
14108    (set_attr "length" "12,16")])
14109
14110 (define_split
14111   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14112         (compare:CC
14113          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14114                          (const_int 0))
14115                   (match_operand:SI 2 "gpc_reg_operand" ""))
14116          (const_int 0)))
14117    (set (match_operand:SI 0 "gpc_reg_operand" "")
14118         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14119   "TARGET_32BIT && reload_completed"
14120   [(set (match_dup 0)
14121         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
14122    (set (match_dup 3)
14123         (compare:CC (match_dup 0)
14124                     (const_int 0)))]
14125   "")
14126
14127 (define_insn ""
14128   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14129         (compare:CC
14130          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14131                          (const_int 0))
14132                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14133          (const_int 0)))
14134    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
14135         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14136   "TARGET_64BIT"
14137   "@
14138    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14139    #"
14140   [(set_attr "type" "compare")
14141    (set_attr "length" "12,16")])
14142
14143 (define_split
14144   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14145         (compare:CC
14146          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14147                          (const_int 0))
14148                   (match_operand:DI 2 "gpc_reg_operand" ""))
14149          (const_int 0)))
14150    (set (match_operand:DI 0 "gpc_reg_operand" "")
14151         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14152   "TARGET_64BIT && reload_completed"
14153   [(set (match_dup 0)
14154         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
14155    (set (match_dup 3)
14156         (compare:CC (match_dup 0)
14157                     (const_int 0)))]
14158   "")
14159
14160 (define_insn_and_split "*gtu<mode>"
14161   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14162         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14163                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14164   ""
14165   "#"
14166   ""
14167   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14168    (set (match_dup 0) (neg:P (match_dup 0)))]
14169   "")
14170
14171 (define_insn_and_split "*gtu<mode>_compare"
14172   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14173         (compare:CC
14174          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14175                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14176          (const_int 0)))
14177    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14178         (gtu:P (match_dup 1) (match_dup 2)))]
14179   ""
14180   "#"
14181   ""
14182   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14183    (parallel [(set (match_dup 3)
14184                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14185               (set (match_dup 0) (neg:P (match_dup 0)))])]
14186   "")
14187
14188 (define_insn_and_split "*plus_gtu<mode>"
14189   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14190         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14191                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14192                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
14193   ""
14194   "#"
14195   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14196   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14197    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14198   "")
14199
14200 (define_insn_and_split "*plus_gtu<mode>_compare"
14201   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14202         (compare:CC
14203          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14204                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
14205                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14206          (const_int 0)))
14207    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14208         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14209   ""
14210   "#"
14211   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14212   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14213    (parallel [(set (match_dup 4)
14214                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14215                                (const_int 0)))
14216               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14217   "")
14218
14219 (define_insn "*neg_gtu<mode>"
14220   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14221         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14222                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14223   ""
14224   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
14225   [(set_attr "type" "two")
14226    (set_attr "length" "8")])
14227
14228 \f
14229 ;; Define both directions of branch and return.  If we need a reload
14230 ;; register, we'd rather use CR0 since it is much easier to copy a
14231 ;; register CC value to there.
14232
14233 (define_insn ""
14234   [(set (pc)
14235         (if_then_else (match_operator 1 "branch_comparison_operator"
14236                                       [(match_operand 2
14237                                                       "cc_reg_operand" "y")
14238                                        (const_int 0)])
14239                       (label_ref (match_operand 0 "" ""))
14240                       (pc)))]
14241   ""
14242   "*
14243 {
14244   return output_cbranch (operands[1], \"%l0\", 0, insn);
14245 }"
14246   [(set_attr "type" "branch")])
14247
14248 (define_insn ""
14249   [(set (pc)
14250         (if_then_else (match_operator 0 "branch_comparison_operator"
14251                                       [(match_operand 1
14252                                                       "cc_reg_operand" "y")
14253                                        (const_int 0)])
14254                       (any_return)
14255                       (pc)))]
14256   "<return_pred>"
14257   "*
14258 {
14259   return output_cbranch (operands[0], NULL, 0, insn);
14260 }"
14261   [(set_attr "type" "jmpreg")
14262    (set_attr "length" "4")])
14263
14264 (define_insn ""
14265   [(set (pc)
14266         (if_then_else (match_operator 1 "branch_comparison_operator"
14267                                       [(match_operand 2
14268                                                       "cc_reg_operand" "y")
14269                                        (const_int 0)])
14270                       (pc)
14271                       (label_ref (match_operand 0 "" ""))))]
14272   ""
14273   "*
14274 {
14275   return output_cbranch (operands[1], \"%l0\", 1, insn);
14276 }"
14277   [(set_attr "type" "branch")])
14278
14279 (define_insn ""
14280   [(set (pc)
14281         (if_then_else (match_operator 0 "branch_comparison_operator"
14282                                       [(match_operand 1
14283                                                       "cc_reg_operand" "y")
14284                                        (const_int 0)])
14285                       (pc)
14286                       (any_return)))]
14287   "<return_pred>"
14288   "*
14289 {
14290   return output_cbranch (operands[0], NULL, 1, insn);
14291 }"
14292   [(set_attr "type" "jmpreg")
14293    (set_attr "length" "4")])
14294
14295 ;; Logic on condition register values.
14296
14297 ; This pattern matches things like
14298 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
14299 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
14300 ;                                  (const_int 1)))
14301 ; which are generated by the branch logic.
14302 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
14303
14304 (define_insn "*cceq_ior_compare"
14305   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14306         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
14307                         [(match_operator:SI 2
14308                                       "branch_positive_comparison_operator"
14309                                       [(match_operand 3
14310                                                       "cc_reg_operand" "y,y")
14311                                        (const_int 0)])
14312                          (match_operator:SI 4
14313                                       "branch_positive_comparison_operator"
14314                                       [(match_operand 5
14315                                                       "cc_reg_operand" "0,y")
14316                                        (const_int 0)])])
14317                       (const_int 1)))]
14318   ""
14319   "cr%q1 %E0,%j2,%j4"
14320   [(set_attr "type" "cr_logical,delayed_cr")])
14321
14322 ; Why is the constant -1 here, but 1 in the previous pattern?
14323 ; Because ~1 has all but the low bit set.
14324 (define_insn ""
14325   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14326         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
14327                         [(not:SI (match_operator:SI 2
14328                                       "branch_positive_comparison_operator"
14329                                       [(match_operand 3
14330                                                       "cc_reg_operand" "y,y")
14331                                        (const_int 0)]))
14332                          (match_operator:SI 4
14333                                 "branch_positive_comparison_operator"
14334                                 [(match_operand 5
14335                                                 "cc_reg_operand" "0,y")
14336                                  (const_int 0)])])
14337                       (const_int -1)))]
14338   ""
14339   "cr%q1 %E0,%j2,%j4"
14340   [(set_attr "type" "cr_logical,delayed_cr")])
14341
14342 (define_insn "*cceq_rev_compare"
14343   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14344         (compare:CCEQ (match_operator:SI 1
14345                                       "branch_positive_comparison_operator"
14346                                       [(match_operand 2
14347                                                       "cc_reg_operand" "0,y")
14348                                        (const_int 0)])
14349                       (const_int 0)))]
14350   ""
14351   "crnot %E0,%j1"
14352   [(set_attr "type" "cr_logical,delayed_cr")])
14353
14354 ;; If we are comparing the result of two comparisons, this can be done
14355 ;; using creqv or crxor.
14356
14357 (define_insn_and_split ""
14358   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
14359         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
14360                               [(match_operand 2 "cc_reg_operand" "y")
14361                                (const_int 0)])
14362                       (match_operator 3 "branch_comparison_operator"
14363                               [(match_operand 4 "cc_reg_operand" "y")
14364                                (const_int 0)])))]
14365   ""
14366   "#"
14367   ""
14368   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
14369                                     (match_dup 5)))]
14370   "
14371 {
14372   int positive_1, positive_2;
14373
14374   positive_1 = branch_positive_comparison_operator (operands[1],
14375                                                     GET_MODE (operands[1]));
14376   positive_2 = branch_positive_comparison_operator (operands[3],
14377                                                     GET_MODE (operands[3]));
14378
14379   if (! positive_1)
14380     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
14381                                                             GET_CODE (operands[1])),
14382                                   SImode,
14383                                   operands[2], const0_rtx);
14384   else if (GET_MODE (operands[1]) != SImode)
14385     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
14386                                   operands[2], const0_rtx);
14387
14388   if (! positive_2)
14389     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
14390                                                             GET_CODE (operands[3])),
14391                                   SImode,
14392                                   operands[4], const0_rtx);
14393   else if (GET_MODE (operands[3]) != SImode)
14394     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
14395                                   operands[4], const0_rtx);
14396
14397   if (positive_1 == positive_2)
14398     {
14399       operands[1] = gen_rtx_NOT (SImode, operands[1]);
14400       operands[5] = constm1_rtx;
14401     }
14402   else
14403     {
14404       operands[5] = const1_rtx;
14405     }
14406 }")
14407
14408 ;; Unconditional branch and return.
14409
14410 (define_insn "jump"
14411   [(set (pc)
14412         (label_ref (match_operand 0 "" "")))]
14413   ""
14414   "b %l0"
14415   [(set_attr "type" "branch")])
14416
14417 (define_insn "<return_str>return"
14418   [(any_return)]
14419   "<return_pred>"
14420   "blr"
14421   [(set_attr "type" "jmpreg")])
14422
14423 (define_expand "indirect_jump"
14424   [(set (pc) (match_operand 0 "register_operand" ""))])
14425
14426 (define_insn "*indirect_jump<mode>"
14427   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
14428   ""
14429   "@
14430    bctr
14431    blr"
14432   [(set_attr "type" "jmpreg")])
14433
14434 ;; Table jump for switch statements:
14435 (define_expand "tablejump"
14436   [(use (match_operand 0 "" ""))
14437    (use (label_ref (match_operand 1 "" "")))]
14438   ""
14439   "
14440 {
14441   if (TARGET_32BIT)
14442     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
14443   else
14444     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
14445   DONE;
14446 }")
14447
14448 (define_expand "tablejumpsi"
14449   [(set (match_dup 3)
14450         (plus:SI (match_operand:SI 0 "" "")
14451                  (match_dup 2)))
14452    (parallel [(set (pc) (match_dup 3))
14453               (use (label_ref (match_operand 1 "" "")))])]
14454   "TARGET_32BIT"
14455   "
14456 { operands[0] = force_reg (SImode, operands[0]);
14457   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
14458   operands[3] = gen_reg_rtx (SImode);
14459 }")
14460
14461 (define_expand "tablejumpdi"
14462   [(set (match_dup 4)
14463         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
14464    (set (match_dup 3)
14465         (plus:DI (match_dup 4)
14466                  (match_dup 2)))
14467    (parallel [(set (pc) (match_dup 3))
14468               (use (label_ref (match_operand 1 "" "")))])]
14469   "TARGET_64BIT"
14470   "
14471 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
14472   operands[3] = gen_reg_rtx (DImode);
14473   operands[4] = gen_reg_rtx (DImode);
14474 }")
14475
14476 (define_insn "*tablejump<mode>_internal1"
14477   [(set (pc)
14478         (match_operand:P 0 "register_operand" "c,*l"))
14479    (use (label_ref (match_operand 1 "" "")))]
14480   ""
14481   "@
14482    bctr
14483    blr"
14484   [(set_attr "type" "jmpreg")])
14485
14486 (define_insn "nop"
14487   [(const_int 0)]
14488   ""
14489   "nop")
14490
14491 (define_insn "group_ending_nop"
14492   [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
14493   ""
14494   "*
14495 {
14496   if (rs6000_cpu_attr == CPU_POWER6)
14497     return \"ori 1,1,0\";
14498   return \"ori 2,2,0\";
14499 }")
14500 \f
14501 ;; Define the subtract-one-and-jump insns, starting with the template
14502 ;; so loop.c knows what to generate.
14503
14504 (define_expand "doloop_end"
14505   [(use (match_operand 0 "" ""))        ; loop pseudo
14506    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
14507    (use (match_operand 2 "" ""))        ; max iterations
14508    (use (match_operand 3 "" ""))        ; loop level
14509    (use (match_operand 4 "" ""))        ; label
14510    (use (match_operand 5 "" ""))]       ; flag: 1 if loop entered at top, else 0
14511   ""
14512   "
14513 {
14514   /* Only use this on innermost loops.  */
14515   if (INTVAL (operands[3]) > 1)
14516     FAIL;
14517   if (TARGET_64BIT)
14518     {
14519       if (GET_MODE (operands[0]) != DImode)
14520         FAIL;
14521       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
14522     }
14523   else
14524     {
14525       if (GET_MODE (operands[0]) != SImode)
14526         FAIL;
14527       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
14528     }
14529   DONE;
14530 }")
14531
14532 (define_expand "ctr<mode>"
14533   [(parallel [(set (pc)
14534                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
14535                                      (const_int 1))
14536                                  (label_ref (match_operand 1 "" ""))
14537                                  (pc)))
14538               (set (match_dup 0)
14539                    (plus:P (match_dup 0)
14540                             (const_int -1)))
14541               (clobber (match_scratch:CC 2 ""))
14542               (clobber (match_scratch:P 3 ""))])]
14543   ""
14544   "")
14545
14546 ;; We need to be able to do this for any operand, including MEM, or we
14547 ;; will cause reload to blow up since we don't allow output reloads on
14548 ;; JUMP_INSNs.
14549 ;; For the length attribute to be calculated correctly, the
14550 ;; label MUST be operand 0.
14551
14552 (define_insn "*ctr<mode>_internal1"
14553   [(set (pc)
14554         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14555                           (const_int 1))
14556                       (label_ref (match_operand 0 "" ""))
14557                       (pc)))
14558    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14559         (plus:P (match_dup 1)
14560                  (const_int -1)))
14561    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14562    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14563   ""
14564   "*
14565 {
14566   if (which_alternative != 0)
14567     return \"#\";
14568   else if (get_attr_length (insn) == 4)
14569     return \"bdnz %l0\";
14570   else
14571     return \"bdz $+8\;b %l0\";
14572 }"
14573   [(set_attr "type" "branch")
14574    (set_attr "length" "*,12,16,16")])
14575
14576 (define_insn "*ctr<mode>_internal2"
14577   [(set (pc)
14578         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14579                           (const_int 1))
14580                       (pc)
14581                       (label_ref (match_operand 0 "" ""))))
14582    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14583         (plus:P (match_dup 1)
14584                  (const_int -1)))
14585    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14586    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14587   ""
14588   "*
14589 {
14590   if (which_alternative != 0)
14591     return \"#\";
14592   else if (get_attr_length (insn) == 4)
14593     return \"bdz %l0\";
14594   else
14595     return \"bdnz $+8\;b %l0\";
14596 }"
14597   [(set_attr "type" "branch")
14598    (set_attr "length" "*,12,16,16")])
14599
14600 ;; Similar but use EQ
14601
14602 (define_insn "*ctr<mode>_internal5"
14603   [(set (pc)
14604         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14605                           (const_int 1))
14606                       (label_ref (match_operand 0 "" ""))
14607                       (pc)))
14608    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14609         (plus:P (match_dup 1)
14610                  (const_int -1)))
14611    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14612    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14613   ""
14614   "*
14615 {
14616   if (which_alternative != 0)
14617     return \"#\";
14618   else if (get_attr_length (insn) == 4)
14619     return \"bdz %l0\";
14620   else
14621     return \"bdnz $+8\;b %l0\";
14622 }"
14623   [(set_attr "type" "branch")
14624    (set_attr "length" "*,12,16,16")])
14625
14626 (define_insn "*ctr<mode>_internal6"
14627   [(set (pc)
14628         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14629                           (const_int 1))
14630                       (pc)
14631                       (label_ref (match_operand 0 "" ""))))
14632    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14633         (plus:P (match_dup 1)
14634                  (const_int -1)))
14635    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14636    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14637   ""
14638   "*
14639 {
14640   if (which_alternative != 0)
14641     return \"#\";
14642   else if (get_attr_length (insn) == 4)
14643     return \"bdnz %l0\";
14644   else
14645     return \"bdz $+8\;b %l0\";
14646 }"
14647   [(set_attr "type" "branch")
14648    (set_attr "length" "*,12,16,16")])
14649
14650 ;; Now the splitters if we could not allocate the CTR register
14651
14652 (define_split
14653   [(set (pc)
14654         (if_then_else (match_operator 2 "comparison_operator"
14655                                       [(match_operand:P 1 "gpc_reg_operand" "")
14656                                        (const_int 1)])
14657                       (match_operand 5 "" "")
14658                       (match_operand 6 "" "")))
14659    (set (match_operand:P 0 "gpc_reg_operand" "")
14660         (plus:P (match_dup 1) (const_int -1)))
14661    (clobber (match_scratch:CC 3 ""))
14662    (clobber (match_scratch:P 4 ""))]
14663   "reload_completed"
14664   [(parallel [(set (match_dup 3)
14665                    (compare:CC (plus:P (match_dup 1)
14666                                         (const_int -1))
14667                                (const_int 0)))
14668               (set (match_dup 0)
14669                    (plus:P (match_dup 1)
14670                             (const_int -1)))])
14671    (set (pc) (if_then_else (match_dup 7)
14672                            (match_dup 5)
14673                            (match_dup 6)))]
14674   "
14675 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14676                                 operands[3], const0_rtx); }")
14677
14678 (define_split
14679   [(set (pc)
14680         (if_then_else (match_operator 2 "comparison_operator"
14681                                       [(match_operand:P 1 "gpc_reg_operand" "")
14682                                        (const_int 1)])
14683                       (match_operand 5 "" "")
14684                       (match_operand 6 "" "")))
14685    (set (match_operand:P 0 "nonimmediate_operand" "")
14686         (plus:P (match_dup 1) (const_int -1)))
14687    (clobber (match_scratch:CC 3 ""))
14688    (clobber (match_scratch:P 4 ""))]
14689   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
14690   [(parallel [(set (match_dup 3)
14691                    (compare:CC (plus:P (match_dup 1)
14692                                         (const_int -1))
14693                                (const_int 0)))
14694               (set (match_dup 4)
14695                    (plus:P (match_dup 1)
14696                             (const_int -1)))])
14697    (set (match_dup 0)
14698         (match_dup 4))
14699    (set (pc) (if_then_else (match_dup 7)
14700                            (match_dup 5)
14701                            (match_dup 6)))]
14702   "
14703 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14704                                 operands[3], const0_rtx); }")
14705 \f
14706 (define_insn "trap"
14707   [(trap_if (const_int 1) (const_int 0))]
14708   ""
14709   "trap"
14710   [(set_attr "type" "trap")])
14711
14712 (define_expand "ctrap<mode>4"
14713   [(trap_if (match_operator 0 "ordered_comparison_operator"
14714                             [(match_operand:GPR 1 "register_operand")
14715                              (match_operand:GPR 2 "reg_or_short_operand")])
14716             (match_operand 3 "zero_constant" ""))]
14717   ""
14718   "")
14719
14720 (define_insn ""
14721   [(trap_if (match_operator 0 "ordered_comparison_operator"
14722                             [(match_operand:GPR 1 "register_operand" "r")
14723                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
14724             (const_int 0))]
14725   ""
14726   "t<wd>%V0%I2 %1,%2"
14727   [(set_attr "type" "trap")])
14728 \f
14729 ;; Insns related to generating the function prologue and epilogue.
14730
14731 (define_expand "prologue"
14732   [(use (const_int 0))]
14733   ""
14734 {
14735   rs6000_emit_prologue ();
14736   if (!TARGET_SCHED_PROLOG)
14737     emit_insn (gen_blockage ());
14738   DONE;
14739 })
14740
14741 (define_insn "*movesi_from_cr_one"
14742   [(match_parallel 0 "mfcr_operation"
14743                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14744                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14745                                      (match_operand 3 "immediate_operand" "n")]
14746                           UNSPEC_MOVESI_FROM_CR))])]
14747   "TARGET_MFCRF"
14748   "*
14749 {
14750   int mask = 0;
14751   int i;
14752   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14753   {
14754     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14755     operands[4] = GEN_INT (mask);
14756     output_asm_insn (\"mfcr %1,%4\", operands);
14757   }
14758   return \"\";
14759 }"
14760   [(set_attr "type" "mfcrf")])
14761
14762 (define_insn "movesi_from_cr"
14763   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14764         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
14765                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
14766                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
14767                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
14768                    UNSPEC_MOVESI_FROM_CR))]
14769   ""
14770   "mfcr %0"
14771   [(set_attr "type" "mfcr")])
14772
14773 (define_insn "*stmw"
14774   [(match_parallel 0 "stmw_operation"
14775                    [(set (match_operand:SI 1 "memory_operand" "=m")
14776                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14777   "TARGET_MULTIPLE"
14778   "stmw %2,%1"
14779   [(set_attr "type" "store_ux")])
14780
14781 ; The following comment applies to:
14782 ;     save_gpregs_*
14783 ;     save_fpregs_*
14784 ;     restore_gpregs*
14785 ;     return_and_restore_gpregs*
14786 ;     return_and_restore_fpregs*
14787 ;     return_and_restore_fpregs_aix*
14788 ;
14789 ; The out-of-line save / restore functions expects one input argument.
14790 ; Since those are not standard call_insn's, we must avoid using
14791 ; MATCH_OPERAND for that argument. That way the register rename
14792 ; optimization will not try to rename this register.
14793 ; Each pattern is repeated for each possible register number used in 
14794 ; various ABIs (r11, r1, and for some functions r12)
14795
14796 (define_insn "*save_gpregs_<mode>_r11"
14797   [(match_parallel 0 "any_parallel_operand"
14798                    [(clobber (reg:P 65))
14799                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14800                     (use (reg:P 11))
14801                     (set (match_operand:P 2 "memory_operand" "=m")
14802                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
14803   ""
14804   "bl %1"
14805   [(set_attr "type" "branch")
14806    (set_attr "length" "4")])
14807
14808 (define_insn "*save_gpregs_<mode>_r12"
14809   [(match_parallel 0 "any_parallel_operand"
14810                    [(clobber (reg:P 65))
14811                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14812                     (use (reg:P 12))
14813                     (set (match_operand:P 2 "memory_operand" "=m")
14814                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
14815   ""
14816   "bl %1"
14817   [(set_attr "type" "branch")
14818    (set_attr "length" "4")])
14819
14820 (define_insn "*save_gpregs_<mode>_r1"
14821   [(match_parallel 0 "any_parallel_operand"
14822                    [(clobber (reg:P 65))
14823                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14824                     (use (reg:P 1))
14825                     (set (match_operand:P 2 "memory_operand" "=m")
14826                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
14827   ""
14828   "bl %1"
14829   [(set_attr "type" "branch")
14830    (set_attr "length" "4")])
14831
14832 (define_insn "*save_fpregs_<mode>_r11"
14833   [(match_parallel 0 "any_parallel_operand"
14834                    [(clobber (reg:P 65))
14835                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14836                     (use (reg:P 11))
14837                     (set (match_operand:DF 2 "memory_operand" "=m")
14838                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14839   ""
14840   "bl %1"
14841   [(set_attr "type" "branch")
14842    (set_attr "length" "4")])
14843
14844 (define_insn "*save_fpregs_<mode>_r12"
14845   [(match_parallel 0 "any_parallel_operand"
14846                    [(clobber (reg:P 65))
14847                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14848                     (use (reg:P 12))
14849                     (set (match_operand:DF 2 "memory_operand" "=m")
14850                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14851   ""
14852   "bl %1"
14853   [(set_attr "type" "branch")
14854    (set_attr "length" "4")])
14855
14856 (define_insn "*save_fpregs_<mode>_r1"
14857   [(match_parallel 0 "any_parallel_operand"
14858                    [(clobber (reg:P 65))
14859                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14860                     (use (reg:P 1))
14861                     (set (match_operand:DF 2 "memory_operand" "=m")
14862                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14863   ""
14864   "bl %1"
14865   [(set_attr "type" "branch")
14866    (set_attr "length" "4")])
14867
14868 ; This is to explain that changes to the stack pointer should
14869 ; not be moved over loads from or stores to stack memory.
14870 (define_insn "stack_tie"
14871   [(match_parallel 0 "tie_operand"
14872                    [(set (mem:BLK (reg 1)) (const_int 0))])]
14873   ""
14874   ""
14875   [(set_attr "length" "0")])
14876
14877 (define_expand "epilogue"
14878   [(use (const_int 0))]
14879   ""
14880 {
14881   if (!TARGET_SCHED_PROLOG)
14882     emit_insn (gen_blockage ());
14883   rs6000_emit_epilogue (FALSE);
14884   DONE;
14885 })
14886
14887 ; On some processors, doing the mtcrf one CC register at a time is
14888 ; faster (like on the 604e).  On others, doing them all at once is
14889 ; faster; for instance, on the 601 and 750.
14890
14891 (define_expand "movsi_to_cr_one"
14892   [(set (match_operand:CC 0 "cc_reg_operand" "")
14893         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
14894                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14895   ""
14896   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14897
14898 (define_insn "*movsi_to_cr"
14899   [(match_parallel 0 "mtcrf_operation"
14900                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14901                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14902                                      (match_operand 3 "immediate_operand" "n")]
14903                                     UNSPEC_MOVESI_TO_CR))])]
14904  ""
14905  "*
14906 {
14907   int mask = 0;
14908   int i;
14909   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14910     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14911   operands[4] = GEN_INT (mask);
14912   return \"mtcrf %4,%2\";
14913 }"
14914   [(set_attr "type" "mtcr")])
14915
14916 (define_insn "*mtcrfsi"
14917   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14918         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14919                     (match_operand 2 "immediate_operand" "n")]
14920                    UNSPEC_MOVESI_TO_CR))]
14921   "GET_CODE (operands[0]) == REG
14922    && CR_REGNO_P (REGNO (operands[0]))
14923    && GET_CODE (operands[2]) == CONST_INT
14924    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14925   "mtcrf %R0,%1"
14926   [(set_attr "type" "mtcr")])
14927
14928 ; The load-multiple instructions have similar properties.
14929 ; Note that "load_multiple" is a name known to the machine-independent
14930 ; code that actually corresponds to the PowerPC load-string.
14931
14932 (define_insn "*lmw"
14933   [(match_parallel 0 "lmw_operation"
14934                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14935                          (match_operand:SI 2 "memory_operand" "m"))])]
14936   "TARGET_MULTIPLE"
14937   "lmw %1,%2"
14938   [(set_attr "type" "load_ux")
14939    (set_attr "cell_micro" "always")])
14940
14941 (define_insn "*return_internal_<mode>"
14942   [(simple_return)
14943    (use (match_operand:P 0 "register_operand" "lc"))]
14944   ""
14945   "b%T0"
14946   [(set_attr "type" "jmpreg")])
14947
14948 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14949 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14950
14951 ; The following comment applies to:
14952 ;     save_gpregs_*
14953 ;     save_fpregs_*
14954 ;     restore_gpregs*
14955 ;     return_and_restore_gpregs*
14956 ;     return_and_restore_fpregs*
14957 ;     return_and_restore_fpregs_aix*
14958 ;
14959 ; The out-of-line save / restore functions expects one input argument.
14960 ; Since those are not standard call_insn's, we must avoid using
14961 ; MATCH_OPERAND for that argument. That way the register rename
14962 ; optimization will not try to rename this register.
14963 ; Each pattern is repeated for each possible register number used in 
14964 ; various ABIs (r11, r1, and for some functions r12)
14965
14966 (define_insn "*restore_gpregs_<mode>_r11"
14967  [(match_parallel 0 "any_parallel_operand"
14968                   [(clobber (match_operand:P 1 "register_operand" "=l"))
14969                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14970                    (use (reg:P 11))
14971                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14972                         (match_operand:P 4 "memory_operand" "m"))])]
14973  ""
14974  "bl %2"
14975  [(set_attr "type" "branch")
14976   (set_attr "length" "4")])
14977
14978 (define_insn "*restore_gpregs_<mode>_r12"
14979  [(match_parallel 0 "any_parallel_operand"
14980                   [(clobber (match_operand:P 1 "register_operand" "=l"))
14981                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14982                    (use (reg:P 12))
14983                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14984                         (match_operand:P 4 "memory_operand" "m"))])]
14985  ""
14986  "bl %2"
14987  [(set_attr "type" "branch")
14988   (set_attr "length" "4")])
14989
14990 (define_insn "*restore_gpregs_<mode>_r1"
14991  [(match_parallel 0 "any_parallel_operand"
14992                   [(clobber (match_operand:P 1 "register_operand" "=l"))
14993                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14994                    (use (reg:P 1))
14995                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14996                         (match_operand:P 4 "memory_operand" "m"))])]
14997  ""
14998  "bl %2"
14999  [(set_attr "type" "branch")
15000   (set_attr "length" "4")])
15001
15002 (define_insn "*return_and_restore_gpregs_<mode>_r11"
15003  [(match_parallel 0 "any_parallel_operand"
15004                   [(return)
15005                    (clobber (match_operand:P 1 "register_operand" "=l"))
15006                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15007                    (use (reg:P 11))
15008                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15009                         (match_operand:P 4 "memory_operand" "m"))])]
15010  ""
15011  "b %2"
15012  [(set_attr "type" "branch")
15013   (set_attr "length" "4")])
15014
15015 (define_insn "*return_and_restore_gpregs_<mode>_r12"
15016  [(match_parallel 0 "any_parallel_operand"
15017                   [(return)
15018                    (clobber (match_operand:P 1 "register_operand" "=l"))
15019                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15020                    (use (reg:P 12))
15021                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15022                         (match_operand:P 4 "memory_operand" "m"))])]
15023  ""
15024  "b %2"
15025  [(set_attr "type" "branch")
15026   (set_attr "length" "4")])
15027
15028 (define_insn "*return_and_restore_gpregs_<mode>_r1"
15029  [(match_parallel 0 "any_parallel_operand"
15030                   [(return)
15031                    (clobber (match_operand:P 1 "register_operand" "=l"))
15032                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15033                    (use (reg:P 1))
15034                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15035                         (match_operand:P 4 "memory_operand" "m"))])]
15036  ""
15037  "b %2"
15038  [(set_attr "type" "branch")
15039   (set_attr "length" "4")])
15040
15041 (define_insn "*return_and_restore_fpregs_<mode>_r11"
15042  [(match_parallel 0 "any_parallel_operand"
15043                   [(return)
15044                    (clobber (match_operand:P 1 "register_operand" "=l"))
15045                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15046                    (use (reg:P 11))
15047                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15048                         (match_operand:DF 4 "memory_operand" "m"))])]
15049  ""
15050  "b %2"
15051  [(set_attr "type" "branch")
15052   (set_attr "length" "4")])
15053
15054 (define_insn "*return_and_restore_fpregs_<mode>_r12"
15055  [(match_parallel 0 "any_parallel_operand"
15056                   [(return)
15057                    (clobber (match_operand:P 1 "register_operand" "=l"))
15058                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15059                    (use (reg:P 12))
15060                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15061                         (match_operand:DF 4 "memory_operand" "m"))])]
15062  ""
15063  "b %2"
15064  [(set_attr "type" "branch")
15065   (set_attr "length" "4")])
15066
15067 (define_insn "*return_and_restore_fpregs_<mode>_r1"
15068  [(match_parallel 0 "any_parallel_operand"
15069                   [(return)
15070                    (clobber (match_operand:P 1 "register_operand" "=l"))
15071                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15072                    (use (reg:P 1))
15073                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15074                         (match_operand:DF 4 "memory_operand" "m"))])]
15075  ""
15076  "b %2"
15077  [(set_attr "type" "branch")
15078   (set_attr "length" "4")])
15079
15080 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
15081  [(match_parallel 0 "any_parallel_operand"
15082                   [(return)
15083                    (use (match_operand:P 1 "register_operand" "l"))
15084                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15085                    (use (reg:P 11))
15086                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15087                         (match_operand:DF 4 "memory_operand" "m"))])]
15088  ""
15089  "b %2"
15090  [(set_attr "type" "branch")
15091   (set_attr "length" "4")])
15092
15093 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
15094  [(match_parallel 0 "any_parallel_operand"
15095                   [(return)
15096                    (use (match_operand:P 1 "register_operand" "l"))
15097                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15098                    (use (reg:P 1))
15099                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15100                         (match_operand:DF 4 "memory_operand" "m"))])]
15101  ""
15102  "b %2"
15103  [(set_attr "type" "branch")
15104   (set_attr "length" "4")])
15105
15106 ; This is used in compiling the unwind routines.
15107 (define_expand "eh_return"
15108   [(use (match_operand 0 "general_operand" ""))]
15109   ""
15110   "
15111 {
15112   if (TARGET_32BIT)
15113     emit_insn (gen_eh_set_lr_si (operands[0]));
15114   else
15115     emit_insn (gen_eh_set_lr_di (operands[0]));
15116   DONE;
15117 }")
15118
15119 ; We can't expand this before we know where the link register is stored.
15120 (define_insn "eh_set_lr_<mode>"
15121   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
15122                     UNSPECV_EH_RR)
15123    (clobber (match_scratch:P 1 "=&b"))]
15124   ""
15125   "#")
15126
15127 (define_split
15128   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
15129    (clobber (match_scratch 1 ""))]
15130   "reload_completed"
15131   [(const_int 0)]
15132   "
15133 {
15134   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
15135   DONE;
15136 }")
15137
15138 (define_insn "prefetch"
15139   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
15140              (match_operand:SI 1 "const_int_operand" "n")
15141              (match_operand:SI 2 "const_int_operand" "n"))]
15142   ""
15143   "*
15144 {
15145   if (GET_CODE (operands[0]) == REG)
15146     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
15147   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
15148 }"
15149   [(set_attr "type" "load")])
15150 \f
15151 (define_insn "bpermd_<mode>"
15152   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15153         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
15154                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
15155   "TARGET_POPCNTD"
15156   "bpermd %0,%1,%2"
15157   [(set_attr "type" "popcnt")])
15158
15159 \f
15160 ;; Builtin fma support.  Handle 
15161 ;; Note that the conditions for expansion are in the FMA_F iterator.
15162
15163 (define_expand "fma<mode>4"
15164   [(set (match_operand:FMA_F 0 "register_operand" "")
15165         (fma:FMA_F
15166           (match_operand:FMA_F 1 "register_operand" "")
15167           (match_operand:FMA_F 2 "register_operand" "")
15168           (match_operand:FMA_F 3 "register_operand" "")))]
15169   ""
15170   "")
15171
15172 ; Altivec only has fma and nfms.
15173 (define_expand "fms<mode>4"
15174   [(set (match_operand:FMA_F 0 "register_operand" "")
15175         (fma:FMA_F
15176           (match_operand:FMA_F 1 "register_operand" "")
15177           (match_operand:FMA_F 2 "register_operand" "")
15178           (neg:FMA_F (match_operand:FMA_F 3 "register_operand" ""))))]
15179   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15180   "")
15181
15182 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
15183 (define_expand "fnma<mode>4"
15184   [(set (match_operand:FMA_F 0 "register_operand" "")
15185         (neg:FMA_F
15186           (fma:FMA_F
15187             (match_operand:FMA_F 1 "register_operand" "")
15188             (match_operand:FMA_F 2 "register_operand" "")
15189             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
15190   "!HONOR_SIGNED_ZEROS (<MODE>mode)"
15191   "")
15192
15193 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
15194 (define_expand "fnms<mode>4"
15195   [(set (match_operand:FMA_F 0 "register_operand" "")
15196         (neg:FMA_F
15197           (fma:FMA_F
15198             (match_operand:FMA_F 1 "register_operand" "")
15199             (match_operand:FMA_F 2 "register_operand" "")
15200             (match_operand:FMA_F 3 "register_operand" ""))))]
15201   "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15202   "")
15203
15204 ; Not an official optab name, but used from builtins.
15205 (define_expand "nfma<mode>4"
15206   [(set (match_operand:FMA_F 0 "register_operand" "")
15207         (neg:FMA_F
15208           (fma:FMA_F
15209             (match_operand:FMA_F 1 "register_operand" "")
15210             (match_operand:FMA_F 2 "register_operand" "")
15211             (match_operand:FMA_F 3 "register_operand" ""))))]
15212   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15213   "")
15214
15215 ; Not an official optab name, but used from builtins.
15216 (define_expand "nfms<mode>4"
15217   [(set (match_operand:FMA_F 0 "register_operand" "")
15218         (neg:FMA_F
15219           (fma:FMA_F
15220             (match_operand:FMA_F 1 "register_operand" "")
15221             (match_operand:FMA_F 2 "register_operand" "")
15222             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
15223   ""
15224   "")
15225
15226 (define_expand "rs6000_get_timebase"
15227   [(use (match_operand:DI 0 "gpc_reg_operand" ""))]
15228   ""
15229 {
15230   if (TARGET_POWERPC64)
15231     emit_insn (gen_rs6000_mftb_di (operands[0]));
15232   else
15233     emit_insn (gen_rs6000_get_timebase_ppc32 (operands[0]));
15234   DONE;
15235 })
15236
15237 (define_insn "rs6000_get_timebase_ppc32"
15238   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
15239         (unspec_volatile:DI [(const_int 0)] UNSPECV_MFTB))
15240    (clobber (match_scratch:SI 1 "=r"))
15241    (clobber (match_scratch:CC 2 "=y"))]
15242   "!TARGET_POWERPC64"
15243 {
15244   if (WORDS_BIG_ENDIAN)
15245     if (TARGET_MFCRF)
15246       {
15247         return "mfspr %0,269\;"
15248                "mfspr %L0,268\;"
15249                "mfspr %1,269\;"
15250                "cmpw %2,%0,%1\;"
15251                "bne- %2,$-16";
15252       }
15253     else
15254       {
15255         return "mftbu %0\;"
15256                "mftb %L0\;"
15257                "mftbu %1\;"
15258                "cmpw %2,%0,%1\;"
15259                "bne- %2,$-16";
15260       }
15261   else
15262     if (TARGET_MFCRF)
15263       {
15264         return "mfspr %L0,269\;"
15265                "mfspr %0,268\;"
15266                "mfspr %1,269\;"
15267                "cmpw %2,%L0,%1\;"
15268                "bne- %2,$-16";
15269       }
15270     else
15271       {
15272         return "mftbu %L0\;"
15273                "mftb %0\;"
15274                "mftbu %1\;"
15275                "cmpw %2,%L0,%1\;"
15276                "bne- %2,$-16";
15277       }
15278 })
15279
15280 (define_insn "rs6000_mftb_<mode>"
15281   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15282         (unspec_volatile:P [(const_int 0)] UNSPECV_MFTB))]
15283   ""
15284 {
15285   if (TARGET_MFCRF)
15286     return "mfspr %0,268";
15287   else
15288     return "mftb %0";
15289 })
15290
15291 \f
15292
15293 (include "sync.md")
15294 (include "vector.md")
15295 (include "vsx.md")
15296 (include "altivec.md")
15297 (include "spe.md")
15298 (include "dfp.md")
15299 (include "paired.md")
15300 (include "crypto.md")