remove unused files
[platform/upstream/gcc48.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   [(STACK_POINTER_REGNUM        1)
29    (TOC_REGNUM                  2)
30    (STATIC_CHAIN_REGNUM         11)
31    (HARD_FRAME_POINTER_REGNUM   31)
32    (LR_REGNO                    65)
33    (CTR_REGNO                   66)
34    (ARG_POINTER_REGNUM          67)
35    (CR0_REGNO                   68)
36    (CR1_REGNO                   69)
37    (CR2_REGNO                   70)
38    (CR3_REGNO                   71)
39    (CR4_REGNO                   72)
40    (CR5_REGNO                   73)
41    (CR6_REGNO                   74)
42    (CR7_REGNO                   75)
43    (MAX_CR_REGNO                75)
44    (CA_REGNO                    76)
45    (FIRST_ALTIVEC_REGNO         77)
46    (LAST_ALTIVEC_REGNO          108)
47    (VRSAVE_REGNO                109)
48    (VSCR_REGNO                  110)
49    (SPE_ACC_REGNO               111)
50    (SPEFSCR_REGNO               112)
51    (FRAME_POINTER_REGNUM        113)
52
53    ; ABI defined stack offsets for storing the TOC pointer with AIX calls.
54    (TOC_SAVE_OFFSET_32BIT       20)
55    (TOC_SAVE_OFFSET_64BIT       40)
56
57    ; Function TOC offset in the AIX function descriptor.
58    (AIX_FUNC_DESC_TOC_32BIT     4)
59    (AIX_FUNC_DESC_TOC_64BIT     8)
60
61    ; Static chain offset in the AIX function descriptor.
62    (AIX_FUNC_DESC_SC_32BIT      8)
63    (AIX_FUNC_DESC_SC_64BIT      16)
64   ])
65
66 ;;
67 ;; UNSPEC usage
68 ;;
69
70 (define_c_enum "unspec"
71   [UNSPEC_FRSP                  ; frsp for POWER machines
72    UNSPEC_PROBE_STACK           ; probe stack memory reference
73    UNSPEC_TOCPTR                ; address of a word pointing to the TOC
74    UNSPEC_TOC                   ; address of the TOC (more-or-less)
75    UNSPEC_MOVSI_GOT
76    UNSPEC_MV_CR_OV              ; move_from_CR_ov_bit
77    UNSPEC_FCTIWZ
78    UNSPEC_FRIM
79    UNSPEC_FRIN
80    UNSPEC_FRIP
81    UNSPEC_FRIZ
82    UNSPEC_LD_MPIC               ; load_macho_picbase
83    UNSPEC_MPIC_CORRECT          ; macho_correct_pic
84    UNSPEC_TLSGD
85    UNSPEC_TLSLD
86    UNSPEC_MOVESI_FROM_CR
87    UNSPEC_MOVESI_TO_CR
88    UNSPEC_TLSDTPREL
89    UNSPEC_TLSDTPRELHA
90    UNSPEC_TLSDTPRELLO
91    UNSPEC_TLSGOTDTPREL
92    UNSPEC_TLSTPREL
93    UNSPEC_TLSTPRELHA
94    UNSPEC_TLSTPRELLO
95    UNSPEC_TLSGOTTPREL
96    UNSPEC_TLSTLS
97    UNSPEC_FIX_TRUNC_TF          ; fadd, rounding towards zero
98    UNSPEC_MV_CR_GT              ; move_from_CR_gt_bit
99    UNSPEC_STFIWX
100    UNSPEC_POPCNTB
101    UNSPEC_FRES
102    UNSPEC_SP_SET
103    UNSPEC_SP_TEST
104    UNSPEC_SYNC
105    UNSPEC_LWSYNC
106    UNSPEC_SYNC_OP
107    UNSPEC_ATOMIC
108    UNSPEC_CMPXCHG
109    UNSPEC_XCHG
110    UNSPEC_AND
111    UNSPEC_DLMZB
112    UNSPEC_DLMZB_CR
113    UNSPEC_DLMZB_STRLEN
114    UNSPEC_RSQRT
115    UNSPEC_TOCREL
116    UNSPEC_MACHOPIC_OFFSET
117    UNSPEC_BPERM
118    UNSPEC_COPYSIGN
119    UNSPEC_PARITY
120    UNSPEC_FCTIW
121    UNSPEC_FCTID
122    UNSPEC_LFIWAX
123    UNSPEC_LFIWZX
124    UNSPEC_FCTIWUZ
125    UNSPEC_GRP_END_NOP
126   ])
127
128 ;;
129 ;; UNSPEC_VOLATILE usage
130 ;;
131
132 (define_c_enum "unspecv"
133   [UNSPECV_BLOCK
134    UNSPECV_LL                   ; load-locked
135    UNSPECV_SC                   ; store-conditional
136    UNSPECV_PROBE_STACK_RANGE    ; probe range of stack addresses
137    UNSPECV_EH_RR                ; eh_reg_restore
138    UNSPECV_ISYNC                ; isync instruction
139    UNSPECV_MFTB                 ; move from time base
140   ])
141
142 \f
143 ;; Define an insn type attribute.  This is used in function unit delay
144 ;; computations.
145 (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"
146   (const_string "integer"))
147
148 ;; Define floating point instruction sub-types for use with Xfpu.md
149 (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"))
150
151 ;; Length (in bytes).
152 ; '(pc)' in the following doesn't include the instruction itself; it is
153 ; calculated as if the instruction had zero size.
154 (define_attr "length" ""
155   (if_then_else (eq_attr "type" "branch")
156                 (if_then_else (and (ge (minus (match_dup 0) (pc))
157                                        (const_int -32768))
158                                    (lt (minus (match_dup 0) (pc))
159                                        (const_int 32764)))
160                               (const_int 4)
161                               (const_int 8))
162                 (const_int 4)))
163
164 ;; Processor type -- this attribute must exactly match the processor_type
165 ;; enumeration in rs6000.h.
166
167 (define_attr "cpu" "rs64a,mpccore,ppc403,ppc405,ppc440,ppc476,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,ppc8548,ppce300c2,ppce300c3,ppce500mc,ppce500mc64,ppce5500,ppce6500,power4,power5,power6,power7,cell,ppca2,titan"
168   (const (symbol_ref "rs6000_cpu_attr")))
169
170
171 ;; If this instruction is microcoded on the CELL processor
172 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
173 (define_attr "cell_micro" "not,conditional,always"
174   (if_then_else (eq_attr "type" "compare,delayed_compare,imul_compare,lmul_compare,load_ext,load_ext_ux,var_shift_rotate,var_delayed_compare")
175                 (const_string "always")
176                 (const_string "not")))
177
178 (automata_option "ndfa")
179
180 (include "rs64.md")
181 (include "mpc.md")
182 (include "40x.md")
183 (include "440.md")
184 (include "476.md")
185 (include "601.md")
186 (include "603.md")
187 (include "6xx.md")
188 (include "7xx.md")
189 (include "7450.md")
190 (include "8540.md")
191 (include "e300c2c3.md")
192 (include "e500mc.md")
193 (include "e500mc64.md")
194 (include "e5500.md")
195 (include "e6500.md")
196 (include "power4.md")
197 (include "power5.md")
198 (include "power6.md")
199 (include "power7.md")
200 (include "cell.md")
201 (include "xfpu.md")
202 (include "a2.md")
203 (include "titan.md")
204
205 (include "predicates.md")
206 (include "constraints.md")
207
208 (include "darwin.md")
209
210 \f
211 ;; Mode iterators
212
213 ; This mode iterator allows :GPR to be used to indicate the allowable size
214 ; of whole values in GPRs.
215 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
216
217 ; Any supported integer mode.
218 (define_mode_iterator INT [QI HI SI DI TI])
219
220 ; Any supported integer mode that fits in one register.
221 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
222
223 ; extend modes for DImode
224 (define_mode_iterator QHSI [QI HI SI])
225
226 ; SImode or DImode, even if DImode doesn't fit in GPRs.
227 (define_mode_iterator SDI [SI DI])
228
229 ; The size of a pointer.  Also, the size of the value that a record-condition
230 ; (one with a '.') will compare; and the size used for arithmetic carries.
231 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
232
233 ; Any hardware-supported floating-point mode
234 (define_mode_iterator FP [
235   (SF "TARGET_HARD_FLOAT 
236    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) || TARGET_E500_SINGLE)")
237   (DF "TARGET_HARD_FLOAT 
238    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)")
239   (TF "!TARGET_IEEEQUAD
240    && TARGET_HARD_FLOAT
241    && (TARGET_FPRS || TARGET_E500_DOUBLE)
242    && TARGET_LONG_DOUBLE_128")
243   (DD "TARGET_DFP")
244   (TD "TARGET_DFP")])
245
246 ; Any fma capable floating-point mode.
247 (define_mode_iterator FMA_F [
248   (SF "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT")
249   (DF "(TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
250        || VECTOR_UNIT_VSX_P (DFmode)")
251   (V2SF "TARGET_PAIRED_FLOAT")
252   (V4SF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)")
253   (V2DF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)")
254   ])
255
256 ; These modes do not fit in integer registers in 32-bit mode.
257 ; but on e500v2, the gpr are 64 bit registers
258 (define_mode_iterator DIFD [DI (DF "!TARGET_E500_DOUBLE") DD])
259
260 ; Iterator for reciprocal estimate instructions
261 (define_mode_iterator RECIPF [SF DF V4SF V2DF])
262
263 ; Iterator for just SF/DF
264 (define_mode_iterator SFDF [SF DF])
265
266 ; Conditional returns.
267 (define_code_iterator any_return [return simple_return])
268 (define_code_attr return_pred [(return "direct_return ()")
269                                (simple_return "1")])
270 (define_code_attr return_str [(return "") (simple_return "simple_")])
271
272 ; Various instructions that come in SI and DI forms.
273 ; A generic w/d attribute, for things like cmpw/cmpd.
274 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
275
276 ; DImode bits
277 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
278
279 ;; ISEL/ISEL64 target selection
280 (define_mode_attr sel [(SI "") (DI "64")])
281
282 ;; Suffix for reload patterns
283 (define_mode_attr ptrsize [(SI "32bit")
284                            (DI "64bit")])
285
286 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
287                             (DI "TARGET_64BIT")])
288
289 (define_mode_attr mptrsize [(SI "si")
290                             (DI "di")])
291
292 (define_mode_attr ptrload [(SI "lwz")
293                            (DI "ld")])
294
295 (define_mode_attr ptrm [(SI "m")
296                         (DI "Y")])
297
298 (define_mode_attr rreg [(SF   "f")
299                         (DF   "ws")
300                         (V4SF "wf")
301                         (V2DF "wd")])
302
303 (define_mode_attr rreg2 [(SF   "f")
304                          (DF   "d")])
305
306 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
307                                  (DF "TARGET_FCFID")])
308
309 (define_mode_attr E500_CONVERT [(SF "!TARGET_FPRS")
310                                 (DF "TARGET_E500_DOUBLE")])
311
312 (define_mode_attr TARGET_FLOAT [(SF "TARGET_SINGLE_FLOAT")
313                                 (DF "TARGET_DOUBLE_FLOAT")])
314 \f
315 ;; Start with fixed-point load and store insns.  Here we put only the more
316 ;; complex forms.  Basic data transfer is done later.
317
318 (define_expand "zero_extend<mode>di2"
319   [(set (match_operand:DI 0 "gpc_reg_operand" "")
320         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
321   "TARGET_POWERPC64"
322   "")
323
324 (define_insn "*zero_extend<mode>di2_internal1"
325   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
326         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
327   "TARGET_POWERPC64"
328   "@
329    l<wd>z%U1%X1 %0,%1
330    rldicl %0,%1,0,<dbits>"
331   [(set_attr "type" "load,*")])
332
333 (define_insn "*zero_extend<mode>di2_internal2"
334   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
335         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
336                     (const_int 0)))
337    (clobber (match_scratch:DI 2 "=r,r"))]
338   "TARGET_64BIT"
339   "@
340    rldicl. %2,%1,0,<dbits>
341    #"
342   [(set_attr "type" "compare")
343    (set_attr "length" "4,8")])
344
345 (define_split
346   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
347         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
348                     (const_int 0)))
349    (clobber (match_scratch:DI 2 ""))]
350   "TARGET_POWERPC64 && reload_completed"
351   [(set (match_dup 2)
352         (zero_extend:DI (match_dup 1)))
353    (set (match_dup 0)
354         (compare:CC (match_dup 2)
355                     (const_int 0)))]
356   "")
357
358 (define_insn "*zero_extend<mode>di2_internal3"
359   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
360         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
361                     (const_int 0)))
362    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
363         (zero_extend:DI (match_dup 1)))]
364   "TARGET_64BIT"
365   "@
366    rldicl. %0,%1,0,<dbits>
367    #"
368   [(set_attr "type" "compare")
369    (set_attr "length" "4,8")])
370
371 (define_split
372   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
373         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
374                     (const_int 0)))
375    (set (match_operand:DI 0 "gpc_reg_operand" "")
376         (zero_extend:DI (match_dup 1)))]
377   "TARGET_POWERPC64 && reload_completed"
378   [(set (match_dup 0)
379         (zero_extend:DI (match_dup 1)))
380    (set (match_dup 2)
381         (compare:CC (match_dup 0)
382                     (const_int 0)))]
383   "")
384
385 (define_insn "extendqidi2"
386   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
387         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
388   "TARGET_POWERPC64"
389   "extsb %0,%1"
390   [(set_attr "type" "exts")])
391
392 (define_insn ""
393   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
394         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
395                     (const_int 0)))
396    (clobber (match_scratch:DI 2 "=r,r"))]
397   "TARGET_64BIT"
398   "@
399    extsb. %2,%1
400    #"
401   [(set_attr "type" "compare")
402    (set_attr "length" "4,8")])
403
404 (define_split
405   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
406         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
407                     (const_int 0)))
408    (clobber (match_scratch:DI 2 ""))]
409   "TARGET_POWERPC64 && reload_completed"
410   [(set (match_dup 2)
411         (sign_extend:DI (match_dup 1)))
412    (set (match_dup 0)
413         (compare:CC (match_dup 2)
414                     (const_int 0)))]
415   "")
416
417 (define_insn ""
418   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
419         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
420                     (const_int 0)))
421    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
422         (sign_extend:DI (match_dup 1)))]
423   "TARGET_64BIT"
424   "@
425    extsb. %0,%1
426    #"
427   [(set_attr "type" "compare")
428    (set_attr "length" "4,8")])
429
430 (define_split
431   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
432         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
433                     (const_int 0)))
434    (set (match_operand:DI 0 "gpc_reg_operand" "")
435         (sign_extend:DI (match_dup 1)))]
436   "TARGET_POWERPC64 && reload_completed"
437   [(set (match_dup 0)
438         (sign_extend:DI (match_dup 1)))
439    (set (match_dup 2)
440         (compare:CC (match_dup 0)
441                     (const_int 0)))]
442   "")
443
444 (define_expand "extendhidi2"
445   [(set (match_operand:DI 0 "gpc_reg_operand" "")
446         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
447   "TARGET_POWERPC64"
448   "")
449
450 (define_insn ""
451   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
452         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
453   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
454   "@
455    lha%U1%X1 %0,%1
456    extsh %0,%1"
457   [(set_attr "type" "load_ext,exts")])
458
459 (define_insn ""
460   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
461         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
462   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
463   "extsh %0,%1"
464   [(set_attr "type" "exts")])
465
466 (define_insn ""
467   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
468         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
469                     (const_int 0)))
470    (clobber (match_scratch:DI 2 "=r,r"))]
471   "TARGET_64BIT"
472   "@
473    extsh. %2,%1
474    #"
475   [(set_attr "type" "compare")
476    (set_attr "length" "4,8")])
477
478 (define_split
479   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
480         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
481                     (const_int 0)))
482    (clobber (match_scratch:DI 2 ""))]
483   "TARGET_POWERPC64 && reload_completed"
484   [(set (match_dup 2)
485         (sign_extend:DI (match_dup 1)))
486    (set (match_dup 0)
487         (compare:CC (match_dup 2)
488                     (const_int 0)))]
489   "")
490
491 (define_insn ""
492   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
493         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
494                     (const_int 0)))
495    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
496         (sign_extend:DI (match_dup 1)))]
497   "TARGET_64BIT"
498   "@
499    extsh. %0,%1
500    #"
501   [(set_attr "type" "compare")
502    (set_attr "length" "4,8")])
503
504 (define_split
505   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
506         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
507                     (const_int 0)))
508    (set (match_operand:DI 0 "gpc_reg_operand" "")
509         (sign_extend:DI (match_dup 1)))]
510   "TARGET_POWERPC64 && reload_completed"
511   [(set (match_dup 0)
512         (sign_extend:DI (match_dup 1)))
513    (set (match_dup 2)
514         (compare:CC (match_dup 0)
515                     (const_int 0)))]
516   "")
517
518 (define_expand "extendsidi2"
519   [(set (match_operand:DI 0 "gpc_reg_operand" "")
520         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
521   "TARGET_POWERPC64"
522   "")
523
524 (define_insn ""
525   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
526         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
527   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
528   "@
529    lwa%U1%X1 %0,%1
530    extsw %0,%1"
531   [(set_attr "type" "load_ext,exts")])
532
533 (define_insn ""
534   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
535         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
536   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
537   "extsw %0,%1"
538   [(set_attr "type" "exts")])
539
540 (define_insn ""
541   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
542         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
543                     (const_int 0)))
544    (clobber (match_scratch:DI 2 "=r,r"))]
545   "TARGET_64BIT"
546   "@
547    extsw. %2,%1
548    #"
549   [(set_attr "type" "compare")
550    (set_attr "length" "4,8")])
551
552 (define_split
553   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
554         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
555                     (const_int 0)))
556    (clobber (match_scratch:DI 2 ""))]
557   "TARGET_POWERPC64 && reload_completed"
558   [(set (match_dup 2)
559         (sign_extend:DI (match_dup 1)))
560    (set (match_dup 0)
561         (compare:CC (match_dup 2)
562                     (const_int 0)))]
563   "")
564
565 (define_insn ""
566   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
567         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
568                     (const_int 0)))
569    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
570         (sign_extend:DI (match_dup 1)))]
571   "TARGET_64BIT"
572   "@
573    extsw. %0,%1
574    #"
575   [(set_attr "type" "compare")
576    (set_attr "length" "4,8")])
577
578 (define_split
579   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
580         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
581                     (const_int 0)))
582    (set (match_operand:DI 0 "gpc_reg_operand" "")
583         (sign_extend:DI (match_dup 1)))]
584   "TARGET_POWERPC64 && reload_completed"
585   [(set (match_dup 0)
586         (sign_extend:DI (match_dup 1)))
587    (set (match_dup 2)
588         (compare:CC (match_dup 0)
589                     (const_int 0)))]
590   "")
591
592 (define_expand "zero_extendqisi2"
593   [(set (match_operand:SI 0 "gpc_reg_operand" "")
594         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
595   ""
596   "")
597
598 (define_insn ""
599   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
600         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
601   ""
602   "@
603    lbz%U1%X1 %0,%1
604    rlwinm %0,%1,0,0xff"
605   [(set_attr "type" "load,*")])
606
607 (define_insn ""
608   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
609         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
610                     (const_int 0)))
611    (clobber (match_scratch:SI 2 "=r,r"))]
612   ""
613   "@
614    andi. %2,%1,0xff
615    #"
616   [(set_attr "type" "fast_compare,compare")
617    (set_attr "length" "4,8")])
618
619 (define_split
620   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
621         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
622                     (const_int 0)))
623    (clobber (match_scratch:SI 2 ""))]
624   "reload_completed"
625   [(set (match_dup 2)
626         (zero_extend:SI (match_dup 1)))
627    (set (match_dup 0)
628         (compare:CC (match_dup 2)
629                     (const_int 0)))]
630   "")
631
632 (define_insn ""
633   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
634         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
635                     (const_int 0)))
636    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
637         (zero_extend:SI (match_dup 1)))]
638   ""
639   "@
640    andi. %0,%1,0xff
641    #"
642   [(set_attr "type" "fast_compare,compare")
643    (set_attr "length" "4,8")])
644
645 (define_split
646   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
647         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
648                     (const_int 0)))
649    (set (match_operand:SI 0 "gpc_reg_operand" "")
650         (zero_extend:SI (match_dup 1)))]
651   "reload_completed"
652   [(set (match_dup 0)
653         (zero_extend:SI (match_dup 1)))
654    (set (match_dup 2)
655         (compare:CC (match_dup 0)
656                     (const_int 0)))]
657   "")
658
659 (define_insn "extendqisi2"
660   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
661         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
662   ""
663   "extsb %0,%1"
664   [(set_attr "type" "exts")])
665
666 (define_insn ""
667   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
668         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
669                     (const_int 0)))
670    (clobber (match_scratch:SI 2 "=r,r"))]
671   ""
672   "@
673    extsb. %2,%1
674    #"
675   [(set_attr "type" "compare")
676    (set_attr "length" "4,8")])
677
678 (define_split
679   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
680         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
681                     (const_int 0)))
682    (clobber (match_scratch:SI 2 ""))]
683   "reload_completed"
684   [(set (match_dup 2)
685         (sign_extend:SI (match_dup 1)))
686    (set (match_dup 0)
687         (compare:CC (match_dup 2)
688                     (const_int 0)))]
689   "")
690
691 (define_insn ""
692   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
693         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
694                     (const_int 0)))
695    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
696         (sign_extend:SI (match_dup 1)))]
697   ""
698   "@
699    extsb. %0,%1
700    #"
701   [(set_attr "type" "compare")
702    (set_attr "length" "4,8")])
703
704 (define_split
705   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
706         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
707                     (const_int 0)))
708    (set (match_operand:SI 0 "gpc_reg_operand" "")
709         (sign_extend:SI (match_dup 1)))]
710   "reload_completed"
711   [(set (match_dup 0)
712         (sign_extend:SI (match_dup 1)))
713    (set (match_dup 2)
714         (compare:CC (match_dup 0)
715                     (const_int 0)))]
716   "")
717
718 (define_insn ""
719   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
720         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
721   ""
722   "@
723    lbz%U1%X1 %0,%1
724    rlwinm %0,%1,0,0xff"
725   [(set_attr "type" "load,*")])
726
727 (define_insn ""
728   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
729         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
730                     (const_int 0)))
731    (clobber (match_scratch:HI 2 "=r,r"))]
732   ""
733   "@
734    andi. %2,%1,0xff
735    #"
736   [(set_attr "type" "fast_compare,compare")
737    (set_attr "length" "4,8")])
738
739 (define_split
740   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
741         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
742                     (const_int 0)))
743    (clobber (match_scratch:HI 2 ""))]
744   "reload_completed"
745   [(set (match_dup 2)
746         (zero_extend:HI (match_dup 1)))
747    (set (match_dup 0)
748         (compare:CC (match_dup 2)
749                     (const_int 0)))]
750   "")
751
752 (define_insn ""
753   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
754         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
755                     (const_int 0)))
756    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
757         (zero_extend:HI (match_dup 1)))]
758   ""
759   "@
760    andi. %0,%1,0xff
761    #"
762   [(set_attr "type" "fast_compare,compare")
763    (set_attr "length" "4,8")])
764
765 (define_split
766   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
767         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
768                     (const_int 0)))
769    (set (match_operand:HI 0 "gpc_reg_operand" "")
770         (zero_extend:HI (match_dup 1)))]
771   "reload_completed"
772   [(set (match_dup 0)
773         (zero_extend:HI (match_dup 1)))
774    (set (match_dup 2)
775         (compare:CC (match_dup 0)
776                     (const_int 0)))]
777   "")
778
779 (define_insn "extendqihi2"
780   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
781         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
782   ""
783   "extsb %0,%1"
784   [(set_attr "type" "exts")])
785
786 (define_insn ""
787   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
788         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
789                     (const_int 0)))
790    (clobber (match_scratch:HI 2 "=r,r"))]
791   ""
792   "@
793    extsb. %2,%1
794    #"
795   [(set_attr "type" "compare")
796    (set_attr "length" "4,8")])
797
798 (define_split
799   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
800         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
801                     (const_int 0)))
802    (clobber (match_scratch:HI 2 ""))]
803   "reload_completed"
804   [(set (match_dup 2)
805         (sign_extend:HI (match_dup 1)))
806    (set (match_dup 0)
807         (compare:CC (match_dup 2)
808                     (const_int 0)))]
809   "")
810
811 (define_insn ""
812   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
813         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
814                     (const_int 0)))
815    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
816         (sign_extend:HI (match_dup 1)))]
817   ""
818   "@
819    extsb. %0,%1
820    #"
821   [(set_attr "type" "compare")
822    (set_attr "length" "4,8")])
823
824 (define_split
825   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
826         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
827                     (const_int 0)))
828    (set (match_operand:HI 0 "gpc_reg_operand" "")
829         (sign_extend:HI (match_dup 1)))]
830   "reload_completed"
831   [(set (match_dup 0)
832         (sign_extend:HI (match_dup 1)))
833    (set (match_dup 2)
834         (compare:CC (match_dup 0)
835                     (const_int 0)))]
836   "")
837
838 (define_expand "zero_extendhisi2"
839   [(set (match_operand:SI 0 "gpc_reg_operand" "")
840         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
841   ""
842   "")
843
844 (define_insn ""
845   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
846         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
847   ""
848   "@
849    lhz%U1%X1 %0,%1
850    rlwinm %0,%1,0,0xffff"
851   [(set_attr "type" "load,*")])
852
853 (define_insn ""
854   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
855         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
856                     (const_int 0)))
857    (clobber (match_scratch:SI 2 "=r,r"))]
858   ""
859   "@
860    andi. %2,%1,0xffff
861    #"
862   [(set_attr "type" "fast_compare,compare")
863    (set_attr "length" "4,8")])
864
865 (define_split
866   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
867         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
868                     (const_int 0)))
869    (clobber (match_scratch:SI 2 ""))]
870   "reload_completed"
871   [(set (match_dup 2)
872         (zero_extend:SI (match_dup 1)))
873    (set (match_dup 0)
874         (compare:CC (match_dup 2)
875                     (const_int 0)))]
876   "")
877
878 (define_insn ""
879   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
880         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
881                     (const_int 0)))
882    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
883         (zero_extend:SI (match_dup 1)))]
884   ""
885   "@
886    andi. %0,%1,0xffff
887    #"
888   [(set_attr "type" "fast_compare,compare")
889    (set_attr "length" "4,8")])
890
891 (define_split
892   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
893         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
894                     (const_int 0)))
895    (set (match_operand:SI 0 "gpc_reg_operand" "")
896         (zero_extend:SI (match_dup 1)))]
897   "reload_completed"
898   [(set (match_dup 0)
899         (zero_extend:SI (match_dup 1)))
900    (set (match_dup 2)
901         (compare:CC (match_dup 0)
902                     (const_int 0)))]
903   "")
904
905 (define_expand "extendhisi2"
906   [(set (match_operand:SI 0 "gpc_reg_operand" "")
907         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
908   ""
909   "")
910
911 (define_insn ""
912   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
913         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
914   "rs6000_gen_cell_microcode"
915   "@
916    lha%U1%X1 %0,%1
917    extsh %0,%1"
918   [(set_attr "type" "load_ext,exts")])
919
920 (define_insn ""
921   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
922         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
923   "!rs6000_gen_cell_microcode"
924   "extsh %0,%1"
925   [(set_attr "type" "exts")])
926
927 (define_insn ""
928   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
929         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
930                     (const_int 0)))
931    (clobber (match_scratch:SI 2 "=r,r"))]
932   ""
933   "@
934    extsh. %2,%1
935    #"
936   [(set_attr "type" "compare")
937    (set_attr "length" "4,8")])
938
939 (define_split
940   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
941         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
942                     (const_int 0)))
943    (clobber (match_scratch:SI 2 ""))]
944   "reload_completed"
945   [(set (match_dup 2)
946         (sign_extend:SI (match_dup 1)))
947    (set (match_dup 0)
948         (compare:CC (match_dup 2)
949                     (const_int 0)))]
950   "")
951
952 (define_insn ""
953   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
954         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
955                     (const_int 0)))
956    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
957         (sign_extend:SI (match_dup 1)))]
958   ""
959   "@
960    extsh. %0,%1
961    #"
962   [(set_attr "type" "compare")
963    (set_attr "length" "4,8")])
964
965 (define_split
966   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
967         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
968                     (const_int 0)))
969    (set (match_operand:SI 0 "gpc_reg_operand" "")
970         (sign_extend:SI (match_dup 1)))]
971   "reload_completed"
972   [(set (match_dup 0)
973         (sign_extend:SI (match_dup 1)))
974    (set (match_dup 2)
975         (compare:CC (match_dup 0)
976                     (const_int 0)))]
977   "")
978 \f
979 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
980
981 (define_insn "*macchwc"
982   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
983         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
984                                        (match_operand:SI 2 "gpc_reg_operand" "r")
985                                        (const_int 16))
986                                       (sign_extend:SI
987                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
988                              (match_operand:SI 4 "gpc_reg_operand" "0"))
989                     (const_int 0)))
990    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
991         (plus:SI (mult:SI (ashiftrt:SI
992                            (match_dup 2)
993                            (const_int 16))
994                           (sign_extend:SI
995                            (match_dup 1)))
996                  (match_dup 4)))]
997   "TARGET_MULHW"
998   "macchw. %0,%1,%2"
999   [(set_attr "type" "imul3")])
1000
1001 (define_insn "*macchw"
1002   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1003         (plus:SI (mult:SI (ashiftrt:SI
1004                            (match_operand:SI 2 "gpc_reg_operand" "r")
1005                            (const_int 16))
1006                           (sign_extend:SI
1007                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1008                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1009   "TARGET_MULHW"
1010   "macchw %0,%1,%2"
1011   [(set_attr "type" "imul3")])
1012
1013 (define_insn "*macchwuc"
1014   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1015         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1016                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1017                                        (const_int 16))
1018                                       (zero_extend:SI
1019                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1020                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1021                     (const_int 0)))
1022    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1023         (plus:SI (mult:SI (lshiftrt:SI
1024                            (match_dup 2)
1025                            (const_int 16))
1026                           (zero_extend:SI
1027                            (match_dup 1)))
1028                  (match_dup 4)))]
1029   "TARGET_MULHW"
1030   "macchwu. %0,%1,%2"
1031   [(set_attr "type" "imul3")])
1032
1033 (define_insn "*macchwu"
1034   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1035         (plus:SI (mult:SI (lshiftrt:SI
1036                            (match_operand:SI 2 "gpc_reg_operand" "r")
1037                            (const_int 16))
1038                           (zero_extend:SI
1039                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1040                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1041   "TARGET_MULHW"
1042   "macchwu %0,%1,%2"
1043   [(set_attr "type" "imul3")])
1044
1045 (define_insn "*machhwc"
1046   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1047         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1048                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1049                                        (const_int 16))
1050                                       (ashiftrt:SI
1051                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1052                                        (const_int 16)))
1053                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1054                     (const_int 0)))
1055    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1056         (plus:SI (mult:SI (ashiftrt:SI
1057                            (match_dup 1)
1058                            (const_int 16))
1059                           (ashiftrt:SI
1060                            (match_dup 2)
1061                            (const_int 16)))
1062                  (match_dup 4)))]
1063   "TARGET_MULHW"
1064   "machhw. %0,%1,%2"
1065   [(set_attr "type" "imul3")])
1066
1067 (define_insn "*machhw"
1068   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1069         (plus:SI (mult:SI (ashiftrt:SI
1070                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1071                            (const_int 16))
1072                           (ashiftrt:SI
1073                            (match_operand:SI 2 "gpc_reg_operand" "r")
1074                            (const_int 16)))
1075                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1076   "TARGET_MULHW"
1077   "machhw %0,%1,%2"
1078   [(set_attr "type" "imul3")])
1079
1080 (define_insn "*machhwuc"
1081   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1082         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1083                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1084                                        (const_int 16))
1085                                       (lshiftrt:SI
1086                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1087                                        (const_int 16)))
1088                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1089                     (const_int 0)))
1090    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1091         (plus:SI (mult:SI (lshiftrt:SI
1092                            (match_dup 1)
1093                            (const_int 16))
1094                           (lshiftrt:SI
1095                            (match_dup 2)
1096                            (const_int 16)))
1097                  (match_dup 4)))]
1098   "TARGET_MULHW"
1099   "machhwu. %0,%1,%2"
1100   [(set_attr "type" "imul3")])
1101
1102 (define_insn "*machhwu"
1103   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1104         (plus:SI (mult:SI (lshiftrt:SI
1105                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1106                            (const_int 16))
1107                           (lshiftrt:SI
1108                            (match_operand:SI 2 "gpc_reg_operand" "r")
1109                            (const_int 16)))
1110                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1111   "TARGET_MULHW"
1112   "machhwu %0,%1,%2"
1113   [(set_attr "type" "imul3")])
1114
1115 (define_insn "*maclhwc"
1116   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1117         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1118                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1119                                       (sign_extend:SI
1120                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1121                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1122                     (const_int 0)))
1123    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1124         (plus:SI (mult:SI (sign_extend:SI
1125                            (match_dup 1))
1126                           (sign_extend:SI
1127                            (match_dup 2)))
1128                  (match_dup 4)))]
1129   "TARGET_MULHW"
1130   "maclhw. %0,%1,%2"
1131   [(set_attr "type" "imul3")])
1132
1133 (define_insn "*maclhw"
1134   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1135         (plus:SI (mult:SI (sign_extend:SI
1136                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1137                           (sign_extend:SI
1138                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1139                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1140   "TARGET_MULHW"
1141   "maclhw %0,%1,%2"
1142   [(set_attr "type" "imul3")])
1143
1144 (define_insn "*maclhwuc"
1145   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1146         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1147                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1148                                       (zero_extend:SI
1149                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1150                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1151                     (const_int 0)))
1152    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1153         (plus:SI (mult:SI (zero_extend:SI
1154                            (match_dup 1))
1155                           (zero_extend:SI
1156                            (match_dup 2)))
1157                  (match_dup 4)))]
1158   "TARGET_MULHW"
1159   "maclhwu. %0,%1,%2"
1160   [(set_attr "type" "imul3")])
1161
1162 (define_insn "*maclhwu"
1163   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1164         (plus:SI (mult:SI (zero_extend:SI
1165                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1166                           (zero_extend:SI
1167                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1168                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1169   "TARGET_MULHW"
1170   "maclhwu %0,%1,%2"
1171   [(set_attr "type" "imul3")])
1172
1173 (define_insn "*nmacchwc"
1174   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1175         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1176                               (mult:SI (ashiftrt:SI
1177                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1178                                         (const_int 16))
1179                                        (sign_extend:SI
1180                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1181                     (const_int 0)))
1182    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1183         (minus:SI (match_dup 4)
1184                   (mult:SI (ashiftrt:SI
1185                             (match_dup 2)
1186                             (const_int 16))
1187                            (sign_extend:SI
1188                             (match_dup 1)))))]
1189   "TARGET_MULHW"
1190   "nmacchw. %0,%1,%2"
1191   [(set_attr "type" "imul3")])
1192
1193 (define_insn "*nmacchw"
1194   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1195         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1196                   (mult:SI (ashiftrt:SI
1197                             (match_operand:SI 2 "gpc_reg_operand" "r")
1198                             (const_int 16))
1199                            (sign_extend:SI
1200                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1201   "TARGET_MULHW"
1202   "nmacchw %0,%1,%2"
1203   [(set_attr "type" "imul3")])
1204
1205 (define_insn "*nmachhwc"
1206   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1207         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1208                               (mult:SI (ashiftrt:SI
1209                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1210                                         (const_int 16))
1211                                        (ashiftrt:SI
1212                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1213                                         (const_int 16))))
1214                     (const_int 0)))
1215    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1216         (minus:SI (match_dup 4)
1217                   (mult:SI (ashiftrt:SI
1218                             (match_dup 1)
1219                             (const_int 16))
1220                            (ashiftrt:SI
1221                             (match_dup 2)
1222                             (const_int 16)))))]
1223   "TARGET_MULHW"
1224   "nmachhw. %0,%1,%2"
1225   [(set_attr "type" "imul3")])
1226
1227 (define_insn "*nmachhw"
1228   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1229         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1230                   (mult:SI (ashiftrt:SI
1231                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1232                             (const_int 16))
1233                            (ashiftrt:SI
1234                             (match_operand:SI 2 "gpc_reg_operand" "r")
1235                             (const_int 16)))))]
1236   "TARGET_MULHW"
1237   "nmachhw %0,%1,%2"
1238   [(set_attr "type" "imul3")])
1239
1240 (define_insn "*nmaclhwc"
1241   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1242         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1243                               (mult:SI (sign_extend:SI
1244                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1245                                        (sign_extend:SI
1246                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1247                     (const_int 0)))
1248    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1249         (minus:SI (match_dup 4)
1250                   (mult:SI (sign_extend:SI
1251                             (match_dup 1))
1252                            (sign_extend:SI
1253                             (match_dup 2)))))]
1254   "TARGET_MULHW"
1255   "nmaclhw. %0,%1,%2"
1256   [(set_attr "type" "imul3")])
1257
1258 (define_insn "*nmaclhw"
1259   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1260         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1261                   (mult:SI (sign_extend:SI
1262                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1263                            (sign_extend:SI
1264                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1265   "TARGET_MULHW"
1266   "nmaclhw %0,%1,%2"
1267   [(set_attr "type" "imul3")])
1268
1269 (define_insn "*mulchwc"
1270   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1271         (compare:CC (mult:SI (ashiftrt:SI
1272                               (match_operand:SI 2 "gpc_reg_operand" "r")
1273                               (const_int 16))
1274                              (sign_extend:SI
1275                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1276                     (const_int 0)))
1277    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1278         (mult:SI (ashiftrt:SI
1279                   (match_dup 2)
1280                   (const_int 16))
1281                  (sign_extend:SI
1282                   (match_dup 1))))]
1283   "TARGET_MULHW"
1284   "mulchw. %0,%1,%2"
1285   [(set_attr "type" "imul3")])
1286
1287 (define_insn "*mulchw"
1288   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1289         (mult:SI (ashiftrt:SI
1290                   (match_operand:SI 2 "gpc_reg_operand" "r")
1291                   (const_int 16))
1292                  (sign_extend:SI
1293                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1294   "TARGET_MULHW"
1295   "mulchw %0,%1,%2"
1296   [(set_attr "type" "imul3")])
1297
1298 (define_insn "*mulchwuc"
1299   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1300         (compare:CC (mult:SI (lshiftrt:SI
1301                               (match_operand:SI 2 "gpc_reg_operand" "r")
1302                               (const_int 16))
1303                              (zero_extend:SI
1304                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1305                     (const_int 0)))
1306    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1307         (mult:SI (lshiftrt:SI
1308                   (match_dup 2)
1309                   (const_int 16))
1310                  (zero_extend:SI
1311                   (match_dup 1))))]
1312   "TARGET_MULHW"
1313   "mulchwu. %0,%1,%2"
1314   [(set_attr "type" "imul3")])
1315
1316 (define_insn "*mulchwu"
1317   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1318         (mult:SI (lshiftrt:SI
1319                   (match_operand:SI 2 "gpc_reg_operand" "r")
1320                   (const_int 16))
1321                  (zero_extend:SI
1322                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1323   "TARGET_MULHW"
1324   "mulchwu %0,%1,%2"
1325   [(set_attr "type" "imul3")])
1326
1327 (define_insn "*mulhhwc"
1328   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1329         (compare:CC (mult:SI (ashiftrt:SI
1330                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1331                               (const_int 16))
1332                              (ashiftrt:SI
1333                               (match_operand:SI 2 "gpc_reg_operand" "r")
1334                               (const_int 16)))
1335                     (const_int 0)))
1336    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1337         (mult:SI (ashiftrt:SI
1338                   (match_dup 1)
1339                   (const_int 16))
1340                  (ashiftrt:SI
1341                   (match_dup 2)
1342                   (const_int 16))))]
1343   "TARGET_MULHW"
1344   "mulhhw. %0,%1,%2"
1345   [(set_attr "type" "imul3")])
1346
1347 (define_insn "*mulhhw"
1348   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1349         (mult:SI (ashiftrt:SI
1350                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1351                   (const_int 16))
1352                  (ashiftrt:SI
1353                   (match_operand:SI 2 "gpc_reg_operand" "r")
1354                   (const_int 16))))]
1355   "TARGET_MULHW"
1356   "mulhhw %0,%1,%2"
1357   [(set_attr "type" "imul3")])
1358
1359 (define_insn "*mulhhwuc"
1360   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1361         (compare:CC (mult:SI (lshiftrt:SI
1362                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1363                               (const_int 16))
1364                              (lshiftrt:SI
1365                               (match_operand:SI 2 "gpc_reg_operand" "r")
1366                               (const_int 16)))
1367                     (const_int 0)))
1368    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1369         (mult:SI (lshiftrt:SI
1370                   (match_dup 1)
1371                   (const_int 16))
1372                  (lshiftrt:SI
1373                   (match_dup 2)
1374                   (const_int 16))))]
1375   "TARGET_MULHW"
1376   "mulhhwu. %0,%1,%2"
1377   [(set_attr "type" "imul3")])
1378
1379 (define_insn "*mulhhwu"
1380   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1381         (mult:SI (lshiftrt:SI
1382                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1383                   (const_int 16))
1384                  (lshiftrt:SI
1385                   (match_operand:SI 2 "gpc_reg_operand" "r")
1386                   (const_int 16))))]
1387   "TARGET_MULHW"
1388   "mulhhwu %0,%1,%2"
1389   [(set_attr "type" "imul3")])
1390
1391 (define_insn "*mullhwc"
1392   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1393         (compare:CC (mult:SI (sign_extend:SI
1394                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1395                              (sign_extend:SI
1396                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1397                     (const_int 0)))
1398    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1399         (mult:SI (sign_extend:SI
1400                   (match_dup 1))
1401                  (sign_extend:SI
1402                   (match_dup 2))))]
1403   "TARGET_MULHW"
1404   "mullhw. %0,%1,%2"
1405   [(set_attr "type" "imul3")])
1406
1407 (define_insn "*mullhw"
1408   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1409         (mult:SI (sign_extend:SI
1410                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1411                  (sign_extend:SI
1412                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1413   "TARGET_MULHW"
1414   "mullhw %0,%1,%2"
1415   [(set_attr "type" "imul3")])
1416
1417 (define_insn "*mullhwuc"
1418   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1419         (compare:CC (mult:SI (zero_extend:SI
1420                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1421                              (zero_extend:SI
1422                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1423                     (const_int 0)))
1424    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1425         (mult:SI (zero_extend:SI
1426                   (match_dup 1))
1427                  (zero_extend:SI
1428                   (match_dup 2))))]
1429   "TARGET_MULHW"
1430   "mullhwu. %0,%1,%2"
1431   [(set_attr "type" "imul3")])
1432
1433 (define_insn "*mullhwu"
1434   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1435         (mult:SI (zero_extend:SI
1436                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1437                  (zero_extend:SI
1438                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1439   "TARGET_MULHW"
1440   "mullhwu %0,%1,%2"
1441   [(set_attr "type" "imul3")])
1442 \f
1443 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1444 (define_insn "dlmzb"
1445   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1446         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1447                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1448                    UNSPEC_DLMZB_CR))
1449    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1450         (unspec:SI [(match_dup 1)
1451                     (match_dup 2)]
1452                    UNSPEC_DLMZB))]
1453   "TARGET_DLMZB"
1454   "dlmzb. %0,%1,%2")
1455
1456 (define_expand "strlensi"
1457   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1458         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1459                     (match_operand:QI 2 "const_int_operand" "")
1460                     (match_operand 3 "const_int_operand" "")]
1461                    UNSPEC_DLMZB_STRLEN))
1462    (clobber (match_scratch:CC 4 "=x"))]
1463   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1464 {
1465   rtx result = operands[0];
1466   rtx src = operands[1];
1467   rtx search_char = operands[2];
1468   rtx align = operands[3];
1469   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1470   rtx loop_label, end_label, mem, cr0, cond;
1471   if (search_char != const0_rtx
1472       || GET_CODE (align) != CONST_INT
1473       || INTVAL (align) < 8)
1474         FAIL;
1475   word1 = gen_reg_rtx (SImode);
1476   word2 = gen_reg_rtx (SImode);
1477   scratch_dlmzb = gen_reg_rtx (SImode);
1478   scratch_string = gen_reg_rtx (Pmode);
1479   loop_label = gen_label_rtx ();
1480   end_label = gen_label_rtx ();
1481   addr = force_reg (Pmode, XEXP (src, 0));
1482   emit_move_insn (scratch_string, addr);
1483   emit_label (loop_label);
1484   mem = change_address (src, SImode, scratch_string);
1485   emit_move_insn (word1, mem);
1486   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1487   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1488   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1489   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1490   emit_jump_insn (gen_rtx_SET (VOIDmode,
1491                                pc_rtx,
1492                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1493                                                      cond,
1494                                                      gen_rtx_LABEL_REF
1495                                                        (VOIDmode,
1496                                                         end_label),
1497                                                      pc_rtx)));
1498   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1499   emit_jump_insn (gen_rtx_SET (VOIDmode,
1500                                pc_rtx,
1501                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1502   emit_barrier ();
1503   emit_label (end_label);
1504   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1505   emit_insn (gen_subsi3 (result, scratch_string, addr));
1506   emit_insn (gen_subsi3 (result, result, const1_rtx));
1507   DONE;
1508 })
1509 \f
1510 ;; Fixed-point arithmetic insns.
1511
1512 (define_expand "add<mode>3"
1513   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1514         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1515                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1516   ""
1517 {
1518   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1519     {
1520       if (non_short_cint_operand (operands[2], DImode))
1521         FAIL;
1522     }
1523   else if (GET_CODE (operands[2]) == CONST_INT
1524            && ! add_operand (operands[2], <MODE>mode))
1525     {
1526       rtx tmp = ((!can_create_pseudo_p ()
1527                   || rtx_equal_p (operands[0], operands[1]))
1528                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1529
1530       HOST_WIDE_INT val = INTVAL (operands[2]);
1531       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1532       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1533
1534       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1535         FAIL;
1536
1537       /* The ordering here is important for the prolog expander.
1538          When space is allocated from the stack, adding 'low' first may
1539          produce a temporary deallocation (which would be bad).  */
1540       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1541       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1542       DONE;
1543     }
1544 })
1545
1546 ;; Discourage ai/addic because of carry but provide it in an alternative
1547 ;; allowing register zero as source.
1548 (define_insn "*add<mode>3_internal1"
1549   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1550         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1551                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1552   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1553   "@
1554    add %0,%1,%2
1555    addi %0,%1,%2
1556    addic %0,%1,%2
1557    addis %0,%1,%v2"
1558   [(set_attr "length" "4,4,4,4")])
1559
1560 (define_insn "addsi3_high"
1561   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1562         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1563                  (high:SI (match_operand 2 "" ""))))]
1564   "TARGET_MACHO && !TARGET_64BIT"
1565   "addis %0,%1,ha16(%2)"
1566   [(set_attr "length" "4")])
1567
1568 (define_insn "*add<mode>3_internal2"
1569   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1570         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1571                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1572                     (const_int 0)))
1573    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1574   ""
1575   "@
1576    add. %3,%1,%2
1577    addic. %3,%1,%2
1578    #
1579    #"
1580   [(set_attr "type" "fast_compare,compare,compare,compare")
1581    (set_attr "length" "4,4,8,8")])
1582
1583 (define_split
1584   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1585         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1586                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1587                     (const_int 0)))
1588    (clobber (match_scratch:GPR 3 ""))]
1589   "reload_completed"
1590   [(set (match_dup 3)
1591         (plus:GPR (match_dup 1)
1592                  (match_dup 2)))
1593    (set (match_dup 0)
1594         (compare:CC (match_dup 3)
1595                     (const_int 0)))]
1596   "")
1597
1598 (define_insn "*add<mode>3_internal3"
1599   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1600         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1601                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1602                     (const_int 0)))
1603    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1604         (plus:P (match_dup 1)
1605                 (match_dup 2)))]
1606   ""
1607   "@
1608    add. %0,%1,%2
1609    addic. %0,%1,%2
1610    #
1611    #"
1612   [(set_attr "type" "fast_compare,compare,compare,compare")
1613    (set_attr "length" "4,4,8,8")])
1614
1615 (define_split
1616   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1617         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1618                             (match_operand:P 2 "reg_or_short_operand" ""))
1619                     (const_int 0)))
1620    (set (match_operand:P 0 "gpc_reg_operand" "")
1621         (plus:P (match_dup 1) (match_dup 2)))]
1622   "reload_completed"
1623   [(set (match_dup 0)
1624         (plus:P (match_dup 1)
1625                 (match_dup 2)))
1626    (set (match_dup 3)
1627         (compare:CC (match_dup 0)
1628                     (const_int 0)))]
1629   "")
1630
1631 ;; Split an add that we can't do in one insn into two insns, each of which
1632 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1633 ;; add should be last in case the result gets used in an address.
1634
1635 (define_split
1636   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1637         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1638                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1639   ""
1640   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1641    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1642 {
1643   HOST_WIDE_INT val = INTVAL (operands[2]);
1644   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1645   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1646
1647   operands[4] = GEN_INT (low);
1648   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1649     operands[3] = GEN_INT (rest);
1650   else if (can_create_pseudo_p ())
1651     {
1652       operands[3] = gen_reg_rtx (DImode);
1653       emit_move_insn (operands[3], operands[2]);
1654       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1655       DONE;
1656     }
1657   else
1658     FAIL;
1659 })
1660
1661 (define_insn "one_cmpl<mode>2"
1662   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1663         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1664   ""
1665   "nor %0,%1,%1")
1666
1667 (define_insn ""
1668   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1669         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1670                     (const_int 0)))
1671    (clobber (match_scratch:P 2 "=r,r"))]
1672   ""
1673   "@
1674    nor. %2,%1,%1
1675    #"
1676   [(set_attr "type" "fast_compare,compare")
1677    (set_attr "length" "4,8")])
1678
1679 (define_split
1680   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1681         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1682                     (const_int 0)))
1683    (clobber (match_scratch:P 2 ""))]
1684   "reload_completed"
1685   [(set (match_dup 2)
1686         (not:P (match_dup 1)))
1687    (set (match_dup 0)
1688         (compare:CC (match_dup 2)
1689                     (const_int 0)))]
1690   "")
1691
1692 (define_insn ""
1693   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1694         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1695                     (const_int 0)))
1696    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1697         (not:P (match_dup 1)))]
1698   ""
1699   "@
1700    nor. %0,%1,%1
1701    #"
1702   [(set_attr "type" "fast_compare,compare")
1703    (set_attr "length" "4,8")])
1704
1705 (define_split
1706   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1707         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1708                     (const_int 0)))
1709    (set (match_operand:P 0 "gpc_reg_operand" "")
1710         (not:P (match_dup 1)))]
1711   "reload_completed"
1712   [(set (match_dup 0)
1713         (not:P (match_dup 1)))
1714    (set (match_dup 2)
1715         (compare:CC (match_dup 0)
1716                     (const_int 0)))]
1717   "")
1718
1719 (define_insn ""
1720   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1721         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1722                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1723   ""
1724   "@
1725    subf %0,%2,%1
1726    subfic %0,%2,%1")
1727
1728 (define_insn ""
1729   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1730         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1731                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1732                     (const_int 0)))
1733    (clobber (match_scratch:P 3 "=r,r"))]
1734   ""
1735   "@
1736    subf. %3,%2,%1
1737    #"
1738   [(set_attr "type" "fast_compare")
1739    (set_attr "length" "4,8")])
1740
1741 (define_split
1742   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1743         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1744                              (match_operand:P 2 "gpc_reg_operand" ""))
1745                     (const_int 0)))
1746    (clobber (match_scratch:P 3 ""))]
1747   "reload_completed"
1748   [(set (match_dup 3)
1749         (minus:P (match_dup 1)
1750                   (match_dup 2)))
1751    (set (match_dup 0)
1752         (compare:CC (match_dup 3)
1753                     (const_int 0)))]
1754   "")
1755
1756 (define_insn ""
1757   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1758         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1759                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1760                     (const_int 0)))
1761    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1762         (minus:P (match_dup 1)
1763                   (match_dup 2)))]
1764   ""
1765   "@
1766    subf. %0,%2,%1
1767    #"
1768   [(set_attr "type" "fast_compare")
1769    (set_attr "length" "4,8")])
1770
1771 (define_split
1772   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1773         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1774                              (match_operand:P 2 "gpc_reg_operand" ""))
1775                     (const_int 0)))
1776    (set (match_operand:P 0 "gpc_reg_operand" "")
1777         (minus:P (match_dup 1)
1778                   (match_dup 2)))]
1779   "reload_completed"
1780   [(set (match_dup 0)
1781         (minus:P (match_dup 1)
1782                   (match_dup 2)))
1783    (set (match_dup 3)
1784         (compare:CC (match_dup 0)
1785                     (const_int 0)))]
1786   "")
1787
1788 (define_expand "sub<mode>3"
1789   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1790         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1791                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1792   ""
1793   "
1794 {
1795   if (GET_CODE (operands[2]) == CONST_INT)
1796     {
1797       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1798                                  negate_rtx (<MODE>mode, operands[2])));
1799       DONE;
1800     }
1801 }")
1802
1803 (define_expand "neg<mode>2"
1804   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1805         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1806   ""
1807   "")
1808
1809 (define_insn "*neg<mode>2_internal"
1810   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1811         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1812   ""
1813   "neg %0,%1")
1814
1815 (define_insn ""
1816   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1817         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1818                     (const_int 0)))
1819    (clobber (match_scratch:P 2 "=r,r"))]
1820   ""
1821   "@
1822    neg. %2,%1
1823    #"
1824   [(set_attr "type" "fast_compare")
1825    (set_attr "length" "4,8")])
1826
1827 (define_split
1828   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1829         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1830                     (const_int 0)))
1831    (clobber (match_scratch:P 2 ""))]
1832   "reload_completed"
1833   [(set (match_dup 2)
1834         (neg:P (match_dup 1)))
1835    (set (match_dup 0)
1836         (compare:CC (match_dup 2)
1837                     (const_int 0)))]
1838   "")
1839
1840 (define_insn ""
1841   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1842         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1843                     (const_int 0)))
1844    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1845         (neg:P (match_dup 1)))]
1846   ""
1847   "@
1848    neg. %0,%1
1849    #"
1850   [(set_attr "type" "fast_compare")
1851    (set_attr "length" "4,8")])
1852
1853 (define_split
1854   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1855         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1856                     (const_int 0)))
1857    (set (match_operand:P 0 "gpc_reg_operand" "")
1858         (neg:P (match_dup 1)))]
1859   "reload_completed"
1860   [(set (match_dup 0)
1861         (neg:P (match_dup 1)))
1862    (set (match_dup 2)
1863         (compare:CC (match_dup 0)
1864                     (const_int 0)))]
1865   "")
1866
1867 (define_insn "clz<mode>2"
1868   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1869         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1870   ""
1871   "cntlz<wd> %0,%1"
1872   [(set_attr "type" "cntlz")])
1873
1874 (define_expand "ctz<mode>2"
1875   [(set (match_dup 2)
1876         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
1877    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
1878                                           (match_dup 2)))
1879               (clobber (scratch:CC))])
1880    (set (match_dup 4) (clz:GPR (match_dup 3)))
1881    (set (match_operand:GPR 0 "gpc_reg_operand" "")
1882         (minus:GPR (match_dup 5) (match_dup 4)))]
1883   ""
1884   {
1885      operands[2] = gen_reg_rtx (<MODE>mode);
1886      operands[3] = gen_reg_rtx (<MODE>mode);
1887      operands[4] = gen_reg_rtx (<MODE>mode);
1888      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
1889   })
1890
1891 (define_expand "ffs<mode>2"
1892   [(set (match_dup 2)
1893         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
1894    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
1895                                           (match_dup 2)))
1896               (clobber (scratch:CC))])
1897    (set (match_dup 4) (clz:GPR (match_dup 3)))
1898    (set (match_operand:GPR 0 "gpc_reg_operand" "")
1899         (minus:GPR (match_dup 5) (match_dup 4)))]
1900   ""
1901   {
1902      operands[2] = gen_reg_rtx (<MODE>mode);
1903      operands[3] = gen_reg_rtx (<MODE>mode);
1904      operands[4] = gen_reg_rtx (<MODE>mode);
1905      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
1906   })
1907
1908 (define_insn "popcntb<mode>2"
1909   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1910         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
1911                      UNSPEC_POPCNTB))]
1912   "TARGET_POPCNTB"
1913   "popcntb %0,%1"
1914   [(set_attr "length" "4")
1915    (set_attr "type" "popcnt")])
1916
1917 (define_insn "popcntd<mode>2"
1918   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1919         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1920   "TARGET_POPCNTD"
1921   "popcnt<wd> %0,%1"
1922   [(set_attr "length" "4")
1923    (set_attr "type" "popcnt")])
1924
1925 (define_expand "popcount<mode>2"
1926   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1927         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
1928   "TARGET_POPCNTB || TARGET_POPCNTD"
1929   {
1930     rs6000_emit_popcount (operands[0], operands[1]);
1931     DONE;
1932   })
1933
1934 (define_insn "parity<mode>2_cmpb"
1935   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1936         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
1937   "TARGET_CMPB && TARGET_POPCNTB"
1938   "prty<wd> %0,%1")
1939
1940 (define_expand "parity<mode>2"
1941   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1942         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
1943   "TARGET_POPCNTB"
1944   {
1945     rs6000_emit_parity (operands[0], operands[1]);
1946     DONE;
1947   })
1948
1949 ;; Since the hardware zeros the upper part of the register, save generating the
1950 ;; AND immediate if we are converting to unsigned
1951 (define_insn "*bswaphi2_extenddi"
1952   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
1953         (zero_extend:DI
1954          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
1955   "TARGET_POWERPC64"
1956   "lhbrx %0,%y1"
1957   [(set_attr "length" "4")
1958    (set_attr "type" "load")])
1959
1960 (define_insn "*bswaphi2_extendsi"
1961   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1962         (zero_extend:SI
1963          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
1964   ""
1965   "lhbrx %0,%y1"
1966   [(set_attr "length" "4")
1967    (set_attr "type" "load")])
1968
1969 (define_expand "bswaphi2"
1970   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
1971                    (bswap:HI
1972                     (match_operand:HI 1 "reg_or_mem_operand" "")))
1973               (clobber (match_scratch:SI 2 ""))])]
1974   ""
1975 {
1976   if (!REG_P (operands[0]) && !REG_P (operands[1]))
1977     operands[1] = force_reg (HImode, operands[1]);
1978 })
1979
1980 (define_insn "bswaphi2_internal"
1981   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
1982         (bswap:HI
1983          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
1984    (clobber (match_scratch:SI 2 "=X,X,&r"))]
1985   ""
1986   "@
1987    lhbrx %0,%y1
1988    sthbrx %1,%y0
1989    #"
1990   [(set_attr "length" "4,4,12")
1991    (set_attr "type" "load,store,*")])
1992
1993 ;; We are always BITS_BIG_ENDIAN, so the (const_int 16) below is
1994 ;; correct for -mlittle as well as -mbig.
1995 (define_split
1996   [(set (match_operand:HI 0 "gpc_reg_operand" "")
1997         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
1998    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
1999   "reload_completed"
2000   [(set (match_dup 3)
2001         (zero_extract:SI (match_dup 4)
2002                          (const_int 8)
2003                          (const_int 16)))
2004    (set (match_dup 2)
2005         (and:SI (ashift:SI (match_dup 4)
2006                            (const_int 8))
2007                 (const_int 65280)))             ;; 0xff00
2008    (set (match_dup 3)
2009         (ior:SI (match_dup 3)
2010                 (match_dup 2)))]
2011   "
2012 {
2013   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2014   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2015 }")
2016
2017 (define_insn "*bswapsi2_extenddi"
2018   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2019         (zero_extend:DI
2020          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2021   "TARGET_POWERPC64"
2022   "lwbrx %0,%y1"
2023   [(set_attr "length" "4")
2024    (set_attr "type" "load")])
2025
2026 (define_expand "bswapsi2"
2027   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2028         (bswap:SI
2029          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2030   ""
2031 {
2032   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2033     operands[1] = force_reg (SImode, operands[1]);
2034 })
2035
2036 (define_insn "*bswapsi2_internal"
2037   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2038         (bswap:SI
2039          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2040   ""
2041   "@
2042    lwbrx %0,%y1
2043    stwbrx %1,%y0
2044    #"
2045   [(set_attr "length" "4,4,12")
2046    (set_attr "type" "load,store,*")])
2047
2048 ;; We are always BITS_BIG_ENDIAN, so the bit positions below in
2049 ;; zero_extract insns do not change for -mlittle.
2050 (define_split
2051   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2052         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2053   "reload_completed"
2054   [(set (match_dup 0)
2055         (rotate:SI (match_dup 1) (const_int 8)))
2056    (set (zero_extract:SI (match_dup 0)
2057                          (const_int 8)
2058                          (const_int 0))
2059         (match_dup 1))
2060    (set (zero_extract:SI (match_dup 0)
2061                          (const_int 8)
2062                          (const_int 16))
2063         (rotate:SI (match_dup 1)
2064                    (const_int 16)))]
2065   "")
2066
2067 (define_expand "bswapdi2"
2068   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2069                    (bswap:DI
2070                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2071               (clobber (match_scratch:DI 2 ""))
2072               (clobber (match_scratch:DI 3 ""))
2073               (clobber (match_scratch:DI 4 ""))])]
2074   ""
2075 {
2076   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2077     operands[1] = force_reg (DImode, operands[1]);
2078
2079   if (!TARGET_POWERPC64)
2080     {
2081       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2082          that uses 64-bit registers needs the same scratch registers as 64-bit
2083          mode.  */
2084       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2085       DONE;
2086     }
2087 })
2088
2089 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2090 (define_insn "*bswapdi2_ldbrx"
2091   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2092         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2093    (clobber (match_scratch:DI 2 "=X,X,&r"))
2094    (clobber (match_scratch:DI 3 "=X,X,&r"))
2095    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2096   "TARGET_POWERPC64 && TARGET_LDBRX
2097    && (REG_P (operands[0]) || REG_P (operands[1]))"
2098   "@
2099    ldbrx %0,%y1
2100    stdbrx %1,%y0
2101    #"
2102   [(set_attr "length" "4,4,36")
2103    (set_attr "type" "load,store,*")])
2104
2105 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2106 (define_insn "*bswapdi2_64bit"
2107   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2108         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2109    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2110    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2111    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2112   "TARGET_POWERPC64 && !TARGET_LDBRX
2113    && (REG_P (operands[0]) || REG_P (operands[1]))
2114    && !(MEM_P (operands[0]) && MEM_VOLATILE_P (operands[0]))
2115    && !(MEM_P (operands[1]) && MEM_VOLATILE_P (operands[1]))"
2116   "#"
2117   [(set_attr "length" "16,12,36")])
2118
2119 (define_split
2120   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2121         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2122    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2123    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2124    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2125   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2126   [(const_int 0)]
2127   "
2128 {
2129   rtx dest   = operands[0];
2130   rtx src    = operands[1];
2131   rtx op2    = operands[2];
2132   rtx op3    = operands[3];
2133   rtx op4    = operands[4];
2134   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode,
2135                                     BYTES_BIG_ENDIAN ? 4 : 0);
2136   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode,
2137                                     BYTES_BIG_ENDIAN ? 4 : 0);
2138   rtx addr1;
2139   rtx addr2;
2140   rtx word_high;
2141   rtx word_low;
2142
2143   addr1 = XEXP (src, 0);
2144   if (GET_CODE (addr1) == PLUS)
2145     {
2146       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2147       if (TARGET_AVOID_XFORM)
2148         {
2149           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2150           addr2 = op2;
2151         }
2152       else
2153         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2154     }
2155   else if (TARGET_AVOID_XFORM)
2156     {
2157       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2158       addr2 = op2;
2159     }
2160   else
2161     {
2162       emit_move_insn (op2, GEN_INT (4));
2163       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2164     }
2165
2166   if (BYTES_BIG_ENDIAN)
2167     {
2168       word_high = change_address (src, SImode, addr1);
2169       word_low  = change_address (src, SImode, addr2);
2170     }
2171   else
2172     {
2173       word_high = change_address (src, SImode, addr2);
2174       word_low  = change_address (src, SImode, addr1);
2175     }
2176
2177   emit_insn (gen_bswapsi2 (op3_32, word_low));
2178   emit_insn (gen_bswapsi2 (op4_32, word_high));
2179   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2180   emit_insn (gen_iordi3 (dest, dest, op4));
2181 }")
2182
2183 (define_split
2184   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2185         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2186    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2187    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2188    (clobber (match_operand:DI 4 "" ""))]
2189   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2190   [(const_int 0)]
2191   "
2192 {
2193   rtx dest   = operands[0];
2194   rtx src    = operands[1];
2195   rtx op2    = operands[2];
2196   rtx op3    = operands[3];
2197   rtx src_si = simplify_gen_subreg (SImode, src, DImode,
2198                                     BYTES_BIG_ENDIAN ? 4 : 0);
2199   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode,
2200                                     BYTES_BIG_ENDIAN ? 4 : 0);
2201   rtx addr1;
2202   rtx addr2;
2203   rtx word_high;
2204   rtx word_low;
2205
2206   addr1 = XEXP (dest, 0);
2207   if (GET_CODE (addr1) == PLUS)
2208     {
2209       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2210       if (TARGET_AVOID_XFORM)
2211         {
2212           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2213           addr2 = op2;
2214         }
2215       else
2216         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2217     }
2218   else if (TARGET_AVOID_XFORM)
2219     {
2220       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2221       addr2 = op2;
2222     }
2223   else
2224     {
2225       emit_move_insn (op2, GEN_INT (4));
2226       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2227     }
2228
2229   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2230   if (BYTES_BIG_ENDIAN)
2231     {
2232       word_high = change_address (dest, SImode, addr1);
2233       word_low  = change_address (dest, SImode, addr2);
2234     }
2235   else
2236     {
2237       word_high = change_address (dest, SImode, addr2);
2238       word_low  = change_address (dest, SImode, addr1);
2239     }
2240   emit_insn (gen_bswapsi2 (word_high, src_si));
2241   emit_insn (gen_bswapsi2 (word_low, op3_si));
2242 }")
2243
2244 (define_split
2245   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2246         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2247    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2248    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2249    (clobber (match_operand:DI 4 "" ""))]
2250   "TARGET_POWERPC64 && reload_completed"
2251   [(const_int 0)]
2252   "
2253 {
2254   rtx dest    = operands[0];
2255   rtx src     = operands[1];
2256   rtx op2     = operands[2];
2257   rtx op3     = operands[3];
2258   int lo_off  = BYTES_BIG_ENDIAN ? 4 : 0;
2259   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, lo_off);
2260   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, lo_off);
2261   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, lo_off);
2262   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, lo_off);
2263
2264   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2265   emit_insn (gen_bswapsi2 (dest_si, src_si));
2266   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2267   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2268   emit_insn (gen_iordi3 (dest, dest, op3));
2269 }")
2270
2271 (define_insn "bswapdi2_32bit"
2272   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2273         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2274    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2275   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2276   "#"
2277   [(set_attr "length" "16,12,36")])
2278
2279 (define_split
2280   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2281         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2282    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2283   "!TARGET_POWERPC64 && reload_completed"
2284   [(const_int 0)]
2285   "
2286 {
2287   rtx dest  = operands[0];
2288   rtx src   = operands[1];
2289   rtx op2   = operands[2];
2290   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2291   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2292   rtx addr1;
2293   rtx addr2;
2294   rtx word1;
2295   rtx word2;
2296
2297   addr1 = XEXP (src, 0);
2298   if (GET_CODE (addr1) == PLUS)
2299     {
2300       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2301       if (TARGET_AVOID_XFORM)
2302         {
2303           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2304           addr2 = op2;
2305         }
2306       else
2307         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2308     }
2309   else if (TARGET_AVOID_XFORM)
2310     {
2311       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2312       addr2 = op2;
2313     }
2314   else
2315     {
2316       emit_move_insn (op2, GEN_INT (4));
2317       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2318     }
2319
2320   word1 = change_address (src, SImode, addr1);
2321   word2 = change_address (src, SImode, addr2);
2322
2323   emit_insn (gen_bswapsi2 (dest2, word1));
2324   emit_insn (gen_bswapsi2 (dest1, word2));
2325 }")
2326
2327 (define_split
2328   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2329         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2330    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2331   "!TARGET_POWERPC64 && reload_completed"
2332   [(const_int 0)]
2333   "
2334 {
2335   rtx dest = operands[0];
2336   rtx src  = operands[1];
2337   rtx op2  = operands[2];
2338   rtx src1 = simplify_gen_subreg (SImode, src, DImode, 0);
2339   rtx src2 = simplify_gen_subreg (SImode, src, DImode, 4);
2340   rtx addr1;
2341   rtx addr2;
2342   rtx word1;
2343   rtx word2;
2344
2345   addr1 = XEXP (dest, 0);
2346   if (GET_CODE (addr1) == PLUS)
2347     {
2348       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2349       if (TARGET_AVOID_XFORM)
2350         {
2351           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2352           addr2 = op2;
2353         }
2354       else
2355         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2356     }
2357   else if (TARGET_AVOID_XFORM)
2358     {
2359       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2360       addr2 = op2;
2361     }
2362   else
2363     {
2364       emit_move_insn (op2, GEN_INT (4));
2365       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2366     }
2367
2368   word1 = change_address (dest, SImode, addr1);
2369   word2 = change_address (dest, SImode, addr2);
2370
2371   emit_insn (gen_bswapsi2 (word2, src1));
2372   emit_insn (gen_bswapsi2 (word1, src2));
2373 }")
2374
2375 (define_split
2376   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2377         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2378    (clobber (match_operand:SI 2 "" ""))]
2379   "!TARGET_POWERPC64 && reload_completed"
2380   [(const_int 0)]
2381   "
2382 {
2383   rtx dest  = operands[0];
2384   rtx src   = operands[1];
2385   rtx src1  = simplify_gen_subreg (SImode, src, DImode, 0);
2386   rtx src2  = simplify_gen_subreg (SImode, src, DImode, 4);
2387   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2388   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2389
2390   emit_insn (gen_bswapsi2 (dest1, src2));
2391   emit_insn (gen_bswapsi2 (dest2, src1));
2392 }")
2393
2394 (define_insn "mulsi3"
2395   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2396         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2397                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2398   ""
2399   "@
2400    mullw %0,%1,%2
2401    mulli %0,%1,%2"
2402    [(set (attr "type")
2403       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2404                 (const_string "imul3")
2405              (match_operand:SI 2 "short_cint_operand" "")
2406                 (const_string "imul2")]
2407         (const_string "imul")))])
2408
2409 (define_insn "*mulsi3_internal1"
2410   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2411         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2412                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2413                     (const_int 0)))
2414    (clobber (match_scratch:SI 3 "=r,r"))]
2415   ""
2416   "@
2417    mullw. %3,%1,%2
2418    #"
2419   [(set_attr "type" "imul_compare")
2420    (set_attr "length" "4,8")])
2421
2422 (define_split
2423   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2424         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2425                              (match_operand:SI 2 "gpc_reg_operand" ""))
2426                     (const_int 0)))
2427    (clobber (match_scratch:SI 3 ""))]
2428   "reload_completed"
2429   [(set (match_dup 3)
2430         (mult:SI (match_dup 1) (match_dup 2)))
2431    (set (match_dup 0)
2432         (compare:CC (match_dup 3)
2433                     (const_int 0)))]
2434   "")
2435
2436 (define_insn "*mulsi3_internal2"
2437   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2438         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2439                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2440                     (const_int 0)))
2441    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2442         (mult:SI (match_dup 1) (match_dup 2)))]
2443   ""
2444   "@
2445    mullw. %0,%1,%2
2446    #"
2447   [(set_attr "type" "imul_compare")
2448    (set_attr "length" "4,8")])
2449
2450 (define_split
2451   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2452         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2453                              (match_operand:SI 2 "gpc_reg_operand" ""))
2454                     (const_int 0)))
2455    (set (match_operand:SI 0 "gpc_reg_operand" "")
2456         (mult:SI (match_dup 1) (match_dup 2)))]
2457   "reload_completed"
2458   [(set (match_dup 0)
2459         (mult:SI (match_dup 1) (match_dup 2)))
2460    (set (match_dup 3)
2461         (compare:CC (match_dup 0)
2462                     (const_int 0)))]
2463   "")
2464
2465
2466 (define_insn "udiv<mode>3"
2467   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2468         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2469                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2470   ""
2471   "div<wd>u %0,%1,%2"
2472    [(set (attr "type")
2473       (cond [(match_operand:SI 0 "" "")
2474                 (const_string "idiv")]
2475         (const_string "ldiv")))])
2476
2477
2478 ;; For powers of two we can do srai/aze for divide and then adjust for
2479 ;; modulus.  If it isn't a power of two, force operands into register and do
2480 ;; a normal divide.
2481 (define_expand "div<mode>3"
2482   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2483         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2484                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2485   ""
2486 {
2487   if (GET_CODE (operands[2]) != CONST_INT
2488       || INTVAL (operands[2]) <= 0
2489       || exact_log2 (INTVAL (operands[2])) < 0)
2490     operands[2] = force_reg (<MODE>mode, operands[2]);
2491 })
2492
2493 (define_insn "*div<mode>3"
2494   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2495         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2496                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2497   ""
2498   "div<wd> %0,%1,%2"
2499   [(set (attr "type")
2500      (cond [(match_operand:SI 0 "" "")
2501                 (const_string "idiv")]
2502         (const_string "ldiv")))])
2503
2504 (define_expand "mod<mode>3"
2505   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2506    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2507    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2508   ""
2509   "
2510 {
2511   int i;
2512   rtx temp1;
2513   rtx temp2;
2514
2515   if (GET_CODE (operands[2]) != CONST_INT
2516       || INTVAL (operands[2]) <= 0
2517       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2518     FAIL;
2519
2520   temp1 = gen_reg_rtx (<MODE>mode);
2521   temp2 = gen_reg_rtx (<MODE>mode);
2522
2523   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2524   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2525   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2526   DONE;
2527 }")
2528
2529 (define_insn ""
2530   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2531         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2532                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2533   ""
2534   "sra<wd>i %0,%1,%p2\;addze %0,%0"
2535   [(set_attr "type" "two")
2536    (set_attr "length" "8")])
2537
2538 (define_insn ""
2539   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2540         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2541                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2542                     (const_int 0)))
2543    (clobber (match_scratch:P 3 "=r,r"))]
2544   ""
2545   "@
2546    sra<wd>i %3,%1,%p2\;addze. %3,%3
2547    #"
2548   [(set_attr "type" "compare")
2549    (set_attr "length" "8,12")
2550    (set_attr "cell_micro" "not")])
2551
2552 (define_split
2553   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2554         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2555                              (match_operand:GPR 2 "exact_log2_cint_operand"
2556                               ""))
2557                     (const_int 0)))
2558    (clobber (match_scratch:GPR 3 ""))]
2559   "reload_completed"
2560   [(set (match_dup 3)
2561         (div:<MODE> (match_dup 1) (match_dup 2)))
2562    (set (match_dup 0)
2563         (compare:CC (match_dup 3)
2564                     (const_int 0)))]
2565   "")
2566
2567 (define_insn ""
2568   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2569         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2570                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2571                     (const_int 0)))
2572    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2573         (div:P (match_dup 1) (match_dup 2)))]
2574   ""
2575   "@
2576    sra<wd>i %0,%1,%p2\;addze. %0,%0
2577    #"
2578   [(set_attr "type" "compare")
2579    (set_attr "length" "8,12")
2580    (set_attr "cell_micro" "not")])
2581
2582 (define_split
2583   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2584         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2585                              (match_operand:GPR 2 "exact_log2_cint_operand"
2586                               ""))
2587                     (const_int 0)))
2588    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2589         (div:GPR (match_dup 1) (match_dup 2)))]
2590   "reload_completed"
2591   [(set (match_dup 0)
2592         (div:<MODE> (match_dup 1) (match_dup 2)))
2593    (set (match_dup 3)
2594         (compare:CC (match_dup 0)
2595                     (const_int 0)))]
2596   "")
2597 \f
2598 ;; Logical instructions
2599 ;; The logical instructions are mostly combined by using match_operator,
2600 ;; but the plain AND insns are somewhat different because there is no
2601 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2602 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2603
2604 (define_expand "andsi3"
2605   [(parallel
2606     [(set (match_operand:SI 0 "gpc_reg_operand" "")
2607           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2608                   (match_operand:SI 2 "and_operand" "")))
2609      (clobber (match_scratch:CC 3 ""))])]
2610   ""
2611   "")
2612
2613 (define_insn "andsi3_mc"
2614   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2615         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2616                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2617    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2618   "rs6000_gen_cell_microcode"
2619   "@
2620    and %0,%1,%2
2621    rlwinm %0,%1,0,%m2,%M2
2622    andi. %0,%1,%b2
2623    andis. %0,%1,%u2"
2624   [(set_attr "type" "*,*,fast_compare,fast_compare")])
2625
2626 (define_insn "andsi3_nomc"
2627   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2628         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2629                 (match_operand:SI 2 "and_operand" "?r,T")))
2630    (clobber (match_scratch:CC 3 "=X,X"))]
2631   "!rs6000_gen_cell_microcode"
2632   "@
2633    and %0,%1,%2
2634    rlwinm %0,%1,0,%m2,%M2")
2635
2636 (define_insn "andsi3_internal0_nomc"
2637   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2638         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2639                 (match_operand:SI 2 "and_operand" "?r,T")))]
2640   "!rs6000_gen_cell_microcode"
2641   "@
2642    and %0,%1,%2
2643    rlwinm %0,%1,0,%m2,%M2")
2644
2645
2646 ;; Note to set cr's other than cr0 we do the and immediate and then
2647 ;; the test again -- this avoids a mfcr which on the higher end
2648 ;; machines causes an execution serialization
2649
2650 (define_insn "*andsi3_internal2_mc"
2651   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2652         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2653                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2654                     (const_int 0)))
2655    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2656    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2657   "TARGET_32BIT && rs6000_gen_cell_microcode"
2658   "@
2659    and. %3,%1,%2
2660    andi. %3,%1,%b2
2661    andis. %3,%1,%u2
2662    rlwinm. %3,%1,0,%m2,%M2
2663    #
2664    #
2665    #
2666    #"
2667   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
2668                      compare,compare,compare,compare")
2669    (set_attr "length" "4,4,4,4,8,8,8,8")])
2670
2671 (define_insn "*andsi3_internal3_mc"
2672   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2673         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2674                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2675                     (const_int 0)))
2676    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2677    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2678   "TARGET_64BIT && rs6000_gen_cell_microcode"
2679   "@
2680    #
2681    andi. %3,%1,%b2
2682    andis. %3,%1,%u2
2683    rlwinm. %3,%1,0,%m2,%M2
2684    #
2685    #
2686    #
2687    #"
2688   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
2689                      compare,compare,compare")
2690    (set_attr "length" "8,4,4,4,8,8,8,8")])
2691
2692 (define_split
2693   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2694         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2695                              (match_operand:GPR 2 "and_operand" ""))
2696                     (const_int 0)))
2697    (clobber (match_scratch:GPR 3 ""))
2698    (clobber (match_scratch:CC 4 ""))]
2699   "reload_completed"
2700   [(parallel [(set (match_dup 3)
2701                    (and:<MODE> (match_dup 1)
2702                                (match_dup 2)))
2703               (clobber (match_dup 4))])
2704    (set (match_dup 0)
2705         (compare:CC (match_dup 3)
2706                     (const_int 0)))]
2707   "")
2708
2709 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2710 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2711
2712 (define_split
2713   [(set (match_operand:CC 0 "cc_reg_operand" "")
2714         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2715                             (match_operand:SI 2 "gpc_reg_operand" ""))
2716                     (const_int 0)))
2717    (clobber (match_scratch:SI 3 ""))
2718    (clobber (match_scratch:CC 4 ""))]
2719   "TARGET_POWERPC64 && reload_completed"
2720   [(parallel [(set (match_dup 3)
2721                    (and:SI (match_dup 1)
2722                            (match_dup 2)))
2723               (clobber (match_dup 4))])
2724    (set (match_dup 0)
2725         (compare:CC (match_dup 3)
2726                     (const_int 0)))]
2727   "")
2728
2729 (define_insn "*andsi3_internal4"
2730   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2731         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2732                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2733                     (const_int 0)))
2734    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2735         (and:SI (match_dup 1)
2736                 (match_dup 2)))
2737    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2738   "TARGET_32BIT && rs6000_gen_cell_microcode"
2739   "@
2740    and. %0,%1,%2
2741    andi. %0,%1,%b2
2742    andis. %0,%1,%u2
2743    rlwinm. %0,%1,0,%m2,%M2
2744    #
2745    #
2746    #
2747    #"
2748   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
2749                      compare,compare,compare,compare")
2750    (set_attr "length" "4,4,4,4,8,8,8,8")])
2751
2752 (define_insn "*andsi3_internal5_mc"
2753   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2754         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2755                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2756                     (const_int 0)))
2757    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2758         (and:SI (match_dup 1)
2759                 (match_dup 2)))
2760    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2761   "TARGET_64BIT && rs6000_gen_cell_microcode"
2762   "@
2763    #
2764    andi. %0,%1,%b2
2765    andis. %0,%1,%u2
2766    rlwinm. %0,%1,0,%m2,%M2
2767    #
2768    #
2769    #
2770    #"
2771   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
2772                      compare,compare,compare")
2773    (set_attr "length" "8,4,4,4,8,8,8,8")])
2774
2775 (define_split
2776   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2777         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2778                             (match_operand:SI 2 "and_operand" ""))
2779                     (const_int 0)))
2780    (set (match_operand:SI 0 "gpc_reg_operand" "")
2781         (and:SI (match_dup 1)
2782                 (match_dup 2)))
2783    (clobber (match_scratch:CC 4 ""))]
2784   "reload_completed"
2785   [(parallel [(set (match_dup 0)
2786                    (and:SI (match_dup 1)
2787                            (match_dup 2)))
2788               (clobber (match_dup 4))])
2789    (set (match_dup 3)
2790         (compare:CC (match_dup 0)
2791                     (const_int 0)))]
2792   "")
2793
2794 (define_split
2795   [(set (match_operand:CC 3 "cc_reg_operand" "")
2796         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2797                             (match_operand:SI 2 "gpc_reg_operand" ""))
2798                     (const_int 0)))
2799    (set (match_operand:SI 0 "gpc_reg_operand" "")
2800         (and:SI (match_dup 1)
2801                 (match_dup 2)))
2802    (clobber (match_scratch:CC 4 ""))]
2803   "TARGET_POWERPC64 && reload_completed"
2804   [(parallel [(set (match_dup 0)
2805                    (and:SI (match_dup 1)
2806                            (match_dup 2)))
2807               (clobber (match_dup 4))])
2808    (set (match_dup 3)
2809         (compare:CC (match_dup 0)
2810                     (const_int 0)))]
2811   "")
2812
2813 ;; Handle the PowerPC64 rlwinm corner case
2814
2815 (define_insn_and_split "*andsi3_internal6"
2816   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2817         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2818                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2819   "TARGET_POWERPC64"
2820   "#"
2821   "TARGET_POWERPC64"
2822   [(set (match_dup 0)
2823         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2824                 (match_dup 4)))
2825    (set (match_dup 0)
2826         (rotate:SI (match_dup 0) (match_dup 5)))]
2827   "
2828 {
2829   int mb = extract_MB (operands[2]);
2830   int me = extract_ME (operands[2]);
2831   operands[3] = GEN_INT (me + 1);
2832   operands[5] = GEN_INT (32 - (me + 1));
2833   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2834 }"
2835   [(set_attr "length" "8")])
2836
2837 (define_expand "iorsi3"
2838   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2839         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2840                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2841   ""
2842   "
2843 {
2844   if (GET_CODE (operands[2]) == CONST_INT
2845       && ! logical_operand (operands[2], SImode))
2846     {
2847       HOST_WIDE_INT value = INTVAL (operands[2]);
2848       rtx tmp = ((!can_create_pseudo_p ()
2849                   || rtx_equal_p (operands[0], operands[1]))
2850                  ? operands[0] : gen_reg_rtx (SImode));
2851
2852       emit_insn (gen_iorsi3 (tmp, operands[1],
2853                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2854       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2855       DONE;
2856     }
2857 }")
2858
2859 (define_expand "xorsi3"
2860   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2861         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2862                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2863   ""
2864   "
2865 {
2866   if (GET_CODE (operands[2]) == CONST_INT
2867       && ! logical_operand (operands[2], SImode))
2868     {
2869       HOST_WIDE_INT value = INTVAL (operands[2]);
2870       rtx tmp = ((!can_create_pseudo_p ()
2871                   || rtx_equal_p (operands[0], operands[1]))
2872                  ? operands[0] : gen_reg_rtx (SImode));
2873
2874       emit_insn (gen_xorsi3 (tmp, operands[1],
2875                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2876       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2877       DONE;
2878     }
2879 }")
2880
2881 (define_insn "*boolsi3_internal1"
2882   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2883         (match_operator:SI 3 "boolean_or_operator"
2884          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2885           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2886   ""
2887   "@
2888    %q3 %0,%1,%2
2889    %q3i %0,%1,%b2
2890    %q3is %0,%1,%u2")
2891
2892 (define_insn "*boolsi3_internal2"
2893   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2894         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2895          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2896           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2897          (const_int 0)))
2898    (clobber (match_scratch:SI 3 "=r,r"))]
2899   "TARGET_32BIT"
2900   "@
2901    %q4. %3,%1,%2
2902    #"
2903   [(set_attr "type" "fast_compare,compare")
2904    (set_attr "length" "4,8")])
2905
2906 (define_split
2907   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2908         (compare:CC (match_operator:SI 4 "boolean_operator"
2909          [(match_operand:SI 1 "gpc_reg_operand" "")
2910           (match_operand:SI 2 "gpc_reg_operand" "")])
2911          (const_int 0)))
2912    (clobber (match_scratch:SI 3 ""))]
2913   "TARGET_32BIT && reload_completed"
2914   [(set (match_dup 3) (match_dup 4))
2915    (set (match_dup 0)
2916         (compare:CC (match_dup 3)
2917                     (const_int 0)))]
2918   "")
2919
2920 (define_insn "*boolsi3_internal3"
2921   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2922         (compare:CC (match_operator:SI 4 "boolean_operator"
2923          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2924           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2925          (const_int 0)))
2926    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2927         (match_dup 4))]
2928   "TARGET_32BIT"
2929   "@
2930    %q4. %0,%1,%2
2931    #"
2932   [(set_attr "type" "fast_compare,compare")
2933    (set_attr "length" "4,8")])
2934
2935 (define_split
2936   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2937         (compare:CC (match_operator:SI 4 "boolean_operator"
2938          [(match_operand:SI 1 "gpc_reg_operand" "")
2939           (match_operand:SI 2 "gpc_reg_operand" "")])
2940          (const_int 0)))
2941    (set (match_operand:SI 0 "gpc_reg_operand" "")
2942         (match_dup 4))]
2943   "TARGET_32BIT && reload_completed"
2944   [(set (match_dup 0) (match_dup 4))
2945    (set (match_dup 3)
2946         (compare:CC (match_dup 0)
2947                     (const_int 0)))]
2948   "")
2949
2950 ;; Split a logical operation that we can't do in one insn into two insns,
2951 ;; each of which does one 16-bit part.  This is used by combine.
2952
2953 (define_split
2954   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2955         (match_operator:SI 3 "boolean_or_operator"
2956          [(match_operand:SI 1 "gpc_reg_operand" "")
2957           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2958   ""
2959   [(set (match_dup 0) (match_dup 4))
2960    (set (match_dup 0) (match_dup 5))]
2961 "
2962 {
2963   rtx i;
2964   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2965   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2966                                 operands[1], i);
2967   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2968   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2969                                 operands[0], i);
2970 }")
2971
2972 (define_insn "*boolcsi3_internal1"
2973   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2974         (match_operator:SI 3 "boolean_operator"
2975          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2976           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2977   ""
2978   "%q3 %0,%2,%1")
2979
2980 (define_insn "*boolcsi3_internal2"
2981   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2982         (compare:CC (match_operator:SI 4 "boolean_operator"
2983          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2984           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2985          (const_int 0)))
2986    (clobber (match_scratch:SI 3 "=r,r"))]
2987   "TARGET_32BIT"
2988   "@
2989    %q4. %3,%2,%1
2990    #"
2991   [(set_attr "type" "compare")
2992    (set_attr "length" "4,8")])
2993
2994 (define_split
2995   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2996         (compare:CC (match_operator:SI 4 "boolean_operator"
2997          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2998           (match_operand:SI 2 "gpc_reg_operand" "")])
2999          (const_int 0)))
3000    (clobber (match_scratch:SI 3 ""))]
3001   "TARGET_32BIT && reload_completed"
3002   [(set (match_dup 3) (match_dup 4))
3003    (set (match_dup 0)
3004         (compare:CC (match_dup 3)
3005                     (const_int 0)))]
3006   "")
3007
3008 (define_insn "*boolcsi3_internal3"
3009   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3010         (compare:CC (match_operator:SI 4 "boolean_operator"
3011          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3012           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3013          (const_int 0)))
3014    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3015         (match_dup 4))]
3016   "TARGET_32BIT"
3017   "@
3018    %q4. %0,%2,%1
3019    #"
3020   [(set_attr "type" "compare")
3021    (set_attr "length" "4,8")])
3022
3023 (define_split
3024   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3025         (compare:CC (match_operator:SI 4 "boolean_operator"
3026          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3027           (match_operand:SI 2 "gpc_reg_operand" "")])
3028          (const_int 0)))
3029    (set (match_operand:SI 0 "gpc_reg_operand" "")
3030         (match_dup 4))]
3031   "TARGET_32BIT && reload_completed"
3032   [(set (match_dup 0) (match_dup 4))
3033    (set (match_dup 3)
3034         (compare:CC (match_dup 0)
3035                     (const_int 0)))]
3036   "")
3037
3038 (define_insn "*boolccsi3_internal1"
3039   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3040         (match_operator:SI 3 "boolean_operator"
3041          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3042           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3043   ""
3044   "%q3 %0,%1,%2")
3045
3046 (define_insn "*boolccsi3_internal2"
3047   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3048         (compare:CC (match_operator:SI 4 "boolean_operator"
3049          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3050           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3051          (const_int 0)))
3052    (clobber (match_scratch:SI 3 "=r,r"))]
3053   "TARGET_32BIT"
3054   "@
3055    %q4. %3,%1,%2
3056    #"
3057   [(set_attr "type" "fast_compare,compare")
3058    (set_attr "length" "4,8")])
3059
3060 (define_split
3061   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3062         (compare:CC (match_operator:SI 4 "boolean_operator"
3063          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3064           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3065          (const_int 0)))
3066    (clobber (match_scratch:SI 3 ""))]
3067   "TARGET_32BIT && reload_completed"
3068   [(set (match_dup 3) (match_dup 4))
3069    (set (match_dup 0)
3070         (compare:CC (match_dup 3)
3071                     (const_int 0)))]
3072   "")
3073
3074 (define_insn "*boolccsi3_internal3"
3075   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3076         (compare:CC (match_operator:SI 4 "boolean_operator"
3077          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3078           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3079          (const_int 0)))
3080    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3081         (match_dup 4))]
3082   "TARGET_32BIT"
3083   "@
3084    %q4. %0,%1,%2
3085    #"
3086   [(set_attr "type" "fast_compare,compare")
3087    (set_attr "length" "4,8")])
3088
3089 (define_split
3090   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3091         (compare:CC (match_operator:SI 4 "boolean_operator"
3092          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3093           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3094          (const_int 0)))
3095    (set (match_operand:SI 0 "gpc_reg_operand" "")
3096         (match_dup 4))]
3097   "TARGET_32BIT && reload_completed"
3098   [(set (match_dup 0) (match_dup 4))
3099    (set (match_dup 3)
3100         (compare:CC (match_dup 0)
3101                     (const_int 0)))]
3102   "")
3103 \f
3104 ;; Rotate and shift insns, in all their variants.  These support shifts,
3105 ;; field inserts and extracts, and various combinations thereof.
3106 (define_expand "insv"
3107   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3108                        (match_operand:SI 1 "const_int_operand" "")
3109                        (match_operand:SI 2 "const_int_operand" ""))
3110         (match_operand 3 "gpc_reg_operand" ""))]
3111   ""
3112   "
3113 {
3114   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3115      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3116      compiler if the address of the structure is taken later.  Likewise, do
3117      not handle invalid E500 subregs.  */
3118   if (GET_CODE (operands[0]) == SUBREG
3119       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3120           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3121               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3122     FAIL;
3123
3124   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3125     emit_insn (gen_insvdi_internal (operands[0], operands[1], operands[2],
3126                                     operands[3]));
3127   else
3128     emit_insn (gen_insvsi_internal (operands[0], operands[1], operands[2],
3129                                     operands[3]));
3130   DONE;
3131 }")
3132
3133 (define_insn "insvsi_internal"
3134   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3135                          (match_operand:SI 1 "const_int_operand" "i")
3136                          (match_operand:SI 2 "const_int_operand" "i"))
3137         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3138   ""
3139   "*
3140 {
3141   int start = INTVAL (operands[2]) & 31;
3142   int size = INTVAL (operands[1]) & 31;
3143
3144   operands[4] = GEN_INT (32 - start - size);
3145   operands[1] = GEN_INT (start + size - 1);
3146   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3147 }"
3148   [(set_attr "type" "insert_word")])
3149
3150 (define_insn "*insvsi_internal1"
3151   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3152                          (match_operand:SI 1 "const_int_operand" "i")
3153                          (match_operand:SI 2 "const_int_operand" "i"))
3154         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3155                    (match_operand:SI 4 "const_int_operand" "i")))]
3156   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3157   "*
3158 {
3159   int shift = INTVAL (operands[4]) & 31;
3160   int start = INTVAL (operands[2]) & 31;
3161   int size = INTVAL (operands[1]) & 31;
3162
3163   operands[4] = GEN_INT (shift - start - size);
3164   operands[1] = GEN_INT (start + size - 1);
3165   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3166 }"
3167   [(set_attr "type" "insert_word")])
3168
3169 (define_insn "*insvsi_internal2"
3170   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3171                          (match_operand:SI 1 "const_int_operand" "i")
3172                          (match_operand:SI 2 "const_int_operand" "i"))
3173         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3174                      (match_operand:SI 4 "const_int_operand" "i")))]
3175   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3176   "*
3177 {
3178   int shift = INTVAL (operands[4]) & 31;
3179   int start = INTVAL (operands[2]) & 31;
3180   int size = INTVAL (operands[1]) & 31;
3181
3182   operands[4] = GEN_INT (32 - shift - start - size);
3183   operands[1] = GEN_INT (start + size - 1);
3184   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3185 }"
3186   [(set_attr "type" "insert_word")])
3187
3188 (define_insn "*insvsi_internal3"
3189   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3190                          (match_operand:SI 1 "const_int_operand" "i")
3191                          (match_operand:SI 2 "const_int_operand" "i"))
3192         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3193                      (match_operand:SI 4 "const_int_operand" "i")))]
3194   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3195   "*
3196 {
3197   int shift = INTVAL (operands[4]) & 31;
3198   int start = INTVAL (operands[2]) & 31;
3199   int size = INTVAL (operands[1]) & 31;
3200
3201   operands[4] = GEN_INT (32 - shift - start - size);
3202   operands[1] = GEN_INT (start + size - 1);
3203   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3204 }"
3205   [(set_attr "type" "insert_word")])
3206
3207 (define_insn "*insvsi_internal4"
3208   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3209                          (match_operand:SI 1 "const_int_operand" "i")
3210                          (match_operand:SI 2 "const_int_operand" "i"))
3211         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3212                          (match_operand:SI 4 "const_int_operand" "i")
3213                          (match_operand:SI 5 "const_int_operand" "i")))]
3214   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3215   "*
3216 {
3217   int extract_start = INTVAL (operands[5]) & 31;
3218   int extract_size = INTVAL (operands[4]) & 31;
3219   int insert_start = INTVAL (operands[2]) & 31;
3220   int insert_size = INTVAL (operands[1]) & 31;
3221
3222 /* Align extract field with insert field */
3223   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3224   operands[1] = GEN_INT (insert_start + insert_size - 1);
3225   return \"rlwimi %0,%3,%h5,%h2,%h1\";
3226 }"
3227   [(set_attr "type" "insert_word")])
3228
3229 ;; combine patterns for rlwimi
3230 (define_insn "*insvsi_internal5"
3231   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3232         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3233                         (match_operand:SI 1 "mask_operand" "i"))
3234                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3235                                      (match_operand:SI 2 "const_int_operand" "i"))
3236                         (match_operand:SI 5 "mask_operand" "i"))))]
3237   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3238   "*
3239 {
3240  int me = extract_ME(operands[5]);
3241  int mb = extract_MB(operands[5]);
3242  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3243  operands[2] = GEN_INT(mb);
3244  operands[1] = GEN_INT(me);
3245  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3246 }"
3247   [(set_attr "type" "insert_word")])
3248
3249 (define_insn "*insvsi_internal6"
3250   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3251         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3252                                      (match_operand:SI 2 "const_int_operand" "i"))
3253                         (match_operand:SI 5 "mask_operand" "i"))
3254                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3255                         (match_operand:SI 1 "mask_operand" "i"))))]
3256   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3257   "*
3258 {
3259  int me = extract_ME(operands[5]);
3260  int mb = extract_MB(operands[5]);
3261  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3262  operands[2] = GEN_INT(mb);
3263  operands[1] = GEN_INT(me);
3264  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3265 }"
3266   [(set_attr "type" "insert_word")])
3267
3268 (define_insn "insvdi_internal"
3269   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3270                          (match_operand:SI 1 "const_int_operand" "i")
3271                          (match_operand:SI 2 "const_int_operand" "i"))
3272         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3273   "TARGET_POWERPC64"
3274   "*
3275 {
3276   int start = INTVAL (operands[2]) & 63;
3277   int size = INTVAL (operands[1]) & 63;
3278
3279   operands[1] = GEN_INT (64 - start - size);
3280   return \"rldimi %0,%3,%H1,%H2\";
3281 }"
3282   [(set_attr "type" "insert_dword")])
3283
3284 (define_insn "*insvdi_internal2"
3285   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3286                          (match_operand:SI 1 "const_int_operand" "i")
3287                          (match_operand:SI 2 "const_int_operand" "i"))
3288         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3289                      (match_operand:SI 4 "const_int_operand" "i")))]
3290   "TARGET_POWERPC64
3291    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3292   "*
3293 {
3294   int shift = INTVAL (operands[4]) & 63;
3295   int start = (INTVAL (operands[2]) & 63) - 32;
3296   int size = INTVAL (operands[1]) & 63;
3297
3298   operands[4] = GEN_INT (64 - shift - start - size);
3299   operands[2] = GEN_INT (start);
3300   operands[1] = GEN_INT (start + size - 1);
3301   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3302 }")
3303
3304 (define_insn "*insvdi_internal3"
3305   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3306                          (match_operand:SI 1 "const_int_operand" "i")
3307                          (match_operand:SI 2 "const_int_operand" "i"))
3308         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3309                      (match_operand:SI 4 "const_int_operand" "i")))]
3310   "TARGET_POWERPC64
3311    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3312   "*
3313 {
3314   int shift = INTVAL (operands[4]) & 63;
3315   int start = (INTVAL (operands[2]) & 63) - 32;
3316   int size = INTVAL (operands[1]) & 63;
3317
3318   operands[4] = GEN_INT (64 - shift - start - size);
3319   operands[2] = GEN_INT (start);
3320   operands[1] = GEN_INT (start + size - 1);
3321   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3322 }")
3323
3324 (define_expand "extzv"
3325   [(set (match_operand 0 "gpc_reg_operand" "")
3326         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3327                        (match_operand:SI 2 "const_int_operand" "")
3328                        (match_operand:SI 3 "const_int_operand" "")))]
3329   ""
3330   "
3331 {
3332   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3333      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3334      compiler if the address of the structure is taken later.  */
3335   if (GET_CODE (operands[0]) == SUBREG
3336       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3337     FAIL;
3338
3339   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3340     emit_insn (gen_extzvdi_internal (operands[0], operands[1], operands[2],
3341                                      operands[3]));
3342   else
3343     emit_insn (gen_extzvsi_internal (operands[0], operands[1], operands[2],
3344                                      operands[3]));
3345   DONE;
3346 }")
3347
3348 (define_insn "extzvsi_internal"
3349   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3350         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3351                          (match_operand:SI 2 "const_int_operand" "i")
3352                          (match_operand:SI 3 "const_int_operand" "i")))]
3353   ""
3354   "*
3355 {
3356   int start = INTVAL (operands[3]) & 31;
3357   int size = INTVAL (operands[2]) & 31;
3358
3359   if (start + size >= 32)
3360     operands[3] = const0_rtx;
3361   else
3362     operands[3] = GEN_INT (start + size);
3363   return \"rlwinm %0,%1,%3,%s2,31\";
3364 }")
3365
3366 (define_insn "*extzvsi_internal1"
3367   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3368         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3369                          (match_operand:SI 2 "const_int_operand" "i,i")
3370                          (match_operand:SI 3 "const_int_operand" "i,i"))
3371                     (const_int 0)))
3372    (clobber (match_scratch:SI 4 "=r,r"))]
3373   ""
3374   "*
3375 {
3376   int start = INTVAL (operands[3]) & 31;
3377   int size = INTVAL (operands[2]) & 31;
3378
3379   /* Force split for non-cc0 compare.  */
3380   if (which_alternative == 1)
3381      return \"#\";
3382
3383   /* If the bit-field being tested fits in the upper or lower half of a
3384      word, it is possible to use andiu. or andil. to test it.  This is
3385      useful because the condition register set-use delay is smaller for
3386      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3387      position is 0 because the LT and GT bits may be set wrong.  */
3388
3389   if ((start > 0 && start + size <= 16) || start >= 16)
3390     {
3391       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3392                               - (1 << (16 - (start & 15) - size))));
3393       if (start < 16)
3394         return \"andis. %4,%1,%3\";
3395       else
3396         return \"andi. %4,%1,%3\";
3397     }
3398
3399   if (start + size >= 32)
3400     operands[3] = const0_rtx;
3401   else
3402     operands[3] = GEN_INT (start + size);
3403   return \"rlwinm. %4,%1,%3,%s2,31\";
3404 }"
3405   [(set_attr "type" "delayed_compare")
3406    (set_attr "length" "4,8")])
3407
3408 (define_split
3409   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3410         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3411                          (match_operand:SI 2 "const_int_operand" "")
3412                          (match_operand:SI 3 "const_int_operand" ""))
3413                     (const_int 0)))
3414    (clobber (match_scratch:SI 4 ""))]
3415   "reload_completed"
3416   [(set (match_dup 4)
3417         (zero_extract:SI (match_dup 1) (match_dup 2)
3418                          (match_dup 3)))
3419    (set (match_dup 0)
3420         (compare:CC (match_dup 4)
3421                     (const_int 0)))]
3422   "")
3423
3424 (define_insn "*extzvsi_internal2"
3425   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3426         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3427                          (match_operand:SI 2 "const_int_operand" "i,i")
3428                          (match_operand:SI 3 "const_int_operand" "i,i"))
3429                     (const_int 0)))
3430    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3431         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3432   ""
3433   "*
3434 {
3435   int start = INTVAL (operands[3]) & 31;
3436   int size = INTVAL (operands[2]) & 31;
3437
3438   /* Force split for non-cc0 compare.  */
3439   if (which_alternative == 1)
3440      return \"#\";
3441
3442   /* Since we are using the output value, we can't ignore any need for
3443      a shift.  The bit-field must end at the LSB.  */
3444   if (start >= 16 && start + size == 32)
3445     {
3446       operands[3] = GEN_INT ((1 << size) - 1);
3447       return \"andi. %0,%1,%3\";
3448     }
3449
3450   if (start + size >= 32)
3451     operands[3] = const0_rtx;
3452   else
3453     operands[3] = GEN_INT (start + size);
3454   return \"rlwinm. %0,%1,%3,%s2,31\";
3455 }"
3456   [(set_attr "type" "delayed_compare")
3457    (set_attr "length" "4,8")])
3458
3459 (define_split
3460   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3461         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3462                          (match_operand:SI 2 "const_int_operand" "")
3463                          (match_operand:SI 3 "const_int_operand" ""))
3464                     (const_int 0)))
3465    (set (match_operand:SI 0 "gpc_reg_operand" "")
3466         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3467   "reload_completed"
3468   [(set (match_dup 0)
3469         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3470    (set (match_dup 4)
3471         (compare:CC (match_dup 0)
3472                     (const_int 0)))]
3473   "")
3474
3475 (define_insn "extzvdi_internal"
3476   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3477         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3478                          (match_operand:SI 2 "const_int_operand" "i")
3479                          (match_operand:SI 3 "const_int_operand" "i")))]
3480   "TARGET_POWERPC64"
3481   "*
3482 {
3483   int start = INTVAL (operands[3]) & 63;
3484   int size = INTVAL (operands[2]) & 63;
3485
3486   if (start + size >= 64)
3487     operands[3] = const0_rtx;
3488   else
3489     operands[3] = GEN_INT (start + size);
3490   operands[2] = GEN_INT (64 - size);
3491   return \"rldicl %0,%1,%3,%2\";
3492 }")
3493
3494 (define_insn "*extzvdi_internal1"
3495   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3496         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3497                          (match_operand:SI 2 "const_int_operand" "i")
3498                          (match_operand:SI 3 "const_int_operand" "i"))
3499                     (const_int 0)))
3500    (clobber (match_scratch:DI 4 "=r"))]
3501   "TARGET_64BIT && rs6000_gen_cell_microcode"
3502   "*
3503 {
3504   int start = INTVAL (operands[3]) & 63;
3505   int size = INTVAL (operands[2]) & 63;
3506
3507   if (start + size >= 64)
3508     operands[3] = const0_rtx;
3509   else
3510     operands[3] = GEN_INT (start + size);
3511   operands[2] = GEN_INT (64 - size);
3512   return \"rldicl. %4,%1,%3,%2\";
3513 }"
3514   [(set_attr "type" "compare")])
3515
3516 (define_insn "*extzvdi_internal2"
3517   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3518         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3519                          (match_operand:SI 2 "const_int_operand" "i")
3520                          (match_operand:SI 3 "const_int_operand" "i"))
3521                     (const_int 0)))
3522    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3523         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3524   "TARGET_64BIT && rs6000_gen_cell_microcode"
3525   "*
3526 {
3527   int start = INTVAL (operands[3]) & 63;
3528   int size = INTVAL (operands[2]) & 63;
3529
3530   if (start + size >= 64)
3531     operands[3] = const0_rtx;
3532   else
3533     operands[3] = GEN_INT (start + size);
3534   operands[2] = GEN_INT (64 - size);
3535   return \"rldicl. %0,%1,%3,%2\";
3536 }"
3537   [(set_attr "type" "compare")])
3538
3539 (define_insn "rotlsi3"
3540   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3541         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3542                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3543   ""
3544   "@
3545    rlwnm %0,%1,%2,0xffffffff
3546    rlwinm %0,%1,%h2,0xffffffff"
3547   [(set_attr "type" "var_shift_rotate,integer")])
3548
3549 (define_insn "*rotlsi3_64"
3550   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3551         (zero_extend:DI
3552             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3553                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
3554   "TARGET_64BIT"
3555   "@
3556    rlwnm %0,%1,%2,0xffffffff
3557    rlwinm %0,%1,%h2,0xffffffff"
3558   [(set_attr "type" "var_shift_rotate,integer")])
3559
3560 (define_insn "*rotlsi3_internal2"
3561   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3562         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3563                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3564                     (const_int 0)))
3565    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3566   ""
3567   "@
3568    rlwnm. %3,%1,%2,0xffffffff
3569    rlwinm. %3,%1,%h2,0xffffffff
3570    #
3571    #"
3572   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3573    (set_attr "length" "4,4,8,8")])
3574
3575 (define_split
3576   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3577         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3578                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3579                     (const_int 0)))
3580    (clobber (match_scratch:SI 3 ""))]
3581   "reload_completed"
3582   [(set (match_dup 3)
3583         (rotate:SI (match_dup 1) (match_dup 2)))
3584    (set (match_dup 0)
3585         (compare:CC (match_dup 3)
3586                     (const_int 0)))]
3587   "")
3588
3589 (define_insn "*rotlsi3_internal3"
3590   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3591         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3592                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3593                     (const_int 0)))
3594    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3595         (rotate:SI (match_dup 1) (match_dup 2)))]
3596   ""
3597   "@
3598    rlwnm. %0,%1,%2,0xffffffff
3599    rlwinm. %0,%1,%h2,0xffffffff
3600    #
3601    #"
3602   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3603    (set_attr "length" "4,4,8,8")])
3604
3605 (define_split
3606   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3607         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3608                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3609                     (const_int 0)))
3610    (set (match_operand:SI 0 "gpc_reg_operand" "")
3611         (rotate:SI (match_dup 1) (match_dup 2)))]
3612   "reload_completed"
3613   [(set (match_dup 0)
3614         (rotate:SI (match_dup 1) (match_dup 2)))
3615    (set (match_dup 3)
3616         (compare:CC (match_dup 0)
3617                     (const_int 0)))]
3618   "")
3619
3620 (define_insn "*rotlsi3_internal4"
3621   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3622         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3623                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
3624                 (match_operand:SI 3 "mask_operand" "n,n")))]
3625   ""
3626   "@
3627    rlwnm %0,%1,%2,%m3,%M3
3628    rlwinm %0,%1,%h2,%m3,%M3"
3629   [(set_attr "type" "var_shift_rotate,integer")])
3630
3631 (define_insn "*rotlsi3_internal5"
3632   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3633         (compare:CC (and:SI
3634                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3635                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3636                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3637                     (const_int 0)))
3638    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
3639   ""
3640   "@
3641    rlwnm. %4,%1,%2,%m3,%M3
3642    rlwinm. %4,%1,%h2,%m3,%M3
3643    #
3644    #"
3645   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3646    (set_attr "length" "4,4,8,8")])
3647
3648 (define_split
3649   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3650         (compare:CC (and:SI
3651                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3652                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3653                      (match_operand:SI 3 "mask_operand" ""))
3654                     (const_int 0)))
3655    (clobber (match_scratch:SI 4 ""))]
3656   "reload_completed"
3657   [(set (match_dup 4)
3658         (and:SI (rotate:SI (match_dup 1)
3659                                 (match_dup 2))
3660                      (match_dup 3)))
3661    (set (match_dup 0)
3662         (compare:CC (match_dup 4)
3663                     (const_int 0)))]
3664   "")
3665
3666 (define_insn "*rotlsi3_internal6"
3667   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
3668         (compare:CC (and:SI
3669                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3670                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3671                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3672                     (const_int 0)))
3673    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3674         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3675   ""
3676   "@
3677    rlwnm. %0,%1,%2,%m3,%M3
3678    rlwinm. %0,%1,%h2,%m3,%M3
3679    #
3680    #"
3681   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3682    (set_attr "length" "4,4,8,8")])
3683
3684 (define_split
3685   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3686         (compare:CC (and:SI
3687                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3688                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3689                      (match_operand:SI 3 "mask_operand" ""))
3690                     (const_int 0)))
3691    (set (match_operand:SI 0 "gpc_reg_operand" "")
3692         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3693   "reload_completed"
3694   [(set (match_dup 0)
3695         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3696    (set (match_dup 4)
3697         (compare:CC (match_dup 0)
3698                     (const_int 0)))]
3699   "")
3700
3701 (define_insn "*rotlsi3_internal7"
3702   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3703         (zero_extend:SI
3704          (subreg:QI
3705           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3706                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3707   ""
3708   "rlw%I2nm %0,%1,%h2,0xff"
3709   [(set (attr "cell_micro")
3710      (if_then_else (match_operand:SI 2 "const_int_operand" "")
3711         (const_string "not")
3712         (const_string "always")))])
3713
3714 (define_insn "*rotlsi3_internal8"
3715   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3716         (compare:CC (zero_extend:SI
3717                      (subreg:QI
3718                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3719                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3720                     (const_int 0)))
3721    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3722   ""
3723   "@
3724    rlwnm. %3,%1,%2,0xff
3725    rlwinm. %3,%1,%h2,0xff
3726    #
3727    #"
3728   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3729    (set_attr "length" "4,4,8,8")])
3730
3731 (define_split
3732   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3733         (compare:CC (zero_extend:SI
3734                      (subreg:QI
3735                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3736                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3737                     (const_int 0)))
3738    (clobber (match_scratch:SI 3 ""))]
3739   "reload_completed"
3740   [(set (match_dup 3)
3741         (zero_extend:SI (subreg:QI
3742                       (rotate:SI (match_dup 1)
3743                                  (match_dup 2)) 0)))
3744    (set (match_dup 0)
3745         (compare:CC (match_dup 3)
3746                     (const_int 0)))]
3747   "")
3748
3749 (define_insn "*rotlsi3_internal9"
3750   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3751         (compare:CC (zero_extend:SI
3752                      (subreg:QI
3753                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3754                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3755                     (const_int 0)))
3756    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3757         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3758   ""
3759   "@
3760    rlwnm. %0,%1,%2,0xff
3761    rlwinm. %0,%1,%h2,0xff
3762    #
3763    #"
3764   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3765    (set_attr "length" "4,4,8,8")])
3766
3767 (define_split
3768   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3769         (compare:CC (zero_extend:SI
3770                      (subreg:QI
3771                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3772                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3773                     (const_int 0)))
3774    (set (match_operand:SI 0 "gpc_reg_operand" "")
3775         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3776   "reload_completed"
3777   [(set (match_dup 0)
3778         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3779    (set (match_dup 3)
3780         (compare:CC (match_dup 0)
3781                     (const_int 0)))]
3782   "")
3783
3784 (define_insn "*rotlsi3_internal10"
3785   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3786         (zero_extend:SI
3787          (subreg:HI
3788           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3789                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
3790   ""
3791   "@
3792    rlwnm %0,%1,%2,0xffff
3793    rlwinm %0,%1,%h2,0xffff"
3794   [(set_attr "type" "var_shift_rotate,integer")])
3795
3796
3797 (define_insn "*rotlsi3_internal11"
3798   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3799         (compare:CC (zero_extend:SI
3800                      (subreg:HI
3801                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3802                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3803                     (const_int 0)))
3804    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3805   ""
3806   "@
3807    rlwnm. %3,%1,%2,0xffff
3808    rlwinm. %3,%1,%h2,0xffff
3809    #
3810    #"
3811   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3812    (set_attr "length" "4,4,8,8")])
3813
3814 (define_split
3815   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3816         (compare:CC (zero_extend:SI
3817                      (subreg:HI
3818                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3819                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3820                     (const_int 0)))
3821    (clobber (match_scratch:SI 3 ""))]
3822   "reload_completed"
3823   [(set (match_dup 3)
3824         (zero_extend:SI (subreg:HI
3825                       (rotate:SI (match_dup 1)
3826                                  (match_dup 2)) 0)))
3827    (set (match_dup 0)
3828         (compare:CC (match_dup 3)
3829                     (const_int 0)))]
3830   "")
3831
3832 (define_insn "*rotlsi3_internal12"
3833   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3834         (compare:CC (zero_extend:SI
3835                      (subreg:HI
3836                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3837                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3838                     (const_int 0)))
3839    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3840         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3841   ""
3842   "@
3843    rlwnm. %0,%1,%2,0xffff
3844    rlwinm. %0,%1,%h2,0xffff
3845    #
3846    #"
3847   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3848    (set_attr "length" "4,4,8,8")])
3849
3850 (define_split
3851   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3852         (compare:CC (zero_extend:SI
3853                      (subreg:HI
3854                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3855                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3856                     (const_int 0)))
3857    (set (match_operand:SI 0 "gpc_reg_operand" "")
3858         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3859   "reload_completed"
3860   [(set (match_dup 0)
3861         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3862    (set (match_dup 3)
3863         (compare:CC (match_dup 0)
3864                     (const_int 0)))]
3865   "")
3866
3867 (define_insn "ashlsi3"
3868   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3869         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3870                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3871   ""
3872   "@
3873    slw %0,%1,%2
3874    slwi %0,%1,%h2"
3875   [(set_attr "type" "var_shift_rotate,shift")])
3876
3877 (define_insn "*ashlsi3_64"
3878   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3879         (zero_extend:DI
3880             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3881                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
3882   "TARGET_POWERPC64"
3883   "@
3884    slw %0,%1,%2
3885    slwi %0,%1,%h2"
3886   [(set_attr "type" "var_shift_rotate,shift")])
3887
3888 (define_insn ""
3889   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3890         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3891                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3892                     (const_int 0)))
3893    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3894   "TARGET_32BIT"
3895   "@
3896    slw. %3,%1,%2
3897    slwi. %3,%1,%h2
3898    #
3899    #"
3900   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3901    (set_attr "length" "4,4,8,8")])
3902
3903 (define_split
3904   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3905         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3906                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3907                     (const_int 0)))
3908    (clobber (match_scratch:SI 3 ""))]
3909   "TARGET_32BIT && reload_completed"
3910   [(set (match_dup 3)
3911         (ashift:SI (match_dup 1) (match_dup 2)))
3912    (set (match_dup 0)
3913         (compare:CC (match_dup 3)
3914                     (const_int 0)))]
3915   "")
3916
3917 (define_insn ""
3918   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3919         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3920                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3921                     (const_int 0)))
3922    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3923         (ashift:SI (match_dup 1) (match_dup 2)))]
3924   "TARGET_32BIT"
3925   "@
3926    slw. %0,%1,%2
3927    slwi. %0,%1,%h2
3928    #
3929    #"
3930   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3931    (set_attr "length" "4,4,8,8")])
3932
3933 (define_split
3934   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3935         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3936                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3937                     (const_int 0)))
3938    (set (match_operand:SI 0 "gpc_reg_operand" "")
3939         (ashift:SI (match_dup 1) (match_dup 2)))]
3940   "TARGET_32BIT && reload_completed"
3941   [(set (match_dup 0)
3942         (ashift:SI (match_dup 1) (match_dup 2)))
3943    (set (match_dup 3)
3944         (compare:CC (match_dup 0)
3945                     (const_int 0)))]
3946   "")
3947
3948 (define_insn "rlwinm"
3949   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3950         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3951                            (match_operand:SI 2 "const_int_operand" "i"))
3952                 (match_operand:SI 3 "mask_operand" "n")))]
3953   "includes_lshift_p (operands[2], operands[3])"
3954   "rlwinm %0,%1,%h2,%m3,%M3")
3955
3956 (define_insn ""
3957   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3958         (compare:CC
3959          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3960                             (match_operand:SI 2 "const_int_operand" "i,i"))
3961                  (match_operand:SI 3 "mask_operand" "n,n"))
3962          (const_int 0)))
3963    (clobber (match_scratch:SI 4 "=r,r"))]
3964   "includes_lshift_p (operands[2], operands[3])"
3965   "@
3966    rlwinm. %4,%1,%h2,%m3,%M3
3967    #"
3968   [(set_attr "type" "delayed_compare")
3969    (set_attr "length" "4,8")])
3970
3971 (define_split
3972   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3973         (compare:CC
3974          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3975                             (match_operand:SI 2 "const_int_operand" ""))
3976                  (match_operand:SI 3 "mask_operand" ""))
3977          (const_int 0)))
3978    (clobber (match_scratch:SI 4 ""))]
3979   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3980   [(set (match_dup 4)
3981         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3982                  (match_dup 3)))
3983    (set (match_dup 0)
3984         (compare:CC (match_dup 4)
3985                     (const_int 0)))]
3986   "")
3987
3988 (define_insn ""
3989   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3990         (compare:CC
3991          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3992                             (match_operand:SI 2 "const_int_operand" "i,i"))
3993                  (match_operand:SI 3 "mask_operand" "n,n"))
3994          (const_int 0)))
3995    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3996         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3997   "includes_lshift_p (operands[2], operands[3])"
3998   "@
3999    rlwinm. %0,%1,%h2,%m3,%M3
4000    #"
4001   [(set_attr "type" "delayed_compare")
4002    (set_attr "length" "4,8")])
4003
4004 (define_split
4005   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4006         (compare:CC
4007          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4008                             (match_operand:SI 2 "const_int_operand" ""))
4009                  (match_operand:SI 3 "mask_operand" ""))
4010          (const_int 0)))
4011    (set (match_operand:SI 0 "gpc_reg_operand" "")
4012         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4013   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4014   [(set (match_dup 0)
4015         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4016    (set (match_dup 4)
4017         (compare:CC (match_dup 0)
4018                     (const_int 0)))]
4019   "")
4020
4021 (define_insn "lshrsi3"
4022   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4023         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4024                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
4025   ""
4026   "@
4027   mr %0,%1
4028   srw %0,%1,%2
4029   srwi %0,%1,%h2"
4030   [(set_attr "type" "integer,var_shift_rotate,shift")])
4031
4032 (define_insn "*lshrsi3_64"
4033   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4034         (zero_extend:DI
4035             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4036                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4037   "TARGET_POWERPC64"
4038   "@
4039   srw %0,%1,%2
4040   srwi %0,%1,%h2"
4041   [(set_attr "type" "var_shift_rotate,shift")])
4042
4043 (define_insn ""
4044   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4045         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4046                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4047                     (const_int 0)))
4048    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
4049   "TARGET_32BIT"
4050   "@
4051    mr. %1,%1
4052    srw. %3,%1,%2
4053    srwi. %3,%1,%h2
4054    #
4055    #
4056    #"
4057   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4058    (set_attr "length" "4,4,4,8,8,8")])
4059
4060 (define_split
4061   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4062         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4063                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4064                     (const_int 0)))
4065    (clobber (match_scratch:SI 3 ""))]
4066   "TARGET_32BIT && reload_completed"
4067   [(set (match_dup 3)
4068         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4069    (set (match_dup 0)
4070         (compare:CC (match_dup 3)
4071                     (const_int 0)))]
4072   "")
4073
4074 (define_insn ""
4075   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4076         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4077                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4078                     (const_int 0)))
4079    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4080         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4081   "TARGET_32BIT"
4082   "@
4083    mr. %0,%1
4084    srw. %0,%1,%2
4085    srwi. %0,%1,%h2
4086    #
4087    #
4088    #"
4089   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4090    (set_attr "length" "4,4,4,8,8,8")])
4091
4092 (define_split
4093   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4094         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4095                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4096                     (const_int 0)))
4097    (set (match_operand:SI 0 "gpc_reg_operand" "")
4098         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4099   "TARGET_32BIT && reload_completed"
4100   [(set (match_dup 0)
4101         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4102    (set (match_dup 3)
4103         (compare:CC (match_dup 0)
4104                     (const_int 0)))]
4105   "")
4106
4107 (define_insn ""
4108   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4109         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4110                              (match_operand:SI 2 "const_int_operand" "i"))
4111                 (match_operand:SI 3 "mask_operand" "n")))]
4112   "includes_rshift_p (operands[2], operands[3])"
4113   "rlwinm %0,%1,%s2,%m3,%M3")
4114
4115 (define_insn ""
4116   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4117         (compare:CC
4118          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4119                               (match_operand:SI 2 "const_int_operand" "i,i"))
4120                  (match_operand:SI 3 "mask_operand" "n,n"))
4121          (const_int 0)))
4122    (clobber (match_scratch:SI 4 "=r,r"))]
4123   "includes_rshift_p (operands[2], operands[3])"
4124   "@
4125    rlwinm. %4,%1,%s2,%m3,%M3
4126    #"
4127   [(set_attr "type" "delayed_compare")
4128    (set_attr "length" "4,8")])
4129
4130 (define_split
4131   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4132         (compare:CC
4133          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4134                               (match_operand:SI 2 "const_int_operand" ""))
4135                  (match_operand:SI 3 "mask_operand" ""))
4136          (const_int 0)))
4137    (clobber (match_scratch:SI 4 ""))]
4138   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4139   [(set (match_dup 4)
4140         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4141                  (match_dup 3)))
4142    (set (match_dup 0)
4143         (compare:CC (match_dup 4)
4144                     (const_int 0)))]
4145   "")
4146
4147 (define_insn ""
4148   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4149         (compare:CC
4150          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4151                               (match_operand:SI 2 "const_int_operand" "i,i"))
4152                  (match_operand:SI 3 "mask_operand" "n,n"))
4153          (const_int 0)))
4154    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4155         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4156   "includes_rshift_p (operands[2], operands[3])"
4157   "@
4158    rlwinm. %0,%1,%s2,%m3,%M3
4159    #"
4160   [(set_attr "type" "delayed_compare")
4161    (set_attr "length" "4,8")])
4162
4163 (define_split
4164   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4165         (compare:CC
4166          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4167                               (match_operand:SI 2 "const_int_operand" ""))
4168                  (match_operand:SI 3 "mask_operand" ""))
4169          (const_int 0)))
4170    (set (match_operand:SI 0 "gpc_reg_operand" "")
4171         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4172   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4173   [(set (match_dup 0)
4174         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4175    (set (match_dup 4)
4176         (compare:CC (match_dup 0)
4177                     (const_int 0)))]
4178   "")
4179
4180 (define_insn ""
4181   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4182         (zero_extend:SI
4183          (subreg:QI
4184           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4185                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4186   "includes_rshift_p (operands[2], GEN_INT (255))"
4187   "rlwinm %0,%1,%s2,0xff")
4188
4189 (define_insn ""
4190   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4191         (compare:CC
4192          (zero_extend:SI
4193           (subreg:QI
4194            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4195                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4196          (const_int 0)))
4197    (clobber (match_scratch:SI 3 "=r,r"))]
4198   "includes_rshift_p (operands[2], GEN_INT (255))"
4199   "@
4200    rlwinm. %3,%1,%s2,0xff
4201    #"
4202   [(set_attr "type" "delayed_compare")
4203    (set_attr "length" "4,8")])
4204
4205 (define_split
4206   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4207         (compare:CC
4208          (zero_extend:SI
4209           (subreg:QI
4210            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4211                         (match_operand:SI 2 "const_int_operand" "")) 0))
4212          (const_int 0)))
4213    (clobber (match_scratch:SI 3 ""))]
4214   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4215   [(set (match_dup 3)
4216         (zero_extend:SI (subreg:QI
4217            (lshiftrt:SI (match_dup 1)
4218                         (match_dup 2)) 0)))
4219    (set (match_dup 0)
4220         (compare:CC (match_dup 3)
4221                     (const_int 0)))]
4222   "")
4223
4224 (define_insn ""
4225   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4226         (compare:CC
4227          (zero_extend:SI
4228           (subreg:QI
4229            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4230                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4231          (const_int 0)))
4232    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4233         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4234   "includes_rshift_p (operands[2], GEN_INT (255))"
4235   "@
4236    rlwinm. %0,%1,%s2,0xff
4237    #"
4238   [(set_attr "type" "delayed_compare")
4239    (set_attr "length" "4,8")])
4240
4241 (define_split
4242   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4243         (compare:CC
4244          (zero_extend:SI
4245           (subreg:QI
4246            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4247                         (match_operand:SI 2 "const_int_operand" "")) 0))
4248          (const_int 0)))
4249    (set (match_operand:SI 0 "gpc_reg_operand" "")
4250         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4251   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4252   [(set (match_dup 0)
4253         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4254    (set (match_dup 3)
4255         (compare:CC (match_dup 0)
4256                     (const_int 0)))]
4257   "")
4258
4259 (define_insn ""
4260   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4261         (zero_extend:SI
4262          (subreg:HI
4263           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4264                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4265   "includes_rshift_p (operands[2], GEN_INT (65535))"
4266   "rlwinm %0,%1,%s2,0xffff")
4267
4268 (define_insn ""
4269   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4270         (compare:CC
4271          (zero_extend:SI
4272           (subreg:HI
4273            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4274                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4275          (const_int 0)))
4276    (clobber (match_scratch:SI 3 "=r,r"))]
4277   "includes_rshift_p (operands[2], GEN_INT (65535))"
4278   "@
4279    rlwinm. %3,%1,%s2,0xffff
4280    #"
4281   [(set_attr "type" "delayed_compare")
4282    (set_attr "length" "4,8")])
4283
4284 (define_split
4285   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4286         (compare:CC
4287          (zero_extend:SI
4288           (subreg:HI
4289            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4290                         (match_operand:SI 2 "const_int_operand" "")) 0))
4291          (const_int 0)))
4292    (clobber (match_scratch:SI 3 ""))]
4293   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4294   [(set (match_dup 3)
4295         (zero_extend:SI (subreg:HI
4296            (lshiftrt:SI (match_dup 1)
4297                         (match_dup 2)) 0)))
4298    (set (match_dup 0)
4299         (compare:CC (match_dup 3)
4300                     (const_int 0)))]
4301   "")
4302
4303 (define_insn ""
4304   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4305         (compare:CC
4306          (zero_extend:SI
4307           (subreg:HI
4308            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4309                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4310          (const_int 0)))
4311    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4312         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4313   "includes_rshift_p (operands[2], GEN_INT (65535))"
4314   "@
4315    rlwinm. %0,%1,%s2,0xffff
4316    #"
4317   [(set_attr "type" "delayed_compare")
4318    (set_attr "length" "4,8")])
4319
4320 (define_split
4321   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4322         (compare:CC
4323          (zero_extend:SI
4324           (subreg:HI
4325            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4326                         (match_operand:SI 2 "const_int_operand" "")) 0))
4327          (const_int 0)))
4328    (set (match_operand:SI 0 "gpc_reg_operand" "")
4329         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4330   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4331   [(set (match_dup 0)
4332         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4333    (set (match_dup 3)
4334         (compare:CC (match_dup 0)
4335                     (const_int 0)))]
4336   "")
4337
4338 (define_insn "ashrsi3"
4339   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4340         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4341                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4342   ""
4343   "@
4344    sraw %0,%1,%2
4345    srawi %0,%1,%h2"
4346   [(set_attr "type" "var_shift_rotate,shift")])
4347
4348 (define_insn "*ashrsi3_64"
4349   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4350         (sign_extend:DI
4351             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4352                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4353   "TARGET_POWERPC64"
4354   "@
4355    sraw %0,%1,%2
4356    srawi %0,%1,%h2"
4357   [(set_attr "type" "var_shift_rotate,shift")])
4358
4359 (define_insn ""
4360   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4361         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4362                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4363                     (const_int 0)))
4364    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4365   ""
4366   "@
4367    sraw. %3,%1,%2
4368    srawi. %3,%1,%h2
4369    #
4370    #"
4371   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4372    (set_attr "length" "4,4,8,8")])
4373
4374 (define_split
4375   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4376         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4377                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4378                     (const_int 0)))
4379    (clobber (match_scratch:SI 3 ""))]
4380   "reload_completed"
4381   [(set (match_dup 3)
4382         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4383    (set (match_dup 0)
4384         (compare:CC (match_dup 3)
4385                     (const_int 0)))]
4386   "")
4387
4388 (define_insn ""
4389   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4390         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4391                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4392                     (const_int 0)))
4393    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4394         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4395   ""
4396   "@
4397    sraw. %0,%1,%2
4398    srawi. %0,%1,%h2
4399    #
4400    #"
4401   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4402    (set_attr "length" "4,4,8,8")])
4403 \f
4404 ;; Builtins to replace a division to generate FRE reciprocal estimate
4405 ;; instructions and the necessary fixup instructions
4406 (define_expand "recip<mode>3"
4407   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
4408    (match_operand:RECIPF 1 "gpc_reg_operand" "")
4409    (match_operand:RECIPF 2 "gpc_reg_operand" "")]
4410   "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
4411 {
4412    rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
4413    DONE;
4414 })
4415
4416 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
4417 ;; hardware division.  This is only done before register allocation and with
4418 ;; -ffast-math.  This must appear before the divsf3/divdf3 insns.
4419 (define_split
4420   [(set (match_operand:RECIPF 0 "gpc_reg_operand" "")
4421         (div:RECIPF (match_operand 1 "gpc_reg_operand" "")
4422                     (match_operand 2 "gpc_reg_operand" "")))]
4423   "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
4424    && can_create_pseudo_p () && optimize_insn_for_speed_p ()
4425    && flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math"
4426   [(const_int 0)]
4427 {
4428   rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
4429   DONE;
4430 })
4431
4432 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
4433 ;; appropriate fixup.
4434 (define_expand "rsqrt<mode>2"
4435   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
4436    (match_operand:RECIPF 1 "gpc_reg_operand" "")]
4437   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
4438 {
4439   rs6000_emit_swrsqrt (operands[0], operands[1]);
4440   DONE;
4441 })
4442 \f
4443 (define_split
4444   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4445         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4446                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4447                     (const_int 0)))
4448    (set (match_operand:SI 0 "gpc_reg_operand" "")
4449         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4450   "reload_completed"
4451   [(set (match_dup 0)
4452         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4453    (set (match_dup 3)
4454         (compare:CC (match_dup 0)
4455                     (const_int 0)))]
4456   "")
4457
4458 ;; Floating-point insns, excluding normal data motion.
4459 ;;
4460 ;; PowerPC has a full set of single-precision floating point instructions.
4461 ;;
4462 ;; For the POWER architecture, we pretend that we have both SFmode and
4463 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4464 ;; The only conversions we will do will be when storing to memory.  In that
4465 ;; case, we will use the "frsp" instruction before storing.
4466 ;;
4467 ;; Note that when we store into a single-precision memory location, we need to
4468 ;; use the frsp insn first.  If the register being stored isn't dead, we
4469 ;; need a scratch register for the frsp.  But this is difficult when the store
4470 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4471 ;; this case, we just lose precision that we would have otherwise gotten but
4472 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4473
4474 (define_expand "extendsfdf2"
4475   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4476         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
4477   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4478   "")
4479
4480 (define_insn_and_split "*extendsfdf2_fpr"
4481   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d")
4482         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
4483   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
4484   "@
4485    #
4486    fmr %0,%1
4487    lfs%U1%X1 %0,%1"
4488   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
4489   [(const_int 0)]
4490 {
4491   emit_note (NOTE_INSN_DELETED);
4492   DONE;
4493 }
4494   [(set_attr "type" "fp,fp,fpload")])
4495
4496 (define_expand "truncdfsf2"
4497   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4498         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
4499   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4500   "")
4501
4502 (define_insn "*truncdfsf2_fpr"
4503   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4504         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
4505   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
4506   "frsp %0,%1"
4507   [(set_attr "type" "fp")])
4508
4509 (define_expand "negsf2"
4510   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4511         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4512   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4513   "")
4514
4515 (define_insn "*negsf2"
4516   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4517         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4518   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4519   "fneg %0,%1"
4520   [(set_attr "type" "fp")])
4521
4522 (define_expand "abssf2"
4523   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4524         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4525   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4526   "")
4527
4528 (define_insn "*abssf2"
4529   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4530         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4531   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4532   "fabs %0,%1"
4533   [(set_attr "type" "fp")])
4534
4535 (define_insn ""
4536   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4537         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4538   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4539   "fnabs %0,%1"
4540   [(set_attr "type" "fp")])
4541
4542 (define_expand "addsf3"
4543   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4544         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4545                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4546   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4547   "")
4548
4549 (define_insn ""
4550   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4551         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4552                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4553   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4554   "fadds %0,%1,%2"
4555   [(set_attr "type" "fp")
4556    (set_attr "fp_type" "fp_addsub_s")])
4557
4558 (define_expand "subsf3"
4559   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4560         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4561                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4562   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4563   "")
4564
4565 (define_insn ""
4566   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4567         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4568                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4569   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4570   "fsubs %0,%1,%2"
4571   [(set_attr "type" "fp")
4572    (set_attr "fp_type" "fp_addsub_s")])
4573
4574 (define_expand "mulsf3"
4575   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4576         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4577                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4578   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4579   "")
4580
4581 (define_insn ""
4582   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4583         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4584                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4585   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4586   "fmuls %0,%1,%2"
4587   [(set_attr "type" "fp")
4588    (set_attr "fp_type" "fp_mul_s")])
4589
4590 (define_expand "divsf3"
4591   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4592         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4593                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4594   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
4595   "")
4596
4597 (define_insn ""
4598   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4599         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4600                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4601   "TARGET_HARD_FLOAT && TARGET_FPRS
4602    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
4603   "fdivs %0,%1,%2"
4604   [(set_attr "type" "sdiv")])
4605
4606 (define_insn "fres"
4607   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4608         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
4609   "TARGET_FRES"
4610   "fres %0,%1"
4611   [(set_attr "type" "fp")])
4612
4613 ; builtin fmaf support
4614 (define_insn "*fmasf4_fpr"
4615   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4616         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4617                 (match_operand:SF 2 "gpc_reg_operand" "f")
4618                 (match_operand:SF 3 "gpc_reg_operand" "f")))]
4619   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4620   "fmadds %0,%1,%2,%3"
4621   [(set_attr "type" "fp")
4622    (set_attr "fp_type" "fp_maddsub_s")])
4623
4624 (define_insn "*fmssf4_fpr"
4625   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4626         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4627                 (match_operand:SF 2 "gpc_reg_operand" "f")
4628                 (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4629   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4630   "fmsubs %0,%1,%2,%3"
4631   [(set_attr "type" "fp")
4632    (set_attr "fp_type" "fp_maddsub_s")])
4633
4634 (define_insn "*nfmasf4_fpr"
4635   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4636         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4637                         (match_operand:SF 2 "gpc_reg_operand" "f")
4638                         (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4639   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4640   "fnmadds %0,%1,%2,%3"
4641   [(set_attr "type" "fp")
4642    (set_attr "fp_type" "fp_maddsub_s")])
4643
4644 (define_insn "*nfmssf4_fpr"
4645   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4646         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4647                         (match_operand:SF 2 "gpc_reg_operand" "f")
4648                         (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f")))))]
4649   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4650   "fnmsubs %0,%1,%2,%3"
4651   [(set_attr "type" "fp")
4652    (set_attr "fp_type" "fp_maddsub_s")])
4653
4654 (define_expand "sqrtsf2"
4655   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4656         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4657   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU)
4658    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
4659    && !TARGET_SIMPLE_FPU"
4660   "")
4661
4662 (define_insn ""
4663   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4664         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4665   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU) && TARGET_HARD_FLOAT
4666    && TARGET_FPRS && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
4667   "fsqrts %0,%1"
4668   [(set_attr "type" "ssqrt")])
4669
4670 (define_insn "*rsqrtsf_internal1"
4671   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4672         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
4673                    UNSPEC_RSQRT))]
4674   "TARGET_FRSQRTES"
4675   "frsqrtes %0,%1"
4676   [(set_attr "type" "fp")])
4677
4678 ;; This expander is here to avoid FLOAT_WORDS_BIGENDIAN tests in
4679 ;; builtins.c and optabs.c that are not correct for IBM long double
4680 ;; when little-endian.
4681 (define_expand "signbittf2"
4682   [(set (match_dup 2)
4683         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))
4684    (set (match_dup 3)
4685         (subreg:DI (match_dup 2) 0))
4686    (set (match_dup 4)
4687         (match_dup 5))
4688    (set (match_operand:SI 0 "gpc_reg_operand" "")
4689         (match_dup 6))]
4690   "!TARGET_IEEEQUAD
4691    && TARGET_HARD_FLOAT
4692    && (TARGET_FPRS || TARGET_E500_DOUBLE)
4693    && TARGET_LONG_DOUBLE_128"
4694 {
4695   operands[2] = gen_reg_rtx (DFmode);
4696   operands[3] = gen_reg_rtx (DImode);
4697   if (TARGET_POWERPC64)
4698     {
4699       operands[4] = gen_reg_rtx (DImode);
4700       operands[5] = gen_rtx_LSHIFTRT (DImode, operands[3], GEN_INT (63));
4701       operands[6] = gen_rtx_SUBREG (SImode, operands[4],
4702                                     WORDS_BIG_ENDIAN ? 4 : 0);
4703     }
4704   else
4705     {
4706       operands[4] = gen_reg_rtx (SImode);
4707       operands[5] = gen_rtx_SUBREG (SImode, operands[3],
4708                                     WORDS_BIG_ENDIAN ? 0 : 4);
4709       operands[6] = gen_rtx_LSHIFTRT (SImode, operands[4], GEN_INT (31));
4710     }
4711 })
4712
4713 (define_expand "copysign<mode>3"
4714   [(set (match_dup 3)
4715         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))
4716    (set (match_dup 4)
4717         (neg:SFDF (abs:SFDF (match_dup 1))))
4718    (set (match_operand:SFDF 0 "gpc_reg_operand" "")
4719         (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand" "")
4720                                (match_dup 5))
4721                          (match_dup 3)
4722                          (match_dup 4)))]
4723   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
4724    && ((TARGET_PPC_GFXOPT
4725         && !HONOR_NANS (<MODE>mode)
4726         && !HONOR_SIGNED_ZEROS (<MODE>mode))
4727        || TARGET_CMPB
4728        || VECTOR_UNIT_VSX_P (<MODE>mode))"
4729 {
4730   if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
4731     {
4732       emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
4733                                              operands[2]));
4734       DONE;
4735     }
4736
4737    operands[3] = gen_reg_rtx (<MODE>mode);
4738    operands[4] = gen_reg_rtx (<MODE>mode);
4739    operands[5] = CONST0_RTX (<MODE>mode);
4740   })
4741
4742 ;; Use an unspec rather providing an if-then-else in RTL, to prevent the
4743 ;; compiler from optimizing -0.0
4744 (define_insn "copysign<mode>3_fcpsgn"
4745   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
4746         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")
4747                       (match_operand:SFDF 2 "gpc_reg_operand" "<rreg2>")]
4748                      UNSPEC_COPYSIGN))]
4749   "TARGET_CMPB && !VECTOR_UNIT_VSX_P (<MODE>mode)"
4750   "fcpsgn %0,%2,%1"
4751   [(set_attr "type" "fp")])
4752
4753 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4754 ;; fsel instruction and some auxiliary computations.  Then we just have a
4755 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4756 ;; combine.
4757 (define_expand "smaxsf3"
4758   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4759         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4760                              (match_operand:SF 2 "gpc_reg_operand" ""))
4761                          (match_dup 1)
4762                          (match_dup 2)))]
4763   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
4764    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
4765   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4766
4767 (define_expand "sminsf3"
4768   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4769         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4770                              (match_operand:SF 2 "gpc_reg_operand" ""))
4771                          (match_dup 2)
4772                          (match_dup 1)))]
4773   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
4774    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
4775   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4776
4777 (define_split
4778   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4779         (match_operator:SF 3 "min_max_operator"
4780          [(match_operand:SF 1 "gpc_reg_operand" "")
4781           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4782   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
4783    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
4784   [(const_int 0)]
4785   "
4786 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4787                       operands[1], operands[2]);
4788   DONE;
4789 }")
4790
4791 (define_expand "mov<mode>cc"
4792    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
4793          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
4794                            (match_operand:GPR 2 "gpc_reg_operand" "")
4795                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
4796   "TARGET_ISEL<sel>"
4797   "
4798 {
4799   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4800     DONE;
4801   else
4802     FAIL;
4803 }")
4804
4805 ;; We use the BASE_REGS for the isel input operands because, if rA is
4806 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4807 ;; because we may switch the operands and rB may end up being rA.
4808 ;;
4809 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4810 ;; leave out the mode in operand 4 and use one pattern, but reload can
4811 ;; change the mode underneath our feet and then gets confused trying
4812 ;; to reload the value.
4813 (define_insn "isel_signed_<mode>"
4814   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4815         (if_then_else:GPR
4816          (match_operator 1 "scc_comparison_operator"
4817                          [(match_operand:CC 4 "cc_reg_operand" "y,y")
4818                           (const_int 0)])
4819          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
4820          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
4821   "TARGET_ISEL<sel>"
4822   "*
4823 { return output_isel (operands); }"
4824   [(set_attr "type" "isel")
4825    (set_attr "length" "4")])
4826
4827 (define_insn "isel_unsigned_<mode>"
4828   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4829         (if_then_else:GPR
4830          (match_operator 1 "scc_comparison_operator"
4831                          [(match_operand:CCUNS 4 "cc_reg_operand" "y,y")
4832                           (const_int 0)])
4833          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
4834          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
4835   "TARGET_ISEL<sel>"
4836   "*
4837 { return output_isel (operands); }"
4838   [(set_attr "type" "isel")
4839    (set_attr "length" "4")])
4840
4841 ;; These patterns can be useful for combine; they let combine know that
4842 ;; isel can handle reversed comparisons so long as the operands are
4843 ;; registers.
4844
4845 (define_insn "*isel_reversed_signed_<mode>"
4846   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4847         (if_then_else:GPR
4848          (match_operator 1 "scc_rev_comparison_operator"
4849                          [(match_operand:CC 4 "cc_reg_operand" "y")
4850                           (const_int 0)])
4851          (match_operand:GPR 2 "gpc_reg_operand" "b")
4852          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
4853   "TARGET_ISEL<sel>"
4854   "*
4855 { return output_isel (operands); }"
4856   [(set_attr "type" "isel")
4857    (set_attr "length" "4")])
4858
4859 (define_insn "*isel_reversed_unsigned_<mode>"
4860   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4861         (if_then_else:GPR
4862          (match_operator 1 "scc_rev_comparison_operator"
4863                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4864                           (const_int 0)])
4865          (match_operand:GPR 2 "gpc_reg_operand" "b")
4866          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
4867   "TARGET_ISEL<sel>"
4868   "*
4869 { return output_isel (operands); }"
4870   [(set_attr "type" "isel")
4871    (set_attr "length" "4")])
4872
4873 (define_expand "movsfcc"
4874    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4875          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4876                           (match_operand:SF 2 "gpc_reg_operand" "")
4877                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4878   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4879   "
4880 {
4881   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4882     DONE;
4883   else
4884     FAIL;
4885 }")
4886
4887 (define_insn "*fselsfsf4"
4888   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4889         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4890                              (match_operand:SF 4 "zero_fp_constant" "F"))
4891                          (match_operand:SF 2 "gpc_reg_operand" "f")
4892                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4893   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4894   "fsel %0,%1,%2,%3"
4895   [(set_attr "type" "fp")])
4896
4897 (define_insn "*fseldfsf4"
4898   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4899         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
4900                              (match_operand:DF 4 "zero_fp_constant" "F"))
4901                          (match_operand:SF 2 "gpc_reg_operand" "f")
4902                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4903   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
4904   "fsel %0,%1,%2,%3"
4905   [(set_attr "type" "fp")])
4906
4907 (define_expand "negdf2"
4908   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4909         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4910   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4911   "")
4912
4913 (define_insn "*negdf2_fpr"
4914   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4915         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
4916   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4917    && !VECTOR_UNIT_VSX_P (DFmode)"
4918   "fneg %0,%1"
4919   [(set_attr "type" "fp")])
4920
4921 (define_expand "absdf2"
4922   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4923         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4924   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4925   "")
4926
4927 (define_insn "*absdf2_fpr"
4928   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4929         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
4930   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4931    && !VECTOR_UNIT_VSX_P (DFmode)"
4932   "fabs %0,%1"
4933   [(set_attr "type" "fp")])
4934
4935 (define_insn "*nabsdf2_fpr"
4936   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4937         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d"))))]
4938   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4939    && !VECTOR_UNIT_VSX_P (DFmode)"
4940   "fnabs %0,%1"
4941   [(set_attr "type" "fp")])
4942
4943 (define_expand "adddf3"
4944   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4945         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
4946                  (match_operand:DF 2 "gpc_reg_operand" "")))]
4947   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4948   "")
4949
4950 (define_insn "*adddf3_fpr"
4951   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4952         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
4953                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
4954   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4955    && !VECTOR_UNIT_VSX_P (DFmode)"
4956   "fadd %0,%1,%2"
4957   [(set_attr "type" "fp")
4958    (set_attr "fp_type" "fp_addsub_d")])
4959
4960 (define_expand "subdf3"
4961   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4962         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
4963                   (match_operand:DF 2 "gpc_reg_operand" "")))]
4964   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4965   "")
4966
4967 (define_insn "*subdf3_fpr"
4968   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4969         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "d")
4970                   (match_operand:DF 2 "gpc_reg_operand" "d")))]
4971   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4972    && !VECTOR_UNIT_VSX_P (DFmode)"
4973   "fsub %0,%1,%2"
4974   [(set_attr "type" "fp")
4975    (set_attr "fp_type" "fp_addsub_d")])
4976
4977 (define_expand "muldf3"
4978   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4979         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
4980                  (match_operand:DF 2 "gpc_reg_operand" "")))]
4981   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4982   "")
4983
4984 (define_insn "*muldf3_fpr"
4985   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4986         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
4987                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
4988   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4989    && !VECTOR_UNIT_VSX_P (DFmode)"
4990   "fmul %0,%1,%2"
4991   [(set_attr "type" "dmul")
4992    (set_attr "fp_type" "fp_mul_d")])
4993
4994 (define_expand "divdf3"
4995   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4996         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
4997                 (match_operand:DF 2 "gpc_reg_operand" "")))]
4998   "TARGET_HARD_FLOAT
4999    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)
5000    && !TARGET_SIMPLE_FPU"
5001   "")
5002
5003 (define_insn "*divdf3_fpr"
5004   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5005         (div:DF (match_operand:DF 1 "gpc_reg_operand" "d")
5006                 (match_operand:DF 2 "gpc_reg_operand" "d")))]
5007   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && !TARGET_SIMPLE_FPU
5008    && !VECTOR_UNIT_VSX_P (DFmode)"
5009   "fdiv %0,%1,%2"
5010   [(set_attr "type" "ddiv")])
5011
5012 (define_insn "*fred_fpr"
5013   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5014         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5015   "TARGET_FRE && !VECTOR_UNIT_VSX_P (DFmode)"
5016   "fre %0,%1"
5017   [(set_attr "type" "fp")])
5018
5019 (define_insn "*rsqrtdf_internal1"
5020   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5021         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")]
5022                    UNSPEC_RSQRT))]
5023   "TARGET_FRSQRTE && !VECTOR_UNIT_VSX_P (DFmode)"
5024   "frsqrte %0,%1"
5025   [(set_attr "type" "fp")])
5026
5027 ; builtin fma support
5028 (define_insn "*fmadf4_fpr"
5029   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5030         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5031                 (match_operand:DF 2 "gpc_reg_operand" "f")
5032                 (match_operand:DF 3 "gpc_reg_operand" "f")))]
5033   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5034    && VECTOR_UNIT_NONE_P (DFmode)"
5035   "fmadd %0,%1,%2,%3"
5036   [(set_attr "type" "fp")
5037    (set_attr "fp_type" "fp_maddsub_d")])
5038
5039 (define_insn "*fmsdf4_fpr"
5040   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5041         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5042                 (match_operand:DF 2 "gpc_reg_operand" "f")
5043                 (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5044   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5045    && VECTOR_UNIT_NONE_P (DFmode)"
5046   "fmsub %0,%1,%2,%3"
5047   [(set_attr "type" "fp")
5048    (set_attr "fp_type" "fp_maddsub_d")])
5049
5050 (define_insn "*nfmadf4_fpr"
5051   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5052         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5053                         (match_operand:DF 2 "gpc_reg_operand" "f")
5054                         (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5055   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5056    && VECTOR_UNIT_NONE_P (DFmode)"
5057   "fnmadd %0,%1,%2,%3"
5058   [(set_attr "type" "fp")
5059    (set_attr "fp_type" "fp_maddsub_d")])
5060
5061 (define_insn "*nfmsdf4_fpr"
5062   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5063         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5064                         (match_operand:DF 2 "gpc_reg_operand" "f")
5065                         (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f")))))]
5066   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5067    && VECTOR_UNIT_NONE_P (DFmode)"
5068   "fnmsub %0,%1,%2,%3"
5069   [(set_attr "type" "fp")
5070    (set_attr "fp_type" "fp_maddsub_d")])
5071
5072 (define_expand "sqrtdf2"
5073   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5074         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5075   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5076   "")
5077
5078 (define_insn "*sqrtdf2_fpr"
5079   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5080         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5081   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5082    && !VECTOR_UNIT_VSX_P (DFmode)"
5083   "fsqrt %0,%1"
5084   [(set_attr "type" "dsqrt")])
5085
5086 ;; The conditional move instructions allow us to perform max and min
5087 ;; operations even when
5088
5089 (define_expand "smaxdf3"
5090   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5091         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5092                              (match_operand:DF 2 "gpc_reg_operand" ""))
5093                          (match_dup 1)
5094                          (match_dup 2)))]
5095   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5096    && !flag_trapping_math"
5097   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5098
5099 (define_expand "smindf3"
5100   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5101         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5102                              (match_operand:DF 2 "gpc_reg_operand" ""))
5103                          (match_dup 2)
5104                          (match_dup 1)))]
5105   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5106    && !flag_trapping_math"
5107   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5108
5109 (define_split
5110   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5111         (match_operator:DF 3 "min_max_operator"
5112          [(match_operand:DF 1 "gpc_reg_operand" "")
5113           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5114   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5115    && !flag_trapping_math"
5116   [(const_int 0)]
5117   "
5118 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5119                       operands[1], operands[2]);
5120   DONE;
5121 }")
5122
5123 (define_expand "movdfcc"
5124    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5125          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5126                           (match_operand:DF 2 "gpc_reg_operand" "")
5127                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5128   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5129   "
5130 {
5131   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5132     DONE;
5133   else
5134     FAIL;
5135 }")
5136
5137 (define_insn "*fseldfdf4"
5138   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5139         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5140                              (match_operand:DF 4 "zero_fp_constant" "F"))
5141                          (match_operand:DF 2 "gpc_reg_operand" "d")
5142                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5143   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5144   "fsel %0,%1,%2,%3"
5145   [(set_attr "type" "fp")])
5146
5147 (define_insn "*fselsfdf4"
5148   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5149         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5150                              (match_operand:SF 4 "zero_fp_constant" "F"))
5151                          (match_operand:DF 2 "gpc_reg_operand" "d")
5152                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5153   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5154   "fsel %0,%1,%2,%3"
5155   [(set_attr "type" "fp")])
5156 \f
5157 ;; Conversions to and from floating-point.
5158
5159 ; We don't define lfiwax/lfiwzx with the normal definition, because we
5160 ; don't want to support putting SImode in FPR registers.
5161 (define_insn "lfiwax"
5162   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5163         (unspec:DI [(match_operand:SI 1 "indexed_or_indirect_operand" "Z")]
5164                    UNSPEC_LFIWAX))]
5165   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX"
5166   "lfiwax %0,%y1"
5167   [(set_attr "type" "fpload")])
5168
5169 ; This split must be run before register allocation because it allocates the
5170 ; memory slot that is needed to move values to/from the FPR.  We don't allocate
5171 ; it earlier to allow for the combiner to merge insns together where it might
5172 ; not be needed and also in case the insns are deleted as dead code.
5173
5174 (define_insn_and_split "floatsi<mode>2_lfiwax"
5175   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5176         (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5177    (clobber (match_scratch:DI 2 "=d"))]
5178   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5179    && <SI_CONVERT_FP> && can_create_pseudo_p ()"
5180   "#"
5181   ""
5182   [(pc)]
5183   "
5184 {
5185   rtx dest = operands[0];
5186   rtx src = operands[1];
5187   rtx tmp;
5188
5189   if (!MEM_P (src) && TARGET_MFPGPR && TARGET_POWERPC64)
5190     tmp = convert_to_mode (DImode, src, false);
5191   else
5192     {
5193       tmp = operands[2];
5194       if (GET_CODE (tmp) == SCRATCH)
5195         tmp = gen_reg_rtx (DImode);
5196       if (MEM_P (src))
5197         {
5198           src = rs6000_address_for_fpconvert (src);
5199           emit_insn (gen_lfiwax (tmp, src));
5200         }
5201       else
5202         {
5203           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5204           emit_move_insn (stack, src);
5205           emit_insn (gen_lfiwax (tmp, stack));
5206         }
5207     }
5208   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5209   DONE;
5210 }"
5211   [(set_attr "length" "12")
5212    (set_attr "type" "fpload")])
5213
5214 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
5215   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5216         (float:SFDF
5217          (sign_extend:DI
5218           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5219    (clobber (match_scratch:DI 2 "=0,d"))]
5220   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5221    && <SI_CONVERT_FP>"
5222   "#"
5223   ""
5224   [(pc)]
5225   "
5226 {
5227   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5228   if (GET_CODE (operands[2]) == SCRATCH)
5229     operands[2] = gen_reg_rtx (DImode);
5230   emit_insn (gen_lfiwax (operands[2], operands[1]));
5231   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5232   DONE;
5233 }"
5234   [(set_attr "length" "8")
5235    (set_attr "type" "fpload")])
5236
5237 (define_insn "lfiwzx"
5238   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5239         (unspec:DI [(match_operand:SI 1 "indexed_or_indirect_operand" "Z")]
5240                    UNSPEC_LFIWZX))]
5241   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX"
5242   "lfiwzx %0,%y1"
5243   [(set_attr "type" "fpload")])
5244
5245 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
5246   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5247         (unsigned_float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5248    (clobber (match_scratch:DI 2 "=d"))]
5249   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5250    && <SI_CONVERT_FP>"
5251   "#"
5252   ""
5253   [(pc)]
5254   "
5255 {
5256   rtx dest = operands[0];
5257   rtx src = operands[1];
5258   rtx tmp;
5259
5260   if (!MEM_P (src) && TARGET_MFPGPR && TARGET_POWERPC64)
5261     tmp = convert_to_mode (DImode, src, true);
5262   else
5263     {
5264       tmp = operands[2];
5265       if (GET_CODE (tmp) == SCRATCH)
5266         tmp = gen_reg_rtx (DImode);
5267       if (MEM_P (src))
5268         {
5269           src = rs6000_address_for_fpconvert (src);
5270           emit_insn (gen_lfiwzx (tmp, src));
5271         }
5272       else
5273         {
5274           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5275           emit_move_insn (stack, src);
5276           emit_insn (gen_lfiwzx (tmp, stack));
5277         }
5278     }
5279   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5280   DONE;
5281 }"
5282   [(set_attr "length" "12")
5283    (set_attr "type" "fpload")])
5284
5285 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
5286   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5287         (unsigned_float:SFDF
5288          (zero_extend:DI
5289           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5290    (clobber (match_scratch:DI 2 "=0,d"))]
5291   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5292    && <SI_CONVERT_FP>"
5293   "#"
5294   ""
5295   [(pc)]
5296   "
5297 {
5298   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5299   if (GET_CODE (operands[2]) == SCRATCH)
5300     operands[2] = gen_reg_rtx (DImode);
5301   emit_insn (gen_lfiwzx (operands[2], operands[1]));
5302   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5303   DONE;
5304 }"
5305   [(set_attr "length" "8")
5306    (set_attr "type" "fpload")])
5307
5308 ; For each of these conversions, there is a define_expand, a define_insn
5309 ; with a '#' template, and a define_split (with C code).  The idea is
5310 ; to allow constant folding with the template of the define_insn,
5311 ; then to have the insns split later (between sched1 and final).
5312
5313 (define_expand "floatsidf2"
5314   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5315                    (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5316               (use (match_dup 2))
5317               (use (match_dup 3))
5318               (clobber (match_dup 4))
5319               (clobber (match_dup 5))
5320               (clobber (match_dup 6))])]
5321   "TARGET_HARD_FLOAT 
5322    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5323   "
5324 {
5325   if (TARGET_E500_DOUBLE)
5326     {
5327       if (!REG_P (operands[1]))
5328         operands[1] = force_reg (SImode, operands[1]);
5329       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5330       DONE;
5331     }
5332   else if (TARGET_LFIWAX && TARGET_FCFID)
5333     {
5334       emit_insn (gen_floatsidf2_lfiwax (operands[0], operands[1]));
5335       DONE;
5336     }
5337   else if (TARGET_FCFID)
5338     {
5339       rtx dreg = operands[1];
5340       if (!REG_P (dreg))
5341         dreg = force_reg (SImode, dreg);
5342       dreg = convert_to_mode (DImode, dreg, false);
5343       emit_insn (gen_floatdidf2 (operands[0], dreg));
5344       DONE;
5345     }
5346
5347   if (!REG_P (operands[1]))
5348     operands[1] = force_reg (SImode, operands[1]);
5349   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5350   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5351   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5352   operands[5] = gen_reg_rtx (DFmode);
5353   operands[6] = gen_reg_rtx (SImode);
5354 }")
5355
5356 (define_insn_and_split "*floatsidf2_internal"
5357   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5358         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5359    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5360    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5361    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5362    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
5363    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5364   "! TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5365   "#"
5366   ""
5367   [(pc)]
5368   "
5369 {
5370   rtx lowword, highword;
5371   gcc_assert (MEM_P (operands[4]));
5372   highword = adjust_address (operands[4], SImode, 0);
5373   lowword = adjust_address (operands[4], SImode, 4);
5374   if (! WORDS_BIG_ENDIAN)
5375     {
5376       rtx tmp;
5377       tmp = highword; highword = lowword; lowword = tmp;
5378     }
5379
5380   emit_insn (gen_xorsi3 (operands[6], operands[1],
5381                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5382   emit_move_insn (lowword, operands[6]);
5383   emit_move_insn (highword, operands[2]);
5384   emit_move_insn (operands[5], operands[4]);
5385   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5386   DONE;
5387 }"
5388   [(set_attr "length" "24")
5389    (set_attr "type" "fp")])
5390
5391 ;; If we don't have a direct conversion to single precision, don't enable this
5392 ;; conversion for 32-bit without fast math, because we don't have the insn to
5393 ;; generate the fixup swizzle to avoid double rounding problems.
5394 (define_expand "floatunssisf2"
5395   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5396         (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5397   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
5398    && (!TARGET_FPRS
5399        || (TARGET_FPRS
5400            && ((TARGET_FCFIDUS && TARGET_LFIWZX)
5401                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
5402                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
5403   "
5404 {
5405   if (!TARGET_FPRS)
5406     {
5407       if (!REG_P (operands[1]))
5408         operands[1] = force_reg (SImode, operands[1]);
5409     }
5410   else if (TARGET_LFIWZX && TARGET_FCFIDUS)
5411     {
5412       emit_insn (gen_floatunssisf2_lfiwzx (operands[0], operands[1]));
5413       DONE;
5414     }
5415   else
5416     {
5417       rtx dreg = operands[1];
5418       if (!REG_P (dreg))
5419         dreg = force_reg (SImode, dreg);
5420       dreg = convert_to_mode (DImode, dreg, true);
5421       emit_insn (gen_floatdisf2 (operands[0], dreg));
5422       DONE;
5423     }
5424 }")
5425
5426 (define_expand "floatunssidf2"
5427   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5428                    (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5429               (use (match_dup 2))
5430               (use (match_dup 3))
5431               (clobber (match_dup 4))
5432               (clobber (match_dup 5))])]
5433   "TARGET_HARD_FLOAT
5434    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5435   "
5436 {
5437   if (TARGET_E500_DOUBLE)
5438     {
5439       if (!REG_P (operands[1]))
5440         operands[1] = force_reg (SImode, operands[1]);
5441       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5442       DONE;
5443     }
5444   else if (TARGET_LFIWZX && TARGET_FCFID)
5445     {
5446       emit_insn (gen_floatunssidf2_lfiwzx (operands[0], operands[1]));
5447       DONE;
5448     }
5449   else if (TARGET_FCFID)
5450     {
5451       rtx dreg = operands[1];
5452       if (!REG_P (dreg))
5453         dreg = force_reg (SImode, dreg);
5454       dreg = convert_to_mode (DImode, dreg, true);
5455       emit_insn (gen_floatdidf2 (operands[0], dreg));
5456       DONE;
5457     }
5458
5459   if (!REG_P (operands[1]))
5460     operands[1] = force_reg (SImode, operands[1]);
5461   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5462   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5463   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5464   operands[5] = gen_reg_rtx (DFmode);
5465 }")
5466
5467 (define_insn_and_split "*floatunssidf2_internal"
5468   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5469         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5470    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5471    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5472    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5473    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
5474   "! TARGET_FCFIDU && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5475    && !(TARGET_FCFID && TARGET_POWERPC64)"
5476   "#"
5477   ""
5478   [(pc)]
5479   "
5480 {
5481   rtx lowword, highword;
5482   gcc_assert (MEM_P (operands[4]));
5483   highword = adjust_address (operands[4], SImode, 0);
5484   lowword = adjust_address (operands[4], SImode, 4);
5485   if (! WORDS_BIG_ENDIAN)
5486     {
5487       rtx tmp;
5488       tmp = highword; highword = lowword; lowword = tmp;
5489     }
5490
5491   emit_move_insn (lowword, operands[1]);
5492   emit_move_insn (highword, operands[2]);
5493   emit_move_insn (operands[5], operands[4]);
5494   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5495   DONE;
5496 }"
5497   [(set_attr "length" "20")
5498    (set_attr "type" "fp")])
5499
5500 (define_expand "fix_trunc<mode>si2"
5501   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5502         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5503   "TARGET_HARD_FLOAT && ((TARGET_FPRS && <TARGET_FLOAT>) || <E500_CONVERT>)"
5504   "
5505 {
5506   if (!<E500_CONVERT>)
5507     {
5508       rtx tmp, stack;
5509
5510       if (TARGET_STFIWX)
5511         emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], operands[1]));
5512       else
5513         {
5514           tmp = gen_reg_rtx (DImode);
5515           stack = rs6000_allocate_stack_temp (DImode, true, false);
5516           emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], operands[1],
5517                                                       tmp, stack));
5518         }
5519       DONE;
5520     }
5521 }")
5522
5523 ; Like the convert to float patterns, this insn must be split before
5524 ; register allocation so that it can allocate the memory slot if it
5525 ; needed
5526 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
5527   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
5528         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
5529    (clobber (match_scratch:DI 2 "=d"))]
5530   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5531    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
5532    && TARGET_STFIWX && can_create_pseudo_p ()"
5533   "#"
5534   ""
5535   [(pc)]
5536 {
5537   rtx dest = operands[0];
5538   rtx src = operands[1];
5539   rtx tmp = operands[2];
5540
5541   if (GET_CODE (tmp) == SCRATCH)
5542     tmp = gen_reg_rtx (DImode);
5543
5544   emit_insn (gen_fctiwz_<mode> (tmp, src));
5545   if (MEM_P (dest))
5546     {
5547       dest = rs6000_address_for_fpconvert (dest);
5548       emit_insn (gen_stfiwx (dest, tmp));
5549       DONE;
5550     }
5551   else if (TARGET_MFPGPR && TARGET_POWERPC64)
5552     {
5553       dest = gen_lowpart (DImode, dest);
5554       emit_move_insn (dest, tmp);
5555       DONE;
5556     }
5557   else
5558     {
5559       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5560       emit_insn (gen_stfiwx (stack, tmp));
5561       emit_move_insn (dest, stack);
5562       DONE;
5563     }
5564 }
5565   [(set_attr "length" "12")
5566    (set_attr "type" "fp")])
5567
5568 (define_insn_and_split "fix_trunc<mode>si2_internal"
5569   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,?r")
5570         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,<rreg>")))
5571    (clobber (match_operand:DI 2 "gpc_reg_operand" "=1,d"))
5572    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o,o"))]
5573   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5574   "#"
5575   ""
5576   [(pc)]
5577   "
5578 {
5579   rtx lowword;
5580   gcc_assert (MEM_P (operands[3]));
5581   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
5582
5583   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
5584   emit_move_insn (operands[3], operands[2]);
5585   emit_move_insn (operands[0], lowword);
5586   DONE;
5587 }"
5588   [(set_attr "length" "16")
5589    (set_attr "type" "fp")])
5590
5591 (define_expand "fix_trunc<mode>di2"
5592   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5593         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5594   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
5595    && TARGET_FCFID"
5596   "")
5597
5598 (define_insn "*fix_trunc<mode>di2_fctidz"
5599   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5600         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
5601   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
5602     && TARGET_FCFID && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5603   "fctidz %0,%1"
5604   [(set_attr "type" "fp")])
5605
5606 (define_expand "fixuns_trunc<mode>si2"
5607   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5608         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5609   "TARGET_HARD_FLOAT
5610    && ((TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ && TARGET_STFIWX)
5611        || <E500_CONVERT>)"
5612   "
5613 {
5614   if (!<E500_CONVERT>)
5615     {
5616       emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1]));
5617       DONE;
5618     }
5619 }")
5620
5621 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
5622   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
5623         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
5624    (clobber (match_scratch:DI 2 "=d"))]
5625   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
5626    && TARGET_STFIWX && can_create_pseudo_p ()"
5627   "#"
5628   ""
5629   [(pc)]
5630 {
5631   rtx dest = operands[0];
5632   rtx src = operands[1];
5633   rtx tmp = operands[2];
5634
5635   if (GET_CODE (tmp) == SCRATCH)
5636     tmp = gen_reg_rtx (DImode);
5637
5638   emit_insn (gen_fctiwuz_<mode> (tmp, src));
5639   if (MEM_P (dest))
5640     {
5641       dest = rs6000_address_for_fpconvert (dest);
5642       emit_insn (gen_stfiwx (dest, tmp));
5643       DONE;
5644     }
5645   else if (TARGET_MFPGPR && TARGET_POWERPC64)
5646     {
5647       dest = gen_lowpart (DImode, dest);
5648       emit_move_insn (dest, tmp);
5649       DONE;
5650     }
5651   else
5652     {
5653       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5654       emit_insn (gen_stfiwx (stack, tmp));
5655       emit_move_insn (dest, stack);
5656       DONE;
5657     }
5658 }
5659   [(set_attr "length" "12")
5660    (set_attr "type" "fp")])
5661
5662 (define_expand "fixuns_trunc<mode>di2"
5663   [(set (match_operand:DI 0 "register_operand" "")
5664         (unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
5665   "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
5666   "")
5667
5668 (define_insn "*fixuns_trunc<mode>di2_fctiduz"
5669   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5670         (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
5671   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
5672     && TARGET_FCTIDUZ && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5673   "fctiduz %0,%1"
5674   [(set_attr "type" "fp")])
5675
5676 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5677 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5678 ; because the first makes it clear that operand 0 is not live
5679 ; before the instruction.
5680 (define_insn "fctiwz_<mode>"
5681   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5682         (unspec:DI [(fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))]
5683                    UNSPEC_FCTIWZ))]
5684   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5685   "fctiwz %0,%1"
5686   [(set_attr "type" "fp")])
5687
5688 (define_insn "fctiwuz_<mode>"
5689   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5690         (unspec:DI [(unsigned_fix:SI
5691                      (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>"))]
5692                    UNSPEC_FCTIWUZ))]
5693   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ"
5694   "fctiwuz %0,%1"
5695   [(set_attr "type" "fp")])
5696
5697 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
5698 ;; since the friz instruction does not truncate the value if the floating
5699 ;; point value is < LONG_MIN or > LONG_MAX.
5700 (define_insn "*friz"
5701   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5702         (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d"))))]
5703   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_FPRND
5704    && !VECTOR_UNIT_VSX_P (DFmode) && flag_unsafe_math_optimizations
5705    && !flag_trapping_math && TARGET_FRIZ"
5706   "friz %0,%1"
5707   [(set_attr "type" "fp")])
5708
5709 ;; Since FCTIWZ doesn't sign extend the upper bits, we have to do a store and a
5710 ;; load to properly sign extend the value, but at least doing a store, load
5711 ;; into a GPR to sign extend, a store from the GPR and a load back into the FPR
5712 ;; if we have 32-bit memory ops
5713 (define_insn_and_split "*round32<mode>2_fprs"
5714   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5715         (float:SFDF
5716          (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
5717    (clobber (match_scratch:DI 2 "=d"))
5718    (clobber (match_scratch:DI 3 "=d"))]
5719   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5720    && <SI_CONVERT_FP> && TARGET_LFIWAX && TARGET_STFIWX && TARGET_FCFID
5721    && can_create_pseudo_p ()"
5722   "#"
5723   ""
5724   [(pc)]
5725 {
5726   rtx dest = operands[0];
5727   rtx src = operands[1];
5728   rtx tmp1 = operands[2];
5729   rtx tmp2 = operands[3];
5730   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5731
5732   if (GET_CODE (tmp1) == SCRATCH)
5733     tmp1 = gen_reg_rtx (DImode);
5734   if (GET_CODE (tmp2) == SCRATCH)
5735     tmp2 = gen_reg_rtx (DImode);
5736
5737   emit_insn (gen_fctiwz_<mode> (tmp1, src));
5738   emit_insn (gen_stfiwx (stack, tmp1));
5739   emit_insn (gen_lfiwax (tmp2, stack));
5740   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
5741   DONE;
5742 }
5743   [(set_attr "type" "fpload")
5744    (set_attr "length" "16")])
5745
5746 (define_insn_and_split "*roundu32<mode>2_fprs"
5747   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5748         (unsigned_float:SFDF
5749          (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
5750    (clobber (match_scratch:DI 2 "=d"))
5751    (clobber (match_scratch:DI 3 "=d"))]
5752   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5753    && TARGET_LFIWZX && TARGET_STFIWX && TARGET_FCFIDU
5754    && can_create_pseudo_p ()"
5755   "#"
5756   ""
5757   [(pc)]
5758 {
5759   rtx dest = operands[0];
5760   rtx src = operands[1];
5761   rtx tmp1 = operands[2];
5762   rtx tmp2 = operands[3];
5763   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5764
5765   if (GET_CODE (tmp1) == SCRATCH)
5766     tmp1 = gen_reg_rtx (DImode);
5767   if (GET_CODE (tmp2) == SCRATCH)
5768     tmp2 = gen_reg_rtx (DImode);
5769
5770   emit_insn (gen_fctiwuz_<mode> (tmp1, src));
5771   emit_insn (gen_stfiwx (stack, tmp1));
5772   emit_insn (gen_lfiwzx (tmp2, stack));
5773   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
5774   DONE;
5775 }
5776   [(set_attr "type" "fpload")
5777    (set_attr "length" "16")])
5778
5779 ;; No VSX equivalent to fctid
5780 (define_insn "lrint<mode>di2"
5781   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5782         (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5783                    UNSPEC_FCTID))]
5784   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5785   "fctid %0,%1"
5786   [(set_attr "type" "fp")])
5787
5788 (define_expand "btrunc<mode>2"
5789   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5790         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
5791                      UNSPEC_FRIZ))]
5792   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5793   "")
5794
5795 (define_insn "*btrunc<mode>2_fpr"
5796   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5797         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5798                      UNSPEC_FRIZ))]
5799   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5800    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5801   "friz %0,%1"
5802   [(set_attr "type" "fp")])
5803
5804 (define_expand "ceil<mode>2"
5805   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5806         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
5807                      UNSPEC_FRIP))]
5808   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5809   "")
5810
5811 (define_insn "*ceil<mode>2_fpr"
5812   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5813         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5814                      UNSPEC_FRIP))]
5815   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5816    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5817   "frip %0,%1"
5818   [(set_attr "type" "fp")])
5819
5820 (define_expand "floor<mode>2"
5821   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5822         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
5823                      UNSPEC_FRIM))]
5824   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5825   "")
5826
5827 (define_insn "*floor<mode>2_fpr"
5828   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5829         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5830                      UNSPEC_FRIM))]
5831   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5832    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5833   "frim %0,%1"
5834   [(set_attr "type" "fp")])
5835
5836 ;; No VSX equivalent to frin
5837 (define_insn "round<mode>2"
5838   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5839         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5840                      UNSPEC_FRIN))]
5841   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5842   "frin %0,%1"
5843   [(set_attr "type" "fp")])
5844
5845 ; An UNSPEC is used so we don't have to support SImode in FP registers.
5846 (define_insn "stfiwx"
5847   [(set (match_operand:SI 0 "memory_operand" "=Z")
5848         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
5849                    UNSPEC_STFIWX))]
5850   "TARGET_PPC_GFXOPT"
5851   "stfiwx %1,%y0"
5852   [(set_attr "type" "fpstore")])
5853
5854 ;; If we don't have a direct conversion to single precision, don't enable this
5855 ;; conversion for 32-bit without fast math, because we don't have the insn to
5856 ;; generate the fixup swizzle to avoid double rounding problems.
5857 (define_expand "floatsisf2"
5858   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5859         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5860   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
5861    && (!TARGET_FPRS
5862        || (TARGET_FPRS
5863            && ((TARGET_FCFIDS && TARGET_LFIWAX)
5864                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
5865                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
5866   "
5867 {
5868   if (!TARGET_FPRS)
5869     {
5870       if (!REG_P (operands[1]))
5871         operands[1] = force_reg (SImode, operands[1]);
5872     }
5873   else if (TARGET_FCFIDS && TARGET_LFIWAX)
5874     {
5875       emit_insn (gen_floatsisf2_lfiwax (operands[0], operands[1]));
5876       DONE;
5877     }
5878   else if (TARGET_FCFID && TARGET_LFIWAX)
5879     {
5880       rtx dfreg = gen_reg_rtx (DFmode);
5881       emit_insn (gen_floatsidf2_lfiwax (dfreg, operands[1]));
5882       emit_insn (gen_truncdfsf2 (operands[0], dfreg));
5883       DONE;
5884     }
5885   else
5886     {
5887       rtx dreg = operands[1];
5888       if (!REG_P (dreg))
5889         dreg = force_reg (SImode, dreg);
5890       dreg = convert_to_mode (DImode, dreg, false);
5891       emit_insn (gen_floatdisf2 (operands[0], dreg));
5892       DONE;
5893     }
5894 }")
5895
5896 (define_expand "floatdidf2"
5897   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5898         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
5899   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
5900   "")
5901
5902 (define_insn "*floatdidf2_fpr"
5903   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5904         (float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
5905   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
5906    && !VECTOR_UNIT_VSX_P (DFmode)"
5907   "fcfid %0,%1"
5908   [(set_attr "type" "fp")])
5909
5910 ; Allow the combiner to merge source memory operands to the conversion so that
5911 ; the optimizer/register allocator doesn't try to load the value too early in a
5912 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
5913 ; hit.  We will split after reload to avoid the trip through the GPRs
5914
5915 (define_insn_and_split "*floatdidf2_mem"
5916   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5917         (float:DF (match_operand:DI 1 "memory_operand" "m")))
5918    (clobber (match_scratch:DI 2 "=d"))]
5919   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCFID"
5920   "#"
5921   "&& reload_completed"
5922   [(set (match_dup 2) (match_dup 1))
5923    (set (match_dup 0) (float:DF (match_dup 2)))]
5924   ""
5925   [(set_attr "length" "8")
5926    (set_attr "type" "fpload")])
5927
5928 (define_expand "floatunsdidf2"
5929   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5930         (unsigned_float:DF
5931          (match_operand:DI 1 "gpc_reg_operand" "")))]
5932   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
5933   "")
5934
5935 (define_insn "*floatunsdidf2_fcfidu"
5936   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5937         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
5938   "TARGET_HARD_FLOAT && TARGET_FCFIDU && !VECTOR_UNIT_VSX_P (DFmode)"
5939   "fcfidu %0,%1"
5940   [(set_attr "type" "fp")
5941    (set_attr "length" "4")])
5942
5943 (define_insn_and_split "*floatunsdidf2_mem"
5944   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5945         (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m")))
5946    (clobber (match_scratch:DI 2 "=d"))]
5947   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
5948   "#"
5949   "&& reload_completed"
5950   [(set (match_dup 2) (match_dup 1))
5951    (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
5952   ""
5953   [(set_attr "length" "8")
5954    (set_attr "type" "fpload")])
5955
5956 (define_expand "floatdisf2"
5957   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5958         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5959   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5960    && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
5961   "
5962 {
5963   if (!TARGET_FCFIDS)
5964     {
5965       rtx val = operands[1];
5966       if (!flag_unsafe_math_optimizations)
5967         {
5968           rtx label = gen_label_rtx ();
5969           val = gen_reg_rtx (DImode);
5970           emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5971           emit_label (label);
5972         }
5973       emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5974       DONE;
5975     }
5976 }")
5977
5978 (define_insn "floatdisf2_fcfids"
5979   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5980         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
5981   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5982    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
5983   "fcfids %0,%1"
5984   [(set_attr "type" "fp")])
5985
5986 (define_insn_and_split "*floatdisf2_mem"
5987   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5988         (float:SF (match_operand:DI 1 "memory_operand" "m")))
5989    (clobber (match_scratch:DI 2 "=f"))]
5990   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5991    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
5992   "#"
5993   "&& reload_completed"
5994   [(pc)]
5995   "
5996 {
5997   emit_move_insn (operands[2], operands[1]);
5998   emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
5999   DONE;
6000 }"
6001   [(set_attr "length" "8")])
6002
6003 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6004 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6005 ;; from double rounding.
6006 ;; Instead of creating a new cpu type for two FP operations, just use fp
6007 (define_insn_and_split "floatdisf2_internal1"
6008   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6009         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
6010    (clobber (match_scratch:DF 2 "=d"))]
6011   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6012   "#"
6013   "&& reload_completed"
6014   [(set (match_dup 2)
6015         (float:DF (match_dup 1)))
6016    (set (match_dup 0)
6017         (float_truncate:SF (match_dup 2)))]
6018   ""
6019   [(set_attr "length" "8")
6020    (set_attr "type" "fp")])
6021
6022 ;; Twiddles bits to avoid double rounding.
6023 ;; Bits that might be truncated when converting to DFmode are replaced
6024 ;; by a bit that won't be lost at that stage, but is below the SFmode
6025 ;; rounding position.
6026 (define_expand "floatdisf2_internal2"
6027   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6028                                    (const_int 53)))
6029    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6030                                                       (const_int 2047)))
6031               (clobber (scratch:CC))])
6032    (set (match_dup 3) (plus:DI (match_dup 3)
6033                                (const_int 1)))
6034    (set (match_dup 0) (plus:DI (match_dup 0)
6035                                (const_int 2047)))
6036    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6037                                      (const_int 2)))
6038    (set (match_dup 0) (ior:DI (match_dup 0)
6039                               (match_dup 1)))
6040    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6041                                          (const_int -2048)))
6042               (clobber (scratch:CC))])
6043    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6044                            (label_ref (match_operand:DI 2 "" ""))
6045                            (pc)))
6046    (set (match_dup 0) (match_dup 1))]
6047   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6048   "
6049 {
6050   operands[3] = gen_reg_rtx (DImode);
6051   operands[4] = gen_reg_rtx (CCUNSmode);
6052 }")
6053
6054 (define_expand "floatunsdisf2"
6055   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6056         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6057   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6058    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6059   "")
6060
6061 (define_insn "floatunsdisf2_fcfidus"
6062   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6063         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6064   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6065    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6066   "fcfidus %0,%1"
6067   [(set_attr "type" "fp")])
6068
6069 (define_insn_and_split "*floatunsdisf2_mem"
6070   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6071         (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m")))
6072    (clobber (match_scratch:DI 2 "=f"))]
6073   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6074    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6075   "#"
6076   "&& reload_completed"
6077   [(pc)]
6078   "
6079 {
6080   emit_move_insn (operands[2], operands[1]);
6081   emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
6082   DONE;
6083 }"
6084   [(set_attr "length" "8")
6085    (set_attr "type" "fpload")])
6086 \f
6087 ;; Define the DImode operations that can be done in a small number
6088 ;; of instructions.  The & constraints are to prevent the register
6089 ;; allocator from allocating registers that overlap with the inputs
6090 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6091 ;; also allow for the output being the same as one of the inputs.
6092
6093 (define_insn "*adddi3_noppc64"
6094   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6095         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6096                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6097   "! TARGET_POWERPC64"
6098   "*
6099 {
6100   if (WORDS_BIG_ENDIAN)
6101     return (GET_CODE (operands[2])) != CONST_INT
6102             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6103             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6104   else
6105     return (GET_CODE (operands[2])) != CONST_INT
6106             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6107             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6108 }"
6109   [(set_attr "type" "two")
6110    (set_attr "length" "8")])
6111
6112 (define_insn "*subdi3_noppc64"
6113   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6114         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6115                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6116   "! TARGET_POWERPC64"
6117   "*
6118 {
6119   if (WORDS_BIG_ENDIAN)
6120     return (GET_CODE (operands[1]) != CONST_INT)
6121             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6122             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6123   else
6124     return (GET_CODE (operands[1]) != CONST_INT)
6125             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6126             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6127 }"
6128   [(set_attr "type" "two")
6129    (set_attr "length" "8")])
6130
6131 (define_insn "*negdi2_noppc64"
6132   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6133         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6134   "! TARGET_POWERPC64"
6135   "*
6136 {
6137   return (WORDS_BIG_ENDIAN)
6138     ? \"subfic %L0,%L1,0\;subfze %0,%1\"
6139     : \"subfic %0,%1,0\;subfze %L0,%L1\";
6140 }"
6141   [(set_attr "type" "two")
6142    (set_attr "length" "8")])
6143
6144 (define_insn "mulsidi3"
6145   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6146         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6147                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6148   "! TARGET_POWERPC64"
6149 {
6150   return (WORDS_BIG_ENDIAN)
6151     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6152     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6153 }
6154   [(set_attr "type" "imul")
6155    (set_attr "length" "8")])
6156
6157 (define_split
6158   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6159         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6160                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6161   "! TARGET_POWERPC64 && reload_completed"
6162   [(set (match_dup 3)
6163         (truncate:SI
6164          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6165                                (sign_extend:DI (match_dup 2)))
6166                       (const_int 32))))
6167    (set (match_dup 4)
6168         (mult:SI (match_dup 1)
6169                  (match_dup 2)))]
6170   "
6171 {
6172   int endian = (WORDS_BIG_ENDIAN == 0);
6173   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6174   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6175 }")
6176
6177 (define_insn "umulsidi3"
6178   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6179         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6180                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6181   "! TARGET_POWERPC64"
6182   "*
6183 {
6184   return (WORDS_BIG_ENDIAN)
6185     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6186     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6187 }"
6188   [(set_attr "type" "imul")
6189    (set_attr "length" "8")])
6190
6191 (define_split
6192   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6193         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6194                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6195   "! TARGET_POWERPC64 && reload_completed"
6196   [(set (match_dup 3)
6197         (truncate:SI
6198          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6199                                (zero_extend:DI (match_dup 2)))
6200                       (const_int 32))))
6201    (set (match_dup 4)
6202         (mult:SI (match_dup 1)
6203                  (match_dup 2)))]
6204   "
6205 {
6206   int endian = (WORDS_BIG_ENDIAN == 0);
6207   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6208   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6209 }")
6210
6211 (define_insn "smulsi3_highpart"
6212   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6213         (truncate:SI
6214          (lshiftrt:DI (mult:DI (sign_extend:DI
6215                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6216                                (sign_extend:DI
6217                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6218                       (const_int 32))))]
6219   ""
6220   "mulhw %0,%1,%2"
6221   [(set_attr "type" "imul")])
6222
6223 (define_insn "umulsi3_highpart"
6224   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6225         (truncate:SI
6226          (lshiftrt:DI (mult:DI (zero_extend:DI
6227                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6228                                (zero_extend:DI
6229                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6230                       (const_int 32))))]
6231   ""
6232   "mulhwu %0,%1,%2"
6233   [(set_attr "type" "imul")])
6234
6235 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6236 ;; just handle shifts by constants.
6237 (define_insn "ashrdi3_no_power"
6238   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6239         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6240                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6241   "!TARGET_POWERPC64"
6242   "*
6243 {
6244   switch (which_alternative)
6245     {
6246     default:
6247       gcc_unreachable ();
6248     case 0:
6249       if (WORDS_BIG_ENDIAN)
6250         return \"srawi %0,%1,31\;srawi %L0,%1,%h2\";
6251       else
6252         return \"srawi %L0,%L1,31\;srawi %0,%L1,%h2\";
6253     case 1:
6254       if (WORDS_BIG_ENDIAN)
6255         return \"srwi %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;srawi %0,%1,%h2\";
6256       else
6257         return \"srwi %0,%1,%h2\;insrwi %0,%L1,%h2,0\;srawi %L0,%L1,%h2\";
6258     }
6259 }"
6260   [(set_attr "type" "two,three")
6261    (set_attr "length" "8,12")])
6262
6263 (define_insn "*ashrdisi3_noppc64"
6264   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6265         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6266                                 (const_int 32)) 4))]
6267   "TARGET_32BIT && !TARGET_POWERPC64"
6268   "*
6269 {
6270   if (REGNO (operands[0]) == REGNO (operands[1]))
6271     return \"\";
6272   else
6273     return \"mr %0,%1\";
6274 }"
6275    [(set_attr "length" "4")])
6276
6277 \f
6278 ;; PowerPC64 DImode operations.
6279
6280 (define_insn "muldi3"
6281   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6282         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6283                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6284   "TARGET_POWERPC64"
6285   "@
6286    mulld %0,%1,%2
6287    mulli %0,%1,%2"
6288    [(set (attr "type")
6289       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6290                 (const_string "imul3")
6291              (match_operand:SI 2 "short_cint_operand" "")
6292                 (const_string "imul2")]
6293         (const_string "lmul")))])
6294
6295 (define_insn "*muldi3_internal1"
6296   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6297         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6298                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6299                     (const_int 0)))
6300    (clobber (match_scratch:DI 3 "=r,r"))]
6301   "TARGET_POWERPC64"
6302   "@
6303    mulld. %3,%1,%2
6304    #"
6305   [(set_attr "type" "lmul_compare")
6306    (set_attr "length" "4,8")])
6307
6308 (define_split
6309   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6310         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6311                              (match_operand:DI 2 "gpc_reg_operand" ""))
6312                     (const_int 0)))
6313    (clobber (match_scratch:DI 3 ""))]
6314   "TARGET_POWERPC64 && reload_completed"
6315   [(set (match_dup 3)
6316         (mult:DI (match_dup 1) (match_dup 2)))
6317    (set (match_dup 0)
6318         (compare:CC (match_dup 3)
6319                     (const_int 0)))]
6320   "")
6321
6322 (define_insn "*muldi3_internal2"
6323   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6324         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6325                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6326                     (const_int 0)))
6327    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6328         (mult:DI (match_dup 1) (match_dup 2)))]
6329   "TARGET_POWERPC64"
6330   "@
6331    mulld. %0,%1,%2
6332    #"
6333   [(set_attr "type" "lmul_compare")
6334    (set_attr "length" "4,8")])
6335
6336 (define_split
6337   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6338         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6339                              (match_operand:DI 2 "gpc_reg_operand" ""))
6340                     (const_int 0)))
6341    (set (match_operand:DI 0 "gpc_reg_operand" "")
6342         (mult:DI (match_dup 1) (match_dup 2)))]
6343   "TARGET_POWERPC64 && reload_completed"
6344   [(set (match_dup 0)
6345         (mult:DI (match_dup 1) (match_dup 2)))
6346    (set (match_dup 3)
6347         (compare:CC (match_dup 0)
6348                     (const_int 0)))]
6349   "")
6350
6351 (define_insn "smuldi3_highpart"
6352   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6353         (truncate:DI
6354          (lshiftrt:TI (mult:TI (sign_extend:TI
6355                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6356                                (sign_extend:TI
6357                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6358                       (const_int 64))))]
6359   "TARGET_POWERPC64"
6360   "mulhd %0,%1,%2"
6361   [(set_attr "type" "lmul")])
6362
6363 (define_insn "umuldi3_highpart"
6364   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6365         (truncate:DI
6366          (lshiftrt:TI (mult:TI (zero_extend:TI
6367                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6368                                (zero_extend:TI
6369                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6370                       (const_int 64))))]
6371   "TARGET_POWERPC64"
6372   "mulhdu %0,%1,%2"
6373   [(set_attr "type" "lmul")])
6374
6375 (define_expand "mulditi3"
6376   [(set (match_operand:TI 0 "gpc_reg_operand")
6377         (mult:TI (sign_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6378                  (sign_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6379   "TARGET_POWERPC64"
6380 {
6381   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6382   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6383   emit_insn (gen_smuldi3_highpart (h, operands[1], operands[2]));
6384   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6385   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6386   DONE;
6387 })
6388
6389 (define_expand "umulditi3"
6390   [(set (match_operand:TI 0 "gpc_reg_operand")
6391         (mult:TI (zero_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6392                  (zero_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6393   "TARGET_POWERPC64"
6394 {
6395   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6396   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6397   emit_insn (gen_umuldi3_highpart (h, operands[1], operands[2]));
6398   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6399   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6400   DONE;
6401 })
6402
6403 (define_insn "rotldi3"
6404   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6405         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6406                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
6407   "TARGET_POWERPC64"
6408   "@
6409    rldcl %0,%1,%2,0
6410    rldicl %0,%1,%H2,0"
6411   [(set_attr "type" "var_shift_rotate,integer")])
6412
6413 (define_insn "*rotldi3_internal2"
6414   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6415         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6416                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6417                     (const_int 0)))
6418    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6419   "TARGET_64BIT"
6420   "@
6421    rldcl. %3,%1,%2,0
6422    rldicl. %3,%1,%H2,0
6423    #
6424    #"
6425   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6426    (set_attr "length" "4,4,8,8")])
6427
6428 (define_split
6429   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6430         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6431                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6432                     (const_int 0)))
6433    (clobber (match_scratch:DI 3 ""))]
6434   "TARGET_POWERPC64 && reload_completed"
6435   [(set (match_dup 3)
6436         (rotate:DI (match_dup 1) (match_dup 2)))
6437    (set (match_dup 0)
6438         (compare:CC (match_dup 3)
6439                     (const_int 0)))]
6440   "")
6441
6442 (define_insn "*rotldi3_internal3"
6443   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6444         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6445                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6446                     (const_int 0)))
6447    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6448         (rotate:DI (match_dup 1) (match_dup 2)))]
6449   "TARGET_64BIT"
6450   "@
6451    rldcl. %0,%1,%2,0
6452    rldicl. %0,%1,%H2,0
6453    #
6454    #"
6455   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6456    (set_attr "length" "4,4,8,8")])
6457
6458 (define_split
6459   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6460         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6461                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6462                     (const_int 0)))
6463    (set (match_operand:DI 0 "gpc_reg_operand" "")
6464         (rotate:DI (match_dup 1) (match_dup 2)))]
6465   "TARGET_POWERPC64 && reload_completed"
6466   [(set (match_dup 0)
6467         (rotate:DI (match_dup 1) (match_dup 2)))
6468    (set (match_dup 3)
6469         (compare:CC (match_dup 0)
6470                     (const_int 0)))]
6471   "")
6472
6473 (define_insn "*rotldi3_internal4"
6474   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6475         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6476                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
6477                 (match_operand:DI 3 "mask64_operand" "n,n")))]
6478   "TARGET_POWERPC64"
6479   "@
6480    rldc%B3 %0,%1,%2,%S3
6481    rldic%B3 %0,%1,%H2,%S3"
6482   [(set_attr "type" "var_shift_rotate,integer")])
6483
6484 (define_insn "*rotldi3_internal5"
6485   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6486         (compare:CC (and:DI
6487                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6488                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6489                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6490                     (const_int 0)))
6491    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
6492   "TARGET_64BIT"
6493   "@
6494    rldc%B3. %4,%1,%2,%S3
6495    rldic%B3. %4,%1,%H2,%S3
6496    #
6497    #"
6498   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6499    (set_attr "length" "4,4,8,8")])
6500
6501 (define_split
6502   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6503         (compare:CC (and:DI
6504                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6505                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6506                      (match_operand:DI 3 "mask64_operand" ""))
6507                     (const_int 0)))
6508    (clobber (match_scratch:DI 4 ""))]
6509   "TARGET_POWERPC64 && reload_completed"
6510   [(set (match_dup 4)
6511         (and:DI (rotate:DI (match_dup 1)
6512                                 (match_dup 2))
6513                      (match_dup 3)))
6514    (set (match_dup 0)
6515         (compare:CC (match_dup 4)
6516                     (const_int 0)))]
6517   "")
6518
6519 (define_insn "*rotldi3_internal6"
6520   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
6521         (compare:CC (and:DI
6522                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6523                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6524                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6525                     (const_int 0)))
6526    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6527         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6528   "TARGET_64BIT"
6529   "@
6530    rldc%B3. %0,%1,%2,%S3
6531    rldic%B3. %0,%1,%H2,%S3
6532    #
6533    #"
6534   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6535    (set_attr "length" "4,4,8,8")])
6536
6537 (define_split
6538   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
6539         (compare:CC (and:DI
6540                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6541                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6542                      (match_operand:DI 3 "mask64_operand" ""))
6543                     (const_int 0)))
6544    (set (match_operand:DI 0 "gpc_reg_operand" "")
6545         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6546   "TARGET_POWERPC64 && reload_completed"
6547   [(set (match_dup 0)
6548         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6549    (set (match_dup 4)
6550         (compare:CC (match_dup 0)
6551                     (const_int 0)))]
6552   "")
6553
6554 (define_insn "*rotldi3_internal7"
6555   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6556         (zero_extend:DI
6557          (subreg:QI
6558           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6559                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6560   "TARGET_POWERPC64"
6561   "@
6562    rldcl %0,%1,%2,56
6563    rldicl %0,%1,%H2,56"
6564   [(set_attr "type" "var_shift_rotate,integer")])
6565
6566 (define_insn "*rotldi3_internal8"
6567   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6568         (compare:CC (zero_extend:DI
6569                      (subreg:QI
6570                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6571                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6572                     (const_int 0)))
6573    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6574   "TARGET_64BIT"
6575   "@
6576    rldcl. %3,%1,%2,56
6577    rldicl. %3,%1,%H2,56
6578    #
6579    #"
6580   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6581    (set_attr "length" "4,4,8,8")])
6582
6583 (define_split
6584   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6585         (compare:CC (zero_extend:DI
6586                      (subreg:QI
6587                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6588                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6589                     (const_int 0)))
6590    (clobber (match_scratch:DI 3 ""))]
6591   "TARGET_POWERPC64 && reload_completed"
6592   [(set (match_dup 3)
6593         (zero_extend:DI (subreg:QI
6594                       (rotate:DI (match_dup 1)
6595                                  (match_dup 2)) 0)))
6596    (set (match_dup 0)
6597         (compare:CC (match_dup 3)
6598                     (const_int 0)))]
6599   "")
6600
6601 (define_insn "*rotldi3_internal9"
6602   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6603         (compare:CC (zero_extend:DI
6604                      (subreg:QI
6605                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6606                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6607                     (const_int 0)))
6608    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6609         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6610   "TARGET_64BIT"
6611   "@
6612    rldcl. %0,%1,%2,56
6613    rldicl. %0,%1,%H2,56
6614    #
6615    #"
6616   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6617    (set_attr "length" "4,4,8,8")])
6618
6619 (define_split
6620   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6621         (compare:CC (zero_extend:DI
6622                      (subreg:QI
6623                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6624                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6625                     (const_int 0)))
6626    (set (match_operand:DI 0 "gpc_reg_operand" "")
6627         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6628   "TARGET_POWERPC64 && reload_completed"
6629   [(set (match_dup 0)
6630         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6631    (set (match_dup 3)
6632         (compare:CC (match_dup 0)
6633                     (const_int 0)))]
6634   "")
6635
6636 (define_insn "*rotldi3_internal10"
6637   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6638         (zero_extend:DI
6639          (subreg:HI
6640           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6641                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6642   "TARGET_POWERPC64"
6643   "@
6644    rldcl %0,%1,%2,48
6645    rldicl %0,%1,%H2,48"
6646   [(set_attr "type" "var_shift_rotate,integer")])
6647
6648 (define_insn "*rotldi3_internal11"
6649   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6650         (compare:CC (zero_extend:DI
6651                      (subreg:HI
6652                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6653                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6654                     (const_int 0)))
6655    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6656   "TARGET_64BIT"
6657   "@
6658    rldcl. %3,%1,%2,48
6659    rldicl. %3,%1,%H2,48
6660    #
6661    #"
6662   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6663    (set_attr "length" "4,4,8,8")])
6664
6665 (define_split
6666   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6667         (compare:CC (zero_extend:DI
6668                      (subreg:HI
6669                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6670                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6671                     (const_int 0)))
6672    (clobber (match_scratch:DI 3 ""))]
6673   "TARGET_POWERPC64 && reload_completed"
6674   [(set (match_dup 3)
6675         (zero_extend:DI (subreg:HI
6676                       (rotate:DI (match_dup 1)
6677                                  (match_dup 2)) 0)))
6678    (set (match_dup 0)
6679         (compare:CC (match_dup 3)
6680                     (const_int 0)))]
6681   "")
6682
6683 (define_insn "*rotldi3_internal12"
6684   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6685         (compare:CC (zero_extend:DI
6686                      (subreg:HI
6687                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6688                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6689                     (const_int 0)))
6690    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6691         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6692   "TARGET_64BIT"
6693   "@
6694    rldcl. %0,%1,%2,48
6695    rldicl. %0,%1,%H2,48
6696    #
6697    #"
6698   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6699    (set_attr "length" "4,4,8,8")])
6700
6701 (define_split
6702   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6703         (compare:CC (zero_extend:DI
6704                      (subreg:HI
6705                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6706                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6707                     (const_int 0)))
6708    (set (match_operand:DI 0 "gpc_reg_operand" "")
6709         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6710   "TARGET_POWERPC64 && reload_completed"
6711   [(set (match_dup 0)
6712         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6713    (set (match_dup 3)
6714         (compare:CC (match_dup 0)
6715                     (const_int 0)))]
6716   "")
6717
6718 (define_insn "*rotldi3_internal13"
6719   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6720         (zero_extend:DI
6721          (subreg:SI
6722           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6723                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6724   "TARGET_POWERPC64"
6725   "@
6726    rldcl %0,%1,%2,32
6727    rldicl %0,%1,%H2,32"
6728   [(set_attr "type" "var_shift_rotate,integer")])
6729
6730 (define_insn "*rotldi3_internal14"
6731   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6732         (compare:CC (zero_extend:DI
6733                      (subreg:SI
6734                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6735                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6736                     (const_int 0)))
6737    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6738   "TARGET_64BIT"
6739   "@
6740    rldcl. %3,%1,%2,32
6741    rldicl. %3,%1,%H2,32
6742    #
6743    #"
6744   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6745    (set_attr "length" "4,4,8,8")])
6746
6747 (define_split
6748   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6749         (compare:CC (zero_extend:DI
6750                      (subreg:SI
6751                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6752                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6753                     (const_int 0)))
6754    (clobber (match_scratch:DI 3 ""))]
6755   "TARGET_POWERPC64 && reload_completed"
6756   [(set (match_dup 3)
6757         (zero_extend:DI (subreg:SI
6758                       (rotate:DI (match_dup 1)
6759                                  (match_dup 2)) 0)))
6760    (set (match_dup 0)
6761         (compare:CC (match_dup 3)
6762                     (const_int 0)))]
6763   "")
6764
6765 (define_insn "*rotldi3_internal15"
6766   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6767         (compare:CC (zero_extend:DI
6768                      (subreg:SI
6769                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6770                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6771                     (const_int 0)))
6772    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6773         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6774   "TARGET_64BIT"
6775   "@
6776    rldcl. %0,%1,%2,32
6777    rldicl. %0,%1,%H2,32
6778    #
6779    #"
6780   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6781    (set_attr "length" "4,4,8,8")])
6782
6783 (define_split
6784   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6785         (compare:CC (zero_extend:DI
6786                      (subreg:SI
6787                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6788                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6789                     (const_int 0)))
6790    (set (match_operand:DI 0 "gpc_reg_operand" "")
6791         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6792   "TARGET_POWERPC64 && reload_completed"
6793   [(set (match_dup 0)
6794         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6795    (set (match_dup 3)
6796         (compare:CC (match_dup 0)
6797                     (const_int 0)))]
6798   "")
6799
6800 (define_expand "ashldi3"
6801   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6802         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6803                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6804   "TARGET_POWERPC64"
6805   "")
6806
6807 (define_insn "*ashldi3_internal1"
6808   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6809         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6810                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
6811   "TARGET_POWERPC64"
6812   "@
6813    sld %0,%1,%2
6814    sldi %0,%1,%H2"
6815   [(set_attr "type" "var_shift_rotate,shift")])
6816
6817 (define_insn "*ashldi3_internal2"
6818   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6819         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6820                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
6821                     (const_int 0)))
6822    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6823   "TARGET_64BIT"
6824   "@
6825    sld. %3,%1,%2
6826    sldi. %3,%1,%H2
6827    #
6828    #"
6829   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6830    (set_attr "length" "4,4,8,8")])
6831
6832 (define_split
6833   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6834         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6835                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6836                     (const_int 0)))
6837    (clobber (match_scratch:DI 3 ""))]
6838   "TARGET_POWERPC64 && reload_completed"
6839   [(set (match_dup 3)
6840         (ashift:DI (match_dup 1) (match_dup 2)))
6841    (set (match_dup 0)
6842         (compare:CC (match_dup 3)
6843                     (const_int 0)))]
6844   "")
6845
6846 (define_insn "*ashldi3_internal3"
6847   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6848         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6849                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
6850                     (const_int 0)))
6851    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6852         (ashift:DI (match_dup 1) (match_dup 2)))]
6853   "TARGET_64BIT"
6854   "@
6855    sld. %0,%1,%2
6856    sldi. %0,%1,%H2
6857    #
6858    #"
6859   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6860    (set_attr "length" "4,4,8,8")])
6861
6862 (define_split
6863   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6864         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6865                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6866                     (const_int 0)))
6867    (set (match_operand:DI 0 "gpc_reg_operand" "")
6868         (ashift:DI (match_dup 1) (match_dup 2)))]
6869   "TARGET_POWERPC64 && reload_completed"
6870   [(set (match_dup 0)
6871         (ashift:DI (match_dup 1) (match_dup 2)))
6872    (set (match_dup 3)
6873         (compare:CC (match_dup 0)
6874                     (const_int 0)))]
6875   "")
6876
6877 (define_insn "*ashldi3_internal4"
6878   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6879         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6880                            (match_operand:SI 2 "const_int_operand" "i"))
6881                 (match_operand:DI 3 "const_int_operand" "n")))]
6882   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6883   "rldic %0,%1,%H2,%W3")
6884
6885 (define_insn "ashldi3_internal5"
6886   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6887         (compare:CC
6888          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6889                             (match_operand:SI 2 "const_int_operand" "i,i"))
6890                  (match_operand:DI 3 "const_int_operand" "n,n"))
6891          (const_int 0)))
6892    (clobber (match_scratch:DI 4 "=r,r"))]
6893   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6894   "@
6895    rldic. %4,%1,%H2,%W3
6896    #"
6897   [(set_attr "type" "compare")
6898    (set_attr "length" "4,8")])
6899
6900 (define_split
6901   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6902         (compare:CC
6903          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6904                             (match_operand:SI 2 "const_int_operand" ""))
6905                  (match_operand:DI 3 "const_int_operand" ""))
6906          (const_int 0)))
6907    (clobber (match_scratch:DI 4 ""))]
6908   "TARGET_POWERPC64 && reload_completed
6909    && includes_rldic_lshift_p (operands[2], operands[3])"
6910   [(set (match_dup 4)
6911         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6912                 (match_dup 3)))
6913    (set (match_dup 0)
6914         (compare:CC (match_dup 4)
6915                     (const_int 0)))]
6916   "")
6917
6918 (define_insn "*ashldi3_internal6"
6919   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6920         (compare:CC
6921          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6922                             (match_operand:SI 2 "const_int_operand" "i,i"))
6923                     (match_operand:DI 3 "const_int_operand" "n,n"))
6924          (const_int 0)))
6925    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6926         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6927   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6928   "@
6929    rldic. %0,%1,%H2,%W3
6930    #"
6931   [(set_attr "type" "compare")
6932    (set_attr "length" "4,8")])
6933
6934 (define_split
6935   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
6936         (compare:CC
6937          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6938                             (match_operand:SI 2 "const_int_operand" ""))
6939                  (match_operand:DI 3 "const_int_operand" ""))
6940          (const_int 0)))
6941    (set (match_operand:DI 0 "gpc_reg_operand" "")
6942         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6943   "TARGET_POWERPC64 && reload_completed
6944    && includes_rldic_lshift_p (operands[2], operands[3])"
6945   [(set (match_dup 0)
6946         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6947                 (match_dup 3)))
6948    (set (match_dup 4)
6949         (compare:CC (match_dup 0)
6950                     (const_int 0)))]
6951   "")
6952
6953 (define_insn "*ashldi3_internal7"
6954   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6955         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6956                            (match_operand:SI 2 "const_int_operand" "i"))
6957                 (match_operand:DI 3 "mask64_operand" "n")))]
6958   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6959   "rldicr %0,%1,%H2,%S3")
6960
6961 (define_insn "ashldi3_internal8"
6962   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6963         (compare:CC
6964          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6965                             (match_operand:SI 2 "const_int_operand" "i,i"))
6966                  (match_operand:DI 3 "mask64_operand" "n,n"))
6967          (const_int 0)))
6968    (clobber (match_scratch:DI 4 "=r,r"))]
6969   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6970   "@
6971    rldicr. %4,%1,%H2,%S3
6972    #"
6973   [(set_attr "type" "compare")
6974    (set_attr "length" "4,8")])
6975
6976 (define_split
6977   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6978         (compare:CC
6979          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6980                             (match_operand:SI 2 "const_int_operand" ""))
6981                  (match_operand:DI 3 "mask64_operand" ""))
6982          (const_int 0)))
6983    (clobber (match_scratch:DI 4 ""))]
6984   "TARGET_POWERPC64 && reload_completed
6985    && includes_rldicr_lshift_p (operands[2], operands[3])"
6986   [(set (match_dup 4)
6987         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6988                 (match_dup 3)))
6989    (set (match_dup 0)
6990         (compare:CC (match_dup 4)
6991                     (const_int 0)))]
6992   "")
6993
6994 (define_insn "*ashldi3_internal9"
6995   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6996         (compare:CC
6997          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6998                             (match_operand:SI 2 "const_int_operand" "i,i"))
6999                     (match_operand:DI 3 "mask64_operand" "n,n"))
7000          (const_int 0)))
7001    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7002         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7003   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7004   "@
7005    rldicr. %0,%1,%H2,%S3
7006    #"
7007   [(set_attr "type" "compare")
7008    (set_attr "length" "4,8")])
7009
7010 (define_split
7011   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7012         (compare:CC
7013          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7014                             (match_operand:SI 2 "const_int_operand" ""))
7015                  (match_operand:DI 3 "mask64_operand" ""))
7016          (const_int 0)))
7017    (set (match_operand:DI 0 "gpc_reg_operand" "")
7018         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7019   "TARGET_POWERPC64 && reload_completed
7020    && includes_rldicr_lshift_p (operands[2], operands[3])"
7021   [(set (match_dup 0)
7022         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7023                 (match_dup 3)))
7024    (set (match_dup 4)
7025         (compare:CC (match_dup 0)
7026                     (const_int 0)))]
7027   "")
7028
7029 (define_expand "lshrdi3"
7030   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7031         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7032                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7033   "TARGET_POWERPC64"
7034   "")
7035
7036 (define_insn "*lshrdi3_internal1"
7037   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7038         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7039                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7040   "TARGET_POWERPC64"
7041   "@
7042    srd %0,%1,%2
7043    srdi %0,%1,%H2"
7044   [(set_attr "type" "var_shift_rotate,shift")])
7045
7046 (define_insn "*lshrdi3_internal2"
7047   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7048         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7049                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7050                     (const_int 0)))
7051    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7052   "TARGET_64BIT "
7053   "@
7054    srd. %3,%1,%2
7055    srdi. %3,%1,%H2
7056    #
7057    #"
7058   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7059    (set_attr "length" "4,4,8,8")])
7060
7061 (define_split
7062   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7063         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7064                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7065                     (const_int 0)))
7066    (clobber (match_scratch:DI 3 ""))]
7067   "TARGET_POWERPC64 && reload_completed"
7068   [(set (match_dup 3)
7069         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7070    (set (match_dup 0)
7071         (compare:CC (match_dup 3)
7072                     (const_int 0)))]
7073   "")
7074
7075 (define_insn "*lshrdi3_internal3"
7076   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7077         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7078                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7079                     (const_int 0)))
7080    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7081         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7082   "TARGET_64BIT"
7083   "@
7084    srd. %0,%1,%2
7085    srdi. %0,%1,%H2
7086    #
7087    #"
7088   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7089    (set_attr "length" "4,4,8,8")])
7090
7091 (define_split
7092   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7093         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7094                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7095                     (const_int 0)))
7096    (set (match_operand:DI 0 "gpc_reg_operand" "")
7097         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7098   "TARGET_POWERPC64 && reload_completed"
7099   [(set (match_dup 0)
7100         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7101    (set (match_dup 3)
7102         (compare:CC (match_dup 0)
7103                     (const_int 0)))]
7104   "")
7105
7106 (define_expand "ashrdi3"
7107   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7108         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7109                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7110   ""
7111   "
7112 {
7113   if (TARGET_POWERPC64)
7114     ;
7115   else if (GET_CODE (operands[2]) == CONST_INT)
7116     {
7117       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7118       DONE;
7119     }
7120   else
7121     FAIL;
7122 }")
7123
7124 (define_insn "*ashrdi3_internal1"
7125   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7126         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7127                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7128   "TARGET_POWERPC64"
7129   "@
7130    srad %0,%1,%2
7131    sradi %0,%1,%H2"
7132   [(set_attr "type" "var_shift_rotate,shift")])
7133
7134 (define_insn "*ashrdi3_internal2"
7135   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7136         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7137                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7138                     (const_int 0)))
7139    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7140   "TARGET_64BIT"
7141   "@
7142    srad. %3,%1,%2
7143    sradi. %3,%1,%H2
7144    #
7145    #"
7146   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7147    (set_attr "length" "4,4,8,8")])
7148
7149 (define_split
7150   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7151         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7152                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7153                     (const_int 0)))
7154    (clobber (match_scratch:DI 3 ""))]
7155   "TARGET_POWERPC64 && reload_completed"
7156   [(set (match_dup 3)
7157         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7158    (set (match_dup 0)
7159         (compare:CC (match_dup 3)
7160                     (const_int 0)))]
7161   "")
7162
7163 (define_insn "*ashrdi3_internal3"
7164   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7165         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7166                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7167                     (const_int 0)))
7168    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7169         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7170   "TARGET_64BIT"
7171   "@
7172    srad. %0,%1,%2
7173    sradi. %0,%1,%H2
7174    #
7175    #"
7176   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7177    (set_attr "length" "4,4,8,8")])
7178
7179 (define_split
7180   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7181         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7182                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7183                     (const_int 0)))
7184    (set (match_operand:DI 0 "gpc_reg_operand" "")
7185         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7186   "TARGET_POWERPC64 && reload_completed"
7187   [(set (match_dup 0)
7188         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7189    (set (match_dup 3)
7190         (compare:CC (match_dup 0)
7191                     (const_int 0)))]
7192   "")
7193
7194 (define_expand "anddi3"
7195   [(parallel
7196     [(set (match_operand:DI 0 "gpc_reg_operand" "")
7197           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7198                   (match_operand:DI 2 "and64_2_operand" "")))
7199      (clobber (match_scratch:CC 3 ""))])]
7200   "TARGET_POWERPC64"
7201   "")
7202
7203 (define_insn "anddi3_mc"
7204   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7205         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7206                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7207    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7208   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
7209   "@
7210    and %0,%1,%2
7211    rldic%B2 %0,%1,0,%S2
7212    rlwinm %0,%1,0,%m2,%M2
7213    andi. %0,%1,%b2
7214    andis. %0,%1,%u2
7215    #"
7216   [(set_attr "type" "*,*,*,fast_compare,fast_compare,*")
7217    (set_attr "length" "4,4,4,4,4,8")])
7218
7219 (define_insn "anddi3_nomc"
7220   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7221         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
7222                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
7223    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
7224   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
7225   "@
7226    and %0,%1,%2
7227    rldic%B2 %0,%1,0,%S2
7228    rlwinm %0,%1,0,%m2,%M2
7229    #"
7230   [(set_attr "length" "4,4,4,8")])
7231
7232 (define_split
7233   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7234         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7235                 (match_operand:DI 2 "mask64_2_operand" "")))
7236    (clobber (match_scratch:CC 3 ""))]
7237   "TARGET_POWERPC64
7238     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7239     && !mask_operand (operands[2], DImode)
7240     && !mask64_operand (operands[2], DImode)"
7241   [(set (match_dup 0)
7242         (and:DI (rotate:DI (match_dup 1)
7243                            (match_dup 4))
7244                 (match_dup 5)))
7245    (set (match_dup 0)
7246         (and:DI (rotate:DI (match_dup 0)
7247                            (match_dup 6))
7248                 (match_dup 7)))]
7249 {
7250   build_mask64_2_operands (operands[2], &operands[4]);
7251 })
7252
7253 (define_insn "*anddi3_internal2_mc"
7254   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7255         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7256                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7257                     (const_int 0)))
7258    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
7259    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7260   "TARGET_64BIT && rs6000_gen_cell_microcode"
7261   "@
7262    and. %3,%1,%2
7263    rldic%B2. %3,%1,0,%S2
7264    rlwinm. %3,%1,0,%m2,%M2
7265    andi. %3,%1,%b2
7266    andis. %3,%1,%u2
7267    #
7268    #
7269    #
7270    #
7271    #
7272    #
7273    #"
7274   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
7275                      fast_compare,compare,compare,compare,compare,compare,\
7276                      compare,compare")
7277    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7278
7279 (define_split
7280   [(set (match_operand:CC 0 "cc_reg_operand" "")
7281         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7282                             (match_operand:DI 2 "mask64_2_operand" ""))
7283                     (const_int 0)))
7284    (clobber (match_scratch:DI 3 ""))
7285    (clobber (match_scratch:CC 4 ""))]
7286   "TARGET_64BIT && reload_completed
7287     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7288     && !mask_operand (operands[2], DImode)
7289     && !mask64_operand (operands[2], DImode)"
7290   [(set (match_dup 3)
7291         (and:DI (rotate:DI (match_dup 1)
7292                            (match_dup 5))
7293                 (match_dup 6)))
7294    (parallel [(set (match_dup 0)
7295                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7296                                                   (match_dup 7))
7297                                        (match_dup 8))
7298                                (const_int 0)))
7299               (clobber (match_dup 3))])]
7300   "
7301 {
7302   build_mask64_2_operands (operands[2], &operands[5]);
7303 }")
7304
7305 (define_insn "*anddi3_internal3_mc"
7306   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7307         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7308                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7309                     (const_int 0)))
7310    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
7311         (and:DI (match_dup 1) (match_dup 2)))
7312    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7313   "TARGET_64BIT && rs6000_gen_cell_microcode"
7314   "@
7315    and. %0,%1,%2
7316    rldic%B2. %0,%1,0,%S2
7317    rlwinm. %0,%1,0,%m2,%M2
7318    andi. %0,%1,%b2
7319    andis. %0,%1,%u2
7320    #
7321    #
7322    #
7323    #
7324    #
7325    #
7326    #"
7327   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
7328                      fast_compare,compare,compare,compare,compare,compare,\
7329                      compare,compare")
7330    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7331
7332 (define_split
7333   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7334         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7335                             (match_operand:DI 2 "and64_2_operand" ""))
7336                     (const_int 0)))
7337    (set (match_operand:DI 0 "gpc_reg_operand" "")
7338         (and:DI (match_dup 1) (match_dup 2)))
7339    (clobber (match_scratch:CC 4 ""))]
7340   "TARGET_64BIT && reload_completed"
7341   [(parallel [(set (match_dup 0)
7342                     (and:DI (match_dup 1) (match_dup 2)))
7343                (clobber (match_dup 4))])
7344    (set (match_dup 3)
7345         (compare:CC (match_dup 0)
7346                     (const_int 0)))]
7347   "")
7348
7349 (define_split
7350   [(set (match_operand:CC 3 "cc_reg_operand" "")
7351         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7352                             (match_operand:DI 2 "mask64_2_operand" ""))
7353                     (const_int 0)))
7354    (set (match_operand:DI 0 "gpc_reg_operand" "")
7355         (and:DI (match_dup 1) (match_dup 2)))
7356    (clobber (match_scratch:CC 4 ""))]
7357   "TARGET_64BIT && reload_completed
7358     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7359     && !mask_operand (operands[2], DImode)
7360     && !mask64_operand (operands[2], DImode)"
7361   [(set (match_dup 0)
7362         (and:DI (rotate:DI (match_dup 1)
7363                            (match_dup 5))
7364                 (match_dup 6)))
7365    (parallel [(set (match_dup 3)
7366                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7367                                                   (match_dup 7))
7368                                        (match_dup 8))
7369                                (const_int 0)))
7370               (set (match_dup 0)
7371                    (and:DI (rotate:DI (match_dup 0)
7372                                       (match_dup 7))
7373                            (match_dup 8)))])]
7374   "
7375 {
7376   build_mask64_2_operands (operands[2], &operands[5]);
7377 }")
7378
7379 (define_expand "iordi3"
7380   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7381         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7382                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7383   "TARGET_POWERPC64"
7384   "
7385 {
7386   if (non_logical_cint_operand (operands[2], DImode))
7387     {
7388       HOST_WIDE_INT value;
7389       rtx tmp = ((!can_create_pseudo_p ()
7390                   || rtx_equal_p (operands[0], operands[1]))
7391                  ? operands[0] : gen_reg_rtx (DImode));
7392
7393       if (GET_CODE (operands[2]) == CONST_INT)
7394         {
7395           value = INTVAL (operands[2]);
7396           emit_insn (gen_iordi3 (tmp, operands[1],
7397                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7398         }
7399       else
7400         {
7401           value = CONST_DOUBLE_LOW (operands[2]);
7402           emit_insn (gen_iordi3 (tmp, operands[1],
7403                                  immed_double_const (value
7404                                                      & (~ (HOST_WIDE_INT) 0xffff),
7405                                                      0, DImode)));
7406         }
7407
7408       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7409       DONE;
7410     }
7411 }")
7412
7413 (define_expand "xordi3"
7414   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7415         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7416                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7417   "TARGET_POWERPC64"
7418   "
7419 {
7420   if (non_logical_cint_operand (operands[2], DImode))
7421     {
7422       HOST_WIDE_INT value;
7423       rtx tmp = ((!can_create_pseudo_p ()
7424                   || rtx_equal_p (operands[0], operands[1]))
7425                  ? operands[0] : gen_reg_rtx (DImode));
7426
7427       if (GET_CODE (operands[2]) == CONST_INT)
7428         {
7429           value = INTVAL (operands[2]);
7430           emit_insn (gen_xordi3 (tmp, operands[1],
7431                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7432         }
7433       else
7434         {
7435           value = CONST_DOUBLE_LOW (operands[2]);
7436           emit_insn (gen_xordi3 (tmp, operands[1],
7437                                  immed_double_const (value
7438                                                      & (~ (HOST_WIDE_INT) 0xffff),
7439                                                      0, DImode)));
7440         }
7441
7442       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7443       DONE;
7444     }
7445 }")
7446
7447 (define_insn "*booldi3_internal1"
7448   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7449         (match_operator:DI 3 "boolean_or_operator"
7450          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7451           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7452   "TARGET_POWERPC64"
7453   "@
7454    %q3 %0,%1,%2
7455    %q3i %0,%1,%b2
7456    %q3is %0,%1,%u2")
7457
7458 (define_insn "*booldi3_internal2"
7459   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7460         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7461          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7462           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7463          (const_int 0)))
7464    (clobber (match_scratch:DI 3 "=r,r"))]
7465   "TARGET_64BIT"
7466   "@
7467    %q4. %3,%1,%2
7468    #"
7469   [(set_attr "type" "fast_compare,compare")
7470    (set_attr "length" "4,8")])
7471
7472 (define_split
7473   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7474         (compare:CC (match_operator:DI 4 "boolean_operator"
7475          [(match_operand:DI 1 "gpc_reg_operand" "")
7476           (match_operand:DI 2 "gpc_reg_operand" "")])
7477          (const_int 0)))
7478    (clobber (match_scratch:DI 3 ""))]
7479   "TARGET_POWERPC64 && reload_completed"
7480   [(set (match_dup 3) (match_dup 4))
7481    (set (match_dup 0)
7482         (compare:CC (match_dup 3)
7483                     (const_int 0)))]
7484   "")
7485
7486 (define_insn "*booldi3_internal3"
7487   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7488         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7489          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7490           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7491          (const_int 0)))
7492    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7493         (match_dup 4))]
7494   "TARGET_64BIT"
7495   "@
7496    %q4. %0,%1,%2
7497    #"
7498   [(set_attr "type" "fast_compare,compare")
7499    (set_attr "length" "4,8")])
7500
7501 (define_split
7502   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7503         (compare:CC (match_operator:DI 4 "boolean_operator"
7504          [(match_operand:DI 1 "gpc_reg_operand" "")
7505           (match_operand:DI 2 "gpc_reg_operand" "")])
7506          (const_int 0)))
7507    (set (match_operand:DI 0 "gpc_reg_operand" "")
7508         (match_dup 4))]
7509   "TARGET_POWERPC64 && reload_completed"
7510   [(set (match_dup 0) (match_dup 4))
7511    (set (match_dup 3)
7512         (compare:CC (match_dup 0)
7513                     (const_int 0)))]
7514   "")
7515
7516 ;; Split a logical operation that we can't do in one insn into two insns,
7517 ;; each of which does one 16-bit part.  This is used by combine.
7518
7519 (define_split
7520   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7521         (match_operator:DI 3 "boolean_or_operator"
7522          [(match_operand:DI 1 "gpc_reg_operand" "")
7523           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7524   "TARGET_POWERPC64"
7525   [(set (match_dup 0) (match_dup 4))
7526    (set (match_dup 0) (match_dup 5))]
7527 "
7528 {
7529   rtx i3,i4;
7530
7531   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7532     {
7533       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7534       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7535                                         0, DImode);
7536       i4 = GEN_INT (value & 0xffff);
7537     }
7538   else
7539     {
7540       i3 = GEN_INT (INTVAL (operands[2])
7541                              & (~ (HOST_WIDE_INT) 0xffff));
7542       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7543     }
7544   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7545                                 operands[1], i3);
7546   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7547                                 operands[0], i4);
7548 }")
7549
7550 (define_insn "*boolcdi3_internal1"
7551   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7552         (match_operator:DI 3 "boolean_operator"
7553          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7554           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7555   "TARGET_POWERPC64"
7556   "%q3 %0,%2,%1")
7557
7558 (define_insn "*boolcdi3_internal2"
7559   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7560         (compare:CC (match_operator:DI 4 "boolean_operator"
7561          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7562           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7563          (const_int 0)))
7564    (clobber (match_scratch:DI 3 "=r,r"))]
7565   "TARGET_64BIT"
7566   "@
7567    %q4. %3,%2,%1
7568    #"
7569   [(set_attr "type" "fast_compare,compare")
7570    (set_attr "length" "4,8")])
7571
7572 (define_split
7573   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7574         (compare:CC (match_operator:DI 4 "boolean_operator"
7575          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7576           (match_operand:DI 2 "gpc_reg_operand" "")])
7577          (const_int 0)))
7578    (clobber (match_scratch:DI 3 ""))]
7579   "TARGET_POWERPC64 && reload_completed"
7580   [(set (match_dup 3) (match_dup 4))
7581    (set (match_dup 0)
7582         (compare:CC (match_dup 3)
7583                     (const_int 0)))]
7584   "")
7585
7586 (define_insn "*boolcdi3_internal3"
7587   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7588         (compare:CC (match_operator:DI 4 "boolean_operator"
7589          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7590           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7591          (const_int 0)))
7592    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7593         (match_dup 4))]
7594   "TARGET_64BIT"
7595   "@
7596    %q4. %0,%2,%1
7597    #"
7598   [(set_attr "type" "fast_compare,compare")
7599    (set_attr "length" "4,8")])
7600
7601 (define_split
7602   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7603         (compare:CC (match_operator:DI 4 "boolean_operator"
7604          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7605           (match_operand:DI 2 "gpc_reg_operand" "")])
7606          (const_int 0)))
7607    (set (match_operand:DI 0 "gpc_reg_operand" "")
7608         (match_dup 4))]
7609   "TARGET_POWERPC64 && reload_completed"
7610   [(set (match_dup 0) (match_dup 4))
7611    (set (match_dup 3)
7612         (compare:CC (match_dup 0)
7613                     (const_int 0)))]
7614   "")
7615
7616 (define_insn "*boolccdi3_internal1"
7617   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7618         (match_operator:DI 3 "boolean_operator"
7619          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7620           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7621   "TARGET_POWERPC64"
7622   "%q3 %0,%1,%2")
7623
7624 (define_insn "*boolccdi3_internal2"
7625   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7626         (compare:CC (match_operator:DI 4 "boolean_operator"
7627          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7628           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7629          (const_int 0)))
7630    (clobber (match_scratch:DI 3 "=r,r"))]
7631   "TARGET_64BIT"
7632   "@
7633    %q4. %3,%1,%2
7634    #"
7635   [(set_attr "type" "fast_compare,compare")
7636    (set_attr "length" "4,8")])
7637
7638 (define_split
7639   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7640         (compare:CC (match_operator:DI 4 "boolean_operator"
7641          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7642           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7643          (const_int 0)))
7644    (clobber (match_scratch:DI 3 ""))]
7645   "TARGET_POWERPC64 && reload_completed"
7646   [(set (match_dup 3) (match_dup 4))
7647    (set (match_dup 0)
7648         (compare:CC (match_dup 3)
7649                     (const_int 0)))]
7650   "")
7651
7652 (define_insn "*boolccdi3_internal3"
7653   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7654         (compare:CC (match_operator:DI 4 "boolean_operator"
7655          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7656           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7657          (const_int 0)))
7658    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7659         (match_dup 4))]
7660   "TARGET_64BIT"
7661   "@
7662    %q4. %0,%1,%2
7663    #"
7664   [(set_attr "type" "fast_compare,compare")
7665    (set_attr "length" "4,8")])
7666
7667 (define_split
7668   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7669         (compare:CC (match_operator:DI 4 "boolean_operator"
7670          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7671           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7672          (const_int 0)))
7673    (set (match_operand:DI 0 "gpc_reg_operand" "")
7674         (match_dup 4))]
7675   "TARGET_POWERPC64 && reload_completed"
7676   [(set (match_dup 0) (match_dup 4))
7677    (set (match_dup 3)
7678         (compare:CC (match_dup 0)
7679                     (const_int 0)))]
7680   "")
7681 \f
7682 ;; Now define ways of moving data around.
7683
7684 ;; Set up a register with a value from the GOT table
7685
7686 (define_expand "movsi_got"
7687   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7688         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7689                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7690   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7691   "
7692 {
7693   if (GET_CODE (operands[1]) == CONST)
7694     {
7695       rtx offset = const0_rtx;
7696       HOST_WIDE_INT value;
7697
7698       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7699       value = INTVAL (offset);
7700       if (value != 0)
7701         {
7702           rtx tmp = (!can_create_pseudo_p ()
7703                      ? operands[0]
7704                      : gen_reg_rtx (Pmode));
7705           emit_insn (gen_movsi_got (tmp, operands[1]));
7706           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7707           DONE;
7708         }
7709     }
7710
7711   operands[2] = rs6000_got_register (operands[1]);
7712 }")
7713
7714 (define_insn "*movsi_got_internal"
7715   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7716         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7717                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7718                    UNSPEC_MOVSI_GOT))]
7719   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7720   "lwz %0,%a1@got(%2)"
7721   [(set_attr "type" "load")])
7722
7723 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7724 ;; didn't get allocated to a hard register.
7725 (define_split
7726   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7727         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7728                     (match_operand:SI 2 "memory_operand" "")]
7729                    UNSPEC_MOVSI_GOT))]
7730   "DEFAULT_ABI == ABI_V4
7731     && flag_pic == 1
7732     && (reload_in_progress || reload_completed)"
7733   [(set (match_dup 0) (match_dup 2))
7734    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7735                                  UNSPEC_MOVSI_GOT))]
7736   "")
7737
7738 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7739 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7740 ;; and this is even supposed to be faster, but it is simpler not to get
7741 ;; integers in the TOC.
7742 (define_insn "movsi_low"
7743   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7744         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7745                            (match_operand 2 "" ""))))]
7746   "TARGET_MACHO && ! TARGET_64BIT"
7747   "lwz %0,lo16(%2)(%1)"
7748   [(set_attr "type" "load")
7749    (set_attr "length" "4")])
7750
7751 (define_insn "*movsi_internal1"
7752   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h")
7753         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0"))]
7754   "!TARGET_SINGLE_FPU &&
7755    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
7756   "@
7757    mr %0,%1
7758    la %0,%a1
7759    lwz%U1%X1 %0,%1
7760    stw%U0%X0 %1,%0
7761    li %0,%1
7762    lis %0,%v1
7763    #
7764    mf%1 %0
7765    mt%0 %1
7766    mt%0 %1
7767    nop"
7768   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*")
7769    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4")])
7770
7771 (define_insn "*movsi_internal1_single"
7772   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h,m,*f")
7773         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0,f,m"))]
7774   "TARGET_SINGLE_FPU &&
7775    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
7776   "@
7777    mr %0,%1
7778    la %0,%a1
7779    lwz%U1%X1 %0,%1
7780    stw%U0%X0 %1,%0
7781    li %0,%1
7782    lis %0,%v1
7783    #
7784    mf%1 %0
7785    mt%0 %1
7786    mt%0 %1
7787    nop
7788    stfs%U0%X0 %1,%0
7789    lfs%U1%X1 %0,%1"
7790   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*,*,*")
7791    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7792
7793 ;; Split a load of a large constant into the appropriate two-insn
7794 ;; sequence.
7795
7796 (define_split
7797   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7798         (match_operand:SI 1 "const_int_operand" ""))]
7799   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7800    && (INTVAL (operands[1]) & 0xffff) != 0"
7801   [(set (match_dup 0)
7802         (match_dup 2))
7803    (set (match_dup 0)
7804         (ior:SI (match_dup 0)
7805                 (match_dup 3)))]
7806   "
7807 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7808
7809   if (tem == operands[0])
7810     DONE;
7811   else
7812     FAIL;
7813 }")
7814
7815 (define_insn "*mov<mode>_internal2"
7816   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7817         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
7818                     (const_int 0)))
7819    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7820   ""
7821   "@
7822    cmp<wd>i %2,%0,0
7823    mr. %0,%1
7824    #"
7825   [(set_attr "type" "cmp,compare,cmp")
7826    (set_attr "length" "4,4,8")])
7827
7828 (define_split
7829   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
7830         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
7831                     (const_int 0)))
7832    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
7833   "reload_completed"
7834   [(set (match_dup 0) (match_dup 1))
7835    (set (match_dup 2)
7836         (compare:CC (match_dup 0)
7837                     (const_int 0)))]
7838   "")
7839 \f
7840 (define_insn "*movhi_internal"
7841   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
7842         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,0"))]
7843   "gpc_reg_operand (operands[0], HImode)
7844    || gpc_reg_operand (operands[1], HImode)"
7845   "@
7846    mr %0,%1
7847    lhz%U1%X1 %0,%1
7848    sth%U0%X0 %1,%0
7849    li %0,%w1
7850    mf%1 %0
7851    mt%0 %1
7852    nop"
7853   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
7854
7855 (define_expand "mov<mode>"
7856   [(set (match_operand:INT 0 "general_operand" "")
7857         (match_operand:INT 1 "any_operand" ""))]
7858   ""
7859   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
7860
7861 (define_insn "*movqi_internal"
7862   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
7863         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,0"))]
7864   "gpc_reg_operand (operands[0], QImode)
7865    || gpc_reg_operand (operands[1], QImode)"
7866   "@
7867    mr %0,%1
7868    lbz%U1%X1 %0,%1
7869    stb%U0%X0 %1,%0
7870    li %0,%1
7871    mf%1 %0
7872    mt%0 %1
7873    nop"
7874   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
7875 \f
7876 ;; Here is how to move condition codes around.  When we store CC data in
7877 ;; an integer register or memory, we store just the high-order 4 bits.
7878 ;; This lets us not shift in the most common case of CR0.
7879 (define_expand "movcc"
7880   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7881         (match_operand:CC 1 "nonimmediate_operand" ""))]
7882   ""
7883   "")
7884
7885 (define_insn "*movcc_internal1"
7886   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,cl,r,m")
7887         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,m,r"))]
7888   "register_operand (operands[0], CCmode)
7889    || register_operand (operands[1], CCmode)"
7890   "@
7891    mcrf %0,%1
7892    mtcrf 128,%1
7893    rlwinm %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;rlwinm %1,%1,%f0,0xffffffff
7894    crxor %0,%0,%0
7895    mfcr %0%Q1
7896    mfcr %0%Q1\;rlwinm %0,%0,%f1,0xf0000000
7897    mr %0,%1
7898    li %0,%1
7899    mf%1 %0
7900    mt%0 %1
7901    lwz%U1%X1 %0,%1
7902    stw%U0%U1 %1,%0"
7903   [(set (attr "type")
7904      (cond [(eq_attr "alternative" "0,3")
7905                 (const_string "cr_logical")
7906             (eq_attr "alternative" "1,2")
7907                 (const_string "mtcr")
7908             (eq_attr "alternative" "6,7")
7909                 (const_string "integer")
7910             (eq_attr "alternative" "8")
7911                 (const_string "mfjmpr")
7912             (eq_attr "alternative" "9")
7913                 (const_string "mtjmpr")
7914             (eq_attr "alternative" "10")
7915                 (const_string "load")
7916             (eq_attr "alternative" "11")
7917                 (const_string "store")
7918             (match_test "TARGET_MFCRF")
7919                 (const_string "mfcrf")
7920            ]
7921         (const_string "mfcr")))
7922    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4")])
7923 \f
7924 ;; For floating-point, we normally deal with the floating-point registers
7925 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7926 ;; can produce floating-point values in fixed-point registers.  Unless the
7927 ;; value is a simple constant or already in memory, we deal with this by
7928 ;; allocating memory and copying the value explicitly via that memory location.
7929 (define_expand "movsf"
7930   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7931         (match_operand:SF 1 "any_operand" ""))]
7932   ""
7933   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7934
7935 (define_split
7936   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7937         (match_operand:SF 1 "const_double_operand" ""))]
7938   "reload_completed
7939    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7940        || (GET_CODE (operands[0]) == SUBREG
7941            && GET_CODE (SUBREG_REG (operands[0])) == REG
7942            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7943   [(set (match_dup 2) (match_dup 3))]
7944   "
7945 {
7946   long l;
7947   REAL_VALUE_TYPE rv;
7948
7949   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7950   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7951
7952   if (! TARGET_POWERPC64)
7953     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7954   else
7955     operands[2] = gen_lowpart (SImode, operands[0]);
7956
7957   operands[3] = gen_int_mode (l, SImode);
7958 }")
7959
7960 (define_insn "*movsf_hardfloat"
7961   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,!r,*h,!r,!r")
7962         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,h,0,G,Fn"))]
7963   "(gpc_reg_operand (operands[0], SFmode)
7964    || gpc_reg_operand (operands[1], SFmode))
7965    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
7966   "@
7967    mr %0,%1
7968    lwz%U1%X1 %0,%1
7969    stw%U0%X0 %1,%0
7970    fmr %0,%1
7971    lfs%U1%X1 %0,%1
7972    stfs%U0%X0 %1,%0
7973    mt%0 %1
7974    mf%1 %0
7975    nop
7976    #
7977    #"
7978   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*")
7979    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8")])
7980
7981 (define_insn "*movsf_softfloat"
7982   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,r,r,m,r,r,r,r,*h")
7983         (match_operand:SF 1 "input_operand" "r,r,h,m,r,I,L,G,Fn,0"))]
7984   "(gpc_reg_operand (operands[0], SFmode)
7985    || gpc_reg_operand (operands[1], SFmode))
7986    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7987   "@
7988    mr %0,%1
7989    mt%0 %1
7990    mf%1 %0
7991    lwz%U1%X1 %0,%1
7992    stw%U0%X0 %1,%0
7993    li %0,%1
7994    lis %0,%v1
7995    #
7996    #
7997    nop"
7998   [(set_attr "type" "*,mtjmpr,mfjmpr,load,store,*,*,*,*,*")
7999    (set_attr "length" "4,4,4,4,4,4,4,4,8,4")])
8000
8001 \f
8002 (define_expand "movdf"
8003   [(set (match_operand:DF 0 "nonimmediate_operand" "")
8004         (match_operand:DF 1 "any_operand" ""))]
8005   ""
8006   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
8007
8008 (define_split
8009   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8010         (match_operand:DF 1 "const_int_operand" ""))]
8011   "! TARGET_POWERPC64 && reload_completed
8012    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8013        || (GET_CODE (operands[0]) == SUBREG
8014            && GET_CODE (SUBREG_REG (operands[0])) == REG
8015            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8016   [(set (match_dup 2) (match_dup 4))
8017    (set (match_dup 3) (match_dup 1))]
8018   "
8019 {
8020   int endian = (WORDS_BIG_ENDIAN == 0);
8021   HOST_WIDE_INT value = INTVAL (operands[1]);
8022
8023   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8024   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8025 #if HOST_BITS_PER_WIDE_INT == 32
8026   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8027 #else
8028   operands[4] = GEN_INT (value >> 32);
8029   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8030 #endif
8031 }")
8032
8033 (define_split
8034   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8035         (match_operand:DF 1 "const_double_operand" ""))]
8036   "! TARGET_POWERPC64 && reload_completed
8037    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8038        || (GET_CODE (operands[0]) == SUBREG
8039            && GET_CODE (SUBREG_REG (operands[0])) == REG
8040            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8041   [(set (match_dup 2) (match_dup 4))
8042    (set (match_dup 3) (match_dup 5))]
8043   "
8044 {
8045   int endian = (WORDS_BIG_ENDIAN == 0);
8046   long l[2];
8047   REAL_VALUE_TYPE rv;
8048
8049   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8050   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8051
8052   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8053   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8054   operands[4] = gen_int_mode (l[endian], SImode);
8055   operands[5] = gen_int_mode (l[1 - endian], SImode);
8056 }")
8057
8058 (define_split
8059   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8060         (match_operand:DF 1 "const_double_operand" ""))]
8061   "TARGET_POWERPC64 && reload_completed
8062    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8063        || (GET_CODE (operands[0]) == SUBREG
8064            && GET_CODE (SUBREG_REG (operands[0])) == REG
8065            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8066   [(set (match_dup 2) (match_dup 3))]
8067   "
8068 {
8069   int endian = (WORDS_BIG_ENDIAN == 0);
8070   long l[2];
8071   REAL_VALUE_TYPE rv;
8072 #if HOST_BITS_PER_WIDE_INT >= 64
8073   HOST_WIDE_INT val;
8074 #endif
8075
8076   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8077   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8078
8079   operands[2] = gen_lowpart (DImode, operands[0]);
8080   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8081 #if HOST_BITS_PER_WIDE_INT >= 64
8082   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8083          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8084
8085   operands[3] = gen_int_mode (val, DImode);
8086 #else
8087   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8088 #endif
8089 }")
8090
8091 ;; Don't have reload use general registers to load a constant.  It is
8092 ;; less efficient than loading the constant into an FP register, since
8093 ;; it will probably be used there.
8094
8095 ;; The move constraints are ordered to prefer floating point registers before
8096 ;; general purpose registers to avoid doing a store and a load to get the value
8097 ;; into a floating point register when it is needed for a floating point
8098 ;; operation.  Prefer traditional floating point registers over VSX registers,
8099 ;; since the D-form version of the memory instructions does not need a GPR for
8100 ;; reloading.
8101
8102 (define_insn "*movdf_hardfloat32"
8103   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,d,d,ws,?wa,Z,?Z,ws,?wa,wa,Y,r,!r,!r,!r,!r")
8104         (match_operand:DF 1 "input_operand" "d,m,d,Z,Z,ws,wa,ws,wa,j,r,Y,r,G,H,F"))]
8105   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8106    && (gpc_reg_operand (operands[0], DFmode)
8107        || gpc_reg_operand (operands[1], DFmode))"
8108   "@
8109    stfd%U0%X0 %1,%0
8110    lfd%U1%X1 %0,%1
8111    fmr %0,%1
8112    lxsd%U1x %x0,%y1
8113    lxsd%U1x %x0,%y1
8114    stxsd%U0x %x1,%y0
8115    stxsd%U0x %x1,%y0
8116    xxlor %x0,%x1,%x1
8117    xxlor %x0,%x1,%x1
8118    xxlxor %x0,%x0,%x0
8119    #
8120    #
8121    #
8122    #
8123    #
8124    #"
8125   [(set_attr "type" "fpstore,fpload,fp,fpload,fpload,fpstore,fpstore,vecsimple,vecsimple,vecsimple,store,load,two,fp,fp,*")
8126    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,8,8,8,12,16")])
8127
8128 (define_insn "*movdf_softfloat32"
8129   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,r,r,r,r")
8130         (match_operand:DF 1 "input_operand" "r,Y,r,G,H,F"))]
8131   "! TARGET_POWERPC64 
8132    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
8133        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
8134    && (gpc_reg_operand (operands[0], DFmode)
8135        || gpc_reg_operand (operands[1], DFmode))"
8136   "#"
8137   [(set_attr "type" "store,load,two,*,*,*")
8138    (set_attr "length" "8,8,8,8,12,16")])
8139
8140 ;; Reload patterns to support gpr load/store with misaligned mem.
8141 ;; and multiple gpr load/store at offset >= 0xfffc
8142 (define_expand "reload_<mode>_store"
8143   [(parallel [(match_operand 0 "memory_operand" "=m")
8144               (match_operand 1 "gpc_reg_operand" "r")
8145               (match_operand:GPR 2 "register_operand" "=&b")])]
8146   ""
8147 {
8148   rs6000_secondary_reload_gpr (operands[1], operands[0], operands[2], true);
8149   DONE;
8150 })
8151
8152 (define_expand "reload_<mode>_load"
8153   [(parallel [(match_operand 0 "gpc_reg_operand" "=r")
8154               (match_operand 1 "memory_operand" "m")
8155               (match_operand:GPR 2 "register_operand" "=b")])]
8156   ""
8157 {
8158   rs6000_secondary_reload_gpr (operands[0], operands[1], operands[2], false);
8159   DONE;
8160 })
8161
8162 ; ld/std require word-aligned displacements -> 'Y' constraint.
8163 ; List Y->r and r->Y before r->r for reload.
8164 (define_insn "*movdf_hardfloat64_mfpgpr"
8165   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,ws,?wa,ws,?wa,Z,?Z,m,d,d,wa,*c*l,!r,*h,!r,!r,!r,r,d")
8166         (match_operand:DF 1 "input_operand" "r,Y,r,ws,?wa,Z,Z,ws,wa,d,m,d,j,r,h,0,G,H,F,d,r"))]
8167   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
8168    && TARGET_DOUBLE_FLOAT
8169    && (gpc_reg_operand (operands[0], DFmode)
8170        || gpc_reg_operand (operands[1], DFmode))"
8171   "@
8172    std%U0%X0 %1,%0
8173    ld%U1%X1 %0,%1
8174    mr %0,%1
8175    xxlor %x0,%x1,%x1
8176    xxlor %x0,%x1,%x1
8177    lxsd%U1x %x0,%y1
8178    lxsd%U1x %x0,%y1
8179    stxsd%U0x %x1,%y0
8180    stxsd%U0x %x1,%y0
8181    stfd%U0%X0 %1,%0
8182    lfd%U1%X1 %0,%1
8183    fmr %0,%1
8184    xxlxor %x0,%x0,%x0
8185    mt%0 %1
8186    mf%1 %0
8187    nop
8188    #
8189    #
8190    #
8191    mftgpr %0,%1
8192    mffgpr %0,%1"
8193   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fpstore,fpload,fp,vecsimple,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
8194    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
8195
8196 ; ld/std require word-aligned displacements -> 'Y' constraint.
8197 ; List Y->r and r->Y before r->r for reload.
8198 (define_insn "*movdf_hardfloat64"
8199   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,d,d,Y,r,!r,ws,?wa,Z,?Z,ws,?wa,wa,*c*l,!r,*h,!r,!r,!r")
8200         (match_operand:DF 1 "input_operand" "d,m,d,r,Y,r,Z,Z,ws,wa,ws,wa,j,r,h,0,G,H,F"))]
8201   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
8202    && TARGET_DOUBLE_FLOAT
8203    && (gpc_reg_operand (operands[0], DFmode)
8204        || gpc_reg_operand (operands[1], DFmode))"
8205   "@
8206    stfd%U0%X0 %1,%0
8207    lfd%U1%X1 %0,%1
8208    fmr %0,%1
8209    std%U0%X0 %1,%0
8210    ld%U1%X1 %0,%1
8211    mr %0,%1
8212    lxsd%U1x %x0,%y1
8213    lxsd%U1x %x0,%y1
8214    stxsd%U0x %x1,%y0
8215    stxsd%U0x %x1,%y0
8216    xxlor %x0,%x1,%x1
8217    xxlor %x0,%x1,%x1
8218    xxlxor %x0,%x0,%x0
8219    mt%0 %1
8220    mf%1 %0
8221    nop
8222    #
8223    #
8224    #"
8225   [(set_attr "type" "fpstore,fpload,fp,store,load,*,fpload,fpload,fpstore,fpstore,vecsimple,vecsimple,vecsimple,mtjmpr,mfjmpr,*,*,*,*")
8226    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16")])
8227
8228 (define_insn "*movdf_softfloat64"
8229   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,r,cl,r,r,r,r,*h")
8230         (match_operand:DF 1 "input_operand" "r,Y,r,r,h,G,H,F,0"))]
8231   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8232    && (gpc_reg_operand (operands[0], DFmode)
8233        || gpc_reg_operand (operands[1], DFmode))"
8234   "@
8235    std%U0%X0 %1,%0
8236    ld%U1%X1 %0,%1
8237    mr %0,%1
8238    mt%0 %1
8239    mf%1 %0
8240    #
8241    #
8242    #
8243    nop"
8244   [(set_attr "type" "store,load,*,mtjmpr,mfjmpr,*,*,*,*")
8245    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8246 \f
8247 (define_expand "movtf"
8248   [(set (match_operand:TF 0 "general_operand" "")
8249         (match_operand:TF 1 "any_operand" ""))]
8250   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
8251   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8252
8253 ;; It's important to list Y->r and r->Y before r->r because otherwise
8254 ;; reload, given m->r, will try to pick r->r and reload it, which
8255 ;; doesn't make progress.
8256 (define_insn_and_split "*movtf_internal"
8257   [(set (match_operand:TF 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
8258         (match_operand:TF 1 "input_operand" "d,m,d,r,YGHF,r"))]
8259   "!TARGET_IEEEQUAD
8260    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8261    && (gpc_reg_operand (operands[0], TFmode)
8262        || gpc_reg_operand (operands[1], TFmode))"
8263   "#"
8264   "&& reload_completed"
8265   [(pc)]
8266 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8267   [(set_attr "length" "8,8,8,20,20,16")])
8268
8269 (define_insn_and_split "*movtf_softfloat"
8270   [(set (match_operand:TF 0 "rs6000_nonimmediate_operand" "=Y,r,r")
8271         (match_operand:TF 1 "input_operand"         "r,YGHF,r"))]
8272   "!TARGET_IEEEQUAD
8273    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
8274    && (gpc_reg_operand (operands[0], TFmode)
8275        || gpc_reg_operand (operands[1], TFmode))"
8276   "#"
8277   "&& reload_completed"
8278   [(pc)]
8279 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8280   [(set_attr "length" "20,20,16")])
8281
8282 (define_expand "extenddftf2"
8283   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8284         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
8285   "!TARGET_IEEEQUAD
8286    && TARGET_HARD_FLOAT
8287    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8288    && TARGET_LONG_DOUBLE_128"
8289 {
8290   if (TARGET_E500_DOUBLE)
8291     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
8292   else
8293     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
8294   DONE;
8295 })
8296
8297 (define_expand "extenddftf2_fprs"
8298   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8299                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8300               (use (match_dup 2))])]
8301   "!TARGET_IEEEQUAD
8302    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8303    && TARGET_LONG_DOUBLE_128"
8304 {
8305   operands[2] = CONST0_RTX (DFmode);
8306   /* Generate GOT reference early for SVR4 PIC.  */
8307   if (DEFAULT_ABI == ABI_V4 && flag_pic)
8308     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
8309 })
8310
8311 (define_insn_and_split "*extenddftf2_internal"
8312   [(set (match_operand:TF 0 "nonimmediate_operand" "=m,Y,d,&d,r")
8313        (float_extend:TF (match_operand:DF 1 "input_operand" "d,r,md,md,rmGHF")))
8314    (use (match_operand:DF 2 "zero_reg_mem_operand" "d,r,m,d,n"))]
8315   "!TARGET_IEEEQUAD
8316    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8317    && TARGET_LONG_DOUBLE_128"
8318   "#"
8319   "&& reload_completed"
8320   [(pc)]
8321 {
8322   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
8323   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
8324   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8325                   operands[1]);
8326   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8327                   operands[2]);
8328   DONE;
8329 })
8330
8331 (define_expand "extendsftf2"
8332   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8333         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8334   "!TARGET_IEEEQUAD
8335    && TARGET_HARD_FLOAT
8336    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8337    && TARGET_LONG_DOUBLE_128"
8338 {
8339   rtx tmp = gen_reg_rtx (DFmode);
8340   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8341   emit_insn (gen_extenddftf2 (operands[0], tmp));
8342   DONE;
8343 })
8344
8345 (define_expand "trunctfdf2"
8346   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8347         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8348   "!TARGET_IEEEQUAD
8349    && TARGET_HARD_FLOAT
8350    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8351    && TARGET_LONG_DOUBLE_128"
8352   "")
8353
8354 (define_insn_and_split "trunctfdf2_internal1"
8355   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
8356         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
8357   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
8358    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8359   "@
8360    #
8361    fmr %0,%1"
8362   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8363   [(const_int 0)]
8364 {
8365   emit_note (NOTE_INSN_DELETED);
8366   DONE;
8367 }
8368   [(set_attr "type" "fp")])
8369
8370 (define_insn "trunctfdf2_internal2"
8371   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
8372         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
8373   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
8374    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8375    && TARGET_LONG_DOUBLE_128"
8376   "fadd %0,%1,%L1"
8377   [(set_attr "type" "fp")
8378    (set_attr "fp_type" "fp_addsub_d")])
8379
8380 (define_expand "trunctfsf2"
8381   [(set (match_operand:SF 0 "gpc_reg_operand" "")
8382         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
8383   "!TARGET_IEEEQUAD
8384    && TARGET_HARD_FLOAT
8385    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8386    && TARGET_LONG_DOUBLE_128"
8387 {
8388   if (TARGET_E500_DOUBLE)
8389     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
8390   else
8391     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
8392   DONE;
8393 })
8394
8395 (define_insn_and_split "trunctfsf2_fprs"
8396   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8397         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
8398    (clobber (match_scratch:DF 2 "=d"))]
8399   "!TARGET_IEEEQUAD
8400    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
8401    && TARGET_LONG_DOUBLE_128"
8402   "#"
8403   "&& reload_completed"
8404   [(set (match_dup 2)
8405         (float_truncate:DF (match_dup 1)))
8406    (set (match_dup 0)
8407         (float_truncate:SF (match_dup 2)))]
8408   "")
8409
8410 (define_expand "floatsitf2"
8411   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8412         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
8413   "!TARGET_IEEEQUAD
8414    && TARGET_HARD_FLOAT
8415    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8416    && TARGET_LONG_DOUBLE_128"
8417 {
8418   rtx tmp = gen_reg_rtx (DFmode);
8419   expand_float (tmp, operands[1], false);
8420   emit_insn (gen_extenddftf2 (operands[0], tmp));
8421   DONE;
8422 })
8423
8424 ; fadd, but rounding towards zero.
8425 ; This is probably not the optimal code sequence.
8426 (define_insn "fix_trunc_helper"
8427   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
8428         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
8429                    UNSPEC_FIX_TRUNC_TF))
8430    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
8431   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
8432   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8433   [(set_attr "type" "fp")
8434    (set_attr "length" "20")])
8435
8436 (define_expand "fix_trunctfsi2"
8437   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8438         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
8439   "!TARGET_IEEEQUAD && TARGET_HARD_FLOAT
8440    && (TARGET_FPRS || TARGET_E500_DOUBLE) && TARGET_LONG_DOUBLE_128"
8441 {
8442   if (TARGET_E500_DOUBLE)
8443     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
8444   else
8445     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
8446   DONE;
8447 })
8448
8449 (define_expand "fix_trunctfsi2_fprs"
8450   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8451                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8452               (clobber (match_dup 2))
8453               (clobber (match_dup 3))
8454               (clobber (match_dup 4))
8455               (clobber (match_dup 5))])]
8456   "!TARGET_IEEEQUAD
8457    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8458 {
8459   operands[2] = gen_reg_rtx (DFmode);
8460   operands[3] = gen_reg_rtx (DFmode);
8461   operands[4] = gen_reg_rtx (DImode);
8462   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode));
8463 })
8464
8465 (define_insn_and_split "*fix_trunctfsi2_internal"
8466   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8467         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
8468    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
8469    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
8470    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
8471    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
8472   "!TARGET_IEEEQUAD
8473    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8474   "#"
8475   ""
8476   [(pc)]
8477 {
8478   rtx lowword;
8479   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8480
8481   gcc_assert (MEM_P (operands[5]));
8482   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8483
8484   emit_insn (gen_fctiwz_df (operands[4], operands[2]));
8485   emit_move_insn (operands[5], operands[4]);
8486   emit_move_insn (operands[0], lowword);
8487   DONE;
8488 })
8489
8490 (define_expand "negtf2"
8491   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8492         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
8493   "!TARGET_IEEEQUAD
8494    && TARGET_HARD_FLOAT
8495    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8496    && TARGET_LONG_DOUBLE_128"
8497   "")
8498
8499 (define_insn "negtf2_internal"
8500   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
8501         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
8502   "!TARGET_IEEEQUAD
8503    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8504   "*
8505 {
8506   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8507     return \"fneg %L0,%L1\;fneg %0,%1\";
8508   else
8509     return \"fneg %0,%1\;fneg %L0,%L1\";
8510 }"
8511   [(set_attr "type" "fp")
8512    (set_attr "length" "8")])
8513
8514 (define_expand "abstf2"
8515   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8516         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
8517   "!TARGET_IEEEQUAD
8518    && TARGET_HARD_FLOAT
8519    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8520    && TARGET_LONG_DOUBLE_128"
8521   "
8522 {
8523   rtx label = gen_label_rtx ();
8524   if (TARGET_E500_DOUBLE)
8525     {
8526       if (flag_finite_math_only && !flag_trapping_math)
8527         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
8528       else
8529         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
8530     }
8531   else
8532     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8533   emit_label (label);
8534   DONE;
8535 }")
8536
8537 (define_expand "abstf2_internal"
8538   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8539         (match_operand:TF 1 "gpc_reg_operand" ""))
8540    (set (match_dup 3) (match_dup 5))
8541    (set (match_dup 5) (abs:DF (match_dup 5)))
8542    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8543    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8544                            (label_ref (match_operand 2 "" ""))
8545                            (pc)))
8546    (set (match_dup 6) (neg:DF (match_dup 6)))]
8547   "!TARGET_IEEEQUAD
8548    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8549    && TARGET_LONG_DOUBLE_128"
8550   "
8551 {
8552   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
8553   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
8554   operands[3] = gen_reg_rtx (DFmode);
8555   operands[4] = gen_reg_rtx (CCFPmode);
8556   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8557   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8558 }")
8559 \f
8560 ;; Next come the multi-word integer load and store and the load and store
8561 ;; multiple insns.
8562
8563 ;; List r->r after r->Y, otherwise reload will try to reload a
8564 ;; non-offsettable address by using r->r which won't make progress.
8565 ;; Use of fprs is disparaged slightly otherwise reload prefers to reload
8566 ;; a gpr into a fpr instead of reloading an invalid 'Y' address
8567 (define_insn "*movdi_internal32"
8568   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=Y,r,r,?m,?*d,?*d,r,?wa")
8569         (match_operand:DI 1 "input_operand" "r,Y,r,d,m,d,IJKnGHF,O"))]
8570   "! TARGET_POWERPC64
8571    && (gpc_reg_operand (operands[0], DImode)
8572        || gpc_reg_operand (operands[1], DImode))"
8573   "@
8574    #
8575    #
8576    #
8577    stfd%U0%X0 %1,%0
8578    lfd%U1%X1 %0,%1
8579    fmr %0,%1
8580    #
8581    xxlxor %x0,%x0,%x0"
8582   [(set_attr "type" "store,load,*,fpstore,fpload,fp,*,vecsimple")])
8583
8584 (define_split
8585   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8586         (match_operand:DI 1 "const_int_operand" ""))]
8587   "! TARGET_POWERPC64 && reload_completed
8588    && gpr_or_gpr_p (operands[0], operands[1])"
8589   [(set (match_dup 2) (match_dup 4))
8590    (set (match_dup 3) (match_dup 1))]
8591   "
8592 {
8593   HOST_WIDE_INT value = INTVAL (operands[1]);
8594   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8595                                        DImode);
8596   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8597                                        DImode);
8598 #if HOST_BITS_PER_WIDE_INT == 32
8599   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8600 #else
8601   operands[4] = GEN_INT (value >> 32);
8602   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8603 #endif
8604 }")
8605
8606 (define_split
8607   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
8608         (match_operand:DIFD 1 "input_operand" ""))]
8609   "reload_completed && !TARGET_POWERPC64
8610    && gpr_or_gpr_p (operands[0], operands[1])"
8611   [(pc)]
8612 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8613
8614 (define_insn "*movdi_mfpgpr"
8615   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,r,r,r,r,?m,?*d,?*d,r,*h,*h,r,?*d")
8616         (match_operand:DI 1 "input_operand" "r,Y,r,I,L,nF,d,m,d,*h,r,0,*d,r"))]
8617   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
8618    && (gpc_reg_operand (operands[0], DImode)
8619        || gpc_reg_operand (operands[1], DImode))"
8620   "@
8621    std%U0%X0 %1,%0
8622    ld%U1%X1 %0,%1
8623    mr %0,%1
8624    li %0,%1
8625    lis %0,%v1
8626    #
8627    stfd%U0%X0 %1,%0
8628    lfd%U1%X1 %0,%1
8629    fmr %0,%1
8630    mf%1 %0
8631    mt%0 %1
8632    nop
8633    mftgpr %0,%1
8634    mffgpr %0,%1"
8635   [(set_attr "type" "store,load,*,*,*,*,fpstore,fpload,fp,mfjmpr,mtjmpr,*,mftgpr,mffgpr")
8636    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4")])
8637
8638 (define_insn "*movdi_internal64"
8639   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,r,r,r,r,?m,?*d,?*d,r,*h,*h,?wa")
8640         (match_operand:DI 1 "input_operand" "r,Y,r,I,L,nF,d,m,d,*h,r,0,O"))]
8641   "TARGET_POWERPC64 && (!TARGET_MFPGPR || !TARGET_HARD_FLOAT || !TARGET_FPRS)
8642    && (gpc_reg_operand (operands[0], DImode)
8643        || gpc_reg_operand (operands[1], DImode))"
8644   "@
8645    std%U0%X0 %1,%0
8646    ld%U1%X1 %0,%1
8647    mr %0,%1
8648    li %0,%1
8649    lis %0,%v1
8650    #
8651    stfd%U0%X0 %1,%0
8652    lfd%U1%X1 %0,%1
8653    fmr %0,%1
8654    mf%1 %0
8655    mt%0 %1
8656    nop
8657    xxlxor %x0,%x0,%x0"
8658   [(set_attr "type" "store,load,*,*,*,*,fpstore,fpload,fp,mfjmpr,mtjmpr,*,vecsimple")
8659    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8660
8661 ;; immediate value valid for a single instruction hiding in a const_double
8662 (define_insn ""
8663   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8664         (match_operand:DI 1 "const_double_operand" "F"))]
8665   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8666    && GET_CODE (operands[1]) == CONST_DOUBLE
8667    && num_insns_constant (operands[1], DImode) == 1"
8668   "*
8669 {
8670   return ((unsigned HOST_WIDE_INT)
8671           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8672          ? \"li %0,%1\" : \"lis %0,%v1\";
8673 }")
8674
8675 ;; Generate all one-bits and clear left or right.
8676 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8677 (define_split
8678   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8679         (match_operand:DI 1 "mask64_operand" ""))]
8680   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8681   [(set (match_dup 0) (const_int -1))
8682    (set (match_dup 0)
8683         (and:DI (rotate:DI (match_dup 0)
8684                            (const_int 0))
8685                 (match_dup 1)))]
8686   "")
8687
8688 ;; Split a load of a large constant into the appropriate five-instruction
8689 ;; sequence.  Handle anything in a constant number of insns.
8690 ;; When non-easy constants can go in the TOC, this should use
8691 ;; easy_fp_constant predicate.
8692 (define_split
8693   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8694         (match_operand:DI 1 "const_int_operand" ""))]
8695   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8696   [(set (match_dup 0) (match_dup 2))
8697    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8698   "
8699 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8700
8701   if (tem == operands[0])
8702     DONE;
8703   else
8704     FAIL;
8705 }")
8706
8707 (define_split
8708   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8709         (match_operand:DI 1 "const_double_operand" ""))]
8710   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8711   [(set (match_dup 0) (match_dup 2))
8712    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8713   "
8714 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8715
8716   if (tem == operands[0])
8717     DONE;
8718   else
8719     FAIL;
8720 }")
8721 \f
8722 ;; TImode is similar, except that we usually want to compute the address into
8723 ;; a register and use lsi/stsi (the exception is during reload).
8724
8725 (define_insn "*movti_string"
8726   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,Y,????r,????r,????r,r")
8727         (match_operand:TI 1 "input_operand" "r,r,Q,Y,r,n"))]
8728   "! TARGET_POWERPC64
8729    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8730   "*
8731 {
8732   switch (which_alternative)
8733     {
8734     default:
8735       gcc_unreachable ();
8736     case 0:
8737       if (TARGET_STRING)
8738         return \"stswi %1,%P0,16\";
8739     case 1:
8740       return \"#\";
8741     case 2:
8742       /* If the address is not used in the output, we can use lsi.  Otherwise,
8743          fall through to generating four loads.  */
8744       if (TARGET_STRING
8745           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8746         return \"lswi %0,%P1,16\";
8747       /* ... fall through ...  */
8748     case 3:
8749     case 4:
8750     case 5:
8751       return \"#\";
8752     }
8753 }"
8754   [(set_attr "type" "store_ux,store_ux,load_ux,load_ux,*,*")
8755    (set (attr "cell_micro") (if_then_else (match_test "TARGET_STRING")
8756                                           (const_string "always")
8757                                           (const_string "conditional")))])
8758
8759 (define_insn "*movti_ppc64"
8760   [(set (match_operand:TI 0 "nonimmediate_operand" "=Y,r,r")
8761         (match_operand:TI 1 "input_operand" "r,Y,r"))]
8762   "(TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8763     || gpc_reg_operand (operands[1], TImode)))
8764    && VECTOR_MEM_NONE_P (TImode)"
8765   "#"
8766   [(set_attr "type" "store,load,*")])
8767
8768 (define_split
8769   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8770         (match_operand:TI 1 "const_double_operand" ""))]
8771   "TARGET_POWERPC64 && VECTOR_MEM_NONE_P (TImode)"
8772   [(set (match_dup 2) (match_dup 4))
8773    (set (match_dup 3) (match_dup 5))]
8774   "
8775 {
8776   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8777                                        TImode);
8778   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8779                                        TImode);
8780   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8781     {
8782       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8783       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8784     }
8785   else if (GET_CODE (operands[1]) == CONST_INT)
8786     {
8787       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8788       operands[5] = operands[1];
8789     }
8790   else
8791     FAIL;
8792 }")
8793
8794 (define_split
8795   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8796         (match_operand:TI 1 "input_operand" ""))]
8797   "reload_completed && VECTOR_MEM_NONE_P (TImode)
8798    && gpr_or_gpr_p (operands[0], operands[1])"
8799   [(pc)]
8800 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8801 \f
8802 (define_expand "load_multiple"
8803   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8804                           (match_operand:SI 1 "" ""))
8805                      (use (match_operand:SI 2 "" ""))])]
8806   "TARGET_STRING && !TARGET_POWERPC64"
8807   "
8808 {
8809   int regno;
8810   int count;
8811   rtx op1;
8812   int i;
8813
8814   /* Support only loading a constant number of fixed-point registers from
8815      memory and only bother with this if more than two; the machine
8816      doesn't support more than eight.  */
8817   if (GET_CODE (operands[2]) != CONST_INT
8818       || INTVAL (operands[2]) <= 2
8819       || INTVAL (operands[2]) > 8
8820       || GET_CODE (operands[1]) != MEM
8821       || GET_CODE (operands[0]) != REG
8822       || REGNO (operands[0]) >= 32)
8823     FAIL;
8824
8825   count = INTVAL (operands[2]);
8826   regno = REGNO (operands[0]);
8827
8828   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8829   op1 = replace_equiv_address (operands[1],
8830                                force_reg (SImode, XEXP (operands[1], 0)));
8831
8832   for (i = 0; i < count; i++)
8833     XVECEXP (operands[3], 0, i)
8834       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8835                      adjust_address_nv (op1, SImode, i * 4));
8836 }")
8837
8838 (define_insn "*ldmsi8"
8839   [(match_parallel 0 "load_multiple_operation"
8840     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8841           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8842      (set (match_operand:SI 3 "gpc_reg_operand" "")
8843           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8844      (set (match_operand:SI 4 "gpc_reg_operand" "")
8845           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8846      (set (match_operand:SI 5 "gpc_reg_operand" "")
8847           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8848      (set (match_operand:SI 6 "gpc_reg_operand" "")
8849           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8850      (set (match_operand:SI 7 "gpc_reg_operand" "")
8851           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8852      (set (match_operand:SI 8 "gpc_reg_operand" "")
8853           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8854      (set (match_operand:SI 9 "gpc_reg_operand" "")
8855           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8856   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8857   "*
8858 { return rs6000_output_load_multiple (operands); }"
8859   [(set_attr "type" "load_ux")
8860    (set_attr "length" "32")])
8861
8862 (define_insn "*ldmsi7"
8863   [(match_parallel 0 "load_multiple_operation"
8864     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8865           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8866      (set (match_operand:SI 3 "gpc_reg_operand" "")
8867           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8868      (set (match_operand:SI 4 "gpc_reg_operand" "")
8869           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8870      (set (match_operand:SI 5 "gpc_reg_operand" "")
8871           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8872      (set (match_operand:SI 6 "gpc_reg_operand" "")
8873           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8874      (set (match_operand:SI 7 "gpc_reg_operand" "")
8875           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8876      (set (match_operand:SI 8 "gpc_reg_operand" "")
8877           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8878   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8879   "*
8880 { return rs6000_output_load_multiple (operands); }"
8881   [(set_attr "type" "load_ux")
8882    (set_attr "length" "32")])
8883
8884 (define_insn "*ldmsi6"
8885   [(match_parallel 0 "load_multiple_operation"
8886     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8887           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8888      (set (match_operand:SI 3 "gpc_reg_operand" "")
8889           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8890      (set (match_operand:SI 4 "gpc_reg_operand" "")
8891           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8892      (set (match_operand:SI 5 "gpc_reg_operand" "")
8893           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8894      (set (match_operand:SI 6 "gpc_reg_operand" "")
8895           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8896      (set (match_operand:SI 7 "gpc_reg_operand" "")
8897           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8898   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8899   "*
8900 { return rs6000_output_load_multiple (operands); }"
8901   [(set_attr "type" "load_ux")
8902    (set_attr "length" "32")])
8903
8904 (define_insn "*ldmsi5"
8905   [(match_parallel 0 "load_multiple_operation"
8906     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8907           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8908      (set (match_operand:SI 3 "gpc_reg_operand" "")
8909           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8910      (set (match_operand:SI 4 "gpc_reg_operand" "")
8911           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8912      (set (match_operand:SI 5 "gpc_reg_operand" "")
8913           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8914      (set (match_operand:SI 6 "gpc_reg_operand" "")
8915           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8916   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8917   "*
8918 { return rs6000_output_load_multiple (operands); }"
8919   [(set_attr "type" "load_ux")
8920    (set_attr "length" "32")])
8921
8922 (define_insn "*ldmsi4"
8923   [(match_parallel 0 "load_multiple_operation"
8924     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8925           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8926      (set (match_operand:SI 3 "gpc_reg_operand" "")
8927           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8928      (set (match_operand:SI 4 "gpc_reg_operand" "")
8929           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8930      (set (match_operand:SI 5 "gpc_reg_operand" "")
8931           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8932   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8933   "*
8934 { return rs6000_output_load_multiple (operands); }"
8935   [(set_attr "type" "load_ux")
8936    (set_attr "length" "32")])
8937
8938 (define_insn "*ldmsi3"
8939   [(match_parallel 0 "load_multiple_operation"
8940     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8941           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8942      (set (match_operand:SI 3 "gpc_reg_operand" "")
8943           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8944      (set (match_operand:SI 4 "gpc_reg_operand" "")
8945           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8946   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8947   "*
8948 { return rs6000_output_load_multiple (operands); }"
8949   [(set_attr "type" "load_ux")
8950    (set_attr "length" "32")])
8951
8952 (define_expand "store_multiple"
8953   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8954                           (match_operand:SI 1 "" ""))
8955                      (clobber (scratch:SI))
8956                      (use (match_operand:SI 2 "" ""))])]
8957   "TARGET_STRING && !TARGET_POWERPC64"
8958   "
8959 {
8960   int regno;
8961   int count;
8962   rtx to;
8963   rtx op0;
8964   int i;
8965
8966   /* Support only storing a constant number of fixed-point registers to
8967      memory and only bother with this if more than two; the machine
8968      doesn't support more than eight.  */
8969   if (GET_CODE (operands[2]) != CONST_INT
8970       || INTVAL (operands[2]) <= 2
8971       || INTVAL (operands[2]) > 8
8972       || GET_CODE (operands[0]) != MEM
8973       || GET_CODE (operands[1]) != REG
8974       || REGNO (operands[1]) >= 32)
8975     FAIL;
8976
8977   count = INTVAL (operands[2]);
8978   regno = REGNO (operands[1]);
8979
8980   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8981   to = force_reg (SImode, XEXP (operands[0], 0));
8982   op0 = replace_equiv_address (operands[0], to);
8983
8984   XVECEXP (operands[3], 0, 0)
8985     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8986   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8987                                                  gen_rtx_SCRATCH (SImode));
8988
8989   for (i = 1; i < count; i++)
8990     XVECEXP (operands[3], 0, i + 1)
8991       = gen_rtx_SET (VOIDmode,
8992                      adjust_address_nv (op0, SImode, i * 4),
8993                      gen_rtx_REG (SImode, regno + i));
8994 }")
8995
8996 (define_insn "*stmsi8"
8997   [(match_parallel 0 "store_multiple_operation"
8998     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8999           (match_operand:SI 2 "gpc_reg_operand" "r"))
9000      (clobber (match_scratch:SI 3 "=X"))
9001      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9002           (match_operand:SI 4 "gpc_reg_operand" "r"))
9003      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9004           (match_operand:SI 5 "gpc_reg_operand" "r"))
9005      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9006           (match_operand:SI 6 "gpc_reg_operand" "r"))
9007      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9008           (match_operand:SI 7 "gpc_reg_operand" "r"))
9009      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9010           (match_operand:SI 8 "gpc_reg_operand" "r"))
9011      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9012           (match_operand:SI 9 "gpc_reg_operand" "r"))
9013      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9014           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9015   "TARGET_STRING && XVECLEN (operands[0], 0) == 9"
9016   "stswi %2,%1,%O0"
9017   [(set_attr "type" "store_ux")
9018    (set_attr "cell_micro" "always")])
9019
9020 (define_insn "*stmsi7"
9021   [(match_parallel 0 "store_multiple_operation"
9022     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9023           (match_operand:SI 2 "gpc_reg_operand" "r"))
9024      (clobber (match_scratch:SI 3 "=X"))
9025      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9026           (match_operand:SI 4 "gpc_reg_operand" "r"))
9027      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9028           (match_operand:SI 5 "gpc_reg_operand" "r"))
9029      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9030           (match_operand:SI 6 "gpc_reg_operand" "r"))
9031      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9032           (match_operand:SI 7 "gpc_reg_operand" "r"))
9033      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9034           (match_operand:SI 8 "gpc_reg_operand" "r"))
9035      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9036           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9037   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
9038   "stswi %2,%1,%O0"
9039   [(set_attr "type" "store_ux")
9040    (set_attr "cell_micro" "always")])
9041
9042 (define_insn "*stmsi6"
9043   [(match_parallel 0 "store_multiple_operation"
9044     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9045           (match_operand:SI 2 "gpc_reg_operand" "r"))
9046      (clobber (match_scratch:SI 3 "=X"))
9047      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9048           (match_operand:SI 4 "gpc_reg_operand" "r"))
9049      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9050           (match_operand:SI 5 "gpc_reg_operand" "r"))
9051      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9052           (match_operand:SI 6 "gpc_reg_operand" "r"))
9053      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9054           (match_operand:SI 7 "gpc_reg_operand" "r"))
9055      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9056           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9057   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
9058   "stswi %2,%1,%O0"
9059   [(set_attr "type" "store_ux")
9060    (set_attr "cell_micro" "always")])
9061
9062 (define_insn "*stmsi5"
9063   [(match_parallel 0 "store_multiple_operation"
9064     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9065           (match_operand:SI 2 "gpc_reg_operand" "r"))
9066      (clobber (match_scratch:SI 3 "=X"))
9067      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9068           (match_operand:SI 4 "gpc_reg_operand" "r"))
9069      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9070           (match_operand:SI 5 "gpc_reg_operand" "r"))
9071      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9072           (match_operand:SI 6 "gpc_reg_operand" "r"))
9073      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9074           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9075   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
9076   "stswi %2,%1,%O0"
9077   [(set_attr "type" "store_ux")
9078    (set_attr "cell_micro" "always")])
9079
9080 (define_insn "*stmsi4"
9081   [(match_parallel 0 "store_multiple_operation"
9082     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9083           (match_operand:SI 2 "gpc_reg_operand" "r"))
9084      (clobber (match_scratch:SI 3 "=X"))
9085      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9086           (match_operand:SI 4 "gpc_reg_operand" "r"))
9087      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9088           (match_operand:SI 5 "gpc_reg_operand" "r"))
9089      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9090           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9091   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
9092   "stswi %2,%1,%O0"
9093   [(set_attr "type" "store_ux")
9094    (set_attr "cell_micro" "always")])
9095
9096 (define_insn "*stmsi3"
9097   [(match_parallel 0 "store_multiple_operation"
9098     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9099           (match_operand:SI 2 "gpc_reg_operand" "r"))
9100      (clobber (match_scratch:SI 3 "=X"))
9101      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9102           (match_operand:SI 4 "gpc_reg_operand" "r"))
9103      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9104           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9105   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
9106   "stswi %2,%1,%O0"
9107   [(set_attr "type" "store_ux")
9108    (set_attr "cell_micro" "always")])
9109 \f
9110 (define_expand "setmemsi"
9111   [(parallel [(set (match_operand:BLK 0 "" "")
9112                    (match_operand 2 "const_int_operand" ""))
9113               (use (match_operand:SI 1 "" ""))
9114               (use (match_operand:SI 3 "" ""))])]
9115   ""
9116   "
9117 {
9118   /* If value to set is not zero, use the library routine.  */
9119   if (operands[2] != const0_rtx)
9120     FAIL;
9121
9122   if (expand_block_clear (operands))
9123     DONE;
9124   else
9125     FAIL;
9126 }")
9127
9128 ;; String/block move insn.
9129 ;; Argument 0 is the destination
9130 ;; Argument 1 is the source
9131 ;; Argument 2 is the length
9132 ;; Argument 3 is the alignment
9133
9134 (define_expand "movmemsi"
9135   [(parallel [(set (match_operand:BLK 0 "" "")
9136                    (match_operand:BLK 1 "" ""))
9137               (use (match_operand:SI 2 "" ""))
9138               (use (match_operand:SI 3 "" ""))])]
9139   ""
9140   "
9141 {
9142   if (expand_block_move (operands))
9143     DONE;
9144   else
9145     FAIL;
9146 }")
9147
9148 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9149 ;; register allocator doesn't have a clue about allocating 8 word registers.
9150 ;; rD/rS = r5 is preferred, efficient form.
9151 (define_expand "movmemsi_8reg"
9152   [(parallel [(set (match_operand 0 "" "")
9153                    (match_operand 1 "" ""))
9154               (use (match_operand 2 "" ""))
9155               (use (match_operand 3 "" ""))
9156               (clobber (reg:SI  5))
9157               (clobber (reg:SI  6))
9158               (clobber (reg:SI  7))
9159               (clobber (reg:SI  8))
9160               (clobber (reg:SI  9))
9161               (clobber (reg:SI 10))
9162               (clobber (reg:SI 11))
9163               (clobber (reg:SI 12))
9164               (clobber (match_scratch:SI 4 ""))])]
9165   "TARGET_STRING"
9166   "")
9167
9168 (define_insn ""
9169   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9170         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9171    (use (match_operand:SI 2 "immediate_operand" "i"))
9172    (use (match_operand:SI 3 "immediate_operand" "i"))
9173    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
9174    (clobber (reg:SI  6))
9175    (clobber (reg:SI  7))
9176    (clobber (reg:SI  8))
9177    (clobber (reg:SI  9))
9178    (clobber (reg:SI 10))
9179    (clobber (reg:SI 11))
9180    (clobber (reg:SI 12))
9181    (clobber (match_scratch:SI 5 "=X"))]
9182   "TARGET_STRING
9183    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9184        || INTVAL (operands[2]) == 0)
9185    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9186    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9187    && REGNO (operands[4]) == 5"
9188   "lswi %4,%1,%2\;stswi %4,%0,%2"
9189   [(set_attr "type" "store_ux")
9190    (set_attr "cell_micro" "always")
9191    (set_attr "length" "8")])
9192
9193 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9194 ;; register allocator doesn't have a clue about allocating 6 word registers.
9195 ;; rD/rS = r5 is preferred, efficient form.
9196 (define_expand "movmemsi_6reg"
9197   [(parallel [(set (match_operand 0 "" "")
9198                    (match_operand 1 "" ""))
9199               (use (match_operand 2 "" ""))
9200               (use (match_operand 3 "" ""))
9201               (clobber (reg:SI  5))
9202               (clobber (reg:SI  6))
9203               (clobber (reg:SI  7))
9204               (clobber (reg:SI  8))
9205               (clobber (reg:SI  9))
9206               (clobber (reg:SI 10))
9207               (clobber (match_scratch:SI 4 ""))])]
9208   "TARGET_STRING"
9209   "")
9210
9211 (define_insn ""
9212   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9213         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9214    (use (match_operand:SI 2 "immediate_operand" "i"))
9215    (use (match_operand:SI 3 "immediate_operand" "i"))
9216    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
9217    (clobber (reg:SI  6))
9218    (clobber (reg:SI  7))
9219    (clobber (reg:SI  8))
9220    (clobber (reg:SI  9))
9221    (clobber (reg:SI 10))
9222    (clobber (match_scratch:SI 5 "=X"))]
9223   "TARGET_STRING
9224    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9225    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9226    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9227    && REGNO (operands[4]) == 5"
9228   "lswi %4,%1,%2\;stswi %4,%0,%2"
9229   [(set_attr "type" "store_ux")
9230    (set_attr "cell_micro" "always")
9231    (set_attr "length" "8")])
9232
9233 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9234 ;; problems with TImode.
9235 ;; rD/rS = r5 is preferred, efficient form.
9236 (define_expand "movmemsi_4reg"
9237   [(parallel [(set (match_operand 0 "" "")
9238                    (match_operand 1 "" ""))
9239               (use (match_operand 2 "" ""))
9240               (use (match_operand 3 "" ""))
9241               (clobber (reg:SI 5))
9242               (clobber (reg:SI 6))
9243               (clobber (reg:SI 7))
9244               (clobber (reg:SI 8))
9245               (clobber (match_scratch:SI 4 ""))])]
9246   "TARGET_STRING"
9247   "")
9248
9249 (define_insn ""
9250   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9251         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9252    (use (match_operand:SI 2 "immediate_operand" "i"))
9253    (use (match_operand:SI 3 "immediate_operand" "i"))
9254    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
9255    (clobber (reg:SI 6))
9256    (clobber (reg:SI 7))
9257    (clobber (reg:SI 8))
9258    (clobber (match_scratch:SI 5 "=X"))]
9259   "TARGET_STRING
9260    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9261    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9262    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9263    && REGNO (operands[4]) == 5"
9264   "lswi %4,%1,%2\;stswi %4,%0,%2"
9265   [(set_attr "type" "store_ux")
9266    (set_attr "cell_micro" "always")
9267    (set_attr "length" "8")])
9268
9269 ;; Move up to 8 bytes at a time.
9270 (define_expand "movmemsi_2reg"
9271   [(parallel [(set (match_operand 0 "" "")
9272                    (match_operand 1 "" ""))
9273               (use (match_operand 2 "" ""))
9274               (use (match_operand 3 "" ""))
9275               (clobber (match_scratch:DI 4 ""))
9276               (clobber (match_scratch:SI 5 ""))])]
9277   "TARGET_STRING && ! TARGET_POWERPC64"
9278   "")
9279
9280 (define_insn ""
9281   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9282         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9283    (use (match_operand:SI 2 "immediate_operand" "i"))
9284    (use (match_operand:SI 3 "immediate_operand" "i"))
9285    (clobber (match_scratch:DI 4 "=&r"))
9286    (clobber (match_scratch:SI 5 "=X"))]
9287   "TARGET_STRING && ! TARGET_POWERPC64
9288    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9289   "lswi %4,%1,%2\;stswi %4,%0,%2"
9290   [(set_attr "type" "store_ux")
9291    (set_attr "cell_micro" "always")
9292    (set_attr "length" "8")])
9293
9294 ;; Move up to 4 bytes at a time.
9295 (define_expand "movmemsi_1reg"
9296   [(parallel [(set (match_operand 0 "" "")
9297                    (match_operand 1 "" ""))
9298               (use (match_operand 2 "" ""))
9299               (use (match_operand 3 "" ""))
9300               (clobber (match_scratch:SI 4 ""))
9301               (clobber (match_scratch:SI 5 ""))])]
9302   "TARGET_STRING"
9303   "")
9304
9305 (define_insn ""
9306   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9307         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9308    (use (match_operand:SI 2 "immediate_operand" "i"))
9309    (use (match_operand:SI 3 "immediate_operand" "i"))
9310    (clobber (match_scratch:SI 4 "=&r"))
9311    (clobber (match_scratch:SI 5 "=X"))]
9312   "TARGET_STRING && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9313   "lswi %4,%1,%2\;stswi %4,%0,%2"
9314   [(set_attr "type" "store_ux")
9315    (set_attr "cell_micro" "always")
9316    (set_attr "length" "8")])
9317 \f
9318 ;; Define insns that do load or store with update.  Some of these we can
9319 ;; get by using pre-decrement or pre-increment, but the hardware can also
9320 ;; do cases where the increment is not the size of the object.
9321 ;;
9322 ;; In all these cases, we use operands 0 and 1 for the register being
9323 ;; incremented because those are the operands that local-alloc will
9324 ;; tie and these are the pair most likely to be tieable (and the ones
9325 ;; that will benefit the most).
9326
9327 (define_insn "*movdi_update1"
9328   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9329         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9330                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9331    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9332         (plus:DI (match_dup 1) (match_dup 2)))]
9333   "TARGET_POWERPC64 && TARGET_UPDATE
9334    && (!avoiding_indexed_address_p (DImode)
9335        || !gpc_reg_operand (operands[2], DImode))"
9336   "@
9337    ldux %3,%0,%2
9338    ldu %3,%2(%0)"
9339   [(set_attr "type" "load_ux,load_u")])
9340
9341 (define_insn "movdi_<mode>_update"
9342   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9343                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9344         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9345    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9346         (plus:P (match_dup 1) (match_dup 2)))]
9347   "TARGET_POWERPC64 && TARGET_UPDATE
9348    && (!avoiding_indexed_address_p (Pmode)
9349        || !gpc_reg_operand (operands[2], Pmode)
9350        || (REG_P (operands[0])
9351            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
9352   "@
9353    stdux %3,%0,%2
9354    stdu %3,%2(%0)"
9355   [(set_attr "type" "store_ux,store_u")])
9356
9357 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
9358 ;; needed for stack allocation, even if the user passes -mno-update.
9359 (define_insn "movdi_<mode>_update_stack"
9360   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9361                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9362         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9363    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9364         (plus:P (match_dup 1) (match_dup 2)))]
9365   "TARGET_POWERPC64"
9366   "@
9367    stdux %3,%0,%2
9368    stdu %3,%2(%0)"
9369   [(set_attr "type" "store_ux,store_u")])
9370
9371 (define_insn "*movsi_update1"
9372   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9373         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9374                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9375    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9376         (plus:SI (match_dup 1) (match_dup 2)))]
9377   "TARGET_UPDATE
9378    && (!avoiding_indexed_address_p (SImode)
9379        || !gpc_reg_operand (operands[2], SImode))"
9380   "@
9381    lwzux %3,%0,%2
9382    lwzu %3,%2(%0)"
9383   [(set_attr "type" "load_ux,load_u")])
9384
9385 (define_insn "*movsi_update2"
9386   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9387         (sign_extend:DI
9388          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9389                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9390    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9391         (plus:DI (match_dup 1) (match_dup 2)))]
9392   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
9393    && !avoiding_indexed_address_p (DImode)"
9394   "lwaux %3,%0,%2"
9395   [(set_attr "type" "load_ext_ux")])
9396
9397 (define_insn "movsi_update"
9398   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9399                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9400         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9401    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9402         (plus:SI (match_dup 1) (match_dup 2)))]
9403   "TARGET_UPDATE
9404    && (!avoiding_indexed_address_p (SImode)
9405        || !gpc_reg_operand (operands[2], SImode)
9406        || (REG_P (operands[0])
9407            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
9408   "@
9409    stwux %3,%0,%2
9410    stwu %3,%2(%0)"
9411   [(set_attr "type" "store_ux,store_u")])
9412
9413 ;; This is an unconditional pattern; needed for stack allocation, even
9414 ;; if the user passes -mno-update.
9415 (define_insn "movsi_update_stack"
9416   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9417                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9418         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9419    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9420         (plus:SI (match_dup 1) (match_dup 2)))]
9421   ""
9422   "@
9423    stwux %3,%0,%2
9424    stwu %3,%2(%0)"
9425   [(set_attr "type" "store_ux,store_u")])
9426
9427 (define_insn "*movhi_update1"
9428   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9429         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9430                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9431    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9432         (plus:SI (match_dup 1) (match_dup 2)))]
9433   "TARGET_UPDATE
9434    && (!avoiding_indexed_address_p (SImode)
9435        || !gpc_reg_operand (operands[2], SImode))"
9436   "@
9437    lhzux %3,%0,%2
9438    lhzu %3,%2(%0)"
9439   [(set_attr "type" "load_ux,load_u")])
9440
9441 (define_insn "*movhi_update2"
9442   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9443         (zero_extend:SI
9444          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9445                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9446    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9447         (plus:SI (match_dup 1) (match_dup 2)))]
9448   "TARGET_UPDATE
9449    && (!avoiding_indexed_address_p (SImode)
9450        || !gpc_reg_operand (operands[2], SImode))"
9451   "@
9452    lhzux %3,%0,%2
9453    lhzu %3,%2(%0)"
9454   [(set_attr "type" "load_ux,load_u")])
9455
9456 (define_insn "*movhi_update3"
9457   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9458         (sign_extend:SI
9459          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9460                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9461    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9462         (plus:SI (match_dup 1) (match_dup 2)))]
9463   "TARGET_UPDATE && rs6000_gen_cell_microcode
9464    && (!avoiding_indexed_address_p (SImode)
9465        || !gpc_reg_operand (operands[2], SImode))"
9466   "@
9467    lhaux %3,%0,%2
9468    lhau %3,%2(%0)"
9469   [(set_attr "type" "load_ext_ux,load_ext_u")])
9470
9471 (define_insn "*movhi_update4"
9472   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9473                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9474         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9475    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9476         (plus:SI (match_dup 1) (match_dup 2)))]
9477   "TARGET_UPDATE
9478    && (!avoiding_indexed_address_p (SImode)
9479        || !gpc_reg_operand (operands[2], SImode))"
9480   "@
9481    sthux %3,%0,%2
9482    sthu %3,%2(%0)"
9483   [(set_attr "type" "store_ux,store_u")])
9484
9485 (define_insn "*movqi_update1"
9486   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9487         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9488                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9489    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9490         (plus:SI (match_dup 1) (match_dup 2)))]
9491   "TARGET_UPDATE
9492    && (!avoiding_indexed_address_p (SImode)
9493        || !gpc_reg_operand (operands[2], SImode))"
9494   "@
9495    lbzux %3,%0,%2
9496    lbzu %3,%2(%0)"
9497   [(set_attr "type" "load_ux,load_u")])
9498
9499 (define_insn "*movqi_update2"
9500   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9501         (zero_extend:SI
9502          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9503                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9504    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9505         (plus:SI (match_dup 1) (match_dup 2)))]
9506   "TARGET_UPDATE
9507    && (!avoiding_indexed_address_p (SImode)
9508        || !gpc_reg_operand (operands[2], SImode))"
9509   "@
9510    lbzux %3,%0,%2
9511    lbzu %3,%2(%0)"
9512   [(set_attr "type" "load_ux,load_u")])
9513
9514 (define_insn "*movqi_update3"
9515   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9516                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9517         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9518    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9519         (plus:SI (match_dup 1) (match_dup 2)))]
9520   "TARGET_UPDATE
9521    && (!avoiding_indexed_address_p (SImode)
9522        || !gpc_reg_operand (operands[2], SImode))"
9523   "@
9524    stbux %3,%0,%2
9525    stbu %3,%2(%0)"
9526   [(set_attr "type" "store_ux,store_u")])
9527
9528 (define_insn "*movsf_update1"
9529   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9530         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9531                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9532    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9533         (plus:SI (match_dup 1) (match_dup 2)))]
9534   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
9535    && (!avoiding_indexed_address_p (SImode)
9536        || !gpc_reg_operand (operands[2], SImode))"
9537   "@
9538    lfsux %3,%0,%2
9539    lfsu %3,%2(%0)"
9540   [(set_attr "type" "fpload_ux,fpload_u")])
9541
9542 (define_insn "*movsf_update2"
9543   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9544                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9545         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9546    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9547         (plus:SI (match_dup 1) (match_dup 2)))]
9548   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
9549    && (!avoiding_indexed_address_p (SImode)
9550        || !gpc_reg_operand (operands[2], SImode))"
9551   "@
9552    stfsux %3,%0,%2
9553    stfsu %3,%2(%0)"
9554   [(set_attr "type" "fpstore_ux,fpstore_u")])
9555
9556 (define_insn "*movsf_update3"
9557   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9558         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9559                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9560    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9561         (plus:SI (match_dup 1) (match_dup 2)))]
9562   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
9563    && (!avoiding_indexed_address_p (SImode)
9564        || !gpc_reg_operand (operands[2], SImode))"
9565   "@
9566    lwzux %3,%0,%2
9567    lwzu %3,%2(%0)"
9568   [(set_attr "type" "load_ux,load_u")])
9569
9570 (define_insn "*movsf_update4"
9571   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9572                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9573         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9574    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9575         (plus:SI (match_dup 1) (match_dup 2)))]
9576   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
9577    && (!avoiding_indexed_address_p (SImode)
9578        || !gpc_reg_operand (operands[2], SImode))"
9579   "@
9580    stwux %3,%0,%2
9581    stwu %3,%2(%0)"
9582   [(set_attr "type" "store_ux,store_u")])
9583
9584 (define_insn "*movdf_update1"
9585   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
9586         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9587                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9588    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9589         (plus:SI (match_dup 1) (match_dup 2)))]
9590   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
9591    && (!avoiding_indexed_address_p (SImode)
9592        || !gpc_reg_operand (operands[2], SImode))"
9593   "@
9594    lfdux %3,%0,%2
9595    lfdu %3,%2(%0)"
9596   [(set_attr "type" "fpload_ux,fpload_u")])
9597
9598 (define_insn "*movdf_update2"
9599   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9600                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9601         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
9602    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9603         (plus:SI (match_dup 1) (match_dup 2)))]
9604   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
9605    && (!avoiding_indexed_address_p (SImode)
9606        || !gpc_reg_operand (operands[2], SImode))"
9607   "@
9608    stfdux %3,%0,%2
9609    stfdu %3,%2(%0)"
9610   [(set_attr "type" "fpstore_ux,fpstore_u")])
9611
9612
9613 ;; After inserting conditional returns we can sometimes have
9614 ;; unnecessary register moves.  Unfortunately we cannot have a
9615 ;; modeless peephole here, because some single SImode sets have early
9616 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
9617 ;; sequences, using get_attr_length here will smash the operands
9618 ;; array.  Neither is there an early_cobbler_p predicate.
9619 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
9620 (define_peephole2
9621   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9622         (match_operand:DF 1 "any_operand" ""))
9623    (set (match_operand:DF 2 "gpc_reg_operand" "")
9624         (match_dup 0))]
9625   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
9626    && peep2_reg_dead_p (2, operands[0])"
9627   [(set (match_dup 2) (match_dup 1))])
9628
9629 (define_peephole2
9630   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9631         (match_operand:SF 1 "any_operand" ""))
9632    (set (match_operand:SF 2 "gpc_reg_operand" "")
9633         (match_dup 0))]
9634   "peep2_reg_dead_p (2, operands[0])"
9635   [(set (match_dup 2) (match_dup 1))])
9636
9637 \f
9638 ;; TLS support.
9639
9640 ;; Mode attributes for different ABIs.
9641 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
9642 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
9643 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
9644 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
9645
9646 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
9647   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9648         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
9649               (match_operand 4 "" "g")))
9650    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9651                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9652                    UNSPEC_TLSGD)
9653    (clobber (reg:SI LR_REGNO))]
9654   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
9655 {
9656   if (TARGET_CMODEL != CMODEL_SMALL)
9657     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;"
9658            "bl %z3\;nop";
9659   else
9660     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;nop";
9661 }
9662   "&& TARGET_TLS_MARKERS"
9663   [(set (match_dup 0)
9664         (unspec:TLSmode [(match_dup 1)
9665                          (match_dup 2)]
9666                         UNSPEC_TLSGD))
9667    (parallel [(set (match_dup 0)
9668                    (call (mem:TLSmode (match_dup 3))
9669                          (match_dup 4)))
9670               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
9671               (clobber (reg:SI LR_REGNO))])]
9672   ""
9673   [(set_attr "type" "two")
9674    (set (attr "length")
9675      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9676                    (const_int 16)
9677                    (const_int 12)))])
9678
9679 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
9680   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9681         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
9682               (match_operand 4 "" "g")))
9683    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9684                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9685                    UNSPEC_TLSGD)
9686    (clobber (reg:SI LR_REGNO))]
9687   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
9688 {
9689   if (flag_pic)
9690     {
9691       if (TARGET_SECURE_PLT && flag_pic == 2)
9692         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
9693       else
9694         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
9695     }
9696   else
9697     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
9698 }
9699   "&& TARGET_TLS_MARKERS"
9700   [(set (match_dup 0)
9701         (unspec:TLSmode [(match_dup 1)
9702                          (match_dup 2)]
9703                         UNSPEC_TLSGD))
9704    (parallel [(set (match_dup 0)
9705                    (call (mem:TLSmode (match_dup 3))
9706                          (match_dup 4)))
9707               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
9708               (clobber (reg:SI LR_REGNO))])]
9709   ""
9710   [(set_attr "type" "two")
9711    (set_attr "length" "8")])
9712
9713 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
9714   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9715         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9716                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9717                         UNSPEC_TLSGD))]
9718   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
9719   "addi %0,%1,%2@got@tlsgd"
9720   "&& TARGET_CMODEL != CMODEL_SMALL"
9721   [(set (match_dup 3)
9722         (high:TLSmode
9723             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))
9724    (set (match_dup 0)
9725         (lo_sum:TLSmode (match_dup 3)
9726             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)))]
9727   "
9728 {
9729   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
9730 }"
9731   [(set (attr "length")
9732      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9733                    (const_int 8)
9734                    (const_int 4)))])
9735
9736 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
9737   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9738      (high:TLSmode
9739        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9740                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9741                        UNSPEC_TLSGD)))]
9742   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
9743   "addis %0,%1,%2@got@tlsgd@ha"
9744   [(set_attr "length" "4")])
9745
9746 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
9747   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9748      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
9749        (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9750                        UNSPEC_TLSGD)))]
9751   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
9752   "addi %0,%1,%2@got@tlsgd@l"
9753   [(set_attr "length" "4")])
9754
9755 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
9756   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9757         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
9758               (match_operand 2 "" "g")))
9759    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
9760                    UNSPEC_TLSGD)
9761    (clobber (reg:SI LR_REGNO))]
9762   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
9763   "bl %z1(%3@tlsgd)\;nop"
9764   [(set_attr "type" "branch")
9765    (set_attr "length" "8")])
9766
9767 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
9768   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9769         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
9770               (match_operand 2 "" "g")))
9771    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
9772                    UNSPEC_TLSGD)
9773    (clobber (reg:SI LR_REGNO))]
9774   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
9775 {
9776   if (flag_pic)
9777     {
9778       if (TARGET_SECURE_PLT && flag_pic == 2)
9779         return "bl %z1+32768(%3@tlsgd)@plt";
9780       return "bl %z1(%3@tlsgd)@plt";
9781     }
9782   return "bl %z1(%3@tlsgd)";
9783 }
9784   [(set_attr "type" "branch")
9785    (set_attr "length" "4")])
9786
9787 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
9788   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9789         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
9790               (match_operand 3 "" "g")))
9791    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
9792                    UNSPEC_TLSLD)
9793    (clobber (reg:SI LR_REGNO))]
9794   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
9795 {
9796   if (TARGET_CMODEL != CMODEL_SMALL)
9797     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;"
9798            "bl %z2\;nop";
9799   else
9800     return "addi %0,%1,%&@got@tlsld\;bl %z2\;nop";
9801 }
9802   "&& TARGET_TLS_MARKERS"
9803   [(set (match_dup 0)
9804         (unspec:TLSmode [(match_dup 1)]
9805                         UNSPEC_TLSLD))
9806    (parallel [(set (match_dup 0)
9807                    (call (mem:TLSmode (match_dup 2))
9808                          (match_dup 3)))
9809               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
9810               (clobber (reg:SI LR_REGNO))])]
9811   ""
9812   [(set_attr "type" "two")
9813    (set (attr "length")
9814      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9815                    (const_int 16)
9816                    (const_int 12)))])
9817
9818 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
9819   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9820         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
9821               (match_operand 3 "" "g")))
9822    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
9823                    UNSPEC_TLSLD)
9824    (clobber (reg:SI LR_REGNO))]
9825   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
9826 {
9827   if (flag_pic)
9828     {
9829       if (TARGET_SECURE_PLT && flag_pic == 2)
9830         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
9831       else
9832         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
9833     }
9834   else
9835     return "addi %0,%1,%&@got@tlsld\;bl %z2";
9836 }
9837   "&& TARGET_TLS_MARKERS"
9838   [(set (match_dup 0)
9839         (unspec:TLSmode [(match_dup 1)]
9840                         UNSPEC_TLSLD))
9841    (parallel [(set (match_dup 0)
9842                    (call (mem:TLSmode (match_dup 2))
9843                          (match_dup 3)))
9844               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
9845               (clobber (reg:SI LR_REGNO))])]
9846   ""
9847   [(set_attr "length" "8")])
9848
9849 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
9850   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9851         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
9852                         UNSPEC_TLSLD))]
9853   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
9854   "addi %0,%1,%&@got@tlsld"
9855   "&& TARGET_CMODEL != CMODEL_SMALL"
9856   [(set (match_dup 2)
9857         (high:TLSmode
9858             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))
9859    (set (match_dup 0)
9860         (lo_sum:TLSmode (match_dup 2)
9861             (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
9862   "
9863 {
9864   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
9865 }"
9866   [(set (attr "length")
9867      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9868                    (const_int 8)
9869                    (const_int 4)))])
9870
9871 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
9872   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9873      (high:TLSmode
9874        (unspec:TLSmode [(const_int 0)
9875                         (match_operand:TLSmode 1 "gpc_reg_operand" "b")]
9876                        UNSPEC_TLSLD)))]
9877   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
9878   "addis %0,%1,%&@got@tlsld@ha"
9879   [(set_attr "length" "4")])
9880
9881 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
9882   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9883      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
9884        (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
9885   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
9886   "addi %0,%1,%&@got@tlsld@l"
9887   [(set_attr "length" "4")])
9888
9889 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
9890   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9891         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
9892               (match_operand 2 "" "g")))
9893    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
9894    (clobber (reg:SI LR_REGNO))]
9895   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
9896   "bl %z1(%&@tlsld)\;nop"
9897   [(set_attr "type" "branch")
9898    (set_attr "length" "8")])
9899
9900 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
9901   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9902         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
9903               (match_operand 2 "" "g")))
9904    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
9905    (clobber (reg:SI LR_REGNO))]
9906   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
9907 {
9908   if (flag_pic)
9909     {
9910       if (TARGET_SECURE_PLT && flag_pic == 2)
9911         return "bl %z1+32768(%&@tlsld)@plt";
9912       return "bl %z1(%&@tlsld)@plt";
9913     }
9914   return "bl %z1(%&@tlsld)";
9915 }
9916   [(set_attr "type" "branch")
9917    (set_attr "length" "4")])
9918
9919 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
9920   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9921         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9922                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9923                         UNSPEC_TLSDTPREL))]
9924   "HAVE_AS_TLS"
9925   "addi %0,%1,%2@dtprel")
9926
9927 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
9928   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9929         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9930                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9931                         UNSPEC_TLSDTPRELHA))]
9932   "HAVE_AS_TLS"
9933   "addis %0,%1,%2@dtprel@ha")
9934
9935 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
9936   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9937         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9938                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9939                         UNSPEC_TLSDTPRELLO))]
9940   "HAVE_AS_TLS"
9941   "addi %0,%1,%2@dtprel@l")
9942
9943 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
9944   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9945         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9946                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9947                         UNSPEC_TLSGOTDTPREL))]
9948   "HAVE_AS_TLS"
9949   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
9950   "&& TARGET_CMODEL != CMODEL_SMALL"
9951   [(set (match_dup 3)
9952         (high:TLSmode
9953             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))
9954    (set (match_dup 0)
9955         (lo_sum:TLSmode (match_dup 3)
9956             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
9957   "
9958 {
9959   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
9960 }"
9961   [(set (attr "length")
9962      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9963                    (const_int 8)
9964                    (const_int 4)))])
9965
9966 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
9967   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9968      (high:TLSmode
9969        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9970                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9971                        UNSPEC_TLSGOTDTPREL)))]
9972   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
9973   "addis %0,%1,%2@got@dtprel@ha"
9974   [(set_attr "length" "4")])
9975
9976 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
9977   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9978      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
9979          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9980                          UNSPEC_TLSGOTDTPREL)))]
9981   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
9982   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
9983   [(set_attr "length" "4")])
9984
9985 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
9986   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9987         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9988                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9989                         UNSPEC_TLSTPREL))]
9990   "HAVE_AS_TLS"
9991   "addi %0,%1,%2@tprel")
9992
9993 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
9994   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9995         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9996                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9997                         UNSPEC_TLSTPRELHA))]
9998   "HAVE_AS_TLS"
9999   "addis %0,%1,%2@tprel@ha")
10000
10001 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
10002   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
10003         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10004                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10005                         UNSPEC_TLSTPRELLO))]
10006   "HAVE_AS_TLS"
10007   "addi %0,%1,%2@tprel@l")
10008
10009 ;; "b" output constraint here and on tls_tls input to support linker tls
10010 ;; optimization.  The linker may edit the instructions emitted by a
10011 ;; tls_got_tprel/tls_tls pair to addis,addi.
10012 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
10013   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10014         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10015                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10016                         UNSPEC_TLSGOTTPREL))]
10017   "HAVE_AS_TLS"
10018   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
10019   "&& TARGET_CMODEL != CMODEL_SMALL"
10020   [(set (match_dup 3)
10021         (high:TLSmode
10022             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))
10023    (set (match_dup 0)
10024         (lo_sum:TLSmode (match_dup 3)
10025             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL)))]
10026   "
10027 {
10028   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
10029 }"
10030   [(set (attr "length")
10031      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10032                    (const_int 8)
10033                    (const_int 4)))])
10034
10035 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
10036   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10037      (high:TLSmode
10038        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10039                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10040                        UNSPEC_TLSGOTTPREL)))]
10041   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
10042   "addis %0,%1,%2@got@tprel@ha"
10043   [(set_attr "length" "4")])
10044
10045 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
10046   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
10047      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
10048          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10049                          UNSPEC_TLSGOTTPREL)))]
10050   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
10051   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
10052   [(set_attr "length" "4")])
10053
10054 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
10055   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
10056         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10057                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10058                         UNSPEC_TLSTLS))]
10059   "TARGET_ELF && HAVE_AS_TLS"
10060   "add %0,%1,%2@tls")
10061
10062 (define_expand "tls_get_tpointer"
10063   [(set (match_operand:SI 0 "gpc_reg_operand" "")
10064         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))]
10065   "TARGET_XCOFF && HAVE_AS_TLS"
10066   "
10067 {
10068   emit_insn (gen_tls_get_tpointer_internal ());
10069   emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
10070   DONE;
10071 }")
10072
10073 (define_insn "tls_get_tpointer_internal"
10074   [(set (reg:SI 3)
10075         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))
10076    (clobber (reg:SI LR_REGNO))]
10077   "TARGET_XCOFF && HAVE_AS_TLS"
10078   "bla __get_tpointer")
10079
10080 (define_expand "tls_get_addr<mode>"
10081   [(set (match_operand:P 0 "gpc_reg_operand" "")
10082         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "")
10083                    (match_operand:P 2 "gpc_reg_operand" "")] UNSPEC_TLSTLS))]
10084   "TARGET_XCOFF && HAVE_AS_TLS"
10085   "
10086 {
10087   emit_move_insn (gen_rtx_REG (Pmode, 3), operands[1]);
10088   emit_move_insn (gen_rtx_REG (Pmode, 4), operands[2]);
10089   emit_insn (gen_tls_get_addr_internal<mode> ());
10090   emit_move_insn (operands[0], gen_rtx_REG (Pmode, 3));
10091   DONE;
10092 }")
10093
10094 (define_insn "tls_get_addr_internal<mode>"
10095   [(set (reg:P 3)
10096         (unspec:P [(reg:P 3) (reg:P 4)] UNSPEC_TLSTLS))
10097    (clobber (reg:P 0))
10098    (clobber (reg:P 4))
10099    (clobber (reg:P 5))
10100    (clobber (reg:P 11))
10101    (clobber (reg:CC CR0_REGNO))
10102    (clobber (reg:P LR_REGNO))]
10103   "TARGET_XCOFF && HAVE_AS_TLS"
10104   "bla __tls_get_addr")
10105 \f
10106 ;; Next come insns related to the calling sequence.
10107 ;;
10108 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
10109 ;; We move the back-chain and decrement the stack pointer.
10110
10111 (define_expand "allocate_stack"
10112   [(set (match_operand 0 "gpc_reg_operand" "")
10113         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
10114    (set (reg 1)
10115         (minus (reg 1) (match_dup 1)))]
10116   ""
10117   "
10118 { rtx chain = gen_reg_rtx (Pmode);
10119   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
10120   rtx neg_op0;
10121   rtx insn, par, set, mem;
10122
10123   emit_move_insn (chain, stack_bot);
10124
10125   /* Check stack bounds if necessary.  */
10126   if (crtl->limit_stack)
10127     {
10128       rtx available;
10129       available = expand_binop (Pmode, sub_optab,
10130                                 stack_pointer_rtx, stack_limit_rtx,
10131                                 NULL_RTX, 1, OPTAB_WIDEN);
10132       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
10133     }
10134
10135   if (GET_CODE (operands[1]) != CONST_INT
10136       || INTVAL (operands[1]) < -32767
10137       || INTVAL (operands[1]) > 32768)
10138     {
10139       neg_op0 = gen_reg_rtx (Pmode);
10140       if (TARGET_32BIT)
10141         emit_insn (gen_negsi2 (neg_op0, operands[1]));
10142       else
10143         emit_insn (gen_negdi2 (neg_op0, operands[1]));
10144     }
10145   else
10146     neg_op0 = GEN_INT (- INTVAL (operands[1]));
10147
10148   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
10149                                        : gen_movdi_di_update_stack))
10150                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
10151                          chain));
10152   /* Since we didn't use gen_frame_mem to generate the MEM, grab
10153      it now and set the alias set/attributes. The above gen_*_update
10154      calls will generate a PARALLEL with the MEM set being the first
10155      operation. */
10156   par = PATTERN (insn);
10157   gcc_assert (GET_CODE (par) == PARALLEL);
10158   set = XVECEXP (par, 0, 0);
10159   gcc_assert (GET_CODE (set) == SET);
10160   mem = SET_DEST (set);
10161   gcc_assert (MEM_P (mem));
10162   MEM_NOTRAP_P (mem) = 1;
10163   set_mem_alias_set (mem, get_frame_alias_set ());
10164
10165   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
10166   DONE;
10167 }")
10168
10169 ;; These patterns say how to save and restore the stack pointer.  We need not
10170 ;; save the stack pointer at function level since we are careful to
10171 ;; preserve the backchain.  At block level, we have to restore the backchain
10172 ;; when we restore the stack pointer.
10173 ;;
10174 ;; For nonlocal gotos, we must save both the stack pointer and its
10175 ;; backchain and restore both.  Note that in the nonlocal case, the
10176 ;; save area is a memory location.
10177
10178 (define_expand "save_stack_function"
10179   [(match_operand 0 "any_operand" "")
10180    (match_operand 1 "any_operand" "")]
10181   ""
10182   "DONE;")
10183
10184 (define_expand "restore_stack_function"
10185   [(match_operand 0 "any_operand" "")
10186    (match_operand 1 "any_operand" "")]
10187   ""
10188   "DONE;")
10189
10190 ;; Adjust stack pointer (op0) to a new value (op1).
10191 ;; First copy old stack backchain to new location, and ensure that the
10192 ;; scheduler won't reorder the sp assignment before the backchain write.
10193 (define_expand "restore_stack_block"
10194   [(set (match_dup 2) (match_dup 3))
10195    (set (match_dup 4) (match_dup 2))
10196    (match_dup 5)
10197    (set (match_operand 0 "register_operand" "")
10198         (match_operand 1 "register_operand" ""))]
10199   ""
10200   "
10201 {
10202   rtvec p;
10203
10204   operands[1] = force_reg (Pmode, operands[1]);
10205   operands[2] = gen_reg_rtx (Pmode);
10206   operands[3] = gen_frame_mem (Pmode, operands[0]);
10207   operands[4] = gen_frame_mem (Pmode, operands[1]);
10208   p = rtvec_alloc (1);
10209   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
10210                                   gen_frame_mem (BLKmode, operands[0]),
10211                                   const0_rtx);
10212   operands[5] = gen_rtx_PARALLEL (VOIDmode, p);
10213 }")
10214
10215 (define_expand "save_stack_nonlocal"
10216   [(set (match_dup 3) (match_dup 4))
10217    (set (match_operand 0 "memory_operand" "") (match_dup 3))
10218    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
10219   ""
10220   "
10221 {
10222   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10223
10224   /* Copy the backchain to the first word, sp to the second.  */
10225   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
10226   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
10227   operands[3] = gen_reg_rtx (Pmode);
10228   operands[4] = gen_frame_mem (Pmode, operands[1]);
10229 }")
10230
10231 (define_expand "restore_stack_nonlocal"
10232   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
10233    (set (match_dup 3) (match_dup 4))
10234    (set (match_dup 5) (match_dup 2))
10235    (match_dup 6)
10236    (set (match_operand 0 "register_operand" "") (match_dup 3))]
10237   ""
10238   "
10239 {
10240   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10241   rtvec p;
10242
10243   /* Restore the backchain from the first word, sp from the second.  */
10244   operands[2] = gen_reg_rtx (Pmode);
10245   operands[3] = gen_reg_rtx (Pmode);
10246   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
10247   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
10248   operands[5] = gen_frame_mem (Pmode, operands[3]);
10249   p = rtvec_alloc (1);
10250   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
10251                                   gen_frame_mem (BLKmode, operands[0]),
10252                                   const0_rtx);
10253   operands[6] = gen_rtx_PARALLEL (VOIDmode, p);
10254 }")
10255 \f
10256 ;; TOC register handling.
10257
10258 ;; Code to initialize the TOC register...
10259
10260 (define_insn "load_toc_aix_si"
10261   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10262                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10263               (use (reg:SI 2))])]
10264   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10265   "*
10266 {
10267   char buf[30];
10268   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10269   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10270   operands[2] = gen_rtx_REG (Pmode, 2);
10271   return \"lwz %0,%1(%2)\";
10272 }"
10273   [(set_attr "type" "load")])
10274
10275 (define_insn "load_toc_aix_di"
10276   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10277                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10278               (use (reg:DI 2))])]
10279   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10280   "*
10281 {
10282   char buf[30];
10283 #ifdef TARGET_RELOCATABLE
10284   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10285                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10286 #else
10287   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10288 #endif
10289   if (TARGET_ELF)
10290     strcat (buf, \"@toc\");
10291   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10292   operands[2] = gen_rtx_REG (Pmode, 2);
10293   return \"ld %0,%1(%2)\";
10294 }"
10295   [(set_attr "type" "load")])
10296
10297 (define_insn "load_toc_v4_pic_si"
10298   [(set (reg:SI LR_REGNO)
10299         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10300   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10301   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10302   [(set_attr "type" "branch")
10303    (set_attr "length" "4")])
10304
10305 (define_expand "load_toc_v4_PIC_1"
10306   [(parallel [(set (reg:SI LR_REGNO)
10307                    (match_operand:SI 0 "immediate_operand" "s"))
10308               (use (unspec [(match_dup 0)] UNSPEC_TOC))])]
10309   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
10310    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10311   "")
10312
10313 (define_insn "load_toc_v4_PIC_1_normal"
10314   [(set (reg:SI LR_REGNO)
10315         (match_operand:SI 0 "immediate_operand" "s"))
10316    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
10317   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX
10318    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10319   "bcl 20,31,%0\\n%0:"
10320   [(set_attr "type" "branch")
10321    (set_attr "length" "4")])
10322
10323 (define_insn "load_toc_v4_PIC_1_476"
10324   [(set (reg:SI LR_REGNO)
10325         (match_operand:SI 0 "immediate_operand" "s"))
10326    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
10327   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX
10328    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10329   "*
10330 {
10331   char name[32];
10332   static char templ[32];
10333
10334   get_ppc476_thunk_name (name);
10335   sprintf (templ, \"bl %s\\n%%0:\", name);
10336   return templ;
10337 }"
10338   [(set_attr "type" "branch")
10339    (set_attr "length" "4")])
10340
10341 (define_expand "load_toc_v4_PIC_1b"
10342   [(parallel [(set (reg:SI LR_REGNO)
10343                    (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
10344                                (label_ref (match_operand 1 "" ""))]
10345                            UNSPEC_TOCPTR))
10346               (match_dup 1)])]
10347   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10348   "")
10349
10350 (define_insn "load_toc_v4_PIC_1b_normal"
10351   [(set (reg:SI LR_REGNO)
10352         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
10353                     (label_ref (match_operand 1 "" ""))]
10354                 UNSPEC_TOCPTR))
10355    (match_dup 1)]
10356   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10357   "bcl 20,31,$+8\;.long %0-$"
10358   [(set_attr "type" "branch")
10359    (set_attr "length" "8")])
10360
10361 (define_insn "load_toc_v4_PIC_1b_476"
10362   [(set (reg:SI LR_REGNO)
10363         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
10364                     (label_ref (match_operand 1 "" ""))]
10365                 UNSPEC_TOCPTR))
10366    (match_dup 1)]
10367   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10368   "*
10369 {
10370   char name[32];
10371   static char templ[32];
10372
10373   get_ppc476_thunk_name (name);
10374   sprintf (templ, \"bl %s\\n\\tb $+8\\n\\t.long %%0-$\", name);
10375   return templ;
10376 }"
10377   [(set_attr "type" "branch")
10378    (set_attr "length" "16")])
10379
10380 (define_insn "load_toc_v4_PIC_2"
10381   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10382         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10383                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10384                              (match_operand:SI 3 "immediate_operand" "s")))))]
10385   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10386   "lwz %0,%2-%3(%1)"
10387   [(set_attr "type" "load")])
10388
10389 (define_insn "load_toc_v4_PIC_3b"
10390   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10391         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10392                  (high:SI
10393                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10394                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
10395   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10396   "addis %0,%1,%2-%3@ha")
10397
10398 (define_insn "load_toc_v4_PIC_3c"
10399   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10400         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10401                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10402                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
10403   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10404   "addi %0,%1,%2-%3@l")
10405
10406 ;; If the TOC is shared over a translation unit, as happens with all
10407 ;; the kinds of PIC that we support, we need to restore the TOC
10408 ;; pointer only when jumping over units of translation.
10409 ;; On Darwin, we need to reload the picbase.
10410
10411 (define_expand "builtin_setjmp_receiver"
10412   [(use (label_ref (match_operand 0 "" "")))]
10413   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10414    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10415    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10416   "
10417 {
10418 #if TARGET_MACHO
10419   if (DEFAULT_ABI == ABI_DARWIN)
10420     {
10421       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
10422       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10423       rtx tmplabrtx;
10424       char tmplab[20];
10425
10426       crtl->uses_pic_offset_table = 1;
10427       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10428                                   CODE_LABEL_NUMBER (operands[0]));
10429       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10430
10431       emit_insn (gen_load_macho_picbase (tmplabrtx));
10432       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
10433       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10434     }
10435   else
10436 #endif
10437     rs6000_emit_load_toc_table (FALSE);
10438   DONE;
10439 }")
10440
10441 ;; Largetoc support
10442 (define_insn "*largetoc_high"
10443   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
10444         (high:DI
10445           (unspec [(match_operand:DI 1 "" "")
10446                    (match_operand:DI 2 "gpc_reg_operand" "b")]
10447                   UNSPEC_TOCREL)))]
10448    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10449    "addis %0,%2,%1@toc@ha")
10450
10451 (define_insn "*largetoc_high_aix<mode>"
10452   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
10453         (high:P
10454           (unspec [(match_operand:P 1 "" "")
10455                    (match_operand:P 2 "gpc_reg_operand" "b")]
10456                   UNSPEC_TOCREL)))]
10457    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
10458    "addis %0,%1@u(%2)")
10459
10460 (define_insn "*largetoc_high_plus"
10461   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
10462         (high:DI
10463           (plus:DI
10464             (unspec [(match_operand:DI 1 "" "")
10465                      (match_operand:DI 2 "gpc_reg_operand" "b")]
10466                     UNSPEC_TOCREL)
10467             (match_operand:DI 3 "add_cint_operand" "n"))))]
10468    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10469    "addis %0,%2,%1+%3@toc@ha")
10470
10471 (define_insn "*largetoc_high_plus_aix<mode>"
10472   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
10473         (high:P
10474           (plus:P
10475             (unspec [(match_operand:P 1 "" "")
10476                      (match_operand:P 2 "gpc_reg_operand" "b")]
10477                     UNSPEC_TOCREL)
10478             (match_operand:P 3 "add_cint_operand" "n"))))]
10479    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
10480    "addis %0,%1+%3@u(%2)")
10481
10482 (define_insn "*largetoc_low"
10483   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
10484         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,!*r")
10485                    (match_operand:DI 2 "" "")))]
10486    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10487    "@
10488     addi %0,%1,%2@l
10489     addic %0,%1,%2@l")
10490
10491 (define_insn "*largetoc_low_aix<mode>"
10492   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10493         (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
10494                    (match_operand:P 2 "" "")))]
10495    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
10496    "la %0,%2@l(%1)")
10497
10498 (define_insn_and_split "*tocref<mode>"
10499   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
10500         (match_operand:P 1 "small_toc_ref" "R"))]
10501    "TARGET_TOC"
10502    "la %0,%a1"
10503    "&& TARGET_CMODEL != CMODEL_SMALL && reload_completed"
10504   [(set (match_dup 0) (high:P (match_dup 1)))
10505    (set (match_dup 0) (lo_sum:P (match_dup 0) (match_dup 1)))])
10506
10507 ;; Elf specific ways of loading addresses for non-PIC code.
10508 ;; The output of this could be r0, but we make a very strong
10509 ;; preference for a base register because it will usually
10510 ;; be needed there.
10511 (define_insn "elf_high"
10512   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
10513         (high:SI (match_operand 1 "" "")))]
10514   "TARGET_ELF && ! TARGET_64BIT"
10515   "lis %0,%1@ha")
10516
10517 (define_insn "elf_low"
10518   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
10519         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
10520                    (match_operand 2 "" "")))]
10521    "TARGET_ELF && ! TARGET_64BIT"
10522    "@
10523     la %0,%2@l(%1)
10524     addic %0,%1,%K2")
10525 \f
10526 ;; Call and call_value insns
10527 (define_expand "call"
10528   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10529                     (match_operand 1 "" ""))
10530               (use (match_operand 2 "" ""))
10531               (clobber (reg:SI LR_REGNO))])]
10532   ""
10533   "
10534 {
10535 #if TARGET_MACHO
10536   if (MACHOPIC_INDIRECT)
10537     operands[0] = machopic_indirect_call_target (operands[0]);
10538 #endif
10539
10540   gcc_assert (GET_CODE (operands[0]) == MEM);
10541   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10542
10543   operands[0] = XEXP (operands[0], 0);
10544
10545   if (GET_CODE (operands[0]) != SYMBOL_REF
10546       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10547       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10548     {
10549       if (INTVAL (operands[2]) & CALL_LONG)
10550         operands[0] = rs6000_longcall_ref (operands[0]);
10551
10552       switch (DEFAULT_ABI)
10553         {
10554         case ABI_V4:
10555         case ABI_DARWIN:
10556           operands[0] = force_reg (Pmode, operands[0]);
10557           break;
10558
10559         case ABI_AIX:
10560           /* AIX function pointers are really pointers to a three word
10561              area.  */
10562           rs6000_call_indirect_aix (NULL_RTX, operands[0], operands[1]);
10563           DONE;
10564
10565         default:
10566           gcc_unreachable ();
10567         }
10568     }
10569 }")
10570
10571 (define_expand "call_value"
10572   [(parallel [(set (match_operand 0 "" "")
10573                    (call (mem:SI (match_operand 1 "address_operand" ""))
10574                          (match_operand 2 "" "")))
10575               (use (match_operand 3 "" ""))
10576               (clobber (reg:SI LR_REGNO))])]
10577   ""
10578   "
10579 {
10580 #if TARGET_MACHO
10581   if (MACHOPIC_INDIRECT)
10582     operands[1] = machopic_indirect_call_target (operands[1]);
10583 #endif
10584
10585   gcc_assert (GET_CODE (operands[1]) == MEM);
10586   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10587
10588   operands[1] = XEXP (operands[1], 0);
10589
10590   if (GET_CODE (operands[1]) != SYMBOL_REF
10591       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10592       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10593     {
10594       if (INTVAL (operands[3]) & CALL_LONG)
10595         operands[1] = rs6000_longcall_ref (operands[1]);
10596
10597       switch (DEFAULT_ABI)
10598         {
10599         case ABI_V4:
10600         case ABI_DARWIN:
10601           operands[1] = force_reg (Pmode, operands[1]);
10602           break;
10603
10604         case ABI_AIX:
10605           /* AIX function pointers are really pointers to a three word
10606              area.  */
10607           rs6000_call_indirect_aix (operands[0], operands[1], operands[2]);
10608           DONE;
10609
10610         default:
10611           gcc_unreachable ();
10612         }
10613     }
10614 }")
10615
10616 ;; Call to function in current module.  No TOC pointer reload needed.
10617 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10618 ;; either the function was not prototyped, or it was prototyped as a
10619 ;; variable argument function.  It is > 0 if FP registers were passed
10620 ;; and < 0 if they were not.
10621
10622 (define_insn "*call_local32"
10623   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10624          (match_operand 1 "" "g,g"))
10625    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10626    (clobber (reg:SI LR_REGNO))]
10627   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10628   "*
10629 {
10630   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10631     output_asm_insn (\"crxor 6,6,6\", operands);
10632
10633   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10634     output_asm_insn (\"creqv 6,6,6\", operands);
10635
10636   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10637 }"
10638   [(set_attr "type" "branch")
10639    (set_attr "length" "4,8")])
10640
10641 (define_insn "*call_local64"
10642   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10643          (match_operand 1 "" "g,g"))
10644    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10645    (clobber (reg:SI LR_REGNO))]
10646   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10647   "*
10648 {
10649   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10650     output_asm_insn (\"crxor 6,6,6\", operands);
10651
10652   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10653     output_asm_insn (\"creqv 6,6,6\", operands);
10654
10655   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10656 }"
10657   [(set_attr "type" "branch")
10658    (set_attr "length" "4,8")])
10659
10660 (define_insn "*call_value_local32"
10661   [(set (match_operand 0 "" "")
10662         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10663               (match_operand 2 "" "g,g")))
10664    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10665    (clobber (reg:SI LR_REGNO))]
10666   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10667   "*
10668 {
10669   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10670     output_asm_insn (\"crxor 6,6,6\", operands);
10671
10672   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10673     output_asm_insn (\"creqv 6,6,6\", operands);
10674
10675   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10676 }"
10677   [(set_attr "type" "branch")
10678    (set_attr "length" "4,8")])
10679
10680
10681 (define_insn "*call_value_local64"
10682   [(set (match_operand 0 "" "")
10683         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10684               (match_operand 2 "" "g,g")))
10685    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10686    (clobber (reg:SI LR_REGNO))]
10687   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10688   "*
10689 {
10690   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10691     output_asm_insn (\"crxor 6,6,6\", operands);
10692
10693   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10694     output_asm_insn (\"creqv 6,6,6\", operands);
10695
10696   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10697 }"
10698   [(set_attr "type" "branch")
10699    (set_attr "length" "4,8")])
10700
10701 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
10702 ;; Operand0 is the addresss of the function to call
10703 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
10704 ;; Operand2 is the location in the function descriptor to load r2 from
10705 ;; Operand3 is the stack location to hold the current TOC pointer
10706
10707 (define_insn "call_indirect_aix<ptrsize>"
10708   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
10709          (match_operand 1 "" "g,g"))
10710    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
10711    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
10712    (use (reg:P STATIC_CHAIN_REGNUM))
10713    (clobber (reg:P LR_REGNO))]
10714   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
10715   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
10716   [(set_attr "type" "jmpreg")
10717    (set_attr "length" "12")])
10718
10719 ;; Like call_indirect_aix<ptrsize>, but no use of the static chain
10720 ;; Operand0 is the addresss of the function to call
10721 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
10722 ;; Operand2 is the location in the function descriptor to load r2 from
10723 ;; Operand3 is the stack location to hold the current TOC pointer
10724
10725 (define_insn "call_indirect_aix<ptrsize>_nor11"
10726   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
10727          (match_operand 1 "" "g,g"))
10728    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
10729    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
10730    (clobber (reg:P LR_REGNO))]
10731   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
10732   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
10733   [(set_attr "type" "jmpreg")
10734    (set_attr "length" "12")])
10735
10736 ;; Operand0 is the return result of the function
10737 ;; Operand1 is the addresss of the function to call
10738 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
10739 ;; Operand3 is the location in the function descriptor to load r2 from
10740 ;; Operand4 is the stack location to hold the current TOC pointer
10741
10742 (define_insn "call_value_indirect_aix<ptrsize>"
10743   [(set (match_operand 0 "" "")
10744         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
10745               (match_operand 2 "" "g,g")))
10746    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
10747    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
10748    (use (reg:P STATIC_CHAIN_REGNUM))
10749    (clobber (reg:P LR_REGNO))]
10750   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
10751   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
10752   [(set_attr "type" "jmpreg")
10753    (set_attr "length" "12")])
10754
10755 ;; Like call_value_indirect_aix<ptrsize>, but no use of the static chain
10756 ;; Operand0 is the return result of the function
10757 ;; Operand1 is the addresss of the function to call
10758 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
10759 ;; Operand3 is the location in the function descriptor to load r2 from
10760 ;; Operand4 is the stack location to hold the current TOC pointer
10761
10762 (define_insn "call_value_indirect_aix<ptrsize>_nor11"
10763   [(set (match_operand 0 "" "")
10764         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
10765               (match_operand 2 "" "g,g")))
10766    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
10767    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
10768    (clobber (reg:P LR_REGNO))]
10769   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
10770   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
10771   [(set_attr "type" "jmpreg")
10772    (set_attr "length" "12")])
10773
10774 ;; Call to function which may be in another module.  Restore the TOC
10775 ;; pointer (r2) after the call unless this is System V.
10776 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10777 ;; either the function was not prototyped, or it was prototyped as a
10778 ;; variable argument function.  It is > 0 if FP registers were passed
10779 ;; and < 0 if they were not.
10780
10781 (define_insn "*call_nonlocal_aix32"
10782   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10783          (match_operand 1 "" "g"))
10784    (use (match_operand:SI 2 "immediate_operand" "O"))
10785    (clobber (reg:SI LR_REGNO))]
10786   "TARGET_32BIT
10787    && DEFAULT_ABI == ABI_AIX
10788    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10789   "bl %z0\;nop"
10790   [(set_attr "type" "branch")
10791    (set_attr "length" "8")])
10792    
10793 (define_insn "*call_nonlocal_aix64"
10794   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10795          (match_operand 1 "" "g"))
10796    (use (match_operand:SI 2 "immediate_operand" "O"))
10797    (clobber (reg:SI LR_REGNO))]
10798   "TARGET_64BIT
10799    && DEFAULT_ABI == ABI_AIX
10800    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10801   "bl %z0\;nop"
10802   [(set_attr "type" "branch")
10803    (set_attr "length" "8")])
10804
10805 (define_insn "*call_value_nonlocal_aix32"
10806   [(set (match_operand 0 "" "")
10807         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10808               (match_operand 2 "" "g")))
10809    (use (match_operand:SI 3 "immediate_operand" "O"))
10810    (clobber (reg:SI LR_REGNO))]
10811   "TARGET_32BIT
10812    && DEFAULT_ABI == ABI_AIX
10813    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10814   "bl %z1\;nop"
10815   [(set_attr "type" "branch")
10816    (set_attr "length" "8")])
10817
10818 (define_insn "*call_value_nonlocal_aix64"
10819   [(set (match_operand 0 "" "")
10820         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10821               (match_operand 2 "" "g")))
10822    (use (match_operand:SI 3 "immediate_operand" "O"))
10823    (clobber (reg:SI LR_REGNO))]
10824   "TARGET_64BIT
10825    && DEFAULT_ABI == ABI_AIX
10826    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10827   "bl %z1\;nop"
10828   [(set_attr "type" "branch")
10829    (set_attr "length" "8")])
10830
10831 ;; A function pointer under System V is just a normal pointer
10832 ;; operands[0] is the function pointer
10833 ;; operands[1] is the stack size to clean up
10834 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10835 ;; which indicates how to set cr1
10836
10837 (define_insn "*call_indirect_nonlocal_sysv<mode>"
10838   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
10839          (match_operand 1 "" "g,g,g,g"))
10840    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
10841    (clobber (reg:SI LR_REGNO))]
10842   "DEFAULT_ABI == ABI_V4
10843    || DEFAULT_ABI == ABI_DARWIN"
10844 {
10845   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10846     output_asm_insn ("crxor 6,6,6", operands);
10847
10848   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10849     output_asm_insn ("creqv 6,6,6", operands);
10850
10851   return "b%T0l";
10852 }
10853   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10854    (set_attr "length" "4,4,8,8")])
10855
10856 (define_insn_and_split "*call_nonlocal_sysv<mode>"
10857   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
10858          (match_operand 1 "" "g,g"))
10859    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10860    (clobber (reg:SI LR_REGNO))]
10861   "(DEFAULT_ABI == ABI_DARWIN
10862    || (DEFAULT_ABI == ABI_V4
10863        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10864 {
10865   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10866     output_asm_insn ("crxor 6,6,6", operands);
10867
10868   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10869     output_asm_insn ("creqv 6,6,6", operands);
10870
10871 #if TARGET_MACHO
10872   return output_call(insn, operands, 0, 2);
10873 #else
10874   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10875     {
10876       gcc_assert (!TARGET_SECURE_PLT);
10877       return "bl %z0@plt";
10878     }
10879   else
10880     return "bl %z0";
10881 #endif
10882 }
10883   "DEFAULT_ABI == ABI_V4
10884    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
10885    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10886   [(parallel [(call (mem:SI (match_dup 0))
10887                     (match_dup 1))
10888               (use (match_dup 2))
10889               (use (match_dup 3))
10890               (clobber (reg:SI LR_REGNO))])]
10891 {
10892   operands[3] = pic_offset_table_rtx;
10893 }
10894   [(set_attr "type" "branch,branch")
10895    (set_attr "length" "4,8")])
10896
10897 (define_insn "*call_nonlocal_sysv_secure<mode>"
10898   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
10899          (match_operand 1 "" "g,g"))
10900    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10901    (use (match_operand:SI 3 "register_operand" "r,r"))
10902    (clobber (reg:SI LR_REGNO))]
10903   "(DEFAULT_ABI == ABI_V4
10904     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
10905     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
10906 {
10907   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10908     output_asm_insn ("crxor 6,6,6", operands);
10909
10910   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10911     output_asm_insn ("creqv 6,6,6", operands);
10912
10913   if (flag_pic == 2)
10914     /* The magic 32768 offset here and in the other sysv call insns
10915        corresponds to the offset of r30 in .got2, as given by LCTOC1.
10916        See sysv4.h:toc_section.  */
10917     return "bl %z0+32768@plt";
10918   else
10919     return "bl %z0@plt";
10920 }
10921   [(set_attr "type" "branch,branch")
10922    (set_attr "length" "4,8")])
10923
10924 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
10925   [(set (match_operand 0 "" "")
10926         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
10927               (match_operand 2 "" "g,g,g,g")))
10928    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
10929    (clobber (reg:SI LR_REGNO))]
10930   "DEFAULT_ABI == ABI_V4
10931    || DEFAULT_ABI == ABI_DARWIN"
10932 {
10933   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10934     output_asm_insn ("crxor 6,6,6", operands);
10935
10936   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10937     output_asm_insn ("creqv 6,6,6", operands);
10938
10939   return "b%T1l";
10940 }
10941   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10942    (set_attr "length" "4,4,8,8")])
10943
10944 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
10945   [(set (match_operand 0 "" "")
10946         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
10947               (match_operand 2 "" "g,g")))
10948    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10949    (clobber (reg:SI LR_REGNO))]
10950   "(DEFAULT_ABI == ABI_DARWIN
10951    || (DEFAULT_ABI == ABI_V4
10952        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10953 {
10954   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10955     output_asm_insn ("crxor 6,6,6", operands);
10956
10957   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10958     output_asm_insn ("creqv 6,6,6", operands);
10959
10960 #if TARGET_MACHO
10961   return output_call(insn, operands, 1, 3);
10962 #else
10963   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10964     {
10965       gcc_assert (!TARGET_SECURE_PLT);
10966       return "bl %z1@plt";
10967     }
10968   else
10969     return "bl %z1";
10970 #endif
10971 }
10972   "DEFAULT_ABI == ABI_V4
10973    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
10974    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10975   [(parallel [(set (match_dup 0)
10976                    (call (mem:SI (match_dup 1))
10977                          (match_dup 2)))
10978               (use (match_dup 3))
10979               (use (match_dup 4))
10980               (clobber (reg:SI LR_REGNO))])]
10981 {
10982   operands[4] = pic_offset_table_rtx;
10983 }
10984   [(set_attr "type" "branch,branch")
10985    (set_attr "length" "4,8")])
10986
10987 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
10988   [(set (match_operand 0 "" "")
10989         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
10990               (match_operand 2 "" "g,g")))
10991    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10992    (use (match_operand:SI 4 "register_operand" "r,r"))
10993    (clobber (reg:SI LR_REGNO))]
10994   "(DEFAULT_ABI == ABI_V4
10995     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
10996     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
10997 {
10998   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10999     output_asm_insn ("crxor 6,6,6", operands);
11000
11001   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11002     output_asm_insn ("creqv 6,6,6", operands);
11003
11004   if (flag_pic == 2)
11005     return "bl %z1+32768@plt";
11006   else
11007     return "bl %z1@plt";
11008 }
11009   [(set_attr "type" "branch,branch")
11010    (set_attr "length" "4,8")])
11011
11012 ;; Call subroutine returning any type.
11013 (define_expand "untyped_call"
11014   [(parallel [(call (match_operand 0 "" "")
11015                     (const_int 0))
11016               (match_operand 1 "" "")
11017               (match_operand 2 "" "")])]
11018   ""
11019   "
11020 {
11021   int i;
11022
11023   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
11024
11025   for (i = 0; i < XVECLEN (operands[2], 0); i++)
11026     {
11027       rtx set = XVECEXP (operands[2], 0, i);
11028       emit_move_insn (SET_DEST (set), SET_SRC (set));
11029     }
11030
11031   /* The optimizer does not know that the call sets the function value
11032      registers we stored in the result block.  We avoid problems by
11033      claiming that all hard registers are used and clobbered at this
11034      point.  */
11035   emit_insn (gen_blockage ());
11036
11037   DONE;
11038 }")
11039
11040 ;; sibling call patterns
11041 (define_expand "sibcall"
11042   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11043                     (match_operand 1 "" ""))
11044               (use (match_operand 2 "" ""))
11045               (use (reg:SI LR_REGNO))
11046               (simple_return)])]
11047   ""
11048   "
11049 {
11050 #if TARGET_MACHO
11051   if (MACHOPIC_INDIRECT)
11052     operands[0] = machopic_indirect_call_target (operands[0]);
11053 #endif
11054
11055   gcc_assert (GET_CODE (operands[0]) == MEM);
11056   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11057
11058   operands[0] = XEXP (operands[0], 0);
11059 }")
11060
11061 ;; this and similar patterns must be marked as using LR, otherwise
11062 ;; dataflow will try to delete the store into it.  This is true
11063 ;; even when the actual reg to jump to is in CTR, when LR was
11064 ;; saved and restored around the PIC-setting BCL.
11065 (define_insn "*sibcall_local32"
11066   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11067          (match_operand 1 "" "g,g"))
11068    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11069    (use (reg:SI LR_REGNO))
11070    (simple_return)]
11071   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11072   "*
11073 {
11074   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11075     output_asm_insn (\"crxor 6,6,6\", operands);
11076
11077   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11078     output_asm_insn (\"creqv 6,6,6\", operands);
11079
11080   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
11081 }"
11082   [(set_attr "type" "branch")
11083    (set_attr "length" "4,8")])
11084
11085 (define_insn "*sibcall_local64"
11086   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11087          (match_operand 1 "" "g,g"))
11088    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11089    (use (reg:SI LR_REGNO))
11090    (simple_return)]
11091   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11092   "*
11093 {
11094   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11095     output_asm_insn (\"crxor 6,6,6\", operands);
11096
11097   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11098     output_asm_insn (\"creqv 6,6,6\", operands);
11099
11100   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
11101 }"
11102   [(set_attr "type" "branch")
11103    (set_attr "length" "4,8")])
11104
11105 (define_insn "*sibcall_value_local32"
11106   [(set (match_operand 0 "" "")
11107         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11108               (match_operand 2 "" "g,g")))
11109    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11110    (use (reg:SI LR_REGNO))
11111    (simple_return)]
11112   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11113   "*
11114 {
11115   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11116     output_asm_insn (\"crxor 6,6,6\", operands);
11117
11118   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11119     output_asm_insn (\"creqv 6,6,6\", operands);
11120
11121   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
11122 }"
11123   [(set_attr "type" "branch")
11124    (set_attr "length" "4,8")])
11125
11126
11127 (define_insn "*sibcall_value_local64"
11128   [(set (match_operand 0 "" "")
11129         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11130               (match_operand 2 "" "g,g")))
11131    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11132    (use (reg:SI LR_REGNO))
11133    (simple_return)]
11134   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11135   "*
11136 {
11137   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11138     output_asm_insn (\"crxor 6,6,6\", operands);
11139
11140   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11141     output_asm_insn (\"creqv 6,6,6\", operands);
11142
11143   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
11144 }"
11145   [(set_attr "type" "branch")
11146    (set_attr "length" "4,8")])
11147
11148 (define_insn "*sibcall_nonlocal_aix<mode>"
11149   [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
11150          (match_operand 1 "" "g,g"))
11151    (use (match_operand:SI 2 "immediate_operand" "O,O"))
11152    (use (reg:SI LR_REGNO))
11153    (simple_return)]
11154   "DEFAULT_ABI == ABI_AIX
11155    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11156   "@
11157    b %z0
11158    b%T0"
11159   [(set_attr "type" "branch")
11160    (set_attr "length" "4")])
11161
11162 (define_insn "*sibcall_value_nonlocal_aix<mode>"
11163   [(set (match_operand 0 "" "")
11164         (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
11165               (match_operand 2 "" "g,g")))
11166    (use (match_operand:SI 3 "immediate_operand" "O,O"))
11167    (use (reg:SI LR_REGNO))
11168    (simple_return)]
11169   "DEFAULT_ABI == ABI_AIX
11170    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11171   "@
11172    b %z1
11173    b%T1"
11174   [(set_attr "type" "branch")
11175    (set_attr "length" "4")])
11176
11177 (define_insn "*sibcall_nonlocal_sysv<mode>"
11178   [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c"))
11179          (match_operand 1 "" ""))
11180    (use (match_operand 2 "immediate_operand" "O,n,O,n"))
11181    (use (reg:SI LR_REGNO))
11182    (simple_return)]
11183   "(DEFAULT_ABI == ABI_DARWIN
11184     || DEFAULT_ABI == ABI_V4)
11185    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11186   "*
11187 {
11188   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11189     output_asm_insn (\"crxor 6,6,6\", operands);
11190
11191   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11192     output_asm_insn (\"creqv 6,6,6\", operands);
11193
11194   if (which_alternative >= 2)
11195     return \"b%T0\";
11196   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
11197     {
11198       gcc_assert (!TARGET_SECURE_PLT);
11199       return \"b %z0@plt\";
11200     }
11201   else
11202     return \"b %z0\";
11203 }"
11204   [(set_attr "type" "branch")
11205    (set_attr "length" "4,8,4,8")])
11206
11207 (define_expand "sibcall_value"
11208   [(parallel [(set (match_operand 0 "register_operand" "")
11209                 (call (mem:SI (match_operand 1 "address_operand" ""))
11210                       (match_operand 2 "" "")))
11211               (use (match_operand 3 "" ""))
11212               (use (reg:SI LR_REGNO))
11213               (simple_return)])]
11214   ""
11215   "
11216 {
11217 #if TARGET_MACHO
11218   if (MACHOPIC_INDIRECT)
11219     operands[1] = machopic_indirect_call_target (operands[1]);
11220 #endif
11221
11222   gcc_assert (GET_CODE (operands[1]) == MEM);
11223   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11224
11225   operands[1] = XEXP (operands[1], 0);
11226 }")
11227
11228 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
11229   [(set (match_operand 0 "" "")
11230         (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c"))
11231               (match_operand 2 "" "")))
11232    (use (match_operand:SI 3 "immediate_operand" "O,n,O,n"))
11233    (use (reg:SI LR_REGNO))
11234    (simple_return)]
11235   "(DEFAULT_ABI == ABI_DARWIN
11236     || DEFAULT_ABI == ABI_V4)
11237    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11238   "*
11239 {
11240   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11241     output_asm_insn (\"crxor 6,6,6\", operands);
11242
11243   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11244     output_asm_insn (\"creqv 6,6,6\", operands);
11245
11246   if (which_alternative >= 2)
11247     return \"b%T1\";
11248   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
11249     {
11250       gcc_assert (!TARGET_SECURE_PLT);
11251       return \"b %z1@plt\";
11252     }
11253   else
11254     return \"b %z1\";
11255 }"
11256   [(set_attr "type" "branch")
11257    (set_attr "length" "4,8,4,8")])
11258
11259 (define_expand "sibcall_epilogue"
11260   [(use (const_int 0))]
11261   ""
11262 {
11263   if (!TARGET_SCHED_PROLOG)
11264     emit_insn (gen_blockage ());
11265   rs6000_emit_epilogue (TRUE);
11266   DONE;
11267 })
11268
11269 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
11270 ;; all of memory.  This blocks insns from being moved across this point.
11271
11272 (define_insn "blockage"
11273   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
11274   ""
11275   "")
11276
11277 (define_expand "probe_stack"
11278   [(set (match_operand 0 "memory_operand" "=m")
11279         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
11280   ""
11281 {
11282   if (TARGET_64BIT)
11283     emit_insn (gen_probe_stack_di (operands[0]));
11284   else
11285     emit_insn (gen_probe_stack_si (operands[0]));
11286   DONE;
11287 })
11288
11289 (define_insn "probe_stack_<mode>"
11290   [(set (match_operand:P 0 "memory_operand" "=m")
11291         (unspec:P [(const_int 0)] UNSPEC_PROBE_STACK))]
11292   ""
11293 {
11294   operands[1] = gen_rtx_REG (Pmode, 0);
11295   return "st<wd>%U0%X0 %1,%0";
11296 }
11297   [(set_attr "type" "store")
11298    (set_attr "length" "4")])
11299
11300 (define_insn "probe_stack_range<P:mode>"
11301   [(set (match_operand:P 0 "register_operand" "=r")
11302         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
11303                             (match_operand:P 2 "register_operand" "r")]
11304                            UNSPECV_PROBE_STACK_RANGE))]
11305   ""
11306   "* return output_probe_stack_range (operands[0], operands[2]);"
11307   [(set_attr "type" "three")])
11308 \f
11309 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
11310 ;; signed & unsigned, and one type of branch.
11311 ;;
11312 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
11313 ;; insns, and branches.
11314
11315 (define_expand "cbranch<mode>4"
11316   [(use (match_operator 0 "rs6000_cbranch_operator"
11317          [(match_operand:GPR 1 "gpc_reg_operand" "")
11318           (match_operand:GPR 2 "reg_or_short_operand" "")]))
11319    (use (match_operand 3 ""))]
11320   ""
11321   "
11322 {
11323   /* Take care of the possibility that operands[2] might be negative but
11324      this might be a logical operation.  That insn doesn't exist.  */
11325   if (GET_CODE (operands[2]) == CONST_INT
11326       && INTVAL (operands[2]) < 0)
11327     {
11328       operands[2] = force_reg (<MODE>mode, operands[2]);
11329       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
11330                                     GET_MODE (operands[0]),
11331                                     operands[1], operands[2]);
11332    }
11333
11334   rs6000_emit_cbranch (<MODE>mode, operands);
11335   DONE;
11336 }")
11337
11338 (define_expand "cbranch<mode>4"
11339   [(use (match_operator 0 "rs6000_cbranch_operator"
11340          [(match_operand:FP 1 "gpc_reg_operand" "")
11341           (match_operand:FP 2 "gpc_reg_operand" "")]))
11342    (use (match_operand 3 ""))]
11343   ""
11344   "
11345 {
11346   rs6000_emit_cbranch (<MODE>mode, operands);
11347   DONE;
11348 }")
11349
11350 (define_expand "cstore<mode>4"
11351   [(use (match_operator 1 "rs6000_cbranch_operator"
11352          [(match_operand:GPR 2 "gpc_reg_operand" "")
11353           (match_operand:GPR 3 "reg_or_short_operand" "")]))
11354    (clobber (match_operand:SI 0 "register_operand"))]
11355   ""
11356   "
11357 {
11358   /* Take care of the possibility that operands[3] might be negative but
11359      this might be a logical operation.  That insn doesn't exist.  */
11360   if (GET_CODE (operands[3]) == CONST_INT
11361       && INTVAL (operands[3]) < 0)
11362     {
11363       operands[3] = force_reg (<MODE>mode, operands[3]);
11364       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
11365                                     GET_MODE (operands[1]),
11366                                     operands[2], operands[3]);
11367     }
11368
11369   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
11370      For SEQ, likewise, except that comparisons with zero should be done
11371      with an scc insns.  However, due to the order that combine see the
11372      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11373      the cases we don't want to handle or are best handled by portable
11374      code.  */
11375   if (GET_CODE (operands[1]) == NE)
11376     FAIL;
11377   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
11378        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
11379       && operands[3] == const0_rtx)
11380     FAIL;
11381   rs6000_emit_sCOND (<MODE>mode, operands);
11382   DONE;
11383 }")
11384
11385 (define_expand "cstore<mode>4"
11386   [(use (match_operator 1 "rs6000_cbranch_operator"
11387          [(match_operand:FP 2 "gpc_reg_operand" "")
11388           (match_operand:FP 3 "gpc_reg_operand" "")]))
11389    (clobber (match_operand:SI 0 "register_operand"))]
11390   ""
11391   "
11392 {
11393   rs6000_emit_sCOND (<MODE>mode, operands);
11394   DONE;
11395 }")
11396
11397
11398 (define_expand "stack_protect_set"
11399   [(match_operand 0 "memory_operand" "")
11400    (match_operand 1 "memory_operand" "")]
11401   ""
11402 {
11403 #ifdef TARGET_THREAD_SSP_OFFSET
11404   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11405   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11406   operands[1] = gen_rtx_MEM (Pmode, addr);
11407 #endif
11408   if (TARGET_64BIT)
11409     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
11410   else
11411     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
11412   DONE;
11413 })
11414
11415 (define_insn "stack_protect_setsi"
11416   [(set (match_operand:SI 0 "memory_operand" "=m")
11417         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11418    (set (match_scratch:SI 2 "=&r") (const_int 0))]
11419   "TARGET_32BIT"
11420   "lwz%U1%X1 %2,%1\;stw%U0%X0 %2,%0\;li %2,0"
11421   [(set_attr "type" "three")
11422    (set_attr "length" "12")])
11423
11424 (define_insn "stack_protect_setdi"
11425   [(set (match_operand:DI 0 "memory_operand" "=Y")
11426         (unspec:DI [(match_operand:DI 1 "memory_operand" "Y")] UNSPEC_SP_SET))
11427    (set (match_scratch:DI 2 "=&r") (const_int 0))]
11428   "TARGET_64BIT"
11429   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;li %2,0"
11430   [(set_attr "type" "three")
11431    (set_attr "length" "12")])
11432
11433 (define_expand "stack_protect_test"
11434   [(match_operand 0 "memory_operand" "")
11435    (match_operand 1 "memory_operand" "")
11436    (match_operand 2 "" "")]
11437   ""
11438 {
11439   rtx test, op0, op1;
11440 #ifdef TARGET_THREAD_SSP_OFFSET
11441   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11442   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11443   operands[1] = gen_rtx_MEM (Pmode, addr);
11444 #endif
11445   op0 = operands[0];
11446   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
11447   test = gen_rtx_EQ (VOIDmode, op0, op1);
11448   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
11449   DONE;
11450 })
11451
11452 (define_insn "stack_protect_testsi"
11453   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11454         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
11455                       (match_operand:SI 2 "memory_operand" "m,m")]
11456                      UNSPEC_SP_TEST))
11457    (set (match_scratch:SI 4 "=r,r") (const_int 0))
11458    (clobber (match_scratch:SI 3 "=&r,&r"))]
11459   "TARGET_32BIT"
11460   "@
11461    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
11462    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;cmplw %0,%3,%4\;li %3,0\;li %4,0"
11463   [(set_attr "length" "16,20")])
11464
11465 (define_insn "stack_protect_testdi"
11466   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11467         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "Y,Y")
11468                       (match_operand:DI 2 "memory_operand" "Y,Y")]
11469                      UNSPEC_SP_TEST))
11470    (set (match_scratch:DI 4 "=r,r") (const_int 0))
11471    (clobber (match_scratch:DI 3 "=&r,&r"))]
11472   "TARGET_64BIT"
11473   "@
11474    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
11475    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;li %3,0\;li %4,0"
11476   [(set_attr "length" "16,20")])
11477
11478 \f
11479 ;; Here are the actual compare insns.
11480 (define_insn "*cmp<mode>_internal1"
11481   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11482         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
11483                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
11484   ""
11485   "cmp<wd>%I2 %0,%1,%2"
11486   [(set_attr "type" "cmp")])
11487
11488 ;; If we are comparing a register for equality with a large constant,
11489 ;; we can do this with an XOR followed by a compare.  But this is profitable
11490 ;; only if the large constant is only used for the comparison (and in this
11491 ;; case we already have a register to reuse as scratch).
11492 ;;
11493 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
11494 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
11495
11496 (define_peephole2
11497   [(set (match_operand:SI 0 "register_operand")
11498         (match_operand:SI 1 "logical_const_operand" ""))
11499    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
11500                        [(match_dup 0)
11501                         (match_operand:SI 2 "logical_const_operand" "")]))
11502    (set (match_operand:CC 4 "cc_reg_operand" "")
11503         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
11504                     (match_dup 0)))
11505    (set (pc)
11506         (if_then_else (match_operator 6 "equality_operator"
11507                        [(match_dup 4) (const_int 0)])
11508                       (match_operand 7 "" "")
11509                       (match_operand 8 "" "")))]
11510   "peep2_reg_dead_p (3, operands[0])
11511    && peep2_reg_dead_p (4, operands[4])"
11512  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
11513   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
11514   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
11515  
11516 {
11517   /* Get the constant we are comparing against, and see what it looks like
11518      when sign-extended from 16 to 32 bits.  Then see what constant we could
11519      XOR with SEXTC to get the sign-extended value.  */
11520   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
11521                                               SImode,
11522                                               operands[1], operands[2]);
11523   HOST_WIDE_INT c = INTVAL (cnst);
11524   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11525   HOST_WIDE_INT xorv = c ^ sextc;
11526
11527   operands[9] = GEN_INT (xorv);
11528   operands[10] = GEN_INT (sextc);
11529 })
11530
11531 (define_insn "*cmpsi_internal2"
11532   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11533         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11534                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11535   ""
11536   "cmplw%I2 %0,%1,%b2"
11537   [(set_attr "type" "cmp")])
11538
11539 (define_insn "*cmpdi_internal2"
11540   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11541         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11542                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11543   ""
11544   "cmpld%I2 %0,%1,%b2"
11545   [(set_attr "type" "cmp")])
11546
11547 ;; The following two insns don't exist as single insns, but if we provide
11548 ;; them, we can swap an add and compare, which will enable us to overlap more
11549 ;; of the required delay between a compare and branch.  We generate code for
11550 ;; them by splitting.
11551
11552 (define_insn ""
11553   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11554         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11555                     (match_operand:SI 2 "short_cint_operand" "i")))
11556    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11557         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11558   ""
11559   "#"
11560   [(set_attr "length" "8")])
11561
11562 (define_insn ""
11563   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11564         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11565                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11566    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11567         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11568   ""
11569   "#"
11570   [(set_attr "length" "8")])
11571
11572 (define_split
11573   [(set (match_operand:CC 3 "cc_reg_operand" "")
11574         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11575                     (match_operand:SI 2 "short_cint_operand" "")))
11576    (set (match_operand:SI 0 "gpc_reg_operand" "")
11577         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11578   ""
11579   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11580    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11581
11582 (define_split
11583   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11584         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11585                        (match_operand:SI 2 "u_short_cint_operand" "")))
11586    (set (match_operand:SI 0 "gpc_reg_operand" "")
11587         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11588   ""
11589   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11590    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11591
11592 (define_insn "*cmpsf_internal1"
11593   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11594         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11595                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11596   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
11597   "fcmpu %0,%1,%2"
11598   [(set_attr "type" "fpcompare")])
11599
11600 (define_insn "*cmpdf_internal1"
11601   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11602         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
11603                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
11604   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
11605    && !VECTOR_UNIT_VSX_P (DFmode)"
11606   "fcmpu %0,%1,%2"
11607   [(set_attr "type" "fpcompare")])
11608
11609 ;; Only need to compare second words if first words equal
11610 (define_insn "*cmptf_internal1"
11611   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11612         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
11613                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
11614   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
11615    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
11616   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11617   [(set_attr "type" "fpcompare")
11618    (set_attr "length" "12")])
11619
11620 (define_insn_and_split "*cmptf_internal2"
11621   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11622         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
11623                       (match_operand:TF 2 "gpc_reg_operand" "d")))
11624     (clobber (match_scratch:DF 3 "=d"))
11625     (clobber (match_scratch:DF 4 "=d"))
11626     (clobber (match_scratch:DF 5 "=d"))
11627     (clobber (match_scratch:DF 6 "=d"))
11628     (clobber (match_scratch:DF 7 "=d"))
11629     (clobber (match_scratch:DF 8 "=d"))
11630     (clobber (match_scratch:DF 9 "=d"))
11631     (clobber (match_scratch:DF 10 "=d"))
11632     (clobber (match_scratch:GPR 11 "=b"))]
11633   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
11634    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
11635   "#"
11636   "&& reload_completed"
11637   [(set (match_dup 3) (match_dup 14))
11638    (set (match_dup 4) (match_dup 15))
11639    (set (match_dup 9) (abs:DF (match_dup 5)))
11640    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11641    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11642                            (label_ref (match_dup 12))
11643                            (pc)))
11644    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11645    (set (pc) (label_ref (match_dup 13)))
11646    (match_dup 12)
11647    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11648    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11649    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11650    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
11651    (match_dup 13)]
11652 {
11653   REAL_VALUE_TYPE rv;
11654   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
11655   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
11656
11657   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11658   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11659   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11660   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11661   operands[12] = gen_label_rtx ();
11662   operands[13] = gen_label_rtx ();
11663   real_inf (&rv);
11664   operands[14] = force_const_mem (DFmode,
11665                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11666   operands[15] = force_const_mem (DFmode,
11667                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11668                                                                 DFmode));
11669   if (TARGET_TOC)
11670     {
11671       rtx tocref;
11672       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
11673       operands[14] = gen_const_mem (DFmode, tocref);
11674       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
11675       operands[15] = gen_const_mem (DFmode, tocref);
11676       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11677       set_mem_alias_set (operands[15], get_TOC_alias_set ());
11678     }
11679 })
11680 \f
11681 ;; Now we have the scc insns.  We can do some combinations because of the
11682 ;; way the machine works.
11683 ;;
11684 ;; Note that this is probably faster if we can put an insn between the
11685 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11686 ;; cases the insns below which don't use an intermediate CR field will
11687 ;; be used instead.
11688 (define_insn ""
11689   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11690         (match_operator:SI 1 "scc_comparison_operator"
11691                            [(match_operand 2 "cc_reg_operand" "y")
11692                             (const_int 0)]))]
11693   ""
11694   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
11695   [(set (attr "type")
11696      (cond [(match_test "TARGET_MFCRF")
11697                 (const_string "mfcrf")
11698            ]
11699         (const_string "mfcr")))
11700    (set_attr "length" "8")])
11701
11702 ;; Same as above, but get the GT bit.
11703 (define_insn "move_from_CR_gt_bit"
11704   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11705         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11706   "TARGET_HARD_FLOAT && !TARGET_FPRS"
11707   "mfcr %0\;rlwinm %0,%0,%D1,31,31"
11708   [(set_attr "type" "mfcr")
11709    (set_attr "length" "8")])
11710
11711 ;; Same as above, but get the OV/ORDERED bit.
11712 (define_insn "move_from_CR_ov_bit"
11713   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11714         (unspec:SI [(match_operand:CC 1 "cc_reg_operand" "y")]
11715                    UNSPEC_MV_CR_OV))]
11716   "TARGET_ISEL"
11717   "mfcr %0\;rlwinm %0,%0,%t1,1"
11718   [(set_attr "type" "mfcr")
11719    (set_attr "length" "8")])
11720
11721 (define_insn ""
11722   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11723         (match_operator:DI 1 "scc_comparison_operator"
11724                            [(match_operand 2 "cc_reg_operand" "y")
11725                             (const_int 0)]))]
11726   "TARGET_POWERPC64"
11727   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
11728   [(set (attr "type")
11729      (cond [(match_test "TARGET_MFCRF")
11730                 (const_string "mfcrf")
11731            ]
11732         (const_string "mfcr")))
11733    (set_attr "length" "8")])
11734
11735 (define_insn ""
11736   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11737         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11738                                        [(match_operand 2 "cc_reg_operand" "y,y")
11739                                         (const_int 0)])
11740                     (const_int 0)))
11741    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11742         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11743   "TARGET_32BIT"
11744   "@
11745    mfcr %3%Q2\;rlwinm. %3,%3,%J1,1
11746    #"
11747   [(set_attr "type" "delayed_compare")
11748    (set_attr "length" "8,16")])
11749
11750 (define_split
11751   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11752         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11753                                        [(match_operand 2 "cc_reg_operand" "")
11754                                         (const_int 0)])
11755                     (const_int 0)))
11756    (set (match_operand:SI 3 "gpc_reg_operand" "")
11757         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11758   "TARGET_32BIT && reload_completed"
11759   [(set (match_dup 3)
11760         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11761    (set (match_dup 0)
11762         (compare:CC (match_dup 3)
11763                     (const_int 0)))]
11764   "")
11765
11766 (define_insn ""
11767   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11768         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11769                                       [(match_operand 2 "cc_reg_operand" "y")
11770                                        (const_int 0)])
11771                    (match_operand:SI 3 "const_int_operand" "n")))]
11772   ""
11773   "*
11774 {
11775   int is_bit = ccr_bit (operands[1], 1);
11776   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11777   int count;
11778
11779   if (is_bit >= put_bit)
11780     count = is_bit - put_bit;
11781   else
11782     count = 32 - (put_bit - is_bit);
11783
11784   operands[4] = GEN_INT (count);
11785   operands[5] = GEN_INT (put_bit);
11786
11787   return \"mfcr %0%Q2\;rlwinm %0,%0,%4,%5,%5\";
11788 }"
11789   [(set (attr "type")
11790      (cond [(match_test "TARGET_MFCRF")
11791                 (const_string "mfcrf")
11792            ]
11793         (const_string "mfcr")))
11794    (set_attr "length" "8")])
11795
11796 (define_insn ""
11797   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11798         (compare:CC
11799          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11800                                        [(match_operand 2 "cc_reg_operand" "y,y")
11801                                         (const_int 0)])
11802                     (match_operand:SI 3 "const_int_operand" "n,n"))
11803          (const_int 0)))
11804    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11805         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11806                    (match_dup 3)))]
11807   ""
11808   "*
11809 {
11810   int is_bit = ccr_bit (operands[1], 1);
11811   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11812   int count;
11813
11814   /* Force split for non-cc0 compare.  */
11815   if (which_alternative == 1)
11816      return \"#\";
11817
11818   if (is_bit >= put_bit)
11819     count = is_bit - put_bit;
11820   else
11821     count = 32 - (put_bit - is_bit);
11822
11823   operands[5] = GEN_INT (count);
11824   operands[6] = GEN_INT (put_bit);
11825
11826   return \"mfcr %4%Q2\;rlwinm. %4,%4,%5,%6,%6\";
11827 }"
11828   [(set_attr "type" "delayed_compare")
11829    (set_attr "length" "8,16")])
11830
11831 (define_split
11832   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
11833         (compare:CC
11834          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11835                                        [(match_operand 2 "cc_reg_operand" "")
11836                                         (const_int 0)])
11837                     (match_operand:SI 3 "const_int_operand" ""))
11838          (const_int 0)))
11839    (set (match_operand:SI 4 "gpc_reg_operand" "")
11840         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11841                    (match_dup 3)))]
11842   "reload_completed"
11843   [(set (match_dup 4)
11844         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11845                    (match_dup 3)))
11846    (set (match_dup 0)
11847         (compare:CC (match_dup 4)
11848                     (const_int 0)))]
11849   "")
11850
11851 ;; There is a 3 cycle delay between consecutive mfcr instructions
11852 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11853
11854 (define_peephole
11855   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11856         (match_operator:SI 1 "scc_comparison_operator"
11857                            [(match_operand 2 "cc_reg_operand" "y")
11858                             (const_int 0)]))
11859    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11860         (match_operator:SI 4 "scc_comparison_operator"
11861                            [(match_operand 5 "cc_reg_operand" "y")
11862                             (const_int 0)]))]
11863   "REGNO (operands[2]) != REGNO (operands[5])"
11864   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
11865   [(set_attr "type" "mfcr")
11866    (set_attr "length" "12")])
11867
11868 (define_peephole
11869   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11870         (match_operator:DI 1 "scc_comparison_operator"
11871                            [(match_operand 2 "cc_reg_operand" "y")
11872                             (const_int 0)]))
11873    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11874         (match_operator:DI 4 "scc_comparison_operator"
11875                            [(match_operand 5 "cc_reg_operand" "y")
11876                             (const_int 0)]))]
11877   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11878   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
11879   [(set_attr "type" "mfcr")
11880    (set_attr "length" "12")])
11881
11882 ;; There are some scc insns that can be done directly, without a compare.
11883 ;; These are faster because they don't involve the communications between
11884 ;; the FXU and branch units.   In fact, we will be replacing all of the
11885 ;; integer scc insns here or in the portable methods in emit_store_flag.
11886 ;;
11887 ;; Also support (neg (scc ..)) since that construct is used to replace
11888 ;; branches, (plus (scc ..) ..) since that construct is common and
11889 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11890 ;; cases where it is no more expensive than (neg (scc ..)).
11891
11892 ;; Have reload force a constant into a register for the simple insns that
11893 ;; otherwise won't accept constants.  We do this because it is faster than
11894 ;; the cmp/mfcr sequence we would otherwise generate.
11895
11896 (define_mode_attr scc_eq_op2 [(SI "rKLI")
11897                               (DI "rKJI")])
11898
11899 (define_insn_and_split "*eq<mode>"
11900   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
11901         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
11902                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
11903   ""
11904   "#"
11905   ""
11906   [(set (match_dup 0)
11907         (clz:GPR (match_dup 3)))
11908    (set (match_dup 0)
11909         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
11910   {
11911     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11912       {
11913         /* Use output operand as intermediate.  */
11914         operands[3] = operands[0];
11915
11916         if (logical_operand (operands[2], <MODE>mode))
11917           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11918                                   gen_rtx_XOR (<MODE>mode,
11919                                                operands[1], operands[2])));
11920         else
11921           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11922                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11923                                                 negate_rtx (<MODE>mode,
11924                                                             operands[2]))));
11925       }
11926     else
11927       operands[3] = operands[1];
11928
11929     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11930   })
11931
11932 (define_insn_and_split "*eq<mode>_compare"
11933   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11934         (compare:CC
11935          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
11936                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
11937          (const_int 0)))
11938    (set (match_operand:P 0 "gpc_reg_operand" "=r")
11939         (eq:P (match_dup 1) (match_dup 2)))]
11940   "optimize_size"
11941   "#"
11942   "optimize_size"
11943   [(set (match_dup 0)
11944         (clz:P (match_dup 4)))
11945    (parallel [(set (match_dup 3)
11946                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
11947                                (const_int 0)))
11948               (set (match_dup 0)
11949                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
11950   {
11951     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11952       {
11953         /* Use output operand as intermediate.  */
11954         operands[4] = operands[0];
11955
11956         if (logical_operand (operands[2], <MODE>mode))
11957           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11958                                   gen_rtx_XOR (<MODE>mode,
11959                                                operands[1], operands[2])));
11960         else
11961           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11962                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11963                                                 negate_rtx (<MODE>mode,
11964                                                             operands[2]))));
11965       }
11966     else
11967       operands[4] = operands[1];
11968
11969     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11970   })
11971
11972 ;; We have insns of the form shown by the first define_insn below.  If
11973 ;; there is something inside the comparison operation, we must split it.
11974 (define_split
11975   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11976         (plus:SI (match_operator 1 "comparison_operator"
11977                                  [(match_operand:SI 2 "" "")
11978                                   (match_operand:SI 3
11979                                                     "reg_or_cint_operand" "")])
11980                  (match_operand:SI 4 "gpc_reg_operand" "")))
11981    (clobber (match_operand:SI 5 "register_operand" ""))]
11982   "! gpc_reg_operand (operands[2], SImode)"
11983   [(set (match_dup 5) (match_dup 2))
11984    (set (match_dup 0) (plus:SI (match_op_dup 1 [(match_dup 5) (match_dup 3)])
11985                                (match_dup 4)))])
11986
11987 (define_insn "*plus_eqsi"
11988   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11989         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11990                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
11991                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11992   "TARGET_32BIT"
11993   "@
11994    xor %0,%1,%2\;subfic %0,%0,0\;addze %0,%3
11995    subfic %0,%1,0\;addze %0,%3
11996    xori %0,%1,%b2\;subfic %0,%0,0\;addze %0,%3
11997    xoris %0,%1,%u2\;subfic %0,%0,0\;addze %0,%3
11998    subfic %0,%1,%2\;subfic %0,%0,0\;addze %0,%3"
11999   [(set_attr "type" "three,two,three,three,three")
12000    (set_attr "length" "12,8,12,12,12")])
12001
12002 (define_insn "*compare_plus_eqsi"
12003   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12004         (compare:CC
12005          (plus:SI
12006           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12007                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12008           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12009          (const_int 0)))
12010    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
12011   "TARGET_32BIT && optimize_size"
12012   "@
12013    xor %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
12014    subfic %4,%1,0\;addze. %4,%3
12015    xori %4,%1,%b2\;subfic %4,%4,0\;addze. %4,%3
12016    xoris %4,%1,%u2\;subfic %4,%4,0\;addze. %4,%3
12017    subfic %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
12018    #
12019    #
12020    #
12021    #
12022    #"
12023   [(set_attr "type" "compare")
12024    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12025
12026 (define_split
12027   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12028         (compare:CC
12029          (plus:SI
12030           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12031                  (match_operand:SI 2 "scc_eq_operand" ""))
12032           (match_operand:SI 3 "gpc_reg_operand" ""))
12033          (const_int 0)))
12034    (clobber (match_scratch:SI 4 ""))]
12035   "TARGET_32BIT && optimize_size && reload_completed"
12036   [(set (match_dup 4)
12037         (plus:SI (eq:SI (match_dup 1)
12038                  (match_dup 2))
12039           (match_dup 3)))
12040    (set (match_dup 0)
12041         (compare:CC (match_dup 4)
12042                     (const_int 0)))]
12043   "")
12044
12045 (define_insn "*plus_eqsi_compare"
12046   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12047         (compare:CC
12048          (plus:SI
12049           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12050                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12051           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12052          (const_int 0)))
12053    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
12054         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12055   "TARGET_32BIT && optimize_size"
12056   "@
12057    xor %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
12058    subfic %0,%1,0\;addze. %0,%3
12059    xori %0,%1,%b2\;subfic %0,%0,0\;addze. %0,%3
12060    xoris %0,%1,%u2\;subfic %0,%0,0\;addze. %0,%3
12061    subfic %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
12062    #
12063    #
12064    #
12065    #
12066    #"
12067   [(set_attr "type" "compare")
12068    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12069
12070 (define_split
12071   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12072         (compare:CC
12073          (plus:SI
12074           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12075                  (match_operand:SI 2 "scc_eq_operand" ""))
12076           (match_operand:SI 3 "gpc_reg_operand" ""))
12077          (const_int 0)))
12078    (set (match_operand:SI 0 "gpc_reg_operand" "")
12079         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12080   "TARGET_32BIT && optimize_size && reload_completed"
12081   [(set (match_dup 0)
12082         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12083    (set (match_dup 4)
12084         (compare:CC (match_dup 0)
12085                     (const_int 0)))]
12086   "")
12087
12088 (define_insn "*neg_eq0<mode>"
12089   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12090         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
12091                      (const_int 0))))]
12092   ""
12093   "addic %0,%1,-1\;subfe %0,%0,%0"
12094   [(set_attr "type" "two")
12095    (set_attr "length" "8")])
12096
12097 (define_insn_and_split "*neg_eq<mode>"
12098   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12099         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
12100                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
12101   ""
12102   "#"
12103   ""
12104   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
12105   {
12106     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12107       {
12108         /* Use output operand as intermediate.  */
12109         operands[3] = operands[0];
12110
12111         if (logical_operand (operands[2], <MODE>mode))
12112           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12113                                   gen_rtx_XOR (<MODE>mode,
12114                                                operands[1], operands[2])));
12115         else
12116           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12117                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12118                                                 negate_rtx (<MODE>mode,
12119                                                             operands[2]))));
12120       }
12121     else
12122       operands[3] = operands[1];
12123   })
12124
12125 (define_insn "*ne0_<mode>"
12126   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12127         (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
12128               (const_int 0)))
12129    (clobber (match_scratch:P 2 "=&r"))]
12130   "!(TARGET_32BIT && TARGET_ISEL)"
12131   "addic %2,%1,-1\;subfe %0,%2,%1"
12132   [(set_attr "type" "two")
12133    (set_attr "length" "8")])
12134
12135 (define_insn "*plus_ne0_<mode>"
12136   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12137         (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
12138                       (const_int 0))
12139                 (match_operand:P 2 "gpc_reg_operand" "r")))
12140    (clobber (match_scratch:P 3 "=&r"))]
12141   ""
12142   "addic %3,%1,-1\;addze %0,%2"
12143   [(set_attr "type" "two")
12144    (set_attr "length" "8")])
12145
12146 (define_insn "*compare_plus_ne0_<mode>"
12147   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12148         (compare:CC (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12149                                   (const_int 0))
12150                             (match_operand:P 2 "gpc_reg_operand" "r,r"))
12151                     (const_int 0)))
12152    (clobber (match_scratch:P 3 "=&r,&r"))
12153    (clobber (match_scratch:P 4 "=X,&r"))]
12154   ""
12155   "@
12156    addic %3,%1,-1\;addze. %3,%2
12157    #"
12158   [(set_attr "type" "compare")
12159    (set_attr "length" "8,12")])
12160
12161 (define_split
12162   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
12163         (compare:CC (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
12164                           (const_int 0))
12165                     (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
12166    (clobber (match_scratch:P 3 ""))
12167    (clobber (match_scratch:P 4 ""))]
12168   "reload_completed"
12169   [(parallel [(set (match_dup 3)
12170                    (plus:P (ne:P (match_dup 1)
12171                                  (const_int 0))
12172                            (match_dup 2)))
12173               (clobber (match_dup 4))])
12174    (set (match_dup 0)
12175         (compare:CC (match_dup 3)
12176                     (const_int 0)))]
12177   "")
12178
12179 ; For combine.
12180 (define_insn "*compare_plus_ne0_<mode>_1"
12181   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12182         (compare:CCEQ (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12183                             (const_int 0))
12184                       (neg:P (match_operand:P 2 "gpc_reg_operand" "r,r"))))
12185    (clobber (match_scratch:P 3 "=&r,&r"))
12186    (clobber (match_scratch:P 4 "=X,&r"))]
12187   ""
12188   "@
12189    addic %3,%1,-1\;addze. %3,%2
12190    #"
12191   [(set_attr "type" "compare")
12192    (set_attr "length" "8,12")])
12193
12194 (define_split
12195   [(set (match_operand:CCEQ 0 "cc_reg_not_micro_cr0_operand" "")
12196         (compare:CCEQ (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
12197                             (const_int 0))
12198                       (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
12199    (clobber (match_scratch:P 3 ""))
12200    (clobber (match_scratch:P 4 ""))]
12201   "reload_completed"
12202   [(parallel [(set (match_dup 3)
12203                    (plus:P (ne:P (match_dup 1)
12204                                  (const_int 0))
12205                            (match_dup 2)))
12206               (clobber (match_dup 4))])
12207    (set (match_dup 0)
12208         (compare:CC (match_dup 3)
12209                     (const_int 0)))]
12210   "")
12211
12212 (define_insn "*plus_ne0_<mode>_compare"
12213   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12214         (compare:CC
12215          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12216                        (const_int 0))
12217                  (match_operand:P 2 "gpc_reg_operand" "r,r"))
12218          (const_int 0)))
12219    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12220         (plus:P (ne:P (match_dup 1)
12221                       (const_int 0))
12222                 (match_dup 2)))
12223    (clobber (match_scratch:P 3 "=&r,&r"))]
12224   ""
12225   "@
12226    addic %3,%1,-1\;addze. %0,%2
12227    #"
12228   [(set_attr "type" "compare")
12229    (set_attr "length" "8,12")])
12230
12231 (define_split
12232   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
12233         (compare:CC
12234          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "")
12235                        (const_int 0))
12236                  (match_operand:P 2 "gpc_reg_operand" ""))
12237          (const_int 0)))
12238    (set (match_operand:P 0 "gpc_reg_operand" "")
12239         (plus:P (ne:P (match_dup 1)
12240                       (const_int 0))
12241                 (match_dup 2)))
12242    (clobber (match_scratch:P 3 ""))]
12243   "reload_completed"
12244   [(parallel [(set (match_dup 0)
12245                    (plus:P (ne:P (match_dup 1)
12246                                  (const_int 0))
12247                            (match_dup 2)))
12248               (clobber (match_dup 3))])
12249    (set (match_dup 4)
12250         (compare:CC (match_dup 0)
12251                     (const_int 0)))]
12252   "")
12253
12254 (define_insn "*leu<mode>"
12255   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12256         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12257                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12258   ""
12259   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12260   [(set_attr "type" "three")
12261    (set_attr "length" "12")])
12262
12263 (define_insn "*leu<mode>_compare"
12264   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12265         (compare:CC
12266          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12267                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12268          (const_int 0)))
12269    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12270         (leu:P (match_dup 1) (match_dup 2)))]
12271   ""
12272   "@
12273    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12274    #"
12275   [(set_attr "type" "compare")
12276    (set_attr "length" "12,16")])
12277
12278 (define_split
12279   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12280         (compare:CC
12281          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
12282                 (match_operand:P 2 "reg_or_short_operand" ""))
12283          (const_int 0)))
12284    (set (match_operand:P 0 "gpc_reg_operand" "")
12285         (leu:P (match_dup 1) (match_dup 2)))]
12286   "reload_completed"
12287   [(set (match_dup 0)
12288         (leu:P (match_dup 1) (match_dup 2)))
12289    (set (match_dup 3)
12290         (compare:CC (match_dup 0)
12291                     (const_int 0)))]
12292   "")
12293
12294 (define_insn "*plus_leu<mode>"
12295   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12296         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12297                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12298                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12299   ""
12300   "subf%I2c %0,%1,%2\;addze %0,%3"
12301   [(set_attr "type" "two")
12302    (set_attr "length" "8")])
12303
12304 (define_insn ""
12305   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12306         (compare:CC
12307          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12308                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12309                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12310          (const_int 0)))
12311    (clobber (match_scratch:SI 4 "=&r,&r"))]
12312   "TARGET_32BIT"
12313   "@
12314    subf%I2c %4,%1,%2\;addze. %4,%3
12315    #"
12316   [(set_attr "type" "compare")
12317    (set_attr "length" "8,12")])
12318
12319 (define_split
12320   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12321         (compare:CC
12322          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12323                           (match_operand:SI 2 "reg_or_short_operand" ""))
12324                   (match_operand:SI 3 "gpc_reg_operand" ""))
12325          (const_int 0)))
12326    (clobber (match_scratch:SI 4 ""))]
12327   "TARGET_32BIT && reload_completed"
12328   [(set (match_dup 4)
12329         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12330                   (match_dup 3)))
12331    (set (match_dup 0)
12332         (compare:CC (match_dup 4)
12333                     (const_int 0)))]
12334   "")
12335
12336 (define_insn ""
12337   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12338         (compare:CC
12339          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12340                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12341                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12342          (const_int 0)))
12343    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12344         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12345   "TARGET_32BIT"
12346   "@
12347    subf%I2c %0,%1,%2\;addze. %0,%3
12348    #"
12349   [(set_attr "type" "compare")
12350    (set_attr "length" "8,12")])
12351
12352 (define_split
12353   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12354         (compare:CC
12355          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12356                           (match_operand:SI 2 "reg_or_short_operand" ""))
12357                   (match_operand:SI 3 "gpc_reg_operand" ""))
12358          (const_int 0)))
12359    (set (match_operand:SI 0 "gpc_reg_operand" "")
12360         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12361   "TARGET_32BIT && reload_completed"
12362   [(set (match_dup 0)
12363         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12364    (set (match_dup 4)
12365         (compare:CC (match_dup 0)
12366                     (const_int 0)))]
12367   "")
12368
12369 (define_insn "*neg_leu<mode>"
12370   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12371         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12372                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12373   ""
12374   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;nand %0,%0,%0"
12375    [(set_attr "type" "three")
12376     (set_attr "length" "12")])
12377
12378 (define_insn "*and_neg_leu<mode>"
12379   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12380         (and:P (neg:P
12381                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12382                         (match_operand:P 2 "reg_or_short_operand" "rI")))
12383                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12384   ""
12385   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc %0,%3,%0"
12386   [(set_attr "type" "three")
12387    (set_attr "length" "12")])
12388
12389 (define_insn ""
12390   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12391         (compare:CC
12392          (and:SI (neg:SI
12393                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12394                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12395                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12396          (const_int 0)))
12397    (clobber (match_scratch:SI 4 "=&r,&r"))]
12398   "TARGET_32BIT"
12399   "@
12400    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;andc. %4,%3,%4
12401    #"
12402   [(set_attr "type" "compare")
12403    (set_attr "length" "12,16")])
12404
12405 (define_split
12406   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12407         (compare:CC
12408          (and:SI (neg:SI
12409                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12410                           (match_operand:SI 2 "reg_or_short_operand" "")))
12411                  (match_operand:SI 3 "gpc_reg_operand" ""))
12412          (const_int 0)))
12413    (clobber (match_scratch:SI 4 ""))]
12414   "TARGET_32BIT && reload_completed"
12415   [(set (match_dup 4)
12416         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12417                 (match_dup 3)))
12418    (set (match_dup 0)
12419         (compare:CC (match_dup 4)
12420                     (const_int 0)))]
12421   "")
12422
12423 (define_insn ""
12424   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12425         (compare:CC
12426          (and:SI (neg:SI
12427                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12428                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12429                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12430          (const_int 0)))
12431    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12432         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12433   "TARGET_32BIT"
12434   "@
12435    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc. %0,%3,%0
12436    #"
12437   [(set_attr "type" "compare")
12438    (set_attr "length" "12,16")])
12439
12440 (define_split
12441   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12442         (compare:CC
12443          (and:SI (neg:SI
12444                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12445                           (match_operand:SI 2 "reg_or_short_operand" "")))
12446                  (match_operand:SI 3 "gpc_reg_operand" ""))
12447          (const_int 0)))
12448    (set (match_operand:SI 0 "gpc_reg_operand" "")
12449         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12450   "TARGET_32BIT && reload_completed"
12451   [(set (match_dup 0)
12452         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12453                 (match_dup 3)))
12454    (set (match_dup 4)
12455         (compare:CC (match_dup 0)
12456                     (const_int 0)))]
12457   "")
12458
12459 (define_insn_and_split "*ltu<mode>"
12460   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12461         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12462                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12463   ""
12464   "#"
12465   ""
12466   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12467    (set (match_dup 0) (neg:P (match_dup 0)))]
12468   "")
12469
12470 (define_insn_and_split "*ltu<mode>_compare"
12471   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12472         (compare:CC
12473          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12474                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12475          (const_int 0)))
12476    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12477         (ltu:P (match_dup 1) (match_dup 2)))]
12478   ""
12479   "#"
12480   ""
12481   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12482    (parallel [(set (match_dup 3)
12483                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
12484               (set (match_dup 0) (neg:P (match_dup 0)))])]
12485   "")
12486
12487 (define_insn_and_split "*plus_ltu<mode>"
12488   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
12489         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12490                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
12491                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
12492   ""
12493   "#"
12494   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12495   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12496    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
12497   "")
12498
12499 (define_insn_and_split "*plus_ltu<mode>_compare"
12500   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12501         (compare:CC
12502          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12503                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12504                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
12505          (const_int 0)))
12506    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12507         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
12508   ""
12509   "#"
12510   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12511   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12512    (parallel [(set (match_dup 4)
12513                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
12514                                (const_int 0)))
12515               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
12516   "")
12517
12518 (define_insn "*neg_ltu<mode>"
12519   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12520         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12521                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
12522   ""
12523   "@
12524    subfc %0,%2,%1\;subfe %0,%0,%0
12525    addic %0,%1,%n2\;subfe %0,%0,%0"
12526   [(set_attr "type" "two")
12527    (set_attr "length" "8")])
12528
12529 (define_insn "*geu<mode>"
12530   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12531         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12532                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12533   ""
12534   "@
12535    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12536    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12537   [(set_attr "type" "three")
12538    (set_attr "length" "12")])
12539
12540 (define_insn "*geu<mode>_compare"
12541   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12542         (compare:CC
12543          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12544                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12545          (const_int 0)))
12546    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12547         (geu:P (match_dup 1) (match_dup 2)))]
12548   ""
12549   "@
12550    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12551    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12552    #
12553    #"
12554   [(set_attr "type" "compare")
12555    (set_attr "length" "12,12,16,16")])
12556
12557 (define_split
12558   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
12559         (compare:CC
12560          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
12561                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
12562          (const_int 0)))
12563    (set (match_operand:P 0 "gpc_reg_operand" "")
12564         (geu:P (match_dup 1) (match_dup 2)))]
12565   "reload_completed"
12566   [(set (match_dup 0)
12567         (geu:P (match_dup 1) (match_dup 2)))
12568    (set (match_dup 3)
12569         (compare:CC (match_dup 0)
12570                     (const_int 0)))]
12571   "")
12572
12573 (define_insn "*plus_geu<mode>"
12574   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
12575         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12576                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
12577                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
12578   ""
12579   "@
12580    subfc %0,%2,%1\;addze %0,%3
12581    addic %0,%1,%n2\;addze %0,%3"
12582   [(set_attr "type" "two")
12583    (set_attr "length" "8")])
12584
12585 (define_insn ""
12586   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12587         (compare:CC
12588          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12589                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12590                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12591          (const_int 0)))
12592    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12593   "TARGET_32BIT"
12594   "@
12595    subfc %4,%2,%1\;addze. %4,%3
12596    addic %4,%1,%n2\;addze. %4,%3
12597    #
12598    #"
12599   [(set_attr "type" "compare")
12600    (set_attr "length" "8,8,12,12")])
12601
12602 (define_split
12603   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12604         (compare:CC
12605          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12606                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12607                   (match_operand:SI 3 "gpc_reg_operand" ""))
12608          (const_int 0)))
12609    (clobber (match_scratch:SI 4 ""))]
12610   "TARGET_32BIT && reload_completed"
12611   [(set (match_dup 4)
12612         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12613                   (match_dup 3)))
12614    (set (match_dup 0)
12615         (compare:CC (match_dup 4)
12616                     (const_int 0)))]
12617   "")
12618
12619 (define_insn ""
12620   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12621         (compare:CC
12622          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12623                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12624                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12625          (const_int 0)))
12626    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12627         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12628   "TARGET_32BIT"
12629   "@
12630    subfc %0,%2,%1\;addze. %0,%3
12631    addic %0,%1,%n2\;addze. %0,%3
12632    #
12633    #"
12634   [(set_attr "type" "compare")
12635    (set_attr "length" "8,8,12,12")])
12636
12637 (define_split
12638   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12639         (compare:CC
12640          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12641                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12642                   (match_operand:SI 3 "gpc_reg_operand" ""))
12643          (const_int 0)))
12644    (set (match_operand:SI 0 "gpc_reg_operand" "")
12645         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12646   "TARGET_32BIT && reload_completed"
12647   [(set (match_dup 0)
12648         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12649    (set (match_dup 4)
12650         (compare:CC (match_dup 0)
12651                     (const_int 0)))]
12652   "")
12653
12654 (define_insn "*neg_geu<mode>"
12655   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12656         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12657                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
12658   ""
12659   "@
12660    subfc %0,%2,%1\;subfe %0,%0,%0\;nand %0,%0,%0
12661    subfic %0,%1,-1\;add%I2c %0,%0,%2\;subfe %0,%0,%0"
12662   [(set_attr "type" "three")
12663    (set_attr "length" "12")])
12664
12665 (define_insn "*and_neg_geu<mode>"
12666   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
12667         (and:P (neg:P
12668                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12669                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
12670                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
12671   ""
12672   "@
12673    subfc %0,%2,%1\;subfe %0,%0,%0\;andc %0,%3,%0
12674    addic %0,%1,%n2\;subfe %0,%0,%0\;andc %0,%3,%0"
12675   [(set_attr "type" "three")
12676    (set_attr "length" "12")])
12677
12678 (define_insn ""
12679   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12680         (compare:CC
12681          (and:SI (neg:SI
12682                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12683                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12684                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12685          (const_int 0)))
12686    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12687   "TARGET_32BIT"
12688   "@
12689    subfc %4,%2,%1\;subfe %4,%4,%4\;andc. %4,%3,%4
12690    addic %4,%1,%n2\;subfe %4,%4,%4\;andc. %4,%3,%4
12691    #
12692    #"
12693   [(set_attr "type" "compare")
12694    (set_attr "length" "12,12,16,16")])
12695
12696 (define_split
12697   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12698         (compare:CC
12699          (and:SI (neg:SI
12700                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12701                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12702                  (match_operand:SI 3 "gpc_reg_operand" ""))
12703          (const_int 0)))
12704    (clobber (match_scratch:SI 4 ""))]
12705   "TARGET_32BIT && reload_completed"
12706   [(set (match_dup 4)
12707         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12708                 (match_dup 3)))
12709    (set (match_dup 0)
12710         (compare:CC (match_dup 4)
12711                     (const_int 0)))]
12712   "")
12713
12714 (define_insn ""
12715   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12716         (compare:CC
12717          (and:SI (neg:SI
12718                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12719                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12720                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12721          (const_int 0)))
12722    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12723         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12724   "TARGET_32BIT"
12725   "@
12726    subfc %0,%2,%1\;subfe %0,%0,%0\;andc. %0,%3,%0
12727    addic %0,%1,%n2\;subfe %0,%0,%0\;andc. %0,%3,%0
12728    #
12729    #"
12730   [(set_attr "type" "compare")
12731    (set_attr "length" "12,12,16,16")])
12732
12733 (define_split
12734   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12735         (compare:CC
12736          (and:SI (neg:SI
12737                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12738                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12739                  (match_operand:SI 3 "gpc_reg_operand" ""))
12740          (const_int 0)))
12741    (set (match_operand:SI 0 "gpc_reg_operand" "")
12742         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12743   "TARGET_32BIT && reload_completed"
12744   [(set (match_dup 0)
12745         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
12746    (set (match_dup 4)
12747         (compare:CC (match_dup 0)
12748                     (const_int 0)))]
12749   "")
12750
12751 (define_insn "*plus_gt0<mode>"
12752   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12753         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
12754                       (const_int 0))
12755                  (match_operand:P 2 "gpc_reg_operand" "r")))]
12756   ""
12757   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
12758   [(set_attr "type" "three")
12759    (set_attr "length" "12")])
12760
12761 (define_insn ""
12762   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12763         (compare:CC
12764          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12765                          (const_int 0))
12766                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12767          (const_int 0)))
12768    (clobber (match_scratch:SI 3 "=&r,&r"))]
12769   "TARGET_32BIT"
12770   "@
12771    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
12772    #"
12773   [(set_attr "type" "compare")
12774    (set_attr "length" "12,16")])
12775
12776 (define_split
12777   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12778         (compare:CC
12779          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12780                          (const_int 0))
12781                   (match_operand:SI 2 "gpc_reg_operand" ""))
12782          (const_int 0)))
12783    (clobber (match_scratch:SI 3 ""))]
12784   "TARGET_32BIT && reload_completed"
12785   [(set (match_dup 3)
12786         (plus:SI (gt:SI (match_dup 1) (const_int 0))
12787                   (match_dup 2)))
12788    (set (match_dup 0)
12789         (compare:CC (match_dup 3)
12790                     (const_int 0)))]
12791   "")
12792
12793 (define_insn ""
12794   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12795         (compare:CC
12796          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12797                          (const_int 0))
12798                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12799          (const_int 0)))
12800    (clobber (match_scratch:DI 3 "=&r,&r"))]
12801   "TARGET_64BIT"
12802   "@
12803    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
12804    #"
12805   [(set_attr "type" "compare")
12806    (set_attr "length" "12,16")])
12807
12808 (define_split
12809   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
12810         (compare:CC
12811          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
12812                          (const_int 0))
12813                   (match_operand:DI 2 "gpc_reg_operand" ""))
12814          (const_int 0)))
12815    (clobber (match_scratch:DI 3 ""))]
12816   "TARGET_64BIT && reload_completed"
12817   [(set (match_dup 3)
12818         (plus:DI (gt:DI (match_dup 1) (const_int 0))
12819                  (match_dup 2)))
12820    (set (match_dup 0)
12821         (compare:CC (match_dup 3)
12822                     (const_int 0)))]
12823   "")
12824
12825 (define_insn ""
12826   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12827         (compare:CC
12828          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12829                          (const_int 0))
12830                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12831          (const_int 0)))
12832    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12833         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
12834   "TARGET_32BIT"
12835   "@
12836    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
12837    #"
12838   [(set_attr "type" "compare")
12839    (set_attr "length" "12,16")])
12840
12841 (define_split
12842   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12843         (compare:CC
12844          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12845                          (const_int 0))
12846                   (match_operand:SI 2 "gpc_reg_operand" ""))
12847          (const_int 0)))
12848    (set (match_operand:SI 0 "gpc_reg_operand" "")
12849         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
12850   "TARGET_32BIT && reload_completed"
12851   [(set (match_dup 0)
12852         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
12853    (set (match_dup 3)
12854         (compare:CC (match_dup 0)
12855                     (const_int 0)))]
12856   "")
12857
12858 (define_insn ""
12859   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12860         (compare:CC
12861          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12862                          (const_int 0))
12863                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12864          (const_int 0)))
12865    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
12866         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
12867   "TARGET_64BIT"
12868   "@
12869    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
12870    #"
12871   [(set_attr "type" "compare")
12872    (set_attr "length" "12,16")])
12873
12874 (define_split
12875   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
12876         (compare:CC
12877          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
12878                          (const_int 0))
12879                   (match_operand:DI 2 "gpc_reg_operand" ""))
12880          (const_int 0)))
12881    (set (match_operand:DI 0 "gpc_reg_operand" "")
12882         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
12883   "TARGET_64BIT && reload_completed"
12884   [(set (match_dup 0)
12885         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
12886    (set (match_dup 3)
12887         (compare:CC (match_dup 0)
12888                     (const_int 0)))]
12889   "")
12890
12891 (define_insn_and_split "*gtu<mode>"
12892   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12893         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
12894                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12895   ""
12896   "#"
12897   ""
12898   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
12899    (set (match_dup 0) (neg:P (match_dup 0)))]
12900   "")
12901
12902 (define_insn_and_split "*gtu<mode>_compare"
12903   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12904         (compare:CC
12905          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12906                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12907          (const_int 0)))
12908    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12909         (gtu:P (match_dup 1) (match_dup 2)))]
12910   ""
12911   "#"
12912   ""
12913   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
12914    (parallel [(set (match_dup 3)
12915                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
12916               (set (match_dup 0) (neg:P (match_dup 0)))])]
12917   "")
12918
12919 (define_insn_and_split "*plus_gtu<mode>"
12920   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12921         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
12922                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12923                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
12924   ""
12925   "#"
12926   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12927   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
12928    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
12929   "")
12930
12931 (define_insn_and_split "*plus_gtu<mode>_compare"
12932   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12933         (compare:CC
12934          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12935                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
12936                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
12937          (const_int 0)))
12938    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12939         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
12940   ""
12941   "#"
12942   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12943   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
12944    (parallel [(set (match_dup 4)
12945                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
12946                                (const_int 0)))
12947               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
12948   "")
12949
12950 (define_insn "*neg_gtu<mode>"
12951   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12952         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
12953                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12954   ""
12955   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
12956   [(set_attr "type" "two")
12957    (set_attr "length" "8")])
12958
12959 \f
12960 ;; Define both directions of branch and return.  If we need a reload
12961 ;; register, we'd rather use CR0 since it is much easier to copy a
12962 ;; register CC value to there.
12963
12964 (define_insn ""
12965   [(set (pc)
12966         (if_then_else (match_operator 1 "branch_comparison_operator"
12967                                       [(match_operand 2
12968                                                       "cc_reg_operand" "y")
12969                                        (const_int 0)])
12970                       (label_ref (match_operand 0 "" ""))
12971                       (pc)))]
12972   ""
12973   "*
12974 {
12975   return output_cbranch (operands[1], \"%l0\", 0, insn);
12976 }"
12977   [(set_attr "type" "branch")])
12978
12979 (define_insn ""
12980   [(set (pc)
12981         (if_then_else (match_operator 0 "branch_comparison_operator"
12982                                       [(match_operand 1
12983                                                       "cc_reg_operand" "y")
12984                                        (const_int 0)])
12985                       (any_return)
12986                       (pc)))]
12987   "<return_pred>"
12988   "*
12989 {
12990   return output_cbranch (operands[0], NULL, 0, insn);
12991 }"
12992   [(set_attr "type" "jmpreg")
12993    (set_attr "length" "4")])
12994
12995 (define_insn ""
12996   [(set (pc)
12997         (if_then_else (match_operator 1 "branch_comparison_operator"
12998                                       [(match_operand 2
12999                                                       "cc_reg_operand" "y")
13000                                        (const_int 0)])
13001                       (pc)
13002                       (label_ref (match_operand 0 "" ""))))]
13003   ""
13004   "*
13005 {
13006   return output_cbranch (operands[1], \"%l0\", 1, insn);
13007 }"
13008   [(set_attr "type" "branch")])
13009
13010 (define_insn ""
13011   [(set (pc)
13012         (if_then_else (match_operator 0 "branch_comparison_operator"
13013                                       [(match_operand 1
13014                                                       "cc_reg_operand" "y")
13015                                        (const_int 0)])
13016                       (pc)
13017                       (any_return)))]
13018   "<return_pred>"
13019   "*
13020 {
13021   return output_cbranch (operands[0], NULL, 1, insn);
13022 }"
13023   [(set_attr "type" "jmpreg")
13024    (set_attr "length" "4")])
13025
13026 ;; Logic on condition register values.
13027
13028 ; This pattern matches things like
13029 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13030 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13031 ;                                  (const_int 1)))
13032 ; which are generated by the branch logic.
13033 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13034
13035 (define_insn "*cceq_ior_compare"
13036   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13037         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13038                         [(match_operator:SI 2
13039                                       "branch_positive_comparison_operator"
13040                                       [(match_operand 3
13041                                                       "cc_reg_operand" "y,y")
13042                                        (const_int 0)])
13043                          (match_operator:SI 4
13044                                       "branch_positive_comparison_operator"
13045                                       [(match_operand 5
13046                                                       "cc_reg_operand" "0,y")
13047                                        (const_int 0)])])
13048                       (const_int 1)))]
13049   ""
13050   "cr%q1 %E0,%j2,%j4"
13051   [(set_attr "type" "cr_logical,delayed_cr")])
13052
13053 ; Why is the constant -1 here, but 1 in the previous pattern?
13054 ; Because ~1 has all but the low bit set.
13055 (define_insn ""
13056   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13057         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13058                         [(not:SI (match_operator:SI 2
13059                                       "branch_positive_comparison_operator"
13060                                       [(match_operand 3
13061                                                       "cc_reg_operand" "y,y")
13062                                        (const_int 0)]))
13063                          (match_operator:SI 4
13064                                 "branch_positive_comparison_operator"
13065                                 [(match_operand 5
13066                                                 "cc_reg_operand" "0,y")
13067                                  (const_int 0)])])
13068                       (const_int -1)))]
13069   ""
13070   "cr%q1 %E0,%j2,%j4"
13071   [(set_attr "type" "cr_logical,delayed_cr")])
13072
13073 (define_insn "*cceq_rev_compare"
13074   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13075         (compare:CCEQ (match_operator:SI 1
13076                                       "branch_positive_comparison_operator"
13077                                       [(match_operand 2
13078                                                       "cc_reg_operand" "0,y")
13079                                        (const_int 0)])
13080                       (const_int 0)))]
13081   ""
13082   "crnot %E0,%j1"
13083   [(set_attr "type" "cr_logical,delayed_cr")])
13084
13085 ;; If we are comparing the result of two comparisons, this can be done
13086 ;; using creqv or crxor.
13087
13088 (define_insn_and_split ""
13089   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13090         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13091                               [(match_operand 2 "cc_reg_operand" "y")
13092                                (const_int 0)])
13093                       (match_operator 3 "branch_comparison_operator"
13094                               [(match_operand 4 "cc_reg_operand" "y")
13095                                (const_int 0)])))]
13096   ""
13097   "#"
13098   ""
13099   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13100                                     (match_dup 5)))]
13101   "
13102 {
13103   int positive_1, positive_2;
13104
13105   positive_1 = branch_positive_comparison_operator (operands[1],
13106                                                     GET_MODE (operands[1]));
13107   positive_2 = branch_positive_comparison_operator (operands[3],
13108                                                     GET_MODE (operands[3]));
13109
13110   if (! positive_1)
13111     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13112                                                             GET_CODE (operands[1])),
13113                                   SImode,
13114                                   operands[2], const0_rtx);
13115   else if (GET_MODE (operands[1]) != SImode)
13116     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13117                                   operands[2], const0_rtx);
13118
13119   if (! positive_2)
13120     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13121                                                             GET_CODE (operands[3])),
13122                                   SImode,
13123                                   operands[4], const0_rtx);
13124   else if (GET_MODE (operands[3]) != SImode)
13125     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13126                                   operands[4], const0_rtx);
13127
13128   if (positive_1 == positive_2)
13129     {
13130       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13131       operands[5] = constm1_rtx;
13132     }
13133   else
13134     {
13135       operands[5] = const1_rtx;
13136     }
13137 }")
13138
13139 ;; Unconditional branch and return.
13140
13141 (define_insn "jump"
13142   [(set (pc)
13143         (label_ref (match_operand 0 "" "")))]
13144   ""
13145   "b %l0"
13146   [(set_attr "type" "branch")])
13147
13148 (define_insn "<return_str>return"
13149   [(any_return)]
13150   "<return_pred>"
13151   "blr"
13152   [(set_attr "type" "jmpreg")])
13153
13154 (define_expand "indirect_jump"
13155   [(set (pc) (match_operand 0 "register_operand" ""))])
13156
13157 (define_insn "*indirect_jump<mode>"
13158   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
13159   ""
13160   "@
13161    bctr
13162    blr"
13163   [(set_attr "type" "jmpreg")])
13164
13165 ;; Table jump for switch statements:
13166 (define_expand "tablejump"
13167   [(use (match_operand 0 "" ""))
13168    (use (label_ref (match_operand 1 "" "")))]
13169   ""
13170   "
13171 {
13172   if (TARGET_32BIT)
13173     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13174   else
13175     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13176   DONE;
13177 }")
13178
13179 (define_expand "tablejumpsi"
13180   [(set (match_dup 3)
13181         (plus:SI (match_operand:SI 0 "" "")
13182                  (match_dup 2)))
13183    (parallel [(set (pc) (match_dup 3))
13184               (use (label_ref (match_operand 1 "" "")))])]
13185   "TARGET_32BIT"
13186   "
13187 { operands[0] = force_reg (SImode, operands[0]);
13188   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13189   operands[3] = gen_reg_rtx (SImode);
13190 }")
13191
13192 (define_expand "tablejumpdi"
13193   [(set (match_dup 4)
13194         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
13195    (set (match_dup 3)
13196         (plus:DI (match_dup 4)
13197                  (match_dup 2)))
13198    (parallel [(set (pc) (match_dup 3))
13199               (use (label_ref (match_operand 1 "" "")))])]
13200   "TARGET_64BIT"
13201   "
13202 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13203   operands[3] = gen_reg_rtx (DImode);
13204   operands[4] = gen_reg_rtx (DImode);
13205 }")
13206
13207 (define_insn "*tablejump<mode>_internal1"
13208   [(set (pc)
13209         (match_operand:P 0 "register_operand" "c,*l"))
13210    (use (label_ref (match_operand 1 "" "")))]
13211   ""
13212   "@
13213    bctr
13214    blr"
13215   [(set_attr "type" "jmpreg")])
13216
13217 (define_insn "nop"
13218   [(const_int 0)]
13219   ""
13220   "nop")
13221
13222 (define_insn "group_ending_nop"
13223   [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
13224   ""
13225   "*
13226 {
13227   if (rs6000_cpu_attr == CPU_POWER6)
13228     return \"ori 1,1,0\";
13229   return \"ori 2,2,0\";
13230 }")
13231 \f
13232 ;; Define the subtract-one-and-jump insns, starting with the template
13233 ;; so loop.c knows what to generate.
13234
13235 (define_expand "doloop_end"
13236   [(use (match_operand 0 "" ""))        ; loop pseudo
13237    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13238    (use (match_operand 2 "" ""))        ; max iterations
13239    (use (match_operand 3 "" ""))        ; loop level
13240    (use (match_operand 4 "" ""))        ; label
13241    (use (match_operand 5 "" ""))]       ; flag: 1 if loop entered at top, else 0
13242   ""
13243   "
13244 {
13245   /* Only use this on innermost loops.  */
13246   if (INTVAL (operands[3]) > 1)
13247     FAIL;
13248   if (TARGET_64BIT)
13249     {
13250       if (GET_MODE (operands[0]) != DImode)
13251         FAIL;
13252       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13253     }
13254   else
13255     {
13256       if (GET_MODE (operands[0]) != SImode)
13257         FAIL;
13258       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13259     }
13260   DONE;
13261 }")
13262
13263 (define_expand "ctr<mode>"
13264   [(parallel [(set (pc)
13265                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
13266                                      (const_int 1))
13267                                  (label_ref (match_operand 1 "" ""))
13268                                  (pc)))
13269               (set (match_dup 0)
13270                    (plus:P (match_dup 0)
13271                             (const_int -1)))
13272               (clobber (match_scratch:CC 2 ""))
13273               (clobber (match_scratch:P 3 ""))])]
13274   ""
13275   "")
13276
13277 ;; We need to be able to do this for any operand, including MEM, or we
13278 ;; will cause reload to blow up since we don't allow output reloads on
13279 ;; JUMP_INSNs.
13280 ;; For the length attribute to be calculated correctly, the
13281 ;; label MUST be operand 0.
13282
13283 (define_insn "*ctr<mode>_internal1"
13284   [(set (pc)
13285         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13286                           (const_int 1))
13287                       (label_ref (match_operand 0 "" ""))
13288                       (pc)))
13289    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13290         (plus:P (match_dup 1)
13291                  (const_int -1)))
13292    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13293    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13294   ""
13295   "*
13296 {
13297   if (which_alternative != 0)
13298     return \"#\";
13299   else if (get_attr_length (insn) == 4)
13300     return \"bdnz %l0\";
13301   else
13302     return \"bdz $+8\;b %l0\";
13303 }"
13304   [(set_attr "type" "branch")
13305    (set_attr "length" "*,12,16,16")])
13306
13307 (define_insn "*ctr<mode>_internal2"
13308   [(set (pc)
13309         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13310                           (const_int 1))
13311                       (pc)
13312                       (label_ref (match_operand 0 "" ""))))
13313    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13314         (plus:P (match_dup 1)
13315                  (const_int -1)))
13316    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13317    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13318   ""
13319   "*
13320 {
13321   if (which_alternative != 0)
13322     return \"#\";
13323   else if (get_attr_length (insn) == 4)
13324     return \"bdz %l0\";
13325   else
13326     return \"bdnz $+8\;b %l0\";
13327 }"
13328   [(set_attr "type" "branch")
13329    (set_attr "length" "*,12,16,16")])
13330
13331 ;; Similar but use EQ
13332
13333 (define_insn "*ctr<mode>_internal5"
13334   [(set (pc)
13335         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13336                           (const_int 1))
13337                       (label_ref (match_operand 0 "" ""))
13338                       (pc)))
13339    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13340         (plus:P (match_dup 1)
13341                  (const_int -1)))
13342    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13343    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13344   ""
13345   "*
13346 {
13347   if (which_alternative != 0)
13348     return \"#\";
13349   else if (get_attr_length (insn) == 4)
13350     return \"bdz %l0\";
13351   else
13352     return \"bdnz $+8\;b %l0\";
13353 }"
13354   [(set_attr "type" "branch")
13355    (set_attr "length" "*,12,16,16")])
13356
13357 (define_insn "*ctr<mode>_internal6"
13358   [(set (pc)
13359         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13360                           (const_int 1))
13361                       (pc)
13362                       (label_ref (match_operand 0 "" ""))))
13363    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13364         (plus:P (match_dup 1)
13365                  (const_int -1)))
13366    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13367    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13368   ""
13369   "*
13370 {
13371   if (which_alternative != 0)
13372     return \"#\";
13373   else if (get_attr_length (insn) == 4)
13374     return \"bdnz %l0\";
13375   else
13376     return \"bdz $+8\;b %l0\";
13377 }"
13378   [(set_attr "type" "branch")
13379    (set_attr "length" "*,12,16,16")])
13380
13381 ;; Now the splitters if we could not allocate the CTR register
13382
13383 (define_split
13384   [(set (pc)
13385         (if_then_else (match_operator 2 "comparison_operator"
13386                                       [(match_operand:P 1 "gpc_reg_operand" "")
13387                                        (const_int 1)])
13388                       (match_operand 5 "" "")
13389                       (match_operand 6 "" "")))
13390    (set (match_operand:P 0 "gpc_reg_operand" "")
13391         (plus:P (match_dup 1) (const_int -1)))
13392    (clobber (match_scratch:CC 3 ""))
13393    (clobber (match_scratch:P 4 ""))]
13394   "reload_completed"
13395   [(parallel [(set (match_dup 3)
13396                    (compare:CC (plus:P (match_dup 1)
13397                                         (const_int -1))
13398                                (const_int 0)))
13399               (set (match_dup 0)
13400                    (plus:P (match_dup 1)
13401                             (const_int -1)))])
13402    (set (pc) (if_then_else (match_dup 7)
13403                            (match_dup 5)
13404                            (match_dup 6)))]
13405   "
13406 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13407                                 operands[3], const0_rtx); }")
13408
13409 (define_split
13410   [(set (pc)
13411         (if_then_else (match_operator 2 "comparison_operator"
13412                                       [(match_operand:P 1 "gpc_reg_operand" "")
13413                                        (const_int 1)])
13414                       (match_operand 5 "" "")
13415                       (match_operand 6 "" "")))
13416    (set (match_operand:P 0 "nonimmediate_operand" "")
13417         (plus:P (match_dup 1) (const_int -1)))
13418    (clobber (match_scratch:CC 3 ""))
13419    (clobber (match_scratch:P 4 ""))]
13420   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
13421   [(parallel [(set (match_dup 3)
13422                    (compare:CC (plus:P (match_dup 1)
13423                                         (const_int -1))
13424                                (const_int 0)))
13425               (set (match_dup 4)
13426                    (plus:P (match_dup 1)
13427                             (const_int -1)))])
13428    (set (match_dup 0)
13429         (match_dup 4))
13430    (set (pc) (if_then_else (match_dup 7)
13431                            (match_dup 5)
13432                            (match_dup 6)))]
13433   "
13434 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13435                                 operands[3], const0_rtx); }")
13436 \f
13437 (define_insn "trap"
13438   [(trap_if (const_int 1) (const_int 0))]
13439   ""
13440   "trap"
13441   [(set_attr "type" "trap")])
13442
13443 (define_expand "ctrap<mode>4"
13444   [(trap_if (match_operator 0 "ordered_comparison_operator"
13445                             [(match_operand:GPR 1 "register_operand")
13446                              (match_operand:GPR 2 "reg_or_short_operand")])
13447             (match_operand 3 "zero_constant" ""))]
13448   ""
13449   "")
13450
13451 (define_insn ""
13452   [(trap_if (match_operator 0 "ordered_comparison_operator"
13453                             [(match_operand:GPR 1 "register_operand" "r")
13454                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
13455             (const_int 0))]
13456   ""
13457   "t<wd>%V0%I2 %1,%2"
13458   [(set_attr "type" "trap")])
13459 \f
13460 ;; Insns related to generating the function prologue and epilogue.
13461
13462 (define_expand "prologue"
13463   [(use (const_int 0))]
13464   ""
13465 {
13466   rs6000_emit_prologue ();
13467   if (!TARGET_SCHED_PROLOG)
13468     emit_insn (gen_blockage ());
13469   DONE;
13470 })
13471
13472 (define_insn "*movesi_from_cr_one"
13473   [(match_parallel 0 "mfcr_operation"
13474                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
13475                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
13476                                      (match_operand 3 "immediate_operand" "n")]
13477                           UNSPEC_MOVESI_FROM_CR))])]
13478   "TARGET_MFCRF"
13479   "*
13480 {
13481   int mask = 0;
13482   int i;
13483   for (i = 0; i < XVECLEN (operands[0], 0); i++)
13484   {
13485     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
13486     operands[4] = GEN_INT (mask);
13487     output_asm_insn (\"mfcr %1,%4\", operands);
13488   }
13489   return \"\";
13490 }"
13491   [(set_attr "type" "mfcrf")])
13492
13493 (define_insn "movesi_from_cr"
13494   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13495         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
13496                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
13497                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
13498                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
13499                    UNSPEC_MOVESI_FROM_CR))]
13500   ""
13501   "mfcr %0"
13502   [(set_attr "type" "mfcr")])
13503
13504 (define_insn "*stmw"
13505   [(match_parallel 0 "stmw_operation"
13506                    [(set (match_operand:SI 1 "memory_operand" "=m")
13507                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
13508   "TARGET_MULTIPLE"
13509   "stmw %2,%1"
13510   [(set_attr "type" "store_ux")])
13511
13512 ; The following comment applies to:
13513 ;     save_gpregs_*
13514 ;     save_fpregs_*
13515 ;     restore_gpregs*
13516 ;     return_and_restore_gpregs*
13517 ;     return_and_restore_fpregs*
13518 ;     return_and_restore_fpregs_aix*
13519 ;
13520 ; The out-of-line save / restore functions expects one input argument.
13521 ; Since those are not standard call_insn's, we must avoid using
13522 ; MATCH_OPERAND for that argument. That way the register rename
13523 ; optimization will not try to rename this register.
13524 ; Each pattern is repeated for each possible register number used in 
13525 ; various ABIs (r11, r1, and for some functions r12)
13526
13527 (define_insn "*save_gpregs_<mode>_r11"
13528   [(match_parallel 0 "any_parallel_operand"
13529                    [(clobber (reg:P 65))
13530                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13531                     (use (reg:P 11))
13532                     (set (match_operand:P 2 "memory_operand" "=m")
13533                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
13534   ""
13535   "bl %1"
13536   [(set_attr "type" "branch")
13537    (set_attr "length" "4")])
13538
13539 (define_insn "*save_gpregs_<mode>_r12"
13540   [(match_parallel 0 "any_parallel_operand"
13541                    [(clobber (reg:P 65))
13542                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13543                     (use (reg:P 12))
13544                     (set (match_operand:P 2 "memory_operand" "=m")
13545                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
13546   ""
13547   "bl %1"
13548   [(set_attr "type" "branch")
13549    (set_attr "length" "4")])
13550
13551 (define_insn "*save_gpregs_<mode>_r1"
13552   [(match_parallel 0 "any_parallel_operand"
13553                    [(clobber (reg:P 65))
13554                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13555                     (use (reg:P 1))
13556                     (set (match_operand:P 2 "memory_operand" "=m")
13557                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
13558   ""
13559   "bl %1"
13560   [(set_attr "type" "branch")
13561    (set_attr "length" "4")])
13562
13563 (define_insn "*save_fpregs_<mode>_r11"
13564   [(match_parallel 0 "any_parallel_operand"
13565                    [(clobber (reg:P 65))
13566                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13567                     (use (reg:P 11))
13568                     (set (match_operand:DF 2 "memory_operand" "=m")
13569                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
13570   ""
13571   "bl %1"
13572   [(set_attr "type" "branch")
13573    (set_attr "length" "4")])
13574
13575 (define_insn "*save_fpregs_<mode>_r12"
13576   [(match_parallel 0 "any_parallel_operand"
13577                    [(clobber (reg:P 65))
13578                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13579                     (use (reg:P 12))
13580                     (set (match_operand:DF 2 "memory_operand" "=m")
13581                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
13582   ""
13583   "bl %1"
13584   [(set_attr "type" "branch")
13585    (set_attr "length" "4")])
13586
13587 (define_insn "*save_fpregs_<mode>_r1"
13588   [(match_parallel 0 "any_parallel_operand"
13589                    [(clobber (reg:P 65))
13590                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13591                     (use (reg:P 1))
13592                     (set (match_operand:DF 2 "memory_operand" "=m")
13593                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
13594   ""
13595   "bl %1"
13596   [(set_attr "type" "branch")
13597    (set_attr "length" "4")])
13598
13599 ; This is to explain that changes to the stack pointer should
13600 ; not be moved over loads from or stores to stack memory.
13601 (define_insn "stack_tie"
13602   [(match_parallel 0 "tie_operand"
13603                    [(set (mem:BLK (reg 1)) (const_int 0))])]
13604   ""
13605   ""
13606   [(set_attr "length" "0")])
13607
13608 (define_expand "epilogue"
13609   [(use (const_int 0))]
13610   ""
13611 {
13612   if (!TARGET_SCHED_PROLOG)
13613     emit_insn (gen_blockage ());
13614   rs6000_emit_epilogue (FALSE);
13615   DONE;
13616 })
13617
13618 ; On some processors, doing the mtcrf one CC register at a time is
13619 ; faster (like on the 604e).  On others, doing them all at once is
13620 ; faster; for instance, on the 601 and 750.
13621
13622 (define_expand "movsi_to_cr_one"
13623   [(set (match_operand:CC 0 "cc_reg_operand" "")
13624         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
13625                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
13626   ""
13627   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
13628
13629 (define_insn "*movsi_to_cr"
13630   [(match_parallel 0 "mtcrf_operation"
13631                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
13632                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
13633                                      (match_operand 3 "immediate_operand" "n")]
13634                                     UNSPEC_MOVESI_TO_CR))])]
13635  ""
13636  "*
13637 {
13638   int mask = 0;
13639   int i;
13640   for (i = 0; i < XVECLEN (operands[0], 0); i++)
13641     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
13642   operands[4] = GEN_INT (mask);
13643   return \"mtcrf %4,%2\";
13644 }"
13645   [(set_attr "type" "mtcr")])
13646
13647 (define_insn "*mtcrfsi"
13648   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
13649         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
13650                     (match_operand 2 "immediate_operand" "n")]
13651                    UNSPEC_MOVESI_TO_CR))]
13652   "GET_CODE (operands[0]) == REG
13653    && CR_REGNO_P (REGNO (operands[0]))
13654    && GET_CODE (operands[2]) == CONST_INT
13655    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
13656   "mtcrf %R0,%1"
13657   [(set_attr "type" "mtcr")])
13658
13659 ; The load-multiple instructions have similar properties.
13660 ; Note that "load_multiple" is a name known to the machine-independent
13661 ; code that actually corresponds to the PowerPC load-string.
13662
13663 (define_insn "*lmw"
13664   [(match_parallel 0 "lmw_operation"
13665                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
13666                          (match_operand:SI 2 "memory_operand" "m"))])]
13667   "TARGET_MULTIPLE"
13668   "lmw %1,%2"
13669   [(set_attr "type" "load_ux")
13670    (set_attr "cell_micro" "always")])
13671
13672 (define_insn "*return_internal_<mode>"
13673   [(simple_return)
13674    (use (match_operand:P 0 "register_operand" "lc"))]
13675   ""
13676   "b%T0"
13677   [(set_attr "type" "jmpreg")])
13678
13679 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
13680 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
13681
13682 ; The following comment applies to:
13683 ;     save_gpregs_*
13684 ;     save_fpregs_*
13685 ;     restore_gpregs*
13686 ;     return_and_restore_gpregs*
13687 ;     return_and_restore_fpregs*
13688 ;     return_and_restore_fpregs_aix*
13689 ;
13690 ; The out-of-line save / restore functions expects one input argument.
13691 ; Since those are not standard call_insn's, we must avoid using
13692 ; MATCH_OPERAND for that argument. That way the register rename
13693 ; optimization will not try to rename this register.
13694 ; Each pattern is repeated for each possible register number used in 
13695 ; various ABIs (r11, r1, and for some functions r12)
13696
13697 (define_insn "*restore_gpregs_<mode>_r11"
13698  [(match_parallel 0 "any_parallel_operand"
13699                   [(clobber (match_operand:P 1 "register_operand" "=l"))
13700                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13701                    (use (reg:P 11))
13702                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13703                         (match_operand:P 4 "memory_operand" "m"))])]
13704  ""
13705  "bl %2"
13706  [(set_attr "type" "branch")
13707   (set_attr "length" "4")])
13708
13709 (define_insn "*restore_gpregs_<mode>_r12"
13710  [(match_parallel 0 "any_parallel_operand"
13711                   [(clobber (match_operand:P 1 "register_operand" "=l"))
13712                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13713                    (use (reg:P 12))
13714                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13715                         (match_operand:P 4 "memory_operand" "m"))])]
13716  ""
13717  "bl %2"
13718  [(set_attr "type" "branch")
13719   (set_attr "length" "4")])
13720
13721 (define_insn "*restore_gpregs_<mode>_r1"
13722  [(match_parallel 0 "any_parallel_operand"
13723                   [(clobber (match_operand:P 1 "register_operand" "=l"))
13724                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13725                    (use (reg:P 1))
13726                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13727                         (match_operand:P 4 "memory_operand" "m"))])]
13728  ""
13729  "bl %2"
13730  [(set_attr "type" "branch")
13731   (set_attr "length" "4")])
13732
13733 (define_insn "*return_and_restore_gpregs_<mode>_r11"
13734  [(match_parallel 0 "any_parallel_operand"
13735                   [(return)
13736                    (clobber (match_operand:P 1 "register_operand" "=l"))
13737                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13738                    (use (reg:P 11))
13739                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13740                         (match_operand:P 4 "memory_operand" "m"))])]
13741  ""
13742  "b %2"
13743  [(set_attr "type" "branch")
13744   (set_attr "length" "4")])
13745
13746 (define_insn "*return_and_restore_gpregs_<mode>_r12"
13747  [(match_parallel 0 "any_parallel_operand"
13748                   [(return)
13749                    (clobber (match_operand:P 1 "register_operand" "=l"))
13750                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13751                    (use (reg:P 12))
13752                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13753                         (match_operand:P 4 "memory_operand" "m"))])]
13754  ""
13755  "b %2"
13756  [(set_attr "type" "branch")
13757   (set_attr "length" "4")])
13758
13759 (define_insn "*return_and_restore_gpregs_<mode>_r1"
13760  [(match_parallel 0 "any_parallel_operand"
13761                   [(return)
13762                    (clobber (match_operand:P 1 "register_operand" "=l"))
13763                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13764                    (use (reg:P 1))
13765                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13766                         (match_operand:P 4 "memory_operand" "m"))])]
13767  ""
13768  "b %2"
13769  [(set_attr "type" "branch")
13770   (set_attr "length" "4")])
13771
13772 (define_insn "*return_and_restore_fpregs_<mode>_r11"
13773  [(match_parallel 0 "any_parallel_operand"
13774                   [(return)
13775                    (clobber (match_operand:P 1 "register_operand" "=l"))
13776                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13777                    (use (reg:P 11))
13778                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13779                         (match_operand:DF 4 "memory_operand" "m"))])]
13780  ""
13781  "b %2"
13782  [(set_attr "type" "branch")
13783   (set_attr "length" "4")])
13784
13785 (define_insn "*return_and_restore_fpregs_<mode>_r12"
13786  [(match_parallel 0 "any_parallel_operand"
13787                   [(return)
13788                    (clobber (match_operand:P 1 "register_operand" "=l"))
13789                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13790                    (use (reg:P 12))
13791                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13792                         (match_operand:DF 4 "memory_operand" "m"))])]
13793  ""
13794  "b %2"
13795  [(set_attr "type" "branch")
13796   (set_attr "length" "4")])
13797
13798 (define_insn "*return_and_restore_fpregs_<mode>_r1"
13799  [(match_parallel 0 "any_parallel_operand"
13800                   [(return)
13801                    (clobber (match_operand:P 1 "register_operand" "=l"))
13802                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13803                    (use (reg:P 1))
13804                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13805                         (match_operand:DF 4 "memory_operand" "m"))])]
13806  ""
13807  "b %2"
13808  [(set_attr "type" "branch")
13809   (set_attr "length" "4")])
13810
13811 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
13812  [(match_parallel 0 "any_parallel_operand"
13813                   [(return)
13814                    (use (match_operand:P 1 "register_operand" "l"))
13815                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13816                    (use (reg:P 11))
13817                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13818                         (match_operand:DF 4 "memory_operand" "m"))])]
13819  ""
13820  "b %2"
13821  [(set_attr "type" "branch")
13822   (set_attr "length" "4")])
13823
13824 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
13825  [(match_parallel 0 "any_parallel_operand"
13826                   [(return)
13827                    (use (match_operand:P 1 "register_operand" "l"))
13828                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13829                    (use (reg:P 1))
13830                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13831                         (match_operand:DF 4 "memory_operand" "m"))])]
13832  ""
13833  "b %2"
13834  [(set_attr "type" "branch")
13835   (set_attr "length" "4")])
13836
13837 ; This is used in compiling the unwind routines.
13838 (define_expand "eh_return"
13839   [(use (match_operand 0 "general_operand" ""))]
13840   ""
13841   "
13842 {
13843   if (TARGET_32BIT)
13844     emit_insn (gen_eh_set_lr_si (operands[0]));
13845   else
13846     emit_insn (gen_eh_set_lr_di (operands[0]));
13847   DONE;
13848 }")
13849
13850 ; We can't expand this before we know where the link register is stored.
13851 (define_insn "eh_set_lr_<mode>"
13852   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
13853                     UNSPECV_EH_RR)
13854    (clobber (match_scratch:P 1 "=&b"))]
13855   ""
13856   "#")
13857
13858 (define_split
13859   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
13860    (clobber (match_scratch 1 ""))]
13861   "reload_completed"
13862   [(const_int 0)]
13863   "
13864 {
13865   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
13866   DONE;
13867 }")
13868
13869 (define_insn "prefetch"
13870   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
13871              (match_operand:SI 1 "const_int_operand" "n")
13872              (match_operand:SI 2 "const_int_operand" "n"))]
13873   ""
13874   "*
13875 {
13876   if (GET_CODE (operands[0]) == REG)
13877     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
13878   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
13879 }"
13880   [(set_attr "type" "load")])
13881 \f
13882 (define_insn "bpermd_<mode>"
13883   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13884         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
13885                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
13886   "TARGET_POPCNTD"
13887   "bpermd %0,%1,%2"
13888   [(set_attr "type" "integer")])
13889
13890 \f
13891 ;; Builtin fma support.  Handle 
13892 ;; Note that the conditions for expansion are in the FMA_F iterator.
13893
13894 (define_expand "fma<mode>4"
13895   [(set (match_operand:FMA_F 0 "register_operand" "")
13896         (fma:FMA_F
13897           (match_operand:FMA_F 1 "register_operand" "")
13898           (match_operand:FMA_F 2 "register_operand" "")
13899           (match_operand:FMA_F 3 "register_operand" "")))]
13900   ""
13901   "")
13902
13903 ; Altivec only has fma and nfms.
13904 (define_expand "fms<mode>4"
13905   [(set (match_operand:FMA_F 0 "register_operand" "")
13906         (fma:FMA_F
13907           (match_operand:FMA_F 1 "register_operand" "")
13908           (match_operand:FMA_F 2 "register_operand" "")
13909           (neg:FMA_F (match_operand:FMA_F 3 "register_operand" ""))))]
13910   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
13911   "")
13912
13913 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
13914 (define_expand "fnma<mode>4"
13915   [(set (match_operand:FMA_F 0 "register_operand" "")
13916         (neg:FMA_F
13917           (fma:FMA_F
13918             (match_operand:FMA_F 1 "register_operand" "")
13919             (match_operand:FMA_F 2 "register_operand" "")
13920             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
13921   "!HONOR_SIGNED_ZEROS (<MODE>mode)"
13922   "")
13923
13924 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
13925 (define_expand "fnms<mode>4"
13926   [(set (match_operand:FMA_F 0 "register_operand" "")
13927         (neg:FMA_F
13928           (fma:FMA_F
13929             (match_operand:FMA_F 1 "register_operand" "")
13930             (match_operand:FMA_F 2 "register_operand" "")
13931             (match_operand:FMA_F 3 "register_operand" ""))))]
13932   "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
13933   "")
13934
13935 ; Not an official optab name, but used from builtins.
13936 (define_expand "nfma<mode>4"
13937   [(set (match_operand:FMA_F 0 "register_operand" "")
13938         (neg:FMA_F
13939           (fma:FMA_F
13940             (match_operand:FMA_F 1 "register_operand" "")
13941             (match_operand:FMA_F 2 "register_operand" "")
13942             (match_operand:FMA_F 3 "register_operand" ""))))]
13943   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
13944   "")
13945
13946 ; Not an official optab name, but used from builtins.
13947 (define_expand "nfms<mode>4"
13948   [(set (match_operand:FMA_F 0 "register_operand" "")
13949         (neg:FMA_F
13950           (fma:FMA_F
13951             (match_operand:FMA_F 1 "register_operand" "")
13952             (match_operand:FMA_F 2 "register_operand" "")
13953             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
13954   ""
13955   "")
13956
13957 (define_expand "rs6000_get_timebase"
13958   [(use (match_operand:DI 0 "gpc_reg_operand" ""))]
13959   ""
13960 {
13961   if (TARGET_POWERPC64)
13962     emit_insn (gen_rs6000_mftb_di (operands[0]));
13963   else
13964     emit_insn (gen_rs6000_get_timebase_ppc32 (operands[0]));
13965   DONE;
13966 })
13967
13968 (define_insn "rs6000_get_timebase_ppc32"
13969   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13970         (unspec_volatile:DI [(const_int 0)] UNSPECV_MFTB))
13971    (clobber (match_scratch:SI 1 "=r"))
13972    (clobber (match_scratch:CC 2 "=y"))]
13973   "!TARGET_POWERPC64"
13974 {
13975   if (WORDS_BIG_ENDIAN)
13976     if (TARGET_MFCRF)
13977       {
13978         return "mfspr %0,269\;"
13979                "mfspr %L0,268\;"
13980                "mfspr %1,269\;"
13981                "cmpw %2,%0,%1\;"
13982                "bne- %2,$-16";
13983       }
13984     else
13985       {
13986         return "mftbu %0\;"
13987                "mftb %L0\;"
13988                "mftbu %1\;"
13989                "cmpw %2,%0,%1\;"
13990                "bne- %2,$-16";
13991       }
13992   else
13993     if (TARGET_MFCRF)
13994       {
13995         return "mfspr %L0,269\;"
13996                "mfspr %0,268\;"
13997                "mfspr %1,269\;"
13998                "cmpw %2,%L0,%1\;"
13999                "bne- %2,$-16";
14000       }
14001     else
14002       {
14003         return "mftbu %L0\;"
14004                "mftb %0\;"
14005                "mftbu %1\;"
14006                "cmpw %2,%L0,%1\;"
14007                "bne- %2,$-16";
14008       }
14009 })
14010
14011 (define_insn "rs6000_mftb_<mode>"
14012   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14013         (unspec_volatile:P [(const_int 0)] UNSPECV_MFTB))]
14014   ""
14015 {
14016   if (TARGET_MFCRF)
14017     return "mfspr %0,268";
14018   else
14019     return "mftb %0";
14020 })
14021
14022 \f
14023
14024 (include "sync.md")
14025 (include "vector.md")
14026 (include "vsx.md")
14027 (include "altivec.md")
14028 (include "spe.md")
14029 (include "dfp.md")
14030 (include "paired.md")