rs6000: Make all shift instructions one type
[platform/upstream/gcc.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990-2014 Free Software Foundation, Inc.
3 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
4
5 ;; This file is part of GCC.
6
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 3, or (at your
10 ;; option) any later version.
11
12 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15 ;; License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
22
23 ;;
24 ;; REGNOS
25 ;;
26
27 (define_constants
28   [(FIRST_GPR_REGNO             0)
29    (STACK_POINTER_REGNUM        1)
30    (TOC_REGNUM                  2)
31    (STATIC_CHAIN_REGNUM         11)
32    (HARD_FRAME_POINTER_REGNUM   31)
33    (LAST_GPR_REGNO              31)
34    (FIRST_FPR_REGNO             32)
35    (LAST_FPR_REGNO              63)
36    (LR_REGNO                    65)
37    (CTR_REGNO                   66)
38    (ARG_POINTER_REGNUM          67)
39    (CR0_REGNO                   68)
40    (CR1_REGNO                   69)
41    (CR2_REGNO                   70)
42    (CR3_REGNO                   71)
43    (CR4_REGNO                   72)
44    (CR5_REGNO                   73)
45    (CR6_REGNO                   74)
46    (CR7_REGNO                   75)
47    (MAX_CR_REGNO                75)
48    (CA_REGNO                    76)
49    (FIRST_ALTIVEC_REGNO         77)
50    (LAST_ALTIVEC_REGNO          108)
51    (VRSAVE_REGNO                109)
52    (VSCR_REGNO                  110)
53    (SPE_ACC_REGNO               111)
54    (SPEFSCR_REGNO               112)
55    (FRAME_POINTER_REGNUM        113)
56    (TFHAR_REGNO                 114)
57    (TFIAR_REGNO                 115)
58    (TEXASR_REGNO                116)
59   ])
60
61 ;;
62 ;; UNSPEC usage
63 ;;
64
65 (define_c_enum "unspec"
66   [UNSPEC_FRSP                  ; frsp for POWER machines
67    UNSPEC_PROBE_STACK           ; probe stack memory reference
68    UNSPEC_TOCPTR                ; address of a word pointing to the TOC
69    UNSPEC_TOC                   ; address of the TOC (more-or-less)
70    UNSPEC_MOVSI_GOT
71    UNSPEC_MV_CR_OV              ; move_from_CR_ov_bit
72    UNSPEC_FCTIWZ
73    UNSPEC_FRIM
74    UNSPEC_FRIN
75    UNSPEC_FRIP
76    UNSPEC_FRIZ
77    UNSPEC_LD_MPIC               ; load_macho_picbase
78    UNSPEC_RELD_MPIC             ; re-load_macho_picbase
79    UNSPEC_MPIC_CORRECT          ; macho_correct_pic
80    UNSPEC_TLSGD
81    UNSPEC_TLSLD
82    UNSPEC_MOVESI_FROM_CR
83    UNSPEC_MOVESI_TO_CR
84    UNSPEC_TLSDTPREL
85    UNSPEC_TLSDTPRELHA
86    UNSPEC_TLSDTPRELLO
87    UNSPEC_TLSGOTDTPREL
88    UNSPEC_TLSTPREL
89    UNSPEC_TLSTPRELHA
90    UNSPEC_TLSTPRELLO
91    UNSPEC_TLSGOTTPREL
92    UNSPEC_TLSTLS
93    UNSPEC_FIX_TRUNC_TF          ; fadd, rounding towards zero
94    UNSPEC_MV_CR_GT              ; move_from_CR_gt_bit
95    UNSPEC_STFIWX
96    UNSPEC_POPCNTB
97    UNSPEC_FRES
98    UNSPEC_SP_SET
99    UNSPEC_SP_TEST
100    UNSPEC_SYNC
101    UNSPEC_LWSYNC
102    UNSPEC_SYNC_OP
103    UNSPEC_ATOMIC
104    UNSPEC_CMPXCHG
105    UNSPEC_XCHG
106    UNSPEC_AND
107    UNSPEC_DLMZB
108    UNSPEC_DLMZB_CR
109    UNSPEC_DLMZB_STRLEN
110    UNSPEC_RSQRT
111    UNSPEC_TOCREL
112    UNSPEC_MACHOPIC_OFFSET
113    UNSPEC_BPERM
114    UNSPEC_COPYSIGN
115    UNSPEC_PARITY
116    UNSPEC_FCTIW
117    UNSPEC_FCTID
118    UNSPEC_LFIWAX
119    UNSPEC_LFIWZX
120    UNSPEC_FCTIWUZ
121    UNSPEC_GRP_END_NOP
122    UNSPEC_P8V_FMRGOW
123    UNSPEC_P8V_MTVSRWZ
124    UNSPEC_P8V_RELOAD_FROM_GPR
125    UNSPEC_P8V_MTVSRD
126    UNSPEC_P8V_XXPERMDI
127    UNSPEC_P8V_RELOAD_FROM_VSX
128    UNSPEC_ADDG6S
129    UNSPEC_CDTBCD
130    UNSPEC_CBCDTD
131    UNSPEC_DIVE
132    UNSPEC_DIVEO
133    UNSPEC_DIVEU
134    UNSPEC_DIVEUO
135    UNSPEC_UNPACK_128BIT
136    UNSPEC_PACK_128BIT
137    UNSPEC_LSQ
138   ])
139
140 ;;
141 ;; UNSPEC_VOLATILE usage
142 ;;
143
144 (define_c_enum "unspecv"
145   [UNSPECV_BLOCK
146    UNSPECV_LL                   ; load-locked
147    UNSPECV_SC                   ; store-conditional
148    UNSPECV_PROBE_STACK_RANGE    ; probe range of stack addresses
149    UNSPECV_EH_RR                ; eh_reg_restore
150    UNSPECV_ISYNC                ; isync instruction
151    UNSPECV_MFTB                 ; move from time base
152    UNSPECV_NLGR                 ; non-local goto receiver
153    UNSPECV_MFFS                 ; Move from FPSCR
154    UNSPECV_MTFSF                ; Move to FPSCR Fields
155   ])
156
157 \f
158 ;; Define an insn type attribute.  This is used in function unit delay
159 ;; computations.
160 (define_attr "type"
161   "integer,two,three,
162    shift,insert,
163    mul,halfmul,div,
164    exts,cntlz,popcnt,isel,
165    load,store,fpload,fpstore,vecload,vecstore,
166    cmp,
167    branch,jmpreg,mfjmpr,mtjmpr,trap,isync,sync,load_l,store_c,
168    compare,fast_compare,
169    cr_logical,delayed_cr,mfcr,mfcrf,mtcr,
170    fpcompare,fp,fpsimple,dmul,sdiv,ddiv,ssqrt,dsqrt,
171    brinc,
172    vecsimple,veccomplex,vecdiv,veccmp,veccmpsimple,vecperm,
173    vecfloat,vecfdiv,vecdouble,mffgpr,mftgpr,crypto,
174    htm"
175   (const_string "integer"))
176
177 ;; What data size does this instruction work on?
178 ;; This is used for insert, mul.
179 (define_attr "size" "8,16,32,64" (const_string "32"))
180
181 ;; Is this instruction record form ("dot", signed compare to 0, writing CR0)?
182 ;; This is used for mul.
183 (define_attr "dot" "no,yes" (const_string "no"))
184
185 ;; Does this instruction sign-extend its result?
186 ;; This is used for load insns.
187 (define_attr "sign_extend" "no,yes" (const_string "no"))
188
189 ;; Does this instruction use indexed (that is, reg+reg) addressing?
190 ;; This is used for load and store insns.  If operand 0 or 1 is a MEM
191 ;; it is automatically set based on that.  If a load or store instruction
192 ;; has fewer than two operands it needs to set this attribute manually
193 ;; or the compiler will crash.
194 (define_attr "indexed" "no,yes"
195   (if_then_else (ior (match_operand 0 "indexed_address_mem")
196                      (match_operand 1 "indexed_address_mem"))
197                 (const_string "yes")
198                 (const_string "no")))
199
200 ;; Does this instruction use update addressing?
201 ;; This is used for load and store insns.  See the comments for "indexed".
202 (define_attr "update" "no,yes"
203   (if_then_else (ior (match_operand 0 "update_address_mem")
204                      (match_operand 1 "update_address_mem"))
205                 (const_string "yes")
206                 (const_string "no")))
207
208 ;; Is this instruction using a shift amount from a register?
209 ;; This is used for shift insns.
210 (define_attr "var_shift" "no,yes" (const_string "no"))
211
212 ;; Define floating point instruction sub-types for use with Xfpu.md
213 (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"))
214
215 ;; Length (in bytes).
216 ; '(pc)' in the following doesn't include the instruction itself; it is
217 ; calculated as if the instruction had zero size.
218 (define_attr "length" ""
219   (if_then_else (eq_attr "type" "branch")
220                 (if_then_else (and (ge (minus (match_dup 0) (pc))
221                                        (const_int -32768))
222                                    (lt (minus (match_dup 0) (pc))
223                                        (const_int 32764)))
224                               (const_int 4)
225                               (const_int 8))
226                 (const_int 4)))
227
228 ;; Processor type -- this attribute must exactly match the processor_type
229 ;; enumeration in rs6000-opts.h.
230 (define_attr "cpu"
231   "ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,
232    ppc750,ppc7400,ppc7450,
233    ppc403,ppc405,ppc440,ppc476,
234    ppc8540,ppc8548,ppce300c2,ppce300c3,ppce500mc,ppce500mc64,ppce5500,ppce6500,
235    power4,power5,power6,power7,power8,
236    rs64a,mpccore,cell,ppca2,titan"
237   (const (symbol_ref "rs6000_cpu_attr")))
238
239
240 ;; If this instruction is microcoded on the CELL processor
241 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
242 (define_attr "cell_micro" "not,conditional,always"
243   (if_then_else (ior (eq_attr "type" "compare")
244                      (and (eq_attr "type" "shift,mul")
245                           (eq_attr "dot" "yes"))
246                      (and (eq_attr "type" "load")
247                           (eq_attr "sign_extend" "yes"))
248                      (and (eq_attr "type" "shift")
249                           (eq_attr "var_shift" "yes")))
250                 (const_string "always")
251                 (const_string "not")))
252
253 (automata_option "ndfa")
254
255 (include "rs64.md")
256 (include "mpc.md")
257 (include "40x.md")
258 (include "440.md")
259 (include "476.md")
260 (include "601.md")
261 (include "603.md")
262 (include "6xx.md")
263 (include "7xx.md")
264 (include "7450.md")
265 (include "8540.md")
266 (include "e300c2c3.md")
267 (include "e500mc.md")
268 (include "e500mc64.md")
269 (include "e5500.md")
270 (include "e6500.md")
271 (include "power4.md")
272 (include "power5.md")
273 (include "power6.md")
274 (include "power7.md")
275 (include "power8.md")
276 (include "cell.md")
277 (include "xfpu.md")
278 (include "a2.md")
279 (include "titan.md")
280
281 (include "predicates.md")
282 (include "constraints.md")
283
284 (include "darwin.md")
285
286 \f
287 ;; Mode iterators
288
289 ; This mode iterator allows :GPR to be used to indicate the allowable size
290 ; of whole values in GPRs.
291 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
292
293 ; Any supported integer mode.
294 (define_mode_iterator INT [QI HI SI DI TI PTI])
295
296 ; Any supported integer mode that fits in one register.
297 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
298
299 ; extend modes for DImode
300 (define_mode_iterator QHSI [QI HI SI])
301
302 ; QImode or HImode for small atomic ops
303 (define_mode_iterator QHI [QI HI])
304
305 ; HImode or SImode for sign extended fusion ops
306 (define_mode_iterator HSI [HI SI])
307
308 ; SImode or DImode, even if DImode doesn't fit in GPRs.
309 (define_mode_iterator SDI [SI DI])
310
311 ; The size of a pointer.  Also, the size of the value that a record-condition
312 ; (one with a '.') will compare; and the size used for arithmetic carries.
313 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
314
315 ; Iterator to add PTImode along with TImode (TImode can go in VSX registers,
316 ; PTImode is GPR only)
317 (define_mode_iterator TI2 [TI PTI])
318
319 ; Any hardware-supported floating-point mode
320 (define_mode_iterator FP [
321   (SF "TARGET_HARD_FLOAT 
322    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) || TARGET_E500_SINGLE)")
323   (DF "TARGET_HARD_FLOAT 
324    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)")
325   (TF "!TARGET_IEEEQUAD
326    && TARGET_HARD_FLOAT
327    && (TARGET_FPRS || TARGET_E500_DOUBLE)
328    && TARGET_LONG_DOUBLE_128")
329   (DD "TARGET_DFP")
330   (TD "TARGET_DFP")])
331
332 ; Any fma capable floating-point mode.
333 (define_mode_iterator FMA_F [
334   (SF "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT")
335   (DF "(TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
336        || VECTOR_UNIT_VSX_P (DFmode)")
337   (V2SF "TARGET_PAIRED_FLOAT")
338   (V4SF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)")
339   (V2DF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)")
340   ])
341
342 ; Floating point move iterators to combine binary and decimal moves
343 (define_mode_iterator FMOVE32 [SF SD])
344 (define_mode_iterator FMOVE64 [DF DD])
345 (define_mode_iterator FMOVE64X [DI DF DD])
346 (define_mode_iterator FMOVE128 [(TF "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128")
347                                 (TD "TARGET_HARD_FLOAT && TARGET_FPRS")])
348
349 ; Iterators for 128 bit types for direct move
350 (define_mode_iterator FMOVE128_GPR [(TI    "TARGET_VSX_TIMODE")
351                                     (V16QI "")
352                                     (V8HI  "")
353                                     (V4SI  "")
354                                     (V4SF  "")
355                                     (V2DI  "")
356                                     (V2DF  "")
357                                     (V1TI  "")])
358
359 ; Whether a floating point move is ok, don't allow SD without hardware FP
360 (define_mode_attr fmove_ok [(SF "")
361                             (DF "")
362                             (SD "TARGET_HARD_FLOAT && TARGET_FPRS")
363                             (DD "")])
364
365 ; Convert REAL_VALUE to the appropriate bits
366 (define_mode_attr real_value_to_target [(SF "REAL_VALUE_TO_TARGET_SINGLE")
367                                         (DF "REAL_VALUE_TO_TARGET_DOUBLE")
368                                         (SD "REAL_VALUE_TO_TARGET_DECIMAL32")
369                                         (DD "REAL_VALUE_TO_TARGET_DECIMAL64")])
370
371 ; Definitions for load to 32-bit fpr register
372 (define_mode_attr f32_lr [(SF "f")               (SD "wz")])
373 (define_mode_attr f32_lm [(SF "m")               (SD "Z")])
374 (define_mode_attr f32_li [(SF "lfs%U1%X1 %0,%1") (SD "lfiwzx %0,%y1")])
375 (define_mode_attr f32_lv [(SF "lxsspx %x0,%y1")  (SD "lxsiwzx %x0,%y1")])
376
377 ; Definitions for store from 32-bit fpr register
378 (define_mode_attr f32_sr [(SF "f")                (SD "wx")])
379 (define_mode_attr f32_sm [(SF "m")                (SD "Z")])
380 (define_mode_attr f32_si [(SF "stfs%U0%X0 %1,%0") (SD "stfiwx %1,%y0")])
381 (define_mode_attr f32_sv [(SF "stxsspx %x1,%y0")  (SD "stxsiwzx %x1,%y0")])
382
383 ; Definitions for 32-bit fpr direct move
384 (define_mode_attr f32_dm [(SF "wn") (SD "wm")])
385
386 ; These modes do not fit in integer registers in 32-bit mode.
387 ; but on e500v2, the gpr are 64 bit registers
388 (define_mode_iterator DIFD [DI (DF "!TARGET_E500_DOUBLE") DD])
389
390 ; Iterator for reciprocal estimate instructions
391 (define_mode_iterator RECIPF [SF DF V4SF V2DF])
392
393 ; Iterator for just SF/DF
394 (define_mode_iterator SFDF [SF DF])
395
396 ; SF/DF suffix for traditional floating instructions
397 (define_mode_attr Ftrad         [(SF "s") (DF "")])
398
399 ; SF/DF suffix for VSX instructions
400 (define_mode_attr Fvsx          [(SF "sp") (DF  "dp")])
401
402 ; SF/DF constraint for arithmetic on traditional floating point registers
403 (define_mode_attr Ff            [(SF "f") (DF "d")])
404
405 ; SF/DF constraint for arithmetic on VSX registers
406 (define_mode_attr Fv            [(SF "wy") (DF "ws")])
407
408 ; s/d suffix for things like fp_addsub_s/fp_addsub_d
409 (define_mode_attr Fs            [(SF "s")  (DF "d")])
410
411 ; FRE/FRES support
412 (define_mode_attr Ffre          [(SF "fres") (DF "fre")])
413 (define_mode_attr FFRE          [(SF "FRES") (DF "FRE")])
414
415 ; Conditional returns.
416 (define_code_iterator any_return [return simple_return])
417 (define_code_attr return_pred [(return "direct_return ()")
418                                (simple_return "1")])
419 (define_code_attr return_str [(return "") (simple_return "simple_")])
420
421 ; Various instructions that come in SI and DI forms.
422 ; A generic w/d attribute, for things like cmpw/cmpd.
423 (define_mode_attr wd [(QI    "b")
424                       (HI    "h")
425                       (SI    "w")
426                       (DI    "d")
427                       (V16QI "b")
428                       (V8HI  "h")
429                       (V4SI  "w")
430                       (V2DI  "d")])
431
432 ;; How many bits in this mode?
433 (define_mode_attr bits [(QI "8") (HI "16") (SI "32") (DI "64")])
434
435 ; DImode bits
436 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
437
438 ;; ISEL/ISEL64 target selection
439 (define_mode_attr sel [(SI "") (DI "64")])
440
441 ;; Suffix for reload patterns
442 (define_mode_attr ptrsize [(SI "32bit")
443                            (DI "64bit")])
444
445 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
446                             (DI "TARGET_64BIT")])
447
448 (define_mode_attr mptrsize [(SI "si")
449                             (DI "di")])
450
451 (define_mode_attr ptrload [(SI "lwz")
452                            (DI "ld")])
453
454 (define_mode_attr ptrm [(SI "m")
455                         (DI "Y")])
456
457 (define_mode_attr rreg [(SF   "f")
458                         (DF   "ws")
459                         (TF   "f")
460                         (TD   "f")
461                         (V4SF "wf")
462                         (V2DF "wd")])
463
464 (define_mode_attr rreg2 [(SF   "f")
465                          (DF   "d")])
466
467 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
468                                  (DF "TARGET_FCFID")])
469
470 (define_mode_attr E500_CONVERT [(SF "!TARGET_FPRS")
471                                 (DF "TARGET_E500_DOUBLE")])
472
473 (define_mode_attr TARGET_FLOAT [(SF "TARGET_SINGLE_FLOAT")
474                                 (DF "TARGET_DOUBLE_FLOAT")])
475
476 ;; Mode iterator for logical operations on 128-bit types
477 (define_mode_iterator BOOL_128          [TI
478                                          PTI
479                                          (V16QI "TARGET_ALTIVEC")
480                                          (V8HI  "TARGET_ALTIVEC")
481                                          (V4SI  "TARGET_ALTIVEC")
482                                          (V4SF  "TARGET_ALTIVEC")
483                                          (V2DI  "TARGET_ALTIVEC")
484                                          (V2DF  "TARGET_ALTIVEC")
485                                          (V1TI  "TARGET_ALTIVEC")])
486
487 ;; For the GPRs we use 3 constraints for register outputs, two that are the
488 ;; same as the output register, and a third where the output register is an
489 ;; early clobber, so we don't have to deal with register overlaps.  For the
490 ;; vector types, we prefer to use the vector registers.  For TI mode, allow
491 ;; either.
492
493 ;; Mode attribute for boolean operation register constraints for output
494 (define_mode_attr BOOL_REGS_OUTPUT      [(TI    "&r,r,r,wa,v")
495                                          (PTI   "&r,r,r")
496                                          (V16QI "wa,v,&?r,?r,?r")
497                                          (V8HI  "wa,v,&?r,?r,?r")
498                                          (V4SI  "wa,v,&?r,?r,?r")
499                                          (V4SF  "wa,v,&?r,?r,?r")
500                                          (V2DI  "wa,v,&?r,?r,?r")
501                                          (V2DF  "wa,v,&?r,?r,?r")
502                                          (V1TI  "wa,v,&?r,?r,?r")])
503
504 ;; Mode attribute for boolean operation register constraints for operand1
505 (define_mode_attr BOOL_REGS_OP1         [(TI    "r,0,r,wa,v")
506                                          (PTI   "r,0,r")
507                                          (V16QI "wa,v,r,0,r")
508                                          (V8HI  "wa,v,r,0,r")
509                                          (V4SI  "wa,v,r,0,r")
510                                          (V4SF  "wa,v,r,0,r")
511                                          (V2DI  "wa,v,r,0,r")
512                                          (V2DF  "wa,v,r,0,r")
513                                          (V1TI  "wa,v,r,0,r")])
514
515 ;; Mode attribute for boolean operation register constraints for operand2
516 (define_mode_attr BOOL_REGS_OP2         [(TI    "r,r,0,wa,v")
517                                          (PTI   "r,r,0")
518                                          (V16QI "wa,v,r,r,0")
519                                          (V8HI  "wa,v,r,r,0")
520                                          (V4SI  "wa,v,r,r,0")
521                                          (V4SF  "wa,v,r,r,0")
522                                          (V2DI  "wa,v,r,r,0")
523                                          (V2DF  "wa,v,r,r,0")
524                                          (V1TI  "wa,v,r,r,0")])
525
526 ;; Mode attribute for boolean operation register constraints for operand1
527 ;; for one_cmpl.  To simplify things, we repeat the constraint where 0
528 ;; is used for operand1 or operand2
529 (define_mode_attr BOOL_REGS_UNARY       [(TI    "r,0,0,wa,v")
530                                          (PTI   "r,0,0")
531                                          (V16QI "wa,v,r,0,0")
532                                          (V8HI  "wa,v,r,0,0")
533                                          (V4SI  "wa,v,r,0,0")
534                                          (V4SF  "wa,v,r,0,0")
535                                          (V2DI  "wa,v,r,0,0")
536                                          (V2DF  "wa,v,r,0,0")
537                                          (V1TI  "wa,v,r,0,0")])
538
539 ;; Mode attribute for the clobber of CC0 for AND expansion.
540 ;; For the 128-bit types, we never do AND immediate, but we need to
541 ;; get the correct number of X's for the number of operands.
542 (define_mode_attr BOOL_REGS_AND_CR0     [(TI    "X,X,X,X,X")
543                                          (PTI   "X,X,X")
544                                          (V16QI "X,X,X,X,X")
545                                          (V8HI  "X,X,X,X,X")
546                                          (V4SI  "X,X,X,X,X")
547                                          (V4SF  "X,X,X,X,X")
548                                          (V2DI  "X,X,X,X,X")
549                                          (V2DF  "X,X,X,X,X")
550                                          (V1TI  "X,X,X,X,X")])
551 \f
552 ;; Start with fixed-point load and store insns.  Here we put only the more
553 ;; complex forms.  Basic data transfer is done later.
554
555 (define_expand "zero_extend<mode>di2"
556   [(set (match_operand:DI 0 "gpc_reg_operand" "")
557         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
558   "TARGET_POWERPC64"
559   "")
560
561 (define_insn "*zero_extend<mode>di2_internal1"
562   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
563         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
564   "TARGET_POWERPC64 && (<MODE>mode != SImode || !TARGET_LFIWZX)"
565   "@
566    l<wd>z%U1%X1 %0,%1
567    rldicl %0,%1,0,<dbits>"
568   [(set_attr "type" "load,*")])
569
570 (define_insn "*zero_extend<mode>di2_internal2"
571   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
572         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
573                     (const_int 0)))
574    (clobber (match_scratch:DI 2 "=r,r"))]
575   "TARGET_64BIT"
576   "@
577    rldicl. %2,%1,0,<dbits>
578    #"
579   [(set_attr "type" "compare")
580    (set_attr "length" "4,8")])
581
582 (define_split
583   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
584         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
585                     (const_int 0)))
586    (clobber (match_scratch:DI 2 ""))]
587   "TARGET_POWERPC64 && reload_completed"
588   [(set (match_dup 2)
589         (zero_extend:DI (match_dup 1)))
590    (set (match_dup 0)
591         (compare:CC (match_dup 2)
592                     (const_int 0)))]
593   "")
594
595 (define_insn "*zero_extend<mode>di2_internal3"
596   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
597         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
598                     (const_int 0)))
599    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
600         (zero_extend:DI (match_dup 1)))]
601   "TARGET_64BIT"
602   "@
603    rldicl. %0,%1,0,<dbits>
604    #"
605   [(set_attr "type" "compare")
606    (set_attr "length" "4,8")])
607
608 (define_split
609   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
610         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
611                     (const_int 0)))
612    (set (match_operand:DI 0 "gpc_reg_operand" "")
613         (zero_extend:DI (match_dup 1)))]
614   "TARGET_POWERPC64 && reload_completed"
615   [(set (match_dup 0)
616         (zero_extend:DI (match_dup 1)))
617    (set (match_dup 2)
618         (compare:CC (match_dup 0)
619                     (const_int 0)))]
620   "")
621
622 (define_insn "*zero_extendsidi2_lfiwzx"
623   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,??wm,!wz,!wu")
624         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r,r,Z,Z")))]
625   "TARGET_POWERPC64 && TARGET_LFIWZX"
626   "@
627    lwz%U1%X1 %0,%1
628    rldicl %0,%1,0,32
629    mtvsrwz %x0,%1
630    lfiwzx %0,%y1
631    lxsiwzx %x0,%y1"
632   [(set_attr "type" "load,*,mffgpr,fpload,fpload")])
633
634 (define_insn "extendqidi2"
635   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
636         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
637   "TARGET_POWERPC64"
638   "extsb %0,%1"
639   [(set_attr "type" "exts")])
640
641 (define_insn ""
642   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
643         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
644                     (const_int 0)))
645    (clobber (match_scratch:DI 2 "=r,r"))]
646   "TARGET_64BIT"
647   "@
648    extsb. %2,%1
649    #"
650   [(set_attr "type" "compare")
651    (set_attr "length" "4,8")])
652
653 (define_split
654   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
655         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
656                     (const_int 0)))
657    (clobber (match_scratch:DI 2 ""))]
658   "TARGET_POWERPC64 && reload_completed"
659   [(set (match_dup 2)
660         (sign_extend:DI (match_dup 1)))
661    (set (match_dup 0)
662         (compare:CC (match_dup 2)
663                     (const_int 0)))]
664   "")
665
666 (define_insn ""
667   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
668         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
669                     (const_int 0)))
670    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
671         (sign_extend:DI (match_dup 1)))]
672   "TARGET_64BIT"
673   "@
674    extsb. %0,%1
675    #"
676   [(set_attr "type" "compare")
677    (set_attr "length" "4,8")])
678
679 (define_split
680   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
681         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
682                     (const_int 0)))
683    (set (match_operand:DI 0 "gpc_reg_operand" "")
684         (sign_extend:DI (match_dup 1)))]
685   "TARGET_POWERPC64 && reload_completed"
686   [(set (match_dup 0)
687         (sign_extend:DI (match_dup 1)))
688    (set (match_dup 2)
689         (compare:CC (match_dup 0)
690                     (const_int 0)))]
691   "")
692
693 (define_expand "extendhidi2"
694   [(set (match_operand:DI 0 "gpc_reg_operand" "")
695         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
696   "TARGET_POWERPC64"
697   "")
698
699 (define_insn ""
700   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
701         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
702   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
703   "@
704    lha%U1%X1 %0,%1
705    extsh %0,%1"
706   [(set_attr "type" "load,exts")
707    (set_attr "sign_extend" "yes")])
708
709 (define_insn ""
710   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
711         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
712   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
713   "extsh %0,%1"
714   [(set_attr "type" "exts")])
715
716 (define_insn ""
717   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
718         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
719                     (const_int 0)))
720    (clobber (match_scratch:DI 2 "=r,r"))]
721   "TARGET_64BIT"
722   "@
723    extsh. %2,%1
724    #"
725   [(set_attr "type" "compare")
726    (set_attr "length" "4,8")])
727
728 (define_split
729   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
730         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
731                     (const_int 0)))
732    (clobber (match_scratch:DI 2 ""))]
733   "TARGET_POWERPC64 && reload_completed"
734   [(set (match_dup 2)
735         (sign_extend:DI (match_dup 1)))
736    (set (match_dup 0)
737         (compare:CC (match_dup 2)
738                     (const_int 0)))]
739   "")
740
741 (define_insn ""
742   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
743         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
744                     (const_int 0)))
745    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
746         (sign_extend:DI (match_dup 1)))]
747   "TARGET_64BIT"
748   "@
749    extsh. %0,%1
750    #"
751   [(set_attr "type" "compare")
752    (set_attr "length" "4,8")])
753
754 (define_split
755   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
756         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
757                     (const_int 0)))
758    (set (match_operand:DI 0 "gpc_reg_operand" "")
759         (sign_extend:DI (match_dup 1)))]
760   "TARGET_POWERPC64 && reload_completed"
761   [(set (match_dup 0)
762         (sign_extend:DI (match_dup 1)))
763    (set (match_dup 2)
764         (compare:CC (match_dup 0)
765                     (const_int 0)))]
766   "")
767
768 (define_expand "extendsidi2"
769   [(set (match_operand:DI 0 "gpc_reg_operand" "")
770         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
771   "TARGET_POWERPC64"
772   "")
773
774 (define_insn "*extendsidi2_lfiwax"
775   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,??wm,!wl,!wu")
776         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "Y,r,r,Z,Z")))]
777   "TARGET_POWERPC64 && TARGET_LFIWAX"
778   "@
779    lwa%U1%X1 %0,%1
780    extsw %0,%1
781    mtvsrwa %x0,%1
782    lfiwax %0,%y1
783    lxsiwax %x0,%y1"
784   [(set_attr "type" "load,exts,mffgpr,fpload,fpload")
785    (set_attr "sign_extend" "yes")])
786
787 (define_insn "*extendsidi2_nocell"
788   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
789         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "Y,r")))]
790   "TARGET_POWERPC64 && rs6000_gen_cell_microcode && !TARGET_LFIWAX"
791   "@
792    lwa%U1%X1 %0,%1
793    extsw %0,%1"
794   [(set_attr "type" "load,exts")
795    (set_attr "sign_extend" "yes")])
796
797 (define_insn "*extendsidi2_nocell"
798   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
799         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
800   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
801   "extsw %0,%1"
802   [(set_attr "type" "exts")])
803
804 (define_insn ""
805   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
806         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
807                     (const_int 0)))
808    (clobber (match_scratch:DI 2 "=r,r"))]
809   "TARGET_64BIT"
810   "@
811    extsw. %2,%1
812    #"
813   [(set_attr "type" "compare")
814    (set_attr "length" "4,8")])
815
816 (define_split
817   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
818         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
819                     (const_int 0)))
820    (clobber (match_scratch:DI 2 ""))]
821   "TARGET_POWERPC64 && reload_completed"
822   [(set (match_dup 2)
823         (sign_extend:DI (match_dup 1)))
824    (set (match_dup 0)
825         (compare:CC (match_dup 2)
826                     (const_int 0)))]
827   "")
828
829 (define_insn ""
830   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
831         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
832                     (const_int 0)))
833    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
834         (sign_extend:DI (match_dup 1)))]
835   "TARGET_64BIT"
836   "@
837    extsw. %0,%1
838    #"
839   [(set_attr "type" "compare")
840    (set_attr "length" "4,8")])
841
842 (define_split
843   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
844         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
845                     (const_int 0)))
846    (set (match_operand:DI 0 "gpc_reg_operand" "")
847         (sign_extend:DI (match_dup 1)))]
848   "TARGET_POWERPC64 && reload_completed"
849   [(set (match_dup 0)
850         (sign_extend:DI (match_dup 1)))
851    (set (match_dup 2)
852         (compare:CC (match_dup 0)
853                     (const_int 0)))]
854   "")
855
856 (define_expand "zero_extendqisi2"
857   [(set (match_operand:SI 0 "gpc_reg_operand" "")
858         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
859   ""
860   "")
861
862 (define_insn ""
863   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
864         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
865   ""
866   "@
867    lbz%U1%X1 %0,%1
868    rlwinm %0,%1,0,0xff"
869   [(set_attr "type" "load,*")])
870
871 (define_insn ""
872   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
873         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
874                     (const_int 0)))
875    (clobber (match_scratch:SI 2 "=r,r"))]
876   ""
877   "@
878    andi. %2,%1,0xff
879    #"
880   [(set_attr "type" "fast_compare,compare")
881    (set_attr "length" "4,8")])
882
883 (define_split
884   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
885         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
886                     (const_int 0)))
887    (clobber (match_scratch:SI 2 ""))]
888   "reload_completed"
889   [(set (match_dup 2)
890         (zero_extend:SI (match_dup 1)))
891    (set (match_dup 0)
892         (compare:CC (match_dup 2)
893                     (const_int 0)))]
894   "")
895
896 (define_insn ""
897   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
898         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
899                     (const_int 0)))
900    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
901         (zero_extend:SI (match_dup 1)))]
902   ""
903   "@
904    andi. %0,%1,0xff
905    #"
906   [(set_attr "type" "fast_compare,compare")
907    (set_attr "length" "4,8")])
908
909 (define_split
910   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
911         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
912                     (const_int 0)))
913    (set (match_operand:SI 0 "gpc_reg_operand" "")
914         (zero_extend:SI (match_dup 1)))]
915   "reload_completed"
916   [(set (match_dup 0)
917         (zero_extend:SI (match_dup 1)))
918    (set (match_dup 2)
919         (compare:CC (match_dup 0)
920                     (const_int 0)))]
921   "")
922
923 (define_insn "extendqisi2"
924   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
925         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
926   ""
927   "extsb %0,%1"
928   [(set_attr "type" "exts")])
929
930 (define_insn ""
931   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
932         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
933                     (const_int 0)))
934    (clobber (match_scratch:SI 2 "=r,r"))]
935   ""
936   "@
937    extsb. %2,%1
938    #"
939   [(set_attr "type" "compare")
940    (set_attr "length" "4,8")])
941
942 (define_split
943   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
944         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
945                     (const_int 0)))
946    (clobber (match_scratch:SI 2 ""))]
947   "reload_completed"
948   [(set (match_dup 2)
949         (sign_extend:SI (match_dup 1)))
950    (set (match_dup 0)
951         (compare:CC (match_dup 2)
952                     (const_int 0)))]
953   "")
954
955 (define_insn ""
956   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
957         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
958                     (const_int 0)))
959    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
960         (sign_extend:SI (match_dup 1)))]
961   ""
962   "@
963    extsb. %0,%1
964    #"
965   [(set_attr "type" "compare")
966    (set_attr "length" "4,8")])
967
968 (define_split
969   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
970         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
971                     (const_int 0)))
972    (set (match_operand:SI 0 "gpc_reg_operand" "")
973         (sign_extend:SI (match_dup 1)))]
974   "reload_completed"
975   [(set (match_dup 0)
976         (sign_extend:SI (match_dup 1)))
977    (set (match_dup 2)
978         (compare:CC (match_dup 0)
979                     (const_int 0)))]
980   "")
981
982 (define_insn ""
983   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
984         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
985   ""
986   "@
987    lbz%U1%X1 %0,%1
988    rlwinm %0,%1,0,0xff"
989   [(set_attr "type" "load,*")])
990
991 (define_insn ""
992   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
993         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
994                     (const_int 0)))
995    (clobber (match_scratch:HI 2 "=r,r"))]
996   ""
997   "@
998    andi. %2,%1,0xff
999    #"
1000   [(set_attr "type" "fast_compare,compare")
1001    (set_attr "length" "4,8")])
1002
1003 (define_split
1004   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1005         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1006                     (const_int 0)))
1007    (clobber (match_scratch:HI 2 ""))]
1008   "reload_completed"
1009   [(set (match_dup 2)
1010         (zero_extend:HI (match_dup 1)))
1011    (set (match_dup 0)
1012         (compare:CC (match_dup 2)
1013                     (const_int 0)))]
1014   "")
1015
1016 (define_insn ""
1017   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1018         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1019                     (const_int 0)))
1020    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1021         (zero_extend:HI (match_dup 1)))]
1022   ""
1023   "@
1024    andi. %0,%1,0xff
1025    #"
1026   [(set_attr "type" "fast_compare,compare")
1027    (set_attr "length" "4,8")])
1028
1029 (define_split
1030   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1031         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1032                     (const_int 0)))
1033    (set (match_operand:HI 0 "gpc_reg_operand" "")
1034         (zero_extend:HI (match_dup 1)))]
1035   "reload_completed"
1036   [(set (match_dup 0)
1037         (zero_extend:HI (match_dup 1)))
1038    (set (match_dup 2)
1039         (compare:CC (match_dup 0)
1040                     (const_int 0)))]
1041   "")
1042
1043 (define_insn "extendqihi2"
1044   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
1045         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
1046   ""
1047   "extsb %0,%1"
1048   [(set_attr "type" "exts")])
1049
1050 (define_insn ""
1051   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1052         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1053                     (const_int 0)))
1054    (clobber (match_scratch:HI 2 "=r,r"))]
1055   ""
1056   "@
1057    extsb. %2,%1
1058    #"
1059   [(set_attr "type" "compare")
1060    (set_attr "length" "4,8")])
1061
1062 (define_split
1063   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1064         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1065                     (const_int 0)))
1066    (clobber (match_scratch:HI 2 ""))]
1067   "reload_completed"
1068   [(set (match_dup 2)
1069         (sign_extend:HI (match_dup 1)))
1070    (set (match_dup 0)
1071         (compare:CC (match_dup 2)
1072                     (const_int 0)))]
1073   "")
1074
1075 (define_insn ""
1076   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1077         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1078                     (const_int 0)))
1079    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1080         (sign_extend:HI (match_dup 1)))]
1081   ""
1082   "@
1083    extsb. %0,%1
1084    #"
1085   [(set_attr "type" "compare")
1086    (set_attr "length" "4,8")])
1087
1088 (define_split
1089   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1090         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1091                     (const_int 0)))
1092    (set (match_operand:HI 0 "gpc_reg_operand" "")
1093         (sign_extend:HI (match_dup 1)))]
1094   "reload_completed"
1095   [(set (match_dup 0)
1096         (sign_extend:HI (match_dup 1)))
1097    (set (match_dup 2)
1098         (compare:CC (match_dup 0)
1099                     (const_int 0)))]
1100   "")
1101
1102 (define_expand "zero_extendhisi2"
1103   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1104         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1105   ""
1106   "")
1107
1108 (define_insn ""
1109   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1110         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1111   ""
1112   "@
1113    lhz%U1%X1 %0,%1
1114    rlwinm %0,%1,0,0xffff"
1115   [(set_attr "type" "load,*")])
1116
1117 (define_insn ""
1118   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1119         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1120                     (const_int 0)))
1121    (clobber (match_scratch:SI 2 "=r,r"))]
1122   ""
1123   "@
1124    andi. %2,%1,0xffff
1125    #"
1126   [(set_attr "type" "fast_compare,compare")
1127    (set_attr "length" "4,8")])
1128
1129 (define_split
1130   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1131         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1132                     (const_int 0)))
1133    (clobber (match_scratch:SI 2 ""))]
1134   "reload_completed"
1135   [(set (match_dup 2)
1136         (zero_extend:SI (match_dup 1)))
1137    (set (match_dup 0)
1138         (compare:CC (match_dup 2)
1139                     (const_int 0)))]
1140   "")
1141
1142 (define_insn ""
1143   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1144         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1145                     (const_int 0)))
1146    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1147         (zero_extend:SI (match_dup 1)))]
1148   ""
1149   "@
1150    andi. %0,%1,0xffff
1151    #"
1152   [(set_attr "type" "fast_compare,compare")
1153    (set_attr "length" "4,8")])
1154
1155 (define_split
1156   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1157         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1158                     (const_int 0)))
1159    (set (match_operand:SI 0 "gpc_reg_operand" "")
1160         (zero_extend:SI (match_dup 1)))]
1161   "reload_completed"
1162   [(set (match_dup 0)
1163         (zero_extend:SI (match_dup 1)))
1164    (set (match_dup 2)
1165         (compare:CC (match_dup 0)
1166                     (const_int 0)))]
1167   "")
1168
1169 (define_expand "extendhisi2"
1170   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1171         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1172   ""
1173   "")
1174
1175 (define_insn ""
1176   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1177         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1178   "rs6000_gen_cell_microcode"
1179   "@
1180    lha%U1%X1 %0,%1
1181    extsh %0,%1"
1182   [(set_attr "type" "load,exts")
1183    (set_attr "sign_extend" "yes")])
1184
1185 (define_insn ""
1186   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1187         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
1188   "!rs6000_gen_cell_microcode"
1189   "extsh %0,%1"
1190   [(set_attr "type" "exts")])
1191
1192 (define_insn ""
1193   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1194         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1195                     (const_int 0)))
1196    (clobber (match_scratch:SI 2 "=r,r"))]
1197   ""
1198   "@
1199    extsh. %2,%1
1200    #"
1201   [(set_attr "type" "compare")
1202    (set_attr "length" "4,8")])
1203
1204 (define_split
1205   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1206         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1207                     (const_int 0)))
1208    (clobber (match_scratch:SI 2 ""))]
1209   "reload_completed"
1210   [(set (match_dup 2)
1211         (sign_extend:SI (match_dup 1)))
1212    (set (match_dup 0)
1213         (compare:CC (match_dup 2)
1214                     (const_int 0)))]
1215   "")
1216
1217 (define_insn ""
1218   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1219         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1220                     (const_int 0)))
1221    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1222         (sign_extend:SI (match_dup 1)))]
1223   ""
1224   "@
1225    extsh. %0,%1
1226    #"
1227   [(set_attr "type" "compare")
1228    (set_attr "length" "4,8")])
1229
1230 (define_split
1231   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1232         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1233                     (const_int 0)))
1234    (set (match_operand:SI 0 "gpc_reg_operand" "")
1235         (sign_extend:SI (match_dup 1)))]
1236   "reload_completed"
1237   [(set (match_dup 0)
1238         (sign_extend:SI (match_dup 1)))
1239    (set (match_dup 2)
1240         (compare:CC (match_dup 0)
1241                     (const_int 0)))]
1242   "")
1243 \f
1244 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
1245
1246 (define_insn "*macchwc"
1247   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1248         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1249                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1250                                        (const_int 16))
1251                                       (sign_extend:SI
1252                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1253                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1254                     (const_int 0)))
1255    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1256         (plus:SI (mult:SI (ashiftrt:SI
1257                            (match_dup 2)
1258                            (const_int 16))
1259                           (sign_extend:SI
1260                            (match_dup 1)))
1261                  (match_dup 4)))]
1262   "TARGET_MULHW"
1263   "macchw. %0,%1,%2"
1264   [(set_attr "type" "halfmul")])
1265
1266 (define_insn "*macchw"
1267   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1268         (plus:SI (mult:SI (ashiftrt:SI
1269                            (match_operand:SI 2 "gpc_reg_operand" "r")
1270                            (const_int 16))
1271                           (sign_extend:SI
1272                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1273                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1274   "TARGET_MULHW"
1275   "macchw %0,%1,%2"
1276   [(set_attr "type" "halfmul")])
1277
1278 (define_insn "*macchwuc"
1279   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1280         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1281                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1282                                        (const_int 16))
1283                                       (zero_extend:SI
1284                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1285                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1286                     (const_int 0)))
1287    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1288         (plus:SI (mult:SI (lshiftrt:SI
1289                            (match_dup 2)
1290                            (const_int 16))
1291                           (zero_extend:SI
1292                            (match_dup 1)))
1293                  (match_dup 4)))]
1294   "TARGET_MULHW"
1295   "macchwu. %0,%1,%2"
1296   [(set_attr "type" "halfmul")])
1297
1298 (define_insn "*macchwu"
1299   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1300         (plus:SI (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                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1306   "TARGET_MULHW"
1307   "macchwu %0,%1,%2"
1308   [(set_attr "type" "halfmul")])
1309
1310 (define_insn "*machhwc"
1311   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1312         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1313                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1314                                        (const_int 16))
1315                                       (ashiftrt:SI
1316                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1317                                        (const_int 16)))
1318                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1319                     (const_int 0)))
1320    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1321         (plus:SI (mult:SI (ashiftrt:SI
1322                            (match_dup 1)
1323                            (const_int 16))
1324                           (ashiftrt:SI
1325                            (match_dup 2)
1326                            (const_int 16)))
1327                  (match_dup 4)))]
1328   "TARGET_MULHW"
1329   "machhw. %0,%1,%2"
1330   [(set_attr "type" "halfmul")])
1331
1332 (define_insn "*machhw"
1333   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1334         (plus:SI (mult:SI (ashiftrt:SI
1335                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1336                            (const_int 16))
1337                           (ashiftrt:SI
1338                            (match_operand:SI 2 "gpc_reg_operand" "r")
1339                            (const_int 16)))
1340                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1341   "TARGET_MULHW"
1342   "machhw %0,%1,%2"
1343   [(set_attr "type" "halfmul")])
1344
1345 (define_insn "*machhwuc"
1346   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1347         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1348                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1349                                        (const_int 16))
1350                                       (lshiftrt:SI
1351                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1352                                        (const_int 16)))
1353                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1354                     (const_int 0)))
1355    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1356         (plus:SI (mult:SI (lshiftrt:SI
1357                            (match_dup 1)
1358                            (const_int 16))
1359                           (lshiftrt:SI
1360                            (match_dup 2)
1361                            (const_int 16)))
1362                  (match_dup 4)))]
1363   "TARGET_MULHW"
1364   "machhwu. %0,%1,%2"
1365   [(set_attr "type" "halfmul")])
1366
1367 (define_insn "*machhwu"
1368   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1369         (plus:SI (mult:SI (lshiftrt:SI
1370                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1371                            (const_int 16))
1372                           (lshiftrt:SI
1373                            (match_operand:SI 2 "gpc_reg_operand" "r")
1374                            (const_int 16)))
1375                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1376   "TARGET_MULHW"
1377   "machhwu %0,%1,%2"
1378   [(set_attr "type" "halfmul")])
1379
1380 (define_insn "*maclhwc"
1381   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1382         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1383                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1384                                       (sign_extend:SI
1385                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1386                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1387                     (const_int 0)))
1388    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1389         (plus:SI (mult:SI (sign_extend:SI
1390                            (match_dup 1))
1391                           (sign_extend:SI
1392                            (match_dup 2)))
1393                  (match_dup 4)))]
1394   "TARGET_MULHW"
1395   "maclhw. %0,%1,%2"
1396   [(set_attr "type" "halfmul")])
1397
1398 (define_insn "*maclhw"
1399   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1400         (plus:SI (mult:SI (sign_extend:SI
1401                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1402                           (sign_extend:SI
1403                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1404                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1405   "TARGET_MULHW"
1406   "maclhw %0,%1,%2"
1407   [(set_attr "type" "halfmul")])
1408
1409 (define_insn "*maclhwuc"
1410   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1411         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1412                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1413                                       (zero_extend:SI
1414                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1415                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1416                     (const_int 0)))
1417    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1418         (plus:SI (mult:SI (zero_extend:SI
1419                            (match_dup 1))
1420                           (zero_extend:SI
1421                            (match_dup 2)))
1422                  (match_dup 4)))]
1423   "TARGET_MULHW"
1424   "maclhwu. %0,%1,%2"
1425   [(set_attr "type" "halfmul")])
1426
1427 (define_insn "*maclhwu"
1428   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1429         (plus:SI (mult:SI (zero_extend:SI
1430                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1431                           (zero_extend:SI
1432                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1433                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1434   "TARGET_MULHW"
1435   "maclhwu %0,%1,%2"
1436   [(set_attr "type" "halfmul")])
1437
1438 (define_insn "*nmacchwc"
1439   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1440         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1441                               (mult:SI (ashiftrt:SI
1442                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1443                                         (const_int 16))
1444                                        (sign_extend:SI
1445                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1446                     (const_int 0)))
1447    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1448         (minus:SI (match_dup 4)
1449                   (mult:SI (ashiftrt:SI
1450                             (match_dup 2)
1451                             (const_int 16))
1452                            (sign_extend:SI
1453                             (match_dup 1)))))]
1454   "TARGET_MULHW"
1455   "nmacchw. %0,%1,%2"
1456   [(set_attr "type" "halfmul")])
1457
1458 (define_insn "*nmacchw"
1459   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1460         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1461                   (mult:SI (ashiftrt:SI
1462                             (match_operand:SI 2 "gpc_reg_operand" "r")
1463                             (const_int 16))
1464                            (sign_extend:SI
1465                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1466   "TARGET_MULHW"
1467   "nmacchw %0,%1,%2"
1468   [(set_attr "type" "halfmul")])
1469
1470 (define_insn "*nmachhwc"
1471   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1472         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1473                               (mult:SI (ashiftrt:SI
1474                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1475                                         (const_int 16))
1476                                        (ashiftrt:SI
1477                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1478                                         (const_int 16))))
1479                     (const_int 0)))
1480    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1481         (minus:SI (match_dup 4)
1482                   (mult:SI (ashiftrt:SI
1483                             (match_dup 1)
1484                             (const_int 16))
1485                            (ashiftrt:SI
1486                             (match_dup 2)
1487                             (const_int 16)))))]
1488   "TARGET_MULHW"
1489   "nmachhw. %0,%1,%2"
1490   [(set_attr "type" "halfmul")])
1491
1492 (define_insn "*nmachhw"
1493   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1494         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1495                   (mult:SI (ashiftrt:SI
1496                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1497                             (const_int 16))
1498                            (ashiftrt:SI
1499                             (match_operand:SI 2 "gpc_reg_operand" "r")
1500                             (const_int 16)))))]
1501   "TARGET_MULHW"
1502   "nmachhw %0,%1,%2"
1503   [(set_attr "type" "halfmul")])
1504
1505 (define_insn "*nmaclhwc"
1506   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1507         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1508                               (mult:SI (sign_extend:SI
1509                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1510                                        (sign_extend:SI
1511                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1512                     (const_int 0)))
1513    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1514         (minus:SI (match_dup 4)
1515                   (mult:SI (sign_extend:SI
1516                             (match_dup 1))
1517                            (sign_extend:SI
1518                             (match_dup 2)))))]
1519   "TARGET_MULHW"
1520   "nmaclhw. %0,%1,%2"
1521   [(set_attr "type" "halfmul")])
1522
1523 (define_insn "*nmaclhw"
1524   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1525         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1526                   (mult:SI (sign_extend:SI
1527                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1528                            (sign_extend:SI
1529                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1530   "TARGET_MULHW"
1531   "nmaclhw %0,%1,%2"
1532   [(set_attr "type" "halfmul")])
1533
1534 (define_insn "*mulchwc"
1535   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1536         (compare:CC (mult:SI (ashiftrt:SI
1537                               (match_operand:SI 2 "gpc_reg_operand" "r")
1538                               (const_int 16))
1539                              (sign_extend:SI
1540                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1541                     (const_int 0)))
1542    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1543         (mult:SI (ashiftrt:SI
1544                   (match_dup 2)
1545                   (const_int 16))
1546                  (sign_extend:SI
1547                   (match_dup 1))))]
1548   "TARGET_MULHW"
1549   "mulchw. %0,%1,%2"
1550   [(set_attr "type" "halfmul")])
1551
1552 (define_insn "*mulchw"
1553   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1554         (mult:SI (ashiftrt:SI
1555                   (match_operand:SI 2 "gpc_reg_operand" "r")
1556                   (const_int 16))
1557                  (sign_extend:SI
1558                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1559   "TARGET_MULHW"
1560   "mulchw %0,%1,%2"
1561   [(set_attr "type" "halfmul")])
1562
1563 (define_insn "*mulchwuc"
1564   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1565         (compare:CC (mult:SI (lshiftrt:SI
1566                               (match_operand:SI 2 "gpc_reg_operand" "r")
1567                               (const_int 16))
1568                              (zero_extend:SI
1569                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1570                     (const_int 0)))
1571    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1572         (mult:SI (lshiftrt:SI
1573                   (match_dup 2)
1574                   (const_int 16))
1575                  (zero_extend:SI
1576                   (match_dup 1))))]
1577   "TARGET_MULHW"
1578   "mulchwu. %0,%1,%2"
1579   [(set_attr "type" "halfmul")])
1580
1581 (define_insn "*mulchwu"
1582   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1583         (mult:SI (lshiftrt:SI
1584                   (match_operand:SI 2 "gpc_reg_operand" "r")
1585                   (const_int 16))
1586                  (zero_extend:SI
1587                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1588   "TARGET_MULHW"
1589   "mulchwu %0,%1,%2"
1590   [(set_attr "type" "halfmul")])
1591
1592 (define_insn "*mulhhwc"
1593   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1594         (compare:CC (mult:SI (ashiftrt:SI
1595                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1596                               (const_int 16))
1597                              (ashiftrt:SI
1598                               (match_operand:SI 2 "gpc_reg_operand" "r")
1599                               (const_int 16)))
1600                     (const_int 0)))
1601    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1602         (mult:SI (ashiftrt:SI
1603                   (match_dup 1)
1604                   (const_int 16))
1605                  (ashiftrt:SI
1606                   (match_dup 2)
1607                   (const_int 16))))]
1608   "TARGET_MULHW"
1609   "mulhhw. %0,%1,%2"
1610   [(set_attr "type" "halfmul")])
1611
1612 (define_insn "*mulhhw"
1613   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1614         (mult:SI (ashiftrt:SI
1615                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1616                   (const_int 16))
1617                  (ashiftrt:SI
1618                   (match_operand:SI 2 "gpc_reg_operand" "r")
1619                   (const_int 16))))]
1620   "TARGET_MULHW"
1621   "mulhhw %0,%1,%2"
1622   [(set_attr "type" "halfmul")])
1623
1624 (define_insn "*mulhhwuc"
1625   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1626         (compare:CC (mult:SI (lshiftrt:SI
1627                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1628                               (const_int 16))
1629                              (lshiftrt:SI
1630                               (match_operand:SI 2 "gpc_reg_operand" "r")
1631                               (const_int 16)))
1632                     (const_int 0)))
1633    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1634         (mult:SI (lshiftrt:SI
1635                   (match_dup 1)
1636                   (const_int 16))
1637                  (lshiftrt:SI
1638                   (match_dup 2)
1639                   (const_int 16))))]
1640   "TARGET_MULHW"
1641   "mulhhwu. %0,%1,%2"
1642   [(set_attr "type" "halfmul")])
1643
1644 (define_insn "*mulhhwu"
1645   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1646         (mult:SI (lshiftrt:SI
1647                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1648                   (const_int 16))
1649                  (lshiftrt:SI
1650                   (match_operand:SI 2 "gpc_reg_operand" "r")
1651                   (const_int 16))))]
1652   "TARGET_MULHW"
1653   "mulhhwu %0,%1,%2"
1654   [(set_attr "type" "halfmul")])
1655
1656 (define_insn "*mullhwc"
1657   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1658         (compare:CC (mult:SI (sign_extend:SI
1659                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1660                              (sign_extend:SI
1661                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1662                     (const_int 0)))
1663    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1664         (mult:SI (sign_extend:SI
1665                   (match_dup 1))
1666                  (sign_extend:SI
1667                   (match_dup 2))))]
1668   "TARGET_MULHW"
1669   "mullhw. %0,%1,%2"
1670   [(set_attr "type" "halfmul")])
1671
1672 (define_insn "*mullhw"
1673   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1674         (mult:SI (sign_extend:SI
1675                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1676                  (sign_extend:SI
1677                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1678   "TARGET_MULHW"
1679   "mullhw %0,%1,%2"
1680   [(set_attr "type" "halfmul")])
1681
1682 (define_insn "*mullhwuc"
1683   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1684         (compare:CC (mult:SI (zero_extend:SI
1685                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1686                              (zero_extend:SI
1687                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1688                     (const_int 0)))
1689    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1690         (mult:SI (zero_extend:SI
1691                   (match_dup 1))
1692                  (zero_extend:SI
1693                   (match_dup 2))))]
1694   "TARGET_MULHW"
1695   "mullhwu. %0,%1,%2"
1696   [(set_attr "type" "halfmul")])
1697
1698 (define_insn "*mullhwu"
1699   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1700         (mult:SI (zero_extend:SI
1701                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1702                  (zero_extend:SI
1703                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1704   "TARGET_MULHW"
1705   "mullhwu %0,%1,%2"
1706   [(set_attr "type" "halfmul")])
1707 \f
1708 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1709 (define_insn "dlmzb"
1710   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1711         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1712                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1713                    UNSPEC_DLMZB_CR))
1714    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1715         (unspec:SI [(match_dup 1)
1716                     (match_dup 2)]
1717                    UNSPEC_DLMZB))]
1718   "TARGET_DLMZB"
1719   "dlmzb. %0,%1,%2")
1720
1721 (define_expand "strlensi"
1722   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1723         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1724                     (match_operand:QI 2 "const_int_operand" "")
1725                     (match_operand 3 "const_int_operand" "")]
1726                    UNSPEC_DLMZB_STRLEN))
1727    (clobber (match_scratch:CC 4 "=x"))]
1728   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1729 {
1730   rtx result = operands[0];
1731   rtx src = operands[1];
1732   rtx search_char = operands[2];
1733   rtx align = operands[3];
1734   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1735   rtx loop_label, end_label, mem, cr0, cond;
1736   if (search_char != const0_rtx
1737       || GET_CODE (align) != CONST_INT
1738       || INTVAL (align) < 8)
1739         FAIL;
1740   word1 = gen_reg_rtx (SImode);
1741   word2 = gen_reg_rtx (SImode);
1742   scratch_dlmzb = gen_reg_rtx (SImode);
1743   scratch_string = gen_reg_rtx (Pmode);
1744   loop_label = gen_label_rtx ();
1745   end_label = gen_label_rtx ();
1746   addr = force_reg (Pmode, XEXP (src, 0));
1747   emit_move_insn (scratch_string, addr);
1748   emit_label (loop_label);
1749   mem = change_address (src, SImode, scratch_string);
1750   emit_move_insn (word1, mem);
1751   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1752   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1753   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1754   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1755   emit_jump_insn (gen_rtx_SET (VOIDmode,
1756                                pc_rtx,
1757                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1758                                                      cond,
1759                                                      gen_rtx_LABEL_REF
1760                                                        (VOIDmode,
1761                                                         end_label),
1762                                                      pc_rtx)));
1763   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1764   emit_jump_insn (gen_rtx_SET (VOIDmode,
1765                                pc_rtx,
1766                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1767   emit_barrier ();
1768   emit_label (end_label);
1769   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1770   emit_insn (gen_subsi3 (result, scratch_string, addr));
1771   emit_insn (gen_subsi3 (result, result, const1_rtx));
1772   DONE;
1773 })
1774 \f
1775 ;; Fixed-point arithmetic insns.
1776
1777 (define_expand "add<mode>3"
1778   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1779         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1780                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1781   ""
1782 {
1783   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1784     {
1785       if (non_short_cint_operand (operands[2], DImode))
1786         FAIL;
1787     }
1788   else if (GET_CODE (operands[2]) == CONST_INT
1789            && ! add_operand (operands[2], <MODE>mode))
1790     {
1791       rtx tmp = ((!can_create_pseudo_p ()
1792                   || rtx_equal_p (operands[0], operands[1]))
1793                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1794
1795       HOST_WIDE_INT val = INTVAL (operands[2]);
1796       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1797       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1798
1799       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1800         FAIL;
1801
1802       /* The ordering here is important for the prolog expander.
1803          When space is allocated from the stack, adding 'low' first may
1804          produce a temporary deallocation (which would be bad).  */
1805       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1806       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1807       DONE;
1808     }
1809 })
1810
1811 ;; Discourage ai/addic because of carry but provide it in an alternative
1812 ;; allowing register zero as source.
1813 (define_insn "*add<mode>3_internal1"
1814   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1815         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1816                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1817   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1818   "@
1819    add %0,%1,%2
1820    addi %0,%1,%2
1821    addic %0,%1,%2
1822    addis %0,%1,%v2"
1823   [(set_attr "length" "4,4,4,4")])
1824
1825 (define_insn "addsi3_high"
1826   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1827         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1828                  (high:SI (match_operand 2 "" ""))))]
1829   "TARGET_MACHO && !TARGET_64BIT"
1830   "addis %0,%1,ha16(%2)"
1831   [(set_attr "length" "4")])
1832
1833 (define_insn "*add<mode>3_internal2"
1834   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1835         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1836                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1837                     (const_int 0)))
1838    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1839   ""
1840   "@
1841    add. %3,%1,%2
1842    addic. %3,%1,%2
1843    #
1844    #"
1845   [(set_attr "type" "fast_compare,compare,compare,compare")
1846    (set_attr "length" "4,4,8,8")])
1847
1848 (define_split
1849   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1850         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1851                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1852                     (const_int 0)))
1853    (clobber (match_scratch:GPR 3 ""))]
1854   "reload_completed"
1855   [(set (match_dup 3)
1856         (plus:GPR (match_dup 1)
1857                  (match_dup 2)))
1858    (set (match_dup 0)
1859         (compare:CC (match_dup 3)
1860                     (const_int 0)))]
1861   "")
1862
1863 (define_insn "*add<mode>3_internal3"
1864   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1865         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1866                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1867                     (const_int 0)))
1868    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1869         (plus:P (match_dup 1)
1870                 (match_dup 2)))]
1871   ""
1872   "@
1873    add. %0,%1,%2
1874    addic. %0,%1,%2
1875    #
1876    #"
1877   [(set_attr "type" "fast_compare,compare,compare,compare")
1878    (set_attr "length" "4,4,8,8")])
1879
1880 (define_split
1881   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1882         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1883                             (match_operand:P 2 "reg_or_short_operand" ""))
1884                     (const_int 0)))
1885    (set (match_operand:P 0 "gpc_reg_operand" "")
1886         (plus:P (match_dup 1) (match_dup 2)))]
1887   "reload_completed"
1888   [(set (match_dup 0)
1889         (plus:P (match_dup 1)
1890                 (match_dup 2)))
1891    (set (match_dup 3)
1892         (compare:CC (match_dup 0)
1893                     (const_int 0)))]
1894   "")
1895
1896 ;; Split an add that we can't do in one insn into two insns, each of which
1897 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1898 ;; add should be last in case the result gets used in an address.
1899
1900 (define_split
1901   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1902         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1903                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1904   ""
1905   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1906    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1907 {
1908   HOST_WIDE_INT val = INTVAL (operands[2]);
1909   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1910   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1911
1912   operands[4] = GEN_INT (low);
1913   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1914     operands[3] = GEN_INT (rest);
1915   else if (can_create_pseudo_p ())
1916     {
1917       operands[3] = gen_reg_rtx (DImode);
1918       emit_move_insn (operands[3], operands[2]);
1919       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1920       DONE;
1921     }
1922   else
1923     FAIL;
1924 })
1925
1926 (define_expand "one_cmpl<mode>2"
1927   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1928         (not:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1929   ""
1930 {
1931   if (<MODE>mode == DImode && !TARGET_POWERPC64)
1932     {
1933       rs6000_split_logical (operands, NOT, false, false, false, NULL_RTX);
1934       DONE;
1935     }
1936 })
1937
1938 (define_insn "*one_cmpl<mode>2"
1939   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1940         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1941   ""
1942   "nor %0,%1,%1")
1943
1944 (define_insn ""
1945   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1946         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1947                     (const_int 0)))
1948    (clobber (match_scratch:P 2 "=r,r"))]
1949   ""
1950   "@
1951    nor. %2,%1,%1
1952    #"
1953   [(set_attr "type" "fast_compare,compare")
1954    (set_attr "length" "4,8")])
1955
1956 (define_split
1957   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1958         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1959                     (const_int 0)))
1960    (clobber (match_scratch:P 2 ""))]
1961   "reload_completed"
1962   [(set (match_dup 2)
1963         (not:P (match_dup 1)))
1964    (set (match_dup 0)
1965         (compare:CC (match_dup 2)
1966                     (const_int 0)))]
1967   "")
1968
1969 (define_insn ""
1970   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1971         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1972                     (const_int 0)))
1973    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1974         (not:P (match_dup 1)))]
1975   ""
1976   "@
1977    nor. %0,%1,%1
1978    #"
1979   [(set_attr "type" "fast_compare,compare")
1980    (set_attr "length" "4,8")])
1981
1982 (define_split
1983   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1984         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1985                     (const_int 0)))
1986    (set (match_operand:P 0 "gpc_reg_operand" "")
1987         (not:P (match_dup 1)))]
1988   "reload_completed"
1989   [(set (match_dup 0)
1990         (not:P (match_dup 1)))
1991    (set (match_dup 2)
1992         (compare:CC (match_dup 0)
1993                     (const_int 0)))]
1994   "")
1995
1996 (define_insn ""
1997   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1998         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1999                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
2000   ""
2001   "@
2002    subf %0,%2,%1
2003    subfic %0,%2,%1")
2004
2005 (define_insn ""
2006   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2007         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2008                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
2009                     (const_int 0)))
2010    (clobber (match_scratch:P 3 "=r,r"))]
2011   ""
2012   "@
2013    subf. %3,%2,%1
2014    #"
2015   [(set_attr "type" "fast_compare")
2016    (set_attr "length" "4,8")])
2017
2018 (define_split
2019   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2020         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
2021                              (match_operand:P 2 "gpc_reg_operand" ""))
2022                     (const_int 0)))
2023    (clobber (match_scratch:P 3 ""))]
2024   "reload_completed"
2025   [(set (match_dup 3)
2026         (minus:P (match_dup 1)
2027                   (match_dup 2)))
2028    (set (match_dup 0)
2029         (compare:CC (match_dup 3)
2030                     (const_int 0)))]
2031   "")
2032
2033 (define_insn ""
2034   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2035         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2036                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
2037                     (const_int 0)))
2038    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2039         (minus:P (match_dup 1)
2040                   (match_dup 2)))]
2041   ""
2042   "@
2043    subf. %0,%2,%1
2044    #"
2045   [(set_attr "type" "fast_compare")
2046    (set_attr "length" "4,8")])
2047
2048 (define_split
2049   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2050         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
2051                              (match_operand:P 2 "gpc_reg_operand" ""))
2052                     (const_int 0)))
2053    (set (match_operand:P 0 "gpc_reg_operand" "")
2054         (minus:P (match_dup 1)
2055                   (match_dup 2)))]
2056   "reload_completed"
2057   [(set (match_dup 0)
2058         (minus:P (match_dup 1)
2059                   (match_dup 2)))
2060    (set (match_dup 3)
2061         (compare:CC (match_dup 0)
2062                     (const_int 0)))]
2063   "")
2064
2065 (define_expand "sub<mode>3"
2066   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2067         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
2068                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
2069   ""
2070   "
2071 {
2072   if (GET_CODE (operands[2]) == CONST_INT)
2073     {
2074       emit_insn (gen_add<mode>3 (operands[0], operands[1],
2075                                  negate_rtx (<MODE>mode, operands[2])));
2076       DONE;
2077     }
2078 }")
2079
2080 (define_expand "neg<mode>2"
2081   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2082         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2083   ""
2084   "")
2085
2086 (define_insn "*neg<mode>2_internal"
2087   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2088         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2089   ""
2090   "neg %0,%1")
2091
2092 (define_insn ""
2093   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2094         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2095                     (const_int 0)))
2096    (clobber (match_scratch:P 2 "=r,r"))]
2097   ""
2098   "@
2099    neg. %2,%1
2100    #"
2101   [(set_attr "type" "fast_compare")
2102    (set_attr "length" "4,8")])
2103
2104 (define_split
2105   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2106         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2107                     (const_int 0)))
2108    (clobber (match_scratch:P 2 ""))]
2109   "reload_completed"
2110   [(set (match_dup 2)
2111         (neg:P (match_dup 1)))
2112    (set (match_dup 0)
2113         (compare:CC (match_dup 2)
2114                     (const_int 0)))]
2115   "")
2116
2117 (define_insn ""
2118   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2119         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2120                     (const_int 0)))
2121    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2122         (neg:P (match_dup 1)))]
2123   ""
2124   "@
2125    neg. %0,%1
2126    #"
2127   [(set_attr "type" "fast_compare")
2128    (set_attr "length" "4,8")])
2129
2130 (define_split
2131   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2132         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2133                     (const_int 0)))
2134    (set (match_operand:P 0 "gpc_reg_operand" "")
2135         (neg:P (match_dup 1)))]
2136   "reload_completed"
2137   [(set (match_dup 0)
2138         (neg:P (match_dup 1)))
2139    (set (match_dup 2)
2140         (compare:CC (match_dup 0)
2141                     (const_int 0)))]
2142   "")
2143
2144 (define_insn "clz<mode>2"
2145   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2146         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2147   ""
2148   "cntlz<wd> %0,%1"
2149   [(set_attr "type" "cntlz")])
2150
2151 (define_expand "ctz<mode>2"
2152   [(set (match_dup 2)
2153         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2154    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2155                                           (match_dup 2)))
2156               (clobber (scratch:CC))])
2157    (set (match_dup 4) (clz:GPR (match_dup 3)))
2158    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2159         (minus:GPR (match_dup 5) (match_dup 4)))]
2160   ""
2161   {
2162      operands[2] = gen_reg_rtx (<MODE>mode);
2163      operands[3] = gen_reg_rtx (<MODE>mode);
2164      operands[4] = gen_reg_rtx (<MODE>mode);
2165      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2166   })
2167
2168 (define_expand "ffs<mode>2"
2169   [(set (match_dup 2)
2170         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2171    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2172                                           (match_dup 2)))
2173               (clobber (scratch:CC))])
2174    (set (match_dup 4) (clz:GPR (match_dup 3)))
2175    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2176         (minus:GPR (match_dup 5) (match_dup 4)))]
2177   ""
2178   {
2179      operands[2] = gen_reg_rtx (<MODE>mode);
2180      operands[3] = gen_reg_rtx (<MODE>mode);
2181      operands[4] = gen_reg_rtx (<MODE>mode);
2182      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2183   })
2184
2185 (define_insn "popcntb<mode>2"
2186   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2187         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2188                      UNSPEC_POPCNTB))]
2189   "TARGET_POPCNTB"
2190   "popcntb %0,%1"
2191   [(set_attr "length" "4")
2192    (set_attr "type" "popcnt")])
2193
2194 (define_insn "popcntd<mode>2"
2195   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2196         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2197   "TARGET_POPCNTD"
2198   "popcnt<wd> %0,%1"
2199   [(set_attr "length" "4")
2200    (set_attr "type" "popcnt")])
2201
2202 (define_expand "popcount<mode>2"
2203   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2204         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2205   "TARGET_POPCNTB || TARGET_POPCNTD"
2206   {
2207     rs6000_emit_popcount (operands[0], operands[1]);
2208     DONE;
2209   })
2210
2211 (define_insn "parity<mode>2_cmpb"
2212   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2213         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
2214   "TARGET_CMPB && TARGET_POPCNTB"
2215   "prty<wd> %0,%1"
2216   [(set_attr "length" "4")
2217    (set_attr "type" "popcnt")])
2218
2219 (define_expand "parity<mode>2"
2220   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2221         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2222   "TARGET_POPCNTB"
2223   {
2224     rs6000_emit_parity (operands[0], operands[1]);
2225     DONE;
2226   })
2227
2228 ;; Since the hardware zeros the upper part of the register, save generating the
2229 ;; AND immediate if we are converting to unsigned
2230 (define_insn "*bswaphi2_extenddi"
2231   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2232         (zero_extend:DI
2233          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2234   "TARGET_POWERPC64"
2235   "lhbrx %0,%y1"
2236   [(set_attr "length" "4")
2237    (set_attr "type" "load")])
2238
2239 (define_insn "*bswaphi2_extendsi"
2240   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2241         (zero_extend:SI
2242          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2243   ""
2244   "lhbrx %0,%y1"
2245   [(set_attr "length" "4")
2246    (set_attr "type" "load")])
2247
2248 (define_expand "bswaphi2"
2249   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
2250                    (bswap:HI
2251                     (match_operand:HI 1 "reg_or_mem_operand" "")))
2252               (clobber (match_scratch:SI 2 ""))])]
2253   ""
2254 {
2255   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2256     operands[1] = force_reg (HImode, operands[1]);
2257 })
2258
2259 (define_insn "bswaphi2_internal"
2260   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
2261         (bswap:HI
2262          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
2263    (clobber (match_scratch:SI 2 "=X,X,&r"))]
2264   ""
2265   "@
2266    lhbrx %0,%y1
2267    sthbrx %1,%y0
2268    #"
2269   [(set_attr "length" "4,4,12")
2270    (set_attr "type" "load,store,*")])
2271
2272 ;; We are always BITS_BIG_ENDIAN, so the (const_int 16) below is
2273 ;; correct for -mlittle as well as -mbig.
2274 (define_split
2275   [(set (match_operand:HI 0 "gpc_reg_operand" "")
2276         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
2277    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2278   "reload_completed"
2279   [(set (match_dup 3)
2280         (zero_extract:SI (match_dup 4)
2281                          (const_int 8)
2282                          (const_int 16)))
2283    (set (match_dup 2)
2284         (and:SI (ashift:SI (match_dup 4)
2285                            (const_int 8))
2286                 (const_int 65280)))             ;; 0xff00
2287    (set (match_dup 3)
2288         (ior:SI (match_dup 3)
2289                 (match_dup 2)))]
2290   "
2291 {
2292   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2293   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2294 }")
2295
2296 (define_insn "*bswapsi2_extenddi"
2297   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2298         (zero_extend:DI
2299          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2300   "TARGET_POWERPC64"
2301   "lwbrx %0,%y1"
2302   [(set_attr "length" "4")
2303    (set_attr "type" "load")])
2304
2305 (define_expand "bswapsi2"
2306   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2307         (bswap:SI
2308          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2309   ""
2310 {
2311   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2312     operands[1] = force_reg (SImode, operands[1]);
2313 })
2314
2315 (define_insn "*bswapsi2_internal"
2316   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2317         (bswap:SI
2318          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2319   ""
2320   "@
2321    lwbrx %0,%y1
2322    stwbrx %1,%y0
2323    #"
2324   [(set_attr "length" "4,4,12")
2325    (set_attr "type" "load,store,*")])
2326
2327 ;; We are always BITS_BIG_ENDIAN, so the bit positions below in
2328 ;; zero_extract insns do not change for -mlittle.
2329 (define_split
2330   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2331         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2332   "reload_completed"
2333   [(set (match_dup 0)
2334         (rotate:SI (match_dup 1) (const_int 8)))
2335    (set (zero_extract:SI (match_dup 0)
2336                          (const_int 8)
2337                          (const_int 0))
2338         (match_dup 1))
2339    (set (zero_extract:SI (match_dup 0)
2340                          (const_int 8)
2341                          (const_int 16))
2342         (rotate:SI (match_dup 1)
2343                    (const_int 16)))]
2344   "")
2345
2346 (define_expand "bswapdi2"
2347   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2348                    (bswap:DI
2349                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2350               (clobber (match_scratch:DI 2 ""))
2351               (clobber (match_scratch:DI 3 ""))
2352               (clobber (match_scratch:DI 4 ""))])]
2353   ""
2354 {
2355   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2356     operands[1] = force_reg (DImode, operands[1]);
2357
2358   if (!TARGET_POWERPC64)
2359     {
2360       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2361          that uses 64-bit registers needs the same scratch registers as 64-bit
2362          mode.  */
2363       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2364       DONE;
2365     }
2366 })
2367
2368 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2369 (define_insn "*bswapdi2_ldbrx"
2370   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2371         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2372    (clobber (match_scratch:DI 2 "=X,X,&r"))
2373    (clobber (match_scratch:DI 3 "=X,X,&r"))
2374    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2375   "TARGET_POWERPC64 && TARGET_LDBRX
2376    && (REG_P (operands[0]) || REG_P (operands[1]))"
2377   "@
2378    ldbrx %0,%y1
2379    stdbrx %1,%y0
2380    #"
2381   [(set_attr "length" "4,4,36")
2382    (set_attr "type" "load,store,*")])
2383
2384 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2385 (define_insn "*bswapdi2_64bit"
2386   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,&r")
2387         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2388    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2389    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2390    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2391   "TARGET_POWERPC64 && !TARGET_LDBRX
2392    && (REG_P (operands[0]) || REG_P (operands[1]))
2393    && !(MEM_P (operands[0]) && MEM_VOLATILE_P (operands[0]))
2394    && !(MEM_P (operands[1]) && MEM_VOLATILE_P (operands[1]))"
2395   "#"
2396   [(set_attr "length" "16,12,36")])
2397
2398 (define_split
2399   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2400         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2401    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2402    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2403    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2404   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2405   [(const_int 0)]
2406   "
2407 {
2408   rtx dest   = operands[0];
2409   rtx src    = operands[1];
2410   rtx op2    = operands[2];
2411   rtx op3    = operands[3];
2412   rtx op4    = operands[4];
2413   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode,
2414                                     BYTES_BIG_ENDIAN ? 4 : 0);
2415   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode,
2416                                     BYTES_BIG_ENDIAN ? 4 : 0);
2417   rtx addr1;
2418   rtx addr2;
2419   rtx word_high;
2420   rtx word_low;
2421
2422   addr1 = XEXP (src, 0);
2423   if (GET_CODE (addr1) == PLUS)
2424     {
2425       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2426       if (TARGET_AVOID_XFORM)
2427         {
2428           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2429           addr2 = op2;
2430         }
2431       else
2432         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2433     }
2434   else if (TARGET_AVOID_XFORM)
2435     {
2436       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2437       addr2 = op2;
2438     }
2439   else
2440     {
2441       emit_move_insn (op2, GEN_INT (4));
2442       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2443     }
2444
2445   if (BYTES_BIG_ENDIAN)
2446     {
2447       word_high = change_address (src, SImode, addr1);
2448       word_low  = change_address (src, SImode, addr2);
2449     }
2450   else
2451     {
2452       word_high = change_address (src, SImode, addr2);
2453       word_low  = change_address (src, SImode, addr1);
2454     }
2455
2456   emit_insn (gen_bswapsi2 (op3_32, word_low));
2457   emit_insn (gen_bswapsi2 (op4_32, word_high));
2458   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2459   emit_insn (gen_iordi3 (dest, dest, op4));
2460 }")
2461
2462 (define_split
2463   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2464         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2465    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2466    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2467    (clobber (match_operand:DI 4 "" ""))]
2468   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2469   [(const_int 0)]
2470   "
2471 {
2472   rtx dest   = operands[0];
2473   rtx src    = operands[1];
2474   rtx op2    = operands[2];
2475   rtx op3    = operands[3];
2476   rtx src_si = simplify_gen_subreg (SImode, src, DImode,
2477                                     BYTES_BIG_ENDIAN ? 4 : 0);
2478   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode,
2479                                     BYTES_BIG_ENDIAN ? 4 : 0);
2480   rtx addr1;
2481   rtx addr2;
2482   rtx word_high;
2483   rtx word_low;
2484
2485   addr1 = XEXP (dest, 0);
2486   if (GET_CODE (addr1) == PLUS)
2487     {
2488       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2489       if (TARGET_AVOID_XFORM)
2490         {
2491           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2492           addr2 = op2;
2493         }
2494       else
2495         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2496     }
2497   else if (TARGET_AVOID_XFORM)
2498     {
2499       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2500       addr2 = op2;
2501     }
2502   else
2503     {
2504       emit_move_insn (op2, GEN_INT (4));
2505       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2506     }
2507
2508   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2509   if (BYTES_BIG_ENDIAN)
2510     {
2511       word_high = change_address (dest, SImode, addr1);
2512       word_low  = change_address (dest, SImode, addr2);
2513     }
2514   else
2515     {
2516       word_high = change_address (dest, SImode, addr2);
2517       word_low  = change_address (dest, SImode, addr1);
2518     }
2519   emit_insn (gen_bswapsi2 (word_high, src_si));
2520   emit_insn (gen_bswapsi2 (word_low, op3_si));
2521 }")
2522
2523 (define_split
2524   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2525         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2526    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2527    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2528    (clobber (match_operand:DI 4 "" ""))]
2529   "TARGET_POWERPC64 && reload_completed"
2530   [(const_int 0)]
2531   "
2532 {
2533   rtx dest    = operands[0];
2534   rtx src     = operands[1];
2535   rtx op2     = operands[2];
2536   rtx op3     = operands[3];
2537   int lo_off  = BYTES_BIG_ENDIAN ? 4 : 0;
2538   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, lo_off);
2539   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, lo_off);
2540   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, lo_off);
2541   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, lo_off);
2542
2543   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2544   emit_insn (gen_bswapsi2 (dest_si, src_si));
2545   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2546   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2547   emit_insn (gen_iordi3 (dest, dest, op3));
2548 }")
2549
2550 (define_insn "bswapdi2_32bit"
2551   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,&r")
2552         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2553    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2554   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2555   "#"
2556   [(set_attr "length" "16,12,36")])
2557
2558 (define_split
2559   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2560         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2561    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2562   "!TARGET_POWERPC64 && reload_completed"
2563   [(const_int 0)]
2564   "
2565 {
2566   rtx dest  = operands[0];
2567   rtx src   = operands[1];
2568   rtx op2   = operands[2];
2569   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2570   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2571   rtx addr1;
2572   rtx addr2;
2573   rtx word1;
2574   rtx word2;
2575
2576   addr1 = XEXP (src, 0);
2577   if (GET_CODE (addr1) == PLUS)
2578     {
2579       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2580       if (TARGET_AVOID_XFORM)
2581         {
2582           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2583           addr2 = op2;
2584         }
2585       else
2586         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2587     }
2588   else if (TARGET_AVOID_XFORM)
2589     {
2590       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2591       addr2 = op2;
2592     }
2593   else
2594     {
2595       emit_move_insn (op2, GEN_INT (4));
2596       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2597     }
2598
2599   word1 = change_address (src, SImode, addr1);
2600   word2 = change_address (src, SImode, addr2);
2601
2602   emit_insn (gen_bswapsi2 (dest2, word1));
2603   emit_insn (gen_bswapsi2 (dest1, word2));
2604 }")
2605
2606 (define_split
2607   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2608         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2609    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2610   "!TARGET_POWERPC64 && reload_completed"
2611   [(const_int 0)]
2612   "
2613 {
2614   rtx dest = operands[0];
2615   rtx src  = operands[1];
2616   rtx op2  = operands[2];
2617   rtx src1 = simplify_gen_subreg (SImode, src, DImode, 0);
2618   rtx src2 = simplify_gen_subreg (SImode, src, DImode, 4);
2619   rtx addr1;
2620   rtx addr2;
2621   rtx word1;
2622   rtx word2;
2623
2624   addr1 = XEXP (dest, 0);
2625   if (GET_CODE (addr1) == PLUS)
2626     {
2627       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2628       if (TARGET_AVOID_XFORM)
2629         {
2630           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2631           addr2 = op2;
2632         }
2633       else
2634         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2635     }
2636   else if (TARGET_AVOID_XFORM)
2637     {
2638       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2639       addr2 = op2;
2640     }
2641   else
2642     {
2643       emit_move_insn (op2, GEN_INT (4));
2644       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2645     }
2646
2647   word1 = change_address (dest, SImode, addr1);
2648   word2 = change_address (dest, SImode, addr2);
2649
2650   emit_insn (gen_bswapsi2 (word2, src1));
2651   emit_insn (gen_bswapsi2 (word1, src2));
2652 }")
2653
2654 (define_split
2655   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2656         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2657    (clobber (match_operand:SI 2 "" ""))]
2658   "!TARGET_POWERPC64 && reload_completed"
2659   [(const_int 0)]
2660   "
2661 {
2662   rtx dest  = operands[0];
2663   rtx src   = operands[1];
2664   rtx src1  = simplify_gen_subreg (SImode, src, DImode, 0);
2665   rtx src2  = simplify_gen_subreg (SImode, src, DImode, 4);
2666   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2667   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2668
2669   emit_insn (gen_bswapsi2 (dest1, src2));
2670   emit_insn (gen_bswapsi2 (dest2, src1));
2671 }")
2672
2673 (define_insn "mulsi3"
2674   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2675         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2676                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2677   ""
2678   "@
2679    mullw %0,%1,%2
2680    mulli %0,%1,%2"
2681    [(set_attr "type" "mul")
2682     (set (attr "size")
2683       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2684                 (const_string "8")
2685              (match_operand:SI 2 "short_cint_operand" "")
2686                 (const_string "16")]
2687         (const_string "32")))])
2688
2689 (define_insn "*mulsi3_internal1"
2690   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2691         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2692                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2693                     (const_int 0)))
2694    (clobber (match_scratch:SI 3 "=r,r"))]
2695   "TARGET_32BIT"
2696   "@
2697    mullw. %3,%1,%2
2698    #"
2699   [(set_attr "type" "mul")
2700    (set_attr "dot" "yes")
2701    (set_attr "length" "4,8")])
2702
2703 (define_split
2704   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2705         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2706                              (match_operand:SI 2 "gpc_reg_operand" ""))
2707                     (const_int 0)))
2708    (clobber (match_scratch:SI 3 ""))]
2709   "TARGET_32BIT && reload_completed"
2710   [(set (match_dup 3)
2711         (mult:SI (match_dup 1) (match_dup 2)))
2712    (set (match_dup 0)
2713         (compare:CC (match_dup 3)
2714                     (const_int 0)))]
2715   "")
2716
2717 (define_insn "*mulsi3_internal2"
2718   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2719         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2720                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2721                     (const_int 0)))
2722    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2723         (mult:SI (match_dup 1) (match_dup 2)))]
2724   "TARGET_32BIT"
2725   "@
2726    mullw. %0,%1,%2
2727    #"
2728   [(set_attr "type" "mul")
2729    (set_attr "dot" "yes")
2730    (set_attr "length" "4,8")])
2731
2732 (define_split
2733   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2734         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2735                              (match_operand:SI 2 "gpc_reg_operand" ""))
2736                     (const_int 0)))
2737    (set (match_operand:SI 0 "gpc_reg_operand" "")
2738         (mult:SI (match_dup 1) (match_dup 2)))]
2739   "TARGET_32BIT && reload_completed"
2740   [(set (match_dup 0)
2741         (mult:SI (match_dup 1) (match_dup 2)))
2742    (set (match_dup 3)
2743         (compare:CC (match_dup 0)
2744                     (const_int 0)))]
2745   "")
2746
2747
2748 (define_insn "udiv<mode>3"
2749   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2750         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2751                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2752   ""
2753   "div<wd>u %0,%1,%2"
2754   [(set_attr "type" "div")
2755    (set_attr "size" "<bits>")])
2756
2757
2758 ;; For powers of two we can do srai/aze for divide and then adjust for
2759 ;; modulus.  If it isn't a power of two, force operands into register and do
2760 ;; a normal divide.
2761 (define_expand "div<mode>3"
2762   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2763         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2764                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2765   ""
2766 {
2767   if (GET_CODE (operands[2]) != CONST_INT
2768       || INTVAL (operands[2]) <= 0
2769       || exact_log2 (INTVAL (operands[2])) < 0)
2770     operands[2] = force_reg (<MODE>mode, operands[2]);
2771 })
2772
2773 (define_insn "*div<mode>3"
2774   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2775         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2776                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2777   ""
2778   "div<wd> %0,%1,%2"
2779   [(set_attr "type" "div")
2780    (set_attr "size" "<bits>")])
2781
2782 (define_expand "mod<mode>3"
2783   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2784    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2785    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2786   ""
2787   "
2788 {
2789   int i;
2790   rtx temp1;
2791   rtx temp2;
2792
2793   if (GET_CODE (operands[2]) != CONST_INT
2794       || INTVAL (operands[2]) <= 0
2795       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2796     FAIL;
2797
2798   temp1 = gen_reg_rtx (<MODE>mode);
2799   temp2 = gen_reg_rtx (<MODE>mode);
2800
2801   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2802   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2803   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2804   DONE;
2805 }")
2806
2807 (define_insn ""
2808   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2809         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2810                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2811   ""
2812   "sra<wd>i %0,%1,%p2\;addze %0,%0"
2813   [(set_attr "type" "two")
2814    (set_attr "length" "8")])
2815
2816 (define_insn ""
2817   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2818         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2819                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2820                     (const_int 0)))
2821    (clobber (match_scratch:P 3 "=r,r"))]
2822   ""
2823   "@
2824    sra<wd>i %3,%1,%p2\;addze. %3,%3
2825    #"
2826   [(set_attr "type" "compare")
2827    (set_attr "length" "8,12")
2828    (set_attr "cell_micro" "not")])
2829
2830 (define_split
2831   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2832         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2833                              (match_operand:GPR 2 "exact_log2_cint_operand"
2834                               ""))
2835                     (const_int 0)))
2836    (clobber (match_scratch:GPR 3 ""))]
2837   "reload_completed"
2838   [(set (match_dup 3)
2839         (div:<MODE> (match_dup 1) (match_dup 2)))
2840    (set (match_dup 0)
2841         (compare:CC (match_dup 3)
2842                     (const_int 0)))]
2843   "")
2844
2845 (define_insn ""
2846   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2847         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2848                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2849                     (const_int 0)))
2850    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2851         (div:P (match_dup 1) (match_dup 2)))]
2852   ""
2853   "@
2854    sra<wd>i %0,%1,%p2\;addze. %0,%0
2855    #"
2856   [(set_attr "type" "compare")
2857    (set_attr "length" "8,12")
2858    (set_attr "cell_micro" "not")])
2859
2860 (define_split
2861   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2862         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2863                              (match_operand:GPR 2 "exact_log2_cint_operand"
2864                               ""))
2865                     (const_int 0)))
2866    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2867         (div:GPR (match_dup 1) (match_dup 2)))]
2868   "reload_completed"
2869   [(set (match_dup 0)
2870         (div:<MODE> (match_dup 1) (match_dup 2)))
2871    (set (match_dup 3)
2872         (compare:CC (match_dup 0)
2873                     (const_int 0)))]
2874   "")
2875 \f
2876 ;; Logical instructions
2877 ;; The logical instructions are mostly combined by using match_operator,
2878 ;; but the plain AND insns are somewhat different because there is no
2879 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2880 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2881
2882 (define_expand "andsi3"
2883   [(parallel
2884     [(set (match_operand:SI 0 "gpc_reg_operand" "")
2885           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2886                   (match_operand:SI 2 "and_operand" "")))
2887      (clobber (match_scratch:CC 3 ""))])]
2888   ""
2889   "")
2890
2891 (define_insn "andsi3_mc"
2892   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2893         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2894                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2895    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2896   "rs6000_gen_cell_microcode"
2897   "@
2898    and %0,%1,%2
2899    rlwinm %0,%1,0,%m2,%M2
2900    andi. %0,%1,%b2
2901    andis. %0,%1,%u2"
2902   [(set_attr "type" "*,*,fast_compare,fast_compare")])
2903
2904 (define_insn "andsi3_nomc"
2905   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2906         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2907                 (match_operand:SI 2 "and_operand" "?r,T")))
2908    (clobber (match_scratch:CC 3 "=X,X"))]
2909   "!rs6000_gen_cell_microcode"
2910   "@
2911    and %0,%1,%2
2912    rlwinm %0,%1,0,%m2,%M2")
2913
2914 (define_insn "andsi3_internal0_nomc"
2915   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2916         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2917                 (match_operand:SI 2 "and_operand" "?r,T")))]
2918   "!rs6000_gen_cell_microcode"
2919   "@
2920    and %0,%1,%2
2921    rlwinm %0,%1,0,%m2,%M2")
2922
2923
2924 ;; Note to set cr's other than cr0 we do the and immediate and then
2925 ;; the test again -- this avoids a mfcr which on the higher end
2926 ;; machines causes an execution serialization
2927
2928 (define_insn "*andsi3_internal2_mc"
2929   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2930         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2931                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2932                     (const_int 0)))
2933    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2934    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2935   "TARGET_32BIT && rs6000_gen_cell_microcode"
2936   "@
2937    and. %3,%1,%2
2938    andi. %3,%1,%b2
2939    andis. %3,%1,%u2
2940    rlwinm. %3,%1,0,%m2,%M2
2941    #
2942    #
2943    #
2944    #"
2945   [(set_attr "type" "fast_compare,fast_compare,fast_compare,shift,\
2946                      compare,compare,compare,compare")
2947    (set_attr "dot" "yes")
2948    (set_attr "length" "4,4,4,4,8,8,8,8")])
2949
2950 (define_insn "*andsi3_internal3_mc"
2951   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2952         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2953                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2954                     (const_int 0)))
2955    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2956    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2957   "TARGET_64BIT && rs6000_gen_cell_microcode"
2958   "@
2959    #
2960    andi. %3,%1,%b2
2961    andis. %3,%1,%u2
2962    rlwinm. %3,%1,0,%m2,%M2
2963    #
2964    #
2965    #
2966    #"
2967   [(set_attr "type" "compare,fast_compare,fast_compare,shift,compare,\
2968                      compare,compare,compare")
2969    (set_attr "dot" "yes")
2970    (set_attr "length" "8,4,4,4,8,8,8,8")])
2971
2972 (define_split
2973   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2974         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2975                              (match_operand:GPR 2 "and_operand" ""))
2976                     (const_int 0)))
2977    (clobber (match_scratch:GPR 3 ""))
2978    (clobber (match_scratch:CC 4 ""))]
2979   "reload_completed"
2980   [(parallel [(set (match_dup 3)
2981                    (and:<MODE> (match_dup 1)
2982                                (match_dup 2)))
2983               (clobber (match_dup 4))])
2984    (set (match_dup 0)
2985         (compare:CC (match_dup 3)
2986                     (const_int 0)))]
2987   "")
2988
2989 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2990 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2991
2992 (define_split
2993   [(set (match_operand:CC 0 "cc_reg_operand" "")
2994         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2995                             (match_operand:SI 2 "gpc_reg_operand" ""))
2996                     (const_int 0)))
2997    (clobber (match_scratch:SI 3 ""))
2998    (clobber (match_scratch:CC 4 ""))]
2999   "TARGET_POWERPC64 && reload_completed"
3000   [(parallel [(set (match_dup 3)
3001                    (and:SI (match_dup 1)
3002                            (match_dup 2)))
3003               (clobber (match_dup 4))])
3004    (set (match_dup 0)
3005         (compare:CC (match_dup 3)
3006                     (const_int 0)))]
3007   "")
3008
3009 (define_insn "*andsi3_internal4"
3010   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3011         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3012                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3013                     (const_int 0)))
3014    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3015         (and:SI (match_dup 1)
3016                 (match_dup 2)))
3017    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3018   "TARGET_32BIT && rs6000_gen_cell_microcode"
3019   "@
3020    and. %0,%1,%2
3021    andi. %0,%1,%b2
3022    andis. %0,%1,%u2
3023    rlwinm. %0,%1,0,%m2,%M2
3024    #
3025    #
3026    #
3027    #"
3028   [(set_attr "type" "fast_compare,fast_compare,fast_compare,shift,\
3029                      compare,compare,compare,compare")
3030    (set_attr "dot" "yes")
3031    (set_attr "length" "4,4,4,4,8,8,8,8")])
3032
3033 (define_insn "*andsi3_internal5_mc"
3034   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3035         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3036                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3037                     (const_int 0)))
3038    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3039         (and:SI (match_dup 1)
3040                 (match_dup 2)))
3041    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3042   "TARGET_64BIT && rs6000_gen_cell_microcode"
3043   "@
3044    #
3045    andi. %0,%1,%b2
3046    andis. %0,%1,%u2
3047    rlwinm. %0,%1,0,%m2,%M2
3048    #
3049    #
3050    #
3051    #"
3052   [(set_attr "type" "compare,fast_compare,fast_compare,shift,compare,\
3053                      compare,compare,compare")
3054    (set_attr "dot" "yes")
3055    (set_attr "length" "8,4,4,4,8,8,8,8")])
3056
3057 (define_split
3058   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3059         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3060                             (match_operand:SI 2 "and_operand" ""))
3061                     (const_int 0)))
3062    (set (match_operand:SI 0 "gpc_reg_operand" "")
3063         (and:SI (match_dup 1)
3064                 (match_dup 2)))
3065    (clobber (match_scratch:CC 4 ""))]
3066   "reload_completed"
3067   [(parallel [(set (match_dup 0)
3068                    (and:SI (match_dup 1)
3069                            (match_dup 2)))
3070               (clobber (match_dup 4))])
3071    (set (match_dup 3)
3072         (compare:CC (match_dup 0)
3073                     (const_int 0)))]
3074   "")
3075
3076 (define_split
3077   [(set (match_operand:CC 3 "cc_reg_operand" "")
3078         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3079                             (match_operand:SI 2 "gpc_reg_operand" ""))
3080                     (const_int 0)))
3081    (set (match_operand:SI 0 "gpc_reg_operand" "")
3082         (and:SI (match_dup 1)
3083                 (match_dup 2)))
3084    (clobber (match_scratch:CC 4 ""))]
3085   "TARGET_POWERPC64 && reload_completed"
3086   [(parallel [(set (match_dup 0)
3087                    (and:SI (match_dup 1)
3088                            (match_dup 2)))
3089               (clobber (match_dup 4))])
3090    (set (match_dup 3)
3091         (compare:CC (match_dup 0)
3092                     (const_int 0)))]
3093   "")
3094
3095 ;; Handle the PowerPC64 rlwinm corner case
3096
3097 (define_insn_and_split "*andsi3_internal6"
3098   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3099         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3100                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3101   "TARGET_POWERPC64"
3102   "#"
3103   "TARGET_POWERPC64"
3104   [(set (match_dup 0)
3105         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3106                 (match_dup 4)))
3107    (set (match_dup 0)
3108         (rotate:SI (match_dup 0) (match_dup 5)))]
3109   "
3110 {
3111   int mb = extract_MB (operands[2]);
3112   int me = extract_ME (operands[2]);
3113   operands[3] = GEN_INT (me + 1);
3114   operands[5] = GEN_INT (32 - (me + 1));
3115   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3116 }"
3117   [(set_attr "length" "8")])
3118
3119 (define_expand "iorsi3"
3120   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3121         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3122                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3123   ""
3124   "
3125 {
3126   if (GET_CODE (operands[2]) == CONST_INT
3127       && ! logical_operand (operands[2], SImode))
3128     {
3129       HOST_WIDE_INT value = INTVAL (operands[2]);
3130       rtx tmp = ((!can_create_pseudo_p ()
3131                   || rtx_equal_p (operands[0], operands[1]))
3132                  ? operands[0] : gen_reg_rtx (SImode));
3133
3134       emit_insn (gen_iorsi3 (tmp, operands[1],
3135                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3136       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3137       DONE;
3138     }
3139 }")
3140
3141 (define_expand "xorsi3"
3142   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3143         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3144                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3145   ""
3146   "
3147 {
3148   if (GET_CODE (operands[2]) == CONST_INT
3149       && ! logical_operand (operands[2], SImode))
3150     {
3151       HOST_WIDE_INT value = INTVAL (operands[2]);
3152       rtx tmp = ((!can_create_pseudo_p ()
3153                   || rtx_equal_p (operands[0], operands[1]))
3154                  ? operands[0] : gen_reg_rtx (SImode));
3155
3156       emit_insn (gen_xorsi3 (tmp, operands[1],
3157                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3158       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3159       DONE;
3160     }
3161 }")
3162
3163 (define_insn "*boolsi3_internal1"
3164   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3165         (match_operator:SI 3 "boolean_or_operator"
3166          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3167           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3168   ""
3169   "@
3170    %q3 %0,%1,%2
3171    %q3i %0,%1,%b2
3172    %q3is %0,%1,%u2")
3173
3174 (define_insn "*boolsi3_internal2"
3175   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3176         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3177          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3178           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3179          (const_int 0)))
3180    (clobber (match_scratch:SI 3 "=r,r"))]
3181   "TARGET_32BIT"
3182   "@
3183    %q4. %3,%1,%2
3184    #"
3185   [(set_attr "type" "fast_compare,compare")
3186    (set_attr "length" "4,8")])
3187
3188 (define_split
3189   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3190         (compare:CC (match_operator:SI 4 "boolean_operator"
3191          [(match_operand:SI 1 "gpc_reg_operand" "")
3192           (match_operand:SI 2 "gpc_reg_operand" "")])
3193          (const_int 0)))
3194    (clobber (match_scratch:SI 3 ""))]
3195   "TARGET_32BIT && reload_completed"
3196   [(set (match_dup 3) (match_dup 4))
3197    (set (match_dup 0)
3198         (compare:CC (match_dup 3)
3199                     (const_int 0)))]
3200   "")
3201
3202 (define_insn "*boolsi3_internal3"
3203   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3204         (compare:CC (match_operator:SI 4 "boolean_operator"
3205          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3206           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3207          (const_int 0)))
3208    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3209         (match_dup 4))]
3210   "TARGET_32BIT"
3211   "@
3212    %q4. %0,%1,%2
3213    #"
3214   [(set_attr "type" "fast_compare,compare")
3215    (set_attr "length" "4,8")])
3216
3217 (define_split
3218   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3219         (compare:CC (match_operator:SI 4 "boolean_operator"
3220          [(match_operand:SI 1 "gpc_reg_operand" "")
3221           (match_operand:SI 2 "gpc_reg_operand" "")])
3222          (const_int 0)))
3223    (set (match_operand:SI 0 "gpc_reg_operand" "")
3224         (match_dup 4))]
3225   "TARGET_32BIT && reload_completed"
3226   [(set (match_dup 0) (match_dup 4))
3227    (set (match_dup 3)
3228         (compare:CC (match_dup 0)
3229                     (const_int 0)))]
3230   "")
3231
3232 ;; Split a logical operation that we can't do in one insn into two insns,
3233 ;; each of which does one 16-bit part.  This is used by combine.
3234
3235 (define_split
3236   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3237         (match_operator:SI 3 "boolean_or_operator"
3238          [(match_operand:SI 1 "gpc_reg_operand" "")
3239           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3240   ""
3241   [(set (match_dup 0) (match_dup 4))
3242    (set (match_dup 0) (match_dup 5))]
3243 "
3244 {
3245   rtx i;
3246   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3247   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3248                                 operands[1], i);
3249   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3250   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3251                                 operands[0], i);
3252 }")
3253
3254 (define_insn "*boolcsi3_internal1"
3255   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3256         (match_operator:SI 3 "boolean_operator"
3257          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3258           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3259   ""
3260   "%q3 %0,%2,%1")
3261
3262 (define_insn "*boolcsi3_internal2"
3263   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3264         (compare:CC (match_operator:SI 4 "boolean_operator"
3265          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3266           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3267          (const_int 0)))
3268    (clobber (match_scratch:SI 3 "=r,r"))]
3269   "TARGET_32BIT"
3270   "@
3271    %q4. %3,%2,%1
3272    #"
3273   [(set_attr "type" "compare")
3274    (set_attr "length" "4,8")])
3275
3276 (define_split
3277   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3278         (compare:CC (match_operator:SI 4 "boolean_operator"
3279          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3280           (match_operand:SI 2 "gpc_reg_operand" "")])
3281          (const_int 0)))
3282    (clobber (match_scratch:SI 3 ""))]
3283   "TARGET_32BIT && reload_completed"
3284   [(set (match_dup 3) (match_dup 4))
3285    (set (match_dup 0)
3286         (compare:CC (match_dup 3)
3287                     (const_int 0)))]
3288   "")
3289
3290 (define_insn "*boolcsi3_internal3"
3291   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3292         (compare:CC (match_operator:SI 4 "boolean_operator"
3293          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3294           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3295          (const_int 0)))
3296    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3297         (match_dup 4))]
3298   "TARGET_32BIT"
3299   "@
3300    %q4. %0,%2,%1
3301    #"
3302   [(set_attr "type" "compare")
3303    (set_attr "length" "4,8")])
3304
3305 (define_split
3306   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3307         (compare:CC (match_operator:SI 4 "boolean_operator"
3308          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3309           (match_operand:SI 2 "gpc_reg_operand" "")])
3310          (const_int 0)))
3311    (set (match_operand:SI 0 "gpc_reg_operand" "")
3312         (match_dup 4))]
3313   "TARGET_32BIT && reload_completed"
3314   [(set (match_dup 0) (match_dup 4))
3315    (set (match_dup 3)
3316         (compare:CC (match_dup 0)
3317                     (const_int 0)))]
3318   "")
3319
3320 (define_insn "*boolccsi3_internal1"
3321   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3322         (match_operator:SI 3 "boolean_operator"
3323          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3324           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3325   ""
3326   "%q3 %0,%1,%2")
3327
3328 (define_insn "*boolccsi3_internal2"
3329   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3330         (compare:CC (match_operator:SI 4 "boolean_operator"
3331          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3332           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3333          (const_int 0)))
3334    (clobber (match_scratch:SI 3 "=r,r"))]
3335   "TARGET_32BIT"
3336   "@
3337    %q4. %3,%1,%2
3338    #"
3339   [(set_attr "type" "fast_compare,compare")
3340    (set_attr "length" "4,8")])
3341
3342 (define_split
3343   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3344         (compare:CC (match_operator:SI 4 "boolean_operator"
3345          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3346           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3347          (const_int 0)))
3348    (clobber (match_scratch:SI 3 ""))]
3349   "TARGET_32BIT && reload_completed"
3350   [(set (match_dup 3) (match_dup 4))
3351    (set (match_dup 0)
3352         (compare:CC (match_dup 3)
3353                     (const_int 0)))]
3354   "")
3355
3356 (define_insn "*boolccsi3_internal3"
3357   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3358         (compare:CC (match_operator:SI 4 "boolean_operator"
3359          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3360           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3361          (const_int 0)))
3362    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3363         (match_dup 4))]
3364   "TARGET_32BIT"
3365   "@
3366    %q4. %0,%1,%2
3367    #"
3368   [(set_attr "type" "fast_compare,compare")
3369    (set_attr "length" "4,8")])
3370
3371 (define_split
3372   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3373         (compare:CC (match_operator:SI 4 "boolean_operator"
3374          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3375           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3376          (const_int 0)))
3377    (set (match_operand:SI 0 "gpc_reg_operand" "")
3378         (match_dup 4))]
3379   "TARGET_32BIT && reload_completed"
3380   [(set (match_dup 0) (match_dup 4))
3381    (set (match_dup 3)
3382         (compare:CC (match_dup 0)
3383                     (const_int 0)))]
3384   "")
3385 \f
3386 ;; Rotate and shift insns, in all their variants.  These support shifts,
3387 ;; field inserts and extracts, and various combinations thereof.
3388 (define_expand "insv"
3389   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3390                        (match_operand:SI 1 "const_int_operand" "")
3391                        (match_operand:SI 2 "const_int_operand" ""))
3392         (match_operand 3 "gpc_reg_operand" ""))]
3393   ""
3394   "
3395 {
3396   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3397      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3398      compiler if the address of the structure is taken later.  Likewise, do
3399      not handle invalid E500 subregs.  */
3400   if (GET_CODE (operands[0]) == SUBREG
3401       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3402           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3403               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3404     FAIL;
3405
3406   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3407     emit_insn (gen_insvdi_internal (operands[0], operands[1], operands[2],
3408                                     operands[3]));
3409   else
3410     emit_insn (gen_insvsi_internal (operands[0], operands[1], operands[2],
3411                                     operands[3]));
3412   DONE;
3413 }")
3414
3415 (define_insn "insvsi_internal"
3416   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3417                          (match_operand:SI 1 "const_int_operand" "i")
3418                          (match_operand:SI 2 "const_int_operand" "i"))
3419         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3420   ""
3421   "*
3422 {
3423   int start = INTVAL (operands[2]) & 31;
3424   int size = INTVAL (operands[1]) & 31;
3425
3426   operands[4] = GEN_INT (32 - start - size);
3427   operands[1] = GEN_INT (start + size - 1);
3428   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3429 }"
3430   [(set_attr "type" "insert")])
3431
3432 (define_insn "*insvsi_internal1"
3433   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3434                          (match_operand:SI 1 "const_int_operand" "i")
3435                          (match_operand:SI 2 "const_int_operand" "i"))
3436         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3437                    (match_operand:SI 4 "const_int_operand" "i")))]
3438   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3439   "*
3440 {
3441   int shift = INTVAL (operands[4]) & 31;
3442   int start = INTVAL (operands[2]) & 31;
3443   int size = INTVAL (operands[1]) & 31;
3444
3445   operands[4] = GEN_INT (shift - start - size);
3446   operands[1] = GEN_INT (start + size - 1);
3447   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3448 }"
3449   [(set_attr "type" "insert")])
3450
3451 (define_insn "*insvsi_internal2"
3452   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3453                          (match_operand:SI 1 "const_int_operand" "i")
3454                          (match_operand:SI 2 "const_int_operand" "i"))
3455         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3456                      (match_operand:SI 4 "const_int_operand" "i")))]
3457   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3458   "*
3459 {
3460   int shift = INTVAL (operands[4]) & 31;
3461   int start = INTVAL (operands[2]) & 31;
3462   int size = INTVAL (operands[1]) & 31;
3463
3464   operands[4] = GEN_INT (32 - shift - start - size);
3465   operands[1] = GEN_INT (start + size - 1);
3466   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3467 }"
3468   [(set_attr "type" "insert")])
3469
3470 (define_insn "*insvsi_internal3"
3471   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3472                          (match_operand:SI 1 "const_int_operand" "i")
3473                          (match_operand:SI 2 "const_int_operand" "i"))
3474         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3475                      (match_operand:SI 4 "const_int_operand" "i")))]
3476   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3477   "*
3478 {
3479   int shift = INTVAL (operands[4]) & 31;
3480   int start = INTVAL (operands[2]) & 31;
3481   int size = INTVAL (operands[1]) & 31;
3482
3483   operands[4] = GEN_INT (32 - shift - start - size);
3484   operands[1] = GEN_INT (start + size - 1);
3485   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3486 }"
3487   [(set_attr "type" "insert")])
3488
3489 (define_insn "*insvsi_internal4"
3490   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3491                          (match_operand:SI 1 "const_int_operand" "i")
3492                          (match_operand:SI 2 "const_int_operand" "i"))
3493         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3494                          (match_operand:SI 4 "const_int_operand" "i")
3495                          (match_operand:SI 5 "const_int_operand" "i")))]
3496   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3497   "*
3498 {
3499   int extract_start = INTVAL (operands[5]) & 31;
3500   int extract_size = INTVAL (operands[4]) & 31;
3501   int insert_start = INTVAL (operands[2]) & 31;
3502   int insert_size = INTVAL (operands[1]) & 31;
3503
3504 /* Align extract field with insert field */
3505   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3506   operands[1] = GEN_INT (insert_start + insert_size - 1);
3507   return \"rlwimi %0,%3,%h5,%h2,%h1\";
3508 }"
3509   [(set_attr "type" "insert")])
3510
3511 ;; combine patterns for rlwimi
3512 (define_insn "*insvsi_internal5"
3513   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3514         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3515                         (match_operand:SI 1 "mask_operand" "i"))
3516                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3517                                      (match_operand:SI 2 "const_int_operand" "i"))
3518                         (match_operand:SI 5 "mask_operand" "i"))))]
3519   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3520   "*
3521 {
3522  int me = extract_ME(operands[5]);
3523  int mb = extract_MB(operands[5]);
3524  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3525  operands[2] = GEN_INT(mb);
3526  operands[1] = GEN_INT(me);
3527  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3528 }"
3529   [(set_attr "type" "insert")])
3530
3531 (define_insn "*insvsi_internal6"
3532   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3533         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3534                                      (match_operand:SI 2 "const_int_operand" "i"))
3535                         (match_operand:SI 5 "mask_operand" "i"))
3536                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3537                         (match_operand:SI 1 "mask_operand" "i"))))]
3538   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3539   "*
3540 {
3541  int me = extract_ME(operands[5]);
3542  int mb = extract_MB(operands[5]);
3543  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3544  operands[2] = GEN_INT(mb);
3545  operands[1] = GEN_INT(me);
3546  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3547 }"
3548   [(set_attr "type" "insert")])
3549
3550 (define_insn "insvdi_internal"
3551   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3552                          (match_operand:SI 1 "const_int_operand" "i")
3553                          (match_operand:SI 2 "const_int_operand" "i"))
3554         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3555   "TARGET_POWERPC64"
3556   "*
3557 {
3558   int start = INTVAL (operands[2]) & 63;
3559   int size = INTVAL (operands[1]) & 63;
3560
3561   operands[1] = GEN_INT (64 - start - size);
3562   return \"rldimi %0,%3,%H1,%H2\";
3563 }"
3564   [(set_attr "type" "insert")
3565    (set_attr "size" "64")])
3566
3567 (define_insn "*insvdi_internal2"
3568   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3569                          (match_operand:SI 1 "const_int_operand" "i")
3570                          (match_operand:SI 2 "const_int_operand" "i"))
3571         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3572                      (match_operand:SI 4 "const_int_operand" "i")))]
3573   "TARGET_POWERPC64
3574    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3575   "*
3576 {
3577   int shift = INTVAL (operands[4]) & 63;
3578   int start = (INTVAL (operands[2]) & 63) - 32;
3579   int size = INTVAL (operands[1]) & 63;
3580
3581   operands[4] = GEN_INT (64 - shift - start - size);
3582   operands[2] = GEN_INT (start);
3583   operands[1] = GEN_INT (start + size - 1);
3584   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3585 }")
3586
3587 (define_insn "*insvdi_internal3"
3588   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3589                          (match_operand:SI 1 "const_int_operand" "i")
3590                          (match_operand:SI 2 "const_int_operand" "i"))
3591         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3592                      (match_operand:SI 4 "const_int_operand" "i")))]
3593   "TARGET_POWERPC64
3594    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3595   "*
3596 {
3597   int shift = INTVAL (operands[4]) & 63;
3598   int start = (INTVAL (operands[2]) & 63) - 32;
3599   int size = INTVAL (operands[1]) & 63;
3600
3601   operands[4] = GEN_INT (64 - shift - start - size);
3602   operands[2] = GEN_INT (start);
3603   operands[1] = GEN_INT (start + size - 1);
3604   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3605 }")
3606
3607 (define_expand "extzv"
3608   [(set (match_operand 0 "gpc_reg_operand" "")
3609         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3610                        (match_operand:SI 2 "const_int_operand" "")
3611                        (match_operand:SI 3 "const_int_operand" "")))]
3612   ""
3613   "
3614 {
3615   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3616      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3617      compiler if the address of the structure is taken later.  */
3618   if (GET_CODE (operands[0]) == SUBREG
3619       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3620     FAIL;
3621
3622   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3623     emit_insn (gen_extzvdi_internal (operands[0], operands[1], operands[2],
3624                                      operands[3]));
3625   else
3626     emit_insn (gen_extzvsi_internal (operands[0], operands[1], operands[2],
3627                                      operands[3]));
3628   DONE;
3629 }")
3630
3631 (define_insn "extzvsi_internal"
3632   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3633         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3634                          (match_operand:SI 2 "const_int_operand" "i")
3635                          (match_operand:SI 3 "const_int_operand" "i")))]
3636   ""
3637   "*
3638 {
3639   int start = INTVAL (operands[3]) & 31;
3640   int size = INTVAL (operands[2]) & 31;
3641
3642   if (start + size >= 32)
3643     operands[3] = const0_rtx;
3644   else
3645     operands[3] = GEN_INT (start + size);
3646   return \"rlwinm %0,%1,%3,%s2,31\";
3647 }")
3648
3649 (define_insn "*extzvsi_internal1"
3650   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3651         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3652                          (match_operand:SI 2 "const_int_operand" "i,i")
3653                          (match_operand:SI 3 "const_int_operand" "i,i"))
3654                     (const_int 0)))
3655    (clobber (match_scratch:SI 4 "=r,r"))]
3656   ""
3657   "*
3658 {
3659   int start = INTVAL (operands[3]) & 31;
3660   int size = INTVAL (operands[2]) & 31;
3661
3662   /* Force split for non-cc0 compare.  */
3663   if (which_alternative == 1)
3664      return \"#\";
3665
3666   /* If the bit-field being tested fits in the upper or lower half of a
3667      word, it is possible to use andiu. or andil. to test it.  This is
3668      useful because the condition register set-use delay is smaller for
3669      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3670      position is 0 because the LT and GT bits may be set wrong.  */
3671
3672   if ((start > 0 && start + size <= 16) || start >= 16)
3673     {
3674       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3675                               - (1 << (16 - (start & 15) - size))));
3676       if (start < 16)
3677         return \"andis. %4,%1,%3\";
3678       else
3679         return \"andi. %4,%1,%3\";
3680     }
3681
3682   if (start + size >= 32)
3683     operands[3] = const0_rtx;
3684   else
3685     operands[3] = GEN_INT (start + size);
3686   return \"rlwinm. %4,%1,%3,%s2,31\";
3687 }"
3688   [(set_attr "type" "shift")
3689    (set_attr "dot" "yes")
3690    (set_attr "length" "4,8")])
3691
3692 (define_split
3693   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3694         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3695                          (match_operand:SI 2 "const_int_operand" "")
3696                          (match_operand:SI 3 "const_int_operand" ""))
3697                     (const_int 0)))
3698    (clobber (match_scratch:SI 4 ""))]
3699   "reload_completed"
3700   [(set (match_dup 4)
3701         (zero_extract:SI (match_dup 1) (match_dup 2)
3702                          (match_dup 3)))
3703    (set (match_dup 0)
3704         (compare:CC (match_dup 4)
3705                     (const_int 0)))]
3706   "")
3707
3708 (define_insn "*extzvsi_internal2"
3709   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3710         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3711                          (match_operand:SI 2 "const_int_operand" "i,i")
3712                          (match_operand:SI 3 "const_int_operand" "i,i"))
3713                     (const_int 0)))
3714    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3715         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3716   ""
3717   "*
3718 {
3719   int start = INTVAL (operands[3]) & 31;
3720   int size = INTVAL (operands[2]) & 31;
3721
3722   /* Force split for non-cc0 compare.  */
3723   if (which_alternative == 1)
3724      return \"#\";
3725
3726   /* Since we are using the output value, we can't ignore any need for
3727      a shift.  The bit-field must end at the LSB.  */
3728   if (start >= 16 && start + size == 32)
3729     {
3730       operands[3] = GEN_INT ((1 << size) - 1);
3731       return \"andi. %0,%1,%3\";
3732     }
3733
3734   if (start + size >= 32)
3735     operands[3] = const0_rtx;
3736   else
3737     operands[3] = GEN_INT (start + size);
3738   return \"rlwinm. %0,%1,%3,%s2,31\";
3739 }"
3740   [(set_attr "type" "shift")
3741    (set_attr "dot" "yes")
3742    (set_attr "length" "4,8")])
3743
3744 (define_split
3745   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3746         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3747                          (match_operand:SI 2 "const_int_operand" "")
3748                          (match_operand:SI 3 "const_int_operand" ""))
3749                     (const_int 0)))
3750    (set (match_operand:SI 0 "gpc_reg_operand" "")
3751         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3752   "reload_completed"
3753   [(set (match_dup 0)
3754         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3755    (set (match_dup 4)
3756         (compare:CC (match_dup 0)
3757                     (const_int 0)))]
3758   "")
3759
3760 (define_insn "extzvdi_internal"
3761   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3762         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3763                          (match_operand:SI 2 "const_int_operand" "i")
3764                          (match_operand:SI 3 "const_int_operand" "i")))]
3765   "TARGET_POWERPC64"
3766   "*
3767 {
3768   int start = INTVAL (operands[3]) & 63;
3769   int size = INTVAL (operands[2]) & 63;
3770
3771   if (start + size >= 64)
3772     operands[3] = const0_rtx;
3773   else
3774     operands[3] = GEN_INT (start + size);
3775   operands[2] = GEN_INT (64 - size);
3776   return \"rldicl %0,%1,%3,%2\";
3777 }")
3778
3779 (define_insn "*extzvdi_internal1"
3780   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3781         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3782                          (match_operand:SI 2 "const_int_operand" "i")
3783                          (match_operand:SI 3 "const_int_operand" "i"))
3784                     (const_int 0)))
3785    (clobber (match_scratch:DI 4 "=r"))]
3786   "TARGET_64BIT && rs6000_gen_cell_microcode"
3787   "*
3788 {
3789   int start = INTVAL (operands[3]) & 63;
3790   int size = INTVAL (operands[2]) & 63;
3791
3792   if (start + size >= 64)
3793     operands[3] = const0_rtx;
3794   else
3795     operands[3] = GEN_INT (start + size);
3796   operands[2] = GEN_INT (64 - size);
3797   return \"rldicl. %4,%1,%3,%2\";
3798 }"
3799   [(set_attr "type" "compare")])
3800
3801 (define_insn "*extzvdi_internal2"
3802   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3803         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3804                          (match_operand:SI 2 "const_int_operand" "i")
3805                          (match_operand:SI 3 "const_int_operand" "i"))
3806                     (const_int 0)))
3807    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3808         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3809   "TARGET_64BIT && rs6000_gen_cell_microcode"
3810   "*
3811 {
3812   int start = INTVAL (operands[3]) & 63;
3813   int size = INTVAL (operands[2]) & 63;
3814
3815   if (start + size >= 64)
3816     operands[3] = const0_rtx;
3817   else
3818     operands[3] = GEN_INT (start + size);
3819   operands[2] = GEN_INT (64 - size);
3820   return \"rldicl. %0,%1,%3,%2\";
3821 }"
3822   [(set_attr "type" "compare")])
3823
3824 (define_insn "rotlsi3"
3825   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3826         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3827                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3828   ""
3829   "@
3830    rlwnm %0,%1,%2,0xffffffff
3831    rlwinm %0,%1,%h2,0xffffffff"
3832   [(set_attr "type" "shift,integer")
3833    (set_attr "var_shift" "yes,no")])
3834
3835 (define_insn "*rotlsi3_64"
3836   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3837         (zero_extend:DI
3838             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3839                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
3840   "TARGET_64BIT"
3841   "@
3842    rlwnm %0,%1,%2,0xffffffff
3843    rlwinm %0,%1,%h2,0xffffffff"
3844   [(set_attr "type" "shift,integer")
3845    (set_attr "var_shift" "yes,no")])
3846
3847 (define_insn "*rotlsi3_internal2"
3848   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3849         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3850                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3851                     (const_int 0)))
3852    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3853   ""
3854   "@
3855    rlwnm. %3,%1,%2,0xffffffff
3856    rlwinm. %3,%1,%h2,0xffffffff
3857    #
3858    #"
3859   [(set_attr "type" "shift")
3860    (set_attr "var_shift" "yes,no,yes,no")
3861    (set_attr "dot" "yes")
3862    (set_attr "length" "4,4,8,8")])
3863
3864 (define_split
3865   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3866         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3867                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3868                     (const_int 0)))
3869    (clobber (match_scratch:SI 3 ""))]
3870   "reload_completed"
3871   [(set (match_dup 3)
3872         (rotate:SI (match_dup 1) (match_dup 2)))
3873    (set (match_dup 0)
3874         (compare:CC (match_dup 3)
3875                     (const_int 0)))]
3876   "")
3877
3878 (define_insn "*rotlsi3_internal3"
3879   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3880         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3881                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3882                     (const_int 0)))
3883    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3884         (rotate:SI (match_dup 1) (match_dup 2)))]
3885   ""
3886   "@
3887    rlwnm. %0,%1,%2,0xffffffff
3888    rlwinm. %0,%1,%h2,0xffffffff
3889    #
3890    #"
3891   [(set_attr "type" "shift")
3892    (set_attr "var_shift" "yes,no,yes,no")
3893    (set_attr "dot" "yes")
3894    (set_attr "length" "4,4,8,8")])
3895
3896 (define_split
3897   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3898         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3899                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3900                     (const_int 0)))
3901    (set (match_operand:SI 0 "gpc_reg_operand" "")
3902         (rotate:SI (match_dup 1) (match_dup 2)))]
3903   "reload_completed"
3904   [(set (match_dup 0)
3905         (rotate:SI (match_dup 1) (match_dup 2)))
3906    (set (match_dup 3)
3907         (compare:CC (match_dup 0)
3908                     (const_int 0)))]
3909   "")
3910
3911 (define_insn "*rotlsi3_internal4"
3912   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3913         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3914                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
3915                 (match_operand:SI 3 "mask_operand" "n,n")))]
3916   ""
3917   "@
3918    rlwnm %0,%1,%2,%m3,%M3
3919    rlwinm %0,%1,%h2,%m3,%M3"
3920   [(set_attr "type" "shift,integer")
3921    (set_attr "var_shift" "yes,no")])
3922
3923 (define_insn "*rotlsi3_internal5"
3924   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3925         (compare:CC (and:SI
3926                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3927                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3928                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3929                     (const_int 0)))
3930    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
3931   ""
3932   "@
3933    rlwnm. %4,%1,%2,%m3,%M3
3934    rlwinm. %4,%1,%h2,%m3,%M3
3935    #
3936    #"
3937   [(set_attr "type" "shift")
3938    (set_attr "var_shift" "yes,no,yes,no")
3939    (set_attr "dot" "yes")
3940    (set_attr "length" "4,4,8,8")])
3941
3942 (define_split
3943   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3944         (compare:CC (and:SI
3945                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3946                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3947                      (match_operand:SI 3 "mask_operand" ""))
3948                     (const_int 0)))
3949    (clobber (match_scratch:SI 4 ""))]
3950   "reload_completed"
3951   [(set (match_dup 4)
3952         (and:SI (rotate:SI (match_dup 1)
3953                                 (match_dup 2))
3954                      (match_dup 3)))
3955    (set (match_dup 0)
3956         (compare:CC (match_dup 4)
3957                     (const_int 0)))]
3958   "")
3959
3960 (define_insn "*rotlsi3_internal6"
3961   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
3962         (compare:CC (and:SI
3963                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3964                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3965                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3966                     (const_int 0)))
3967    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3968         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3969   ""
3970   "@
3971    rlwnm. %0,%1,%2,%m3,%M3
3972    rlwinm. %0,%1,%h2,%m3,%M3
3973    #
3974    #"
3975   [(set_attr "type" "shift")
3976    (set_attr "var_shift" "yes,no,yes,no")
3977    (set_attr "dot" "yes")
3978    (set_attr "length" "4,4,8,8")])
3979
3980 (define_split
3981   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3982         (compare:CC (and:SI
3983                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3984                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3985                      (match_operand:SI 3 "mask_operand" ""))
3986                     (const_int 0)))
3987    (set (match_operand:SI 0 "gpc_reg_operand" "")
3988         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3989   "reload_completed"
3990   [(set (match_dup 0)
3991         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3992    (set (match_dup 4)
3993         (compare:CC (match_dup 0)
3994                     (const_int 0)))]
3995   "")
3996
3997 (define_insn "*rotlsi3_internal7le"
3998   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3999         (zero_extend:SI
4000          (subreg:QI
4001           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4002                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4003   "!BYTES_BIG_ENDIAN"
4004   "rlw%I2nm %0,%1,%h2,0xff"
4005   [(set (attr "cell_micro")
4006      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4007         (const_string "not")
4008         (const_string "always")))])
4009
4010 (define_insn "*rotlsi3_internal7be"
4011   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4012         (zero_extend:SI
4013          (subreg:QI
4014           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4015                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 3)))]
4016   "BYTES_BIG_ENDIAN"
4017   "rlw%I2nm %0,%1,%h2,0xff"
4018   [(set (attr "cell_micro")
4019      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4020         (const_string "not")
4021         (const_string "always")))])
4022
4023 (define_insn "*rotlsi3_internal8le"
4024   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4025         (compare:CC (zero_extend:SI
4026                      (subreg:QI
4027                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4028                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4029                     (const_int 0)))
4030    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4031   "!BYTES_BIG_ENDIAN"
4032   "@
4033    rlwnm. %3,%1,%2,0xff
4034    rlwinm. %3,%1,%h2,0xff
4035    #
4036    #"
4037   [(set_attr "type" "shift")
4038    (set_attr "var_shift" "yes,no,yes,no")
4039    (set_attr "dot" "yes")
4040    (set_attr "length" "4,4,8,8")])
4041
4042 (define_insn "*rotlsi3_internal8be"
4043   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4044         (compare:CC (zero_extend:SI
4045                      (subreg:QI
4046                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4047                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 3))
4048                     (const_int 0)))
4049    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4050   "BYTES_BIG_ENDIAN"
4051   "@
4052    rlwnm. %3,%1,%2,0xff
4053    rlwinm. %3,%1,%h2,0xff
4054    #
4055    #"
4056   [(set_attr "type" "shift")
4057    (set_attr "var_shift" "yes,no,yes,no")
4058    (set_attr "dot" "yes")
4059    (set_attr "length" "4,4,8,8")])
4060
4061 (define_split
4062   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4063         (compare:CC (zero_extend:SI
4064                      (subreg:QI
4065                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4066                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4067                     (const_int 0)))
4068    (clobber (match_scratch:SI 3 ""))]
4069   "!BYTES_BIG_ENDIAN && reload_completed"
4070   [(set (match_dup 3)
4071         (zero_extend:SI (subreg:QI
4072                       (rotate:SI (match_dup 1)
4073                                  (match_dup 2)) 0)))
4074    (set (match_dup 0)
4075         (compare:CC (match_dup 3)
4076                     (const_int 0)))]
4077   "")
4078
4079 (define_split
4080   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4081         (compare:CC (zero_extend:SI
4082                      (subreg:QI
4083                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4084                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 3))
4085                     (const_int 0)))
4086    (clobber (match_scratch:SI 3 ""))]
4087   "BYTES_BIG_ENDIAN && reload_completed"
4088   [(set (match_dup 3)
4089         (zero_extend:SI (subreg:QI
4090                       (rotate:SI (match_dup 1)
4091                                  (match_dup 2)) 3)))
4092    (set (match_dup 0)
4093         (compare:CC (match_dup 3)
4094                     (const_int 0)))]
4095   "")
4096
4097 (define_insn "*rotlsi3_internal9le"
4098   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4099         (compare:CC (zero_extend:SI
4100                      (subreg:QI
4101                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4102                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4103                     (const_int 0)))
4104    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4105         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4106   "!BYTES_BIG_ENDIAN"
4107   "@
4108    rlwnm. %0,%1,%2,0xff
4109    rlwinm. %0,%1,%h2,0xff
4110    #
4111    #"
4112   [(set_attr "type" "shift")
4113    (set_attr "var_shift" "yes,no,yes,no")
4114    (set_attr "dot" "yes")
4115    (set_attr "length" "4,4,8,8")])
4116
4117 (define_insn "*rotlsi3_internal9be"
4118   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4119         (compare:CC (zero_extend:SI
4120                      (subreg:QI
4121                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4122                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 3))
4123                     (const_int 0)))
4124    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4125         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))]
4126   "BYTES_BIG_ENDIAN"
4127   "@
4128    rlwnm. %0,%1,%2,0xff
4129    rlwinm. %0,%1,%h2,0xff
4130    #
4131    #"
4132   [(set_attr "type" "shift")
4133    (set_attr "var_shift" "yes,no,yes,no")
4134    (set_attr "dot" "yes")
4135    (set_attr "length" "4,4,8,8")])
4136
4137 (define_split
4138   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4139         (compare:CC (zero_extend:SI
4140                      (subreg:QI
4141                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4142                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4143                     (const_int 0)))
4144    (set (match_operand:SI 0 "gpc_reg_operand" "")
4145         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4146   "!BYTES_BIG_ENDIAN && reload_completed"
4147   [(set (match_dup 0)
4148         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4149    (set (match_dup 3)
4150         (compare:CC (match_dup 0)
4151                     (const_int 0)))]
4152   "")
4153
4154 (define_split
4155   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4156         (compare:CC (zero_extend:SI
4157                      (subreg:QI
4158                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4159                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 3))
4160                     (const_int 0)))
4161    (set (match_operand:SI 0 "gpc_reg_operand" "")
4162         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))]
4163   "BYTES_BIG_ENDIAN && reload_completed"
4164   [(set (match_dup 0)
4165         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))
4166    (set (match_dup 3)
4167         (compare:CC (match_dup 0)
4168                     (const_int 0)))]
4169   "")
4170
4171 (define_insn "*rotlsi3_internal10le"
4172   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4173         (zero_extend:SI
4174          (subreg:HI
4175           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4176                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4177   "!BYTES_BIG_ENDIAN"
4178   "@
4179    rlwnm %0,%1,%2,0xffff
4180    rlwinm %0,%1,%h2,0xffff"
4181   [(set_attr "type" "shift,integer")
4182    (set_attr "var_shift" "yes,no")])
4183
4184 (define_insn "*rotlsi3_internal10be"
4185   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4186         (zero_extend:SI
4187          (subreg:HI
4188           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4189                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 2)))]
4190   "BYTES_BIG_ENDIAN"
4191   "@
4192    rlwnm %0,%1,%2,0xffff
4193    rlwinm %0,%1,%h2,0xffff"
4194   [(set_attr "type" "shift,integer")
4195    (set_attr "var_shift" "yes,no")])
4196
4197 (define_insn "*rotlsi3_internal11le"
4198   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4199         (compare:CC (zero_extend:SI
4200                      (subreg:HI
4201                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4202                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4203                     (const_int 0)))
4204    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4205   "!BYTES_BIG_ENDIAN"
4206   "@
4207    rlwnm. %3,%1,%2,0xffff
4208    rlwinm. %3,%1,%h2,0xffff
4209    #
4210    #"
4211   [(set_attr "type" "shift")
4212    (set_attr "var_shift" "yes,no,yes,no")
4213    (set_attr "dot" "yes")
4214    (set_attr "length" "4,4,8,8")])
4215
4216 (define_insn "*rotlsi3_internal11be"
4217   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4218         (compare:CC (zero_extend:SI
4219                      (subreg:HI
4220                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4221                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 2))
4222                     (const_int 0)))
4223    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4224   "BYTES_BIG_ENDIAN"
4225   "@
4226    rlwnm. %3,%1,%2,0xffff
4227    rlwinm. %3,%1,%h2,0xffff
4228    #
4229    #"
4230   [(set_attr "type" "shift")
4231    (set_attr "var_shift" "yes,no,yes,no")
4232    (set_attr "dot" "yes")
4233    (set_attr "length" "4,4,8,8")])
4234
4235 (define_split
4236   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4237         (compare:CC (zero_extend:SI
4238                      (subreg:HI
4239                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4240                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4241                     (const_int 0)))
4242    (clobber (match_scratch:SI 3 ""))]
4243   "!BYTES_BIG_ENDIAN && reload_completed"
4244   [(set (match_dup 3)
4245         (zero_extend:SI (subreg:HI
4246                       (rotate:SI (match_dup 1)
4247                                  (match_dup 2)) 0)))
4248    (set (match_dup 0)
4249         (compare:CC (match_dup 3)
4250                     (const_int 0)))]
4251   "")
4252
4253 (define_split
4254   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4255         (compare:CC (zero_extend:SI
4256                      (subreg:HI
4257                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4258                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 2))
4259                     (const_int 0)))
4260    (clobber (match_scratch:SI 3 ""))]
4261   "BYTES_BIG_ENDIAN && reload_completed"
4262   [(set (match_dup 3)
4263         (zero_extend:SI (subreg:HI
4264                       (rotate:SI (match_dup 1)
4265                                  (match_dup 2)) 2)))
4266    (set (match_dup 0)
4267         (compare:CC (match_dup 3)
4268                     (const_int 0)))]
4269   "")
4270
4271 (define_insn "*rotlsi3_internal12le"
4272   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4273         (compare:CC (zero_extend:SI
4274                      (subreg:HI
4275                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4276                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4277                     (const_int 0)))
4278    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4279         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4280   "!BYTES_BIG_ENDIAN"
4281   "@
4282    rlwnm. %0,%1,%2,0xffff
4283    rlwinm. %0,%1,%h2,0xffff
4284    #
4285    #"
4286   [(set_attr "type" "shift")
4287    (set_attr "var_shift" "yes,no,yes,no")
4288    (set_attr "dot" "yes")
4289    (set_attr "length" "4,4,8,8")])
4290
4291 (define_insn "*rotlsi3_internal12be"
4292   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4293         (compare:CC (zero_extend:SI
4294                      (subreg:HI
4295                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4296                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 2))
4297                     (const_int 0)))
4298    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4299         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))]
4300   "BYTES_BIG_ENDIAN"
4301   "@
4302    rlwnm. %0,%1,%2,0xffff
4303    rlwinm. %0,%1,%h2,0xffff
4304    #
4305    #"
4306   [(set_attr "type" "shift")
4307    (set_attr "var_shift" "yes,no,yes,no")
4308    (set_attr "dot" "yes")
4309    (set_attr "length" "4,4,8,8")])
4310
4311 (define_split
4312   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4313         (compare:CC (zero_extend:SI
4314                      (subreg:HI
4315                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4316                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4317                     (const_int 0)))
4318    (set (match_operand:SI 0 "gpc_reg_operand" "")
4319         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4320   "!BYTES_BIG_ENDIAN && reload_completed"
4321   [(set (match_dup 0)
4322         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4323    (set (match_dup 3)
4324         (compare:CC (match_dup 0)
4325                     (const_int 0)))]
4326   "")
4327
4328 (define_split
4329   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4330         (compare:CC (zero_extend:SI
4331                      (subreg:HI
4332                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4333                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 2))
4334                     (const_int 0)))
4335    (set (match_operand:SI 0 "gpc_reg_operand" "")
4336         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))]
4337   "BYTES_BIG_ENDIAN && reload_completed"
4338   [(set (match_dup 0)
4339         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))
4340    (set (match_dup 3)
4341         (compare:CC (match_dup 0)
4342                     (const_int 0)))]
4343   "")
4344
4345 (define_insn "ashlsi3"
4346   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4347         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4348                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4349   ""
4350   "@
4351    slw %0,%1,%2
4352    slwi %0,%1,%h2"
4353   [(set_attr "type" "shift")
4354    (set_attr "var_shift" "yes,no")])
4355
4356 (define_insn "*ashlsi3_64"
4357   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4358         (zero_extend:DI
4359             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4360                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4361   "TARGET_POWERPC64"
4362   "@
4363    slw %0,%1,%2
4364    slwi %0,%1,%h2"
4365   [(set_attr "type" "shift")
4366    (set_attr "var_shift" "yes,no")])
4367
4368 (define_insn ""
4369   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4370         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4371                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4372                     (const_int 0)))
4373    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4374   "TARGET_32BIT"
4375   "@
4376    slw. %3,%1,%2
4377    slwi. %3,%1,%h2
4378    #
4379    #"
4380   [(set_attr "type" "shift")
4381    (set_attr "var_shift" "yes,no,yes,no")
4382    (set_attr "dot" "yes")
4383    (set_attr "length" "4,4,8,8")])
4384
4385 (define_split
4386   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4387         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4388                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4389                     (const_int 0)))
4390    (clobber (match_scratch:SI 3 ""))]
4391   "TARGET_32BIT && reload_completed"
4392   [(set (match_dup 3)
4393         (ashift:SI (match_dup 1) (match_dup 2)))
4394    (set (match_dup 0)
4395         (compare:CC (match_dup 3)
4396                     (const_int 0)))]
4397   "")
4398
4399 (define_insn ""
4400   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4401         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4402                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4403                     (const_int 0)))
4404    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4405         (ashift:SI (match_dup 1) (match_dup 2)))]
4406   "TARGET_32BIT"
4407   "@
4408    slw. %0,%1,%2
4409    slwi. %0,%1,%h2
4410    #
4411    #"
4412   [(set_attr "type" "shift")
4413    (set_attr "var_shift" "yes,no,yes,no")
4414    (set_attr "dot" "yes")
4415    (set_attr "length" "4,4,8,8")])
4416
4417 (define_split
4418   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4419         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4420                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4421                     (const_int 0)))
4422    (set (match_operand:SI 0 "gpc_reg_operand" "")
4423         (ashift:SI (match_dup 1) (match_dup 2)))]
4424   "TARGET_32BIT && reload_completed"
4425   [(set (match_dup 0)
4426         (ashift:SI (match_dup 1) (match_dup 2)))
4427    (set (match_dup 3)
4428         (compare:CC (match_dup 0)
4429                     (const_int 0)))]
4430   "")
4431
4432 (define_insn "rlwinm"
4433   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4434         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4435                            (match_operand:SI 2 "const_int_operand" "i"))
4436                 (match_operand:SI 3 "mask_operand" "n")))]
4437   "includes_lshift_p (operands[2], operands[3])"
4438   "rlwinm %0,%1,%h2,%m3,%M3")
4439
4440 (define_insn ""
4441   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4442         (compare:CC
4443          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4444                             (match_operand:SI 2 "const_int_operand" "i,i"))
4445                  (match_operand:SI 3 "mask_operand" "n,n"))
4446          (const_int 0)))
4447    (clobber (match_scratch:SI 4 "=r,r"))]
4448   "includes_lshift_p (operands[2], operands[3])"
4449   "@
4450    rlwinm. %4,%1,%h2,%m3,%M3
4451    #"
4452   [(set_attr "type" "shift")
4453    (set_attr "dot" "yes")
4454    (set_attr "length" "4,8")])
4455
4456 (define_split
4457   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4458         (compare:CC
4459          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4460                             (match_operand:SI 2 "const_int_operand" ""))
4461                  (match_operand:SI 3 "mask_operand" ""))
4462          (const_int 0)))
4463    (clobber (match_scratch:SI 4 ""))]
4464   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4465   [(set (match_dup 4)
4466         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4467                  (match_dup 3)))
4468    (set (match_dup 0)
4469         (compare:CC (match_dup 4)
4470                     (const_int 0)))]
4471   "")
4472
4473 (define_insn ""
4474   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4475         (compare:CC
4476          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4477                             (match_operand:SI 2 "const_int_operand" "i,i"))
4478                  (match_operand:SI 3 "mask_operand" "n,n"))
4479          (const_int 0)))
4480    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4481         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4482   "includes_lshift_p (operands[2], operands[3])"
4483   "@
4484    rlwinm. %0,%1,%h2,%m3,%M3
4485    #"
4486   [(set_attr "type" "shift")
4487    (set_attr "dot" "yes")
4488    (set_attr "length" "4,8")])
4489
4490 (define_split
4491   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4492         (compare:CC
4493          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4494                             (match_operand:SI 2 "const_int_operand" ""))
4495                  (match_operand:SI 3 "mask_operand" ""))
4496          (const_int 0)))
4497    (set (match_operand:SI 0 "gpc_reg_operand" "")
4498         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4499   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4500   [(set (match_dup 0)
4501         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4502    (set (match_dup 4)
4503         (compare:CC (match_dup 0)
4504                     (const_int 0)))]
4505   "")
4506
4507 (define_insn "lshrsi3"
4508   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4509         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4510                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
4511   ""
4512   "@
4513   mr %0,%1
4514   srw %0,%1,%2
4515   srwi %0,%1,%h2"
4516   [(set_attr "type" "integer,shift,shift")
4517    (set_attr "var_shift" "no,yes,no")])
4518
4519 (define_insn "*lshrsi3_64"
4520   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4521         (zero_extend:DI
4522             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4523                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4524   "TARGET_POWERPC64"
4525   "@
4526   srw %0,%1,%2
4527   srwi %0,%1,%h2"
4528   [(set_attr "type" "shift")
4529    (set_attr "var_shift" "yes,no")])
4530
4531 (define_insn ""
4532   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4533         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4534                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4535                     (const_int 0)))
4536    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
4537   "TARGET_32BIT"
4538   "@
4539    mr. %1,%1
4540    srw. %3,%1,%2
4541    srwi. %3,%1,%h2
4542    #
4543    #
4544    #"
4545   [(set_attr "type" "fast_compare,shift,shift,shift,shift,shift")
4546    (set_attr "var_shift" "no,yes,no,no,yes,no")
4547    (set_attr "dot" "yes")
4548    (set_attr "length" "4,4,4,8,8,8")])
4549
4550 (define_split
4551   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4552         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4553                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4554                     (const_int 0)))
4555    (clobber (match_scratch:SI 3 ""))]
4556   "TARGET_32BIT && reload_completed"
4557   [(set (match_dup 3)
4558         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4559    (set (match_dup 0)
4560         (compare:CC (match_dup 3)
4561                     (const_int 0)))]
4562   "")
4563
4564 (define_insn ""
4565   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4566         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4567                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4568                     (const_int 0)))
4569    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4570         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4571   "TARGET_32BIT"
4572   "@
4573    mr. %0,%1
4574    srw. %0,%1,%2
4575    srwi. %0,%1,%h2
4576    #
4577    #
4578    #"
4579   [(set_attr "type" "fast_compare,shift,shift,shift,shift,shift")
4580    (set_attr "var_shift" "no,yes,no,no,yes,no")
4581    (set_attr "dot" "yes")
4582    (set_attr "length" "4,4,4,8,8,8")])
4583
4584 (define_split
4585   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4586         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4587                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4588                     (const_int 0)))
4589    (set (match_operand:SI 0 "gpc_reg_operand" "")
4590         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4591   "TARGET_32BIT && reload_completed"
4592   [(set (match_dup 0)
4593         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4594    (set (match_dup 3)
4595         (compare:CC (match_dup 0)
4596                     (const_int 0)))]
4597   "")
4598
4599 (define_insn ""
4600   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4601         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4602                              (match_operand:SI 2 "const_int_operand" "i"))
4603                 (match_operand:SI 3 "mask_operand" "n")))]
4604   "includes_rshift_p (operands[2], operands[3])"
4605   "rlwinm %0,%1,%s2,%m3,%M3")
4606
4607 (define_insn ""
4608   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4609         (compare:CC
4610          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4611                               (match_operand:SI 2 "const_int_operand" "i,i"))
4612                  (match_operand:SI 3 "mask_operand" "n,n"))
4613          (const_int 0)))
4614    (clobber (match_scratch:SI 4 "=r,r"))]
4615   "includes_rshift_p (operands[2], operands[3])"
4616   "@
4617    rlwinm. %4,%1,%s2,%m3,%M3
4618    #"
4619   [(set_attr "type" "shift")
4620    (set_attr "dot" "yes")
4621    (set_attr "length" "4,8")])
4622
4623 (define_split
4624   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4625         (compare:CC
4626          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4627                               (match_operand:SI 2 "const_int_operand" ""))
4628                  (match_operand:SI 3 "mask_operand" ""))
4629          (const_int 0)))
4630    (clobber (match_scratch:SI 4 ""))]
4631   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4632   [(set (match_dup 4)
4633         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4634                  (match_dup 3)))
4635    (set (match_dup 0)
4636         (compare:CC (match_dup 4)
4637                     (const_int 0)))]
4638   "")
4639
4640 (define_insn ""
4641   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4642         (compare:CC
4643          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4644                               (match_operand:SI 2 "const_int_operand" "i,i"))
4645                  (match_operand:SI 3 "mask_operand" "n,n"))
4646          (const_int 0)))
4647    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4648         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4649   "includes_rshift_p (operands[2], operands[3])"
4650   "@
4651    rlwinm. %0,%1,%s2,%m3,%M3
4652    #"
4653   [(set_attr "type" "shift")
4654    (set_attr "dot" "yes")
4655    (set_attr "length" "4,8")])
4656
4657 (define_split
4658   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4659         (compare:CC
4660          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4661                               (match_operand:SI 2 "const_int_operand" ""))
4662                  (match_operand:SI 3 "mask_operand" ""))
4663          (const_int 0)))
4664    (set (match_operand:SI 0 "gpc_reg_operand" "")
4665         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4666   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4667   [(set (match_dup 0)
4668         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4669    (set (match_dup 4)
4670         (compare:CC (match_dup 0)
4671                     (const_int 0)))]
4672   "")
4673
4674 (define_insn "*lshiftrt_internal1le"
4675   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4676         (zero_extend:SI
4677          (subreg:QI
4678           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4679                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4680   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4681   "rlwinm %0,%1,%s2,0xff")
4682
4683 (define_insn "*lshiftrt_internal1be"
4684   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4685         (zero_extend:SI
4686          (subreg:QI
4687           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4688                        (match_operand:SI 2 "const_int_operand" "i")) 3)))]
4689   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4690   "rlwinm %0,%1,%s2,0xff")
4691
4692 (define_insn "*lshiftrt_internal2le"
4693   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4694         (compare:CC
4695          (zero_extend:SI
4696           (subreg:QI
4697            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4698                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4699          (const_int 0)))
4700    (clobber (match_scratch:SI 3 "=r,r"))]
4701   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4702   "@
4703    rlwinm. %3,%1,%s2,0xff
4704    #"
4705   [(set_attr "type" "shift")
4706    (set_attr "dot" "yes")
4707    (set_attr "length" "4,8")])
4708
4709 (define_insn "*lshiftrt_internal2be"
4710   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4711         (compare:CC
4712          (zero_extend:SI
4713           (subreg:QI
4714            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4715                         (match_operand:SI 2 "const_int_operand" "i,i")) 3))
4716          (const_int 0)))
4717    (clobber (match_scratch:SI 3 "=r,r"))]
4718   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4719   "@
4720    rlwinm. %3,%1,%s2,0xff
4721    #"
4722   [(set_attr "type" "shift")
4723    (set_attr "dot" "yes")
4724    (set_attr "length" "4,8")])
4725
4726 (define_split
4727   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4728         (compare:CC
4729          (zero_extend:SI
4730           (subreg:QI
4731            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4732                         (match_operand:SI 2 "const_int_operand" "")) 0))
4733          (const_int 0)))
4734    (clobber (match_scratch:SI 3 ""))]
4735   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4736   [(set (match_dup 3)
4737         (zero_extend:SI (subreg:QI
4738            (lshiftrt:SI (match_dup 1)
4739                         (match_dup 2)) 0)))
4740    (set (match_dup 0)
4741         (compare:CC (match_dup 3)
4742                     (const_int 0)))]
4743   "")
4744
4745 (define_split
4746   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4747         (compare:CC
4748          (zero_extend:SI
4749           (subreg:QI
4750            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4751                         (match_operand:SI 2 "const_int_operand" "")) 3))
4752          (const_int 0)))
4753    (clobber (match_scratch:SI 3 ""))]
4754   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4755   [(set (match_dup 3)
4756         (zero_extend:SI (subreg:QI
4757            (lshiftrt:SI (match_dup 1)
4758                         (match_dup 2)) 3)))
4759    (set (match_dup 0)
4760         (compare:CC (match_dup 3)
4761                     (const_int 0)))]
4762   "")
4763
4764 (define_insn "*lshiftrt_internal3le"
4765   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4766         (compare:CC
4767          (zero_extend:SI
4768           (subreg:QI
4769            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4770                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4771          (const_int 0)))
4772    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4773         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4774   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4775   "@
4776    rlwinm. %0,%1,%s2,0xff
4777    #"
4778   [(set_attr "type" "shift")
4779    (set_attr "dot" "yes")
4780    (set_attr "length" "4,8")])
4781
4782 (define_insn "*lshiftrt_internal3be"
4783   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4784         (compare:CC
4785          (zero_extend:SI
4786           (subreg:QI
4787            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4788                         (match_operand:SI 2 "const_int_operand" "i,i")) 3))
4789          (const_int 0)))
4790    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4791         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))]
4792   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4793   "@
4794    rlwinm. %0,%1,%s2,0xff
4795    #"
4796   [(set_attr "type" "shift")
4797    (set_attr "dot" "yes")
4798    (set_attr "length" "4,8")])
4799
4800 (define_split
4801   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4802         (compare:CC
4803          (zero_extend:SI
4804           (subreg:QI
4805            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4806                         (match_operand:SI 2 "const_int_operand" "")) 0))
4807          (const_int 0)))
4808    (set (match_operand:SI 0 "gpc_reg_operand" "")
4809         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4810   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4811   [(set (match_dup 0)
4812         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4813    (set (match_dup 3)
4814         (compare:CC (match_dup 0)
4815                     (const_int 0)))]
4816   "")
4817
4818 (define_split
4819   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4820         (compare:CC
4821          (zero_extend:SI
4822           (subreg:QI
4823            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4824                         (match_operand:SI 2 "const_int_operand" "")) 3))
4825          (const_int 0)))
4826    (set (match_operand:SI 0 "gpc_reg_operand" "")
4827         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))]
4828   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4829   [(set (match_dup 0)
4830         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))
4831    (set (match_dup 3)
4832         (compare:CC (match_dup 0)
4833                     (const_int 0)))]
4834   "")
4835
4836 (define_insn "*lshiftrt_internal4le"
4837   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4838         (zero_extend:SI
4839          (subreg:HI
4840           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4841                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4842   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4843   "rlwinm %0,%1,%s2,0xffff")
4844
4845 (define_insn "*lshiftrt_internal4be"
4846   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4847         (zero_extend:SI
4848          (subreg:HI
4849           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4850                        (match_operand:SI 2 "const_int_operand" "i")) 2)))]
4851   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4852   "rlwinm %0,%1,%s2,0xffff")
4853
4854 (define_insn "*lshiftrt_internal5le"
4855   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4856         (compare:CC
4857          (zero_extend:SI
4858           (subreg:HI
4859            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4860                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4861          (const_int 0)))
4862    (clobber (match_scratch:SI 3 "=r,r"))]
4863   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4864   "@
4865    rlwinm. %3,%1,%s2,0xffff
4866    #"
4867   [(set_attr "type" "shift")
4868    (set_attr "dot" "yes")
4869    (set_attr "length" "4,8")])
4870
4871 (define_insn "*lshiftrt_internal5be"
4872   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4873         (compare:CC
4874          (zero_extend:SI
4875           (subreg:HI
4876            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4877                         (match_operand:SI 2 "const_int_operand" "i,i")) 2))
4878          (const_int 0)))
4879    (clobber (match_scratch:SI 3 "=r,r"))]
4880   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4881   "@
4882    rlwinm. %3,%1,%s2,0xffff
4883    #"
4884   [(set_attr "type" "shift")
4885    (set_attr "dot" "yes")
4886    (set_attr "length" "4,8")])
4887
4888 (define_split
4889   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4890         (compare:CC
4891          (zero_extend:SI
4892           (subreg:HI
4893            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4894                         (match_operand:SI 2 "const_int_operand" "")) 0))
4895          (const_int 0)))
4896    (clobber (match_scratch:SI 3 ""))]
4897   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4898   [(set (match_dup 3)
4899         (zero_extend:SI (subreg:HI
4900            (lshiftrt:SI (match_dup 1)
4901                         (match_dup 2)) 0)))
4902    (set (match_dup 0)
4903         (compare:CC (match_dup 3)
4904                     (const_int 0)))]
4905   "")
4906
4907 (define_split
4908   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4909         (compare:CC
4910          (zero_extend:SI
4911           (subreg:HI
4912            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4913                         (match_operand:SI 2 "const_int_operand" "")) 2))
4914          (const_int 0)))
4915    (clobber (match_scratch:SI 3 ""))]
4916   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4917   [(set (match_dup 3)
4918         (zero_extend:SI (subreg:HI
4919            (lshiftrt:SI (match_dup 1)
4920                         (match_dup 2)) 2)))
4921    (set (match_dup 0)
4922         (compare:CC (match_dup 3)
4923                     (const_int 0)))]
4924   "")
4925
4926 (define_insn "*lshiftrt_internal5le"
4927   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4928         (compare:CC
4929          (zero_extend:SI
4930           (subreg:HI
4931            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4932                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4933          (const_int 0)))
4934    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4935         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4936   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4937   "@
4938    rlwinm. %0,%1,%s2,0xffff
4939    #"
4940   [(set_attr "type" "shift")
4941    (set_attr "dot" "yes")
4942    (set_attr "length" "4,8")])
4943
4944 (define_insn "*lshiftrt_internal5be"
4945   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4946         (compare:CC
4947          (zero_extend:SI
4948           (subreg:HI
4949            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4950                         (match_operand:SI 2 "const_int_operand" "i,i")) 2))
4951          (const_int 0)))
4952    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4953         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))]
4954   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4955   "@
4956    rlwinm. %0,%1,%s2,0xffff
4957    #"
4958   [(set_attr "type" "shift")
4959    (set_attr "dot" "yes")
4960    (set_attr "length" "4,8")])
4961
4962 (define_split
4963   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4964         (compare:CC
4965          (zero_extend:SI
4966           (subreg:HI
4967            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4968                         (match_operand:SI 2 "const_int_operand" "")) 0))
4969          (const_int 0)))
4970    (set (match_operand:SI 0 "gpc_reg_operand" "")
4971         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4972   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4973   [(set (match_dup 0)
4974         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4975    (set (match_dup 3)
4976         (compare:CC (match_dup 0)
4977                     (const_int 0)))]
4978   "")
4979
4980 (define_split
4981   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4982         (compare:CC
4983          (zero_extend:SI
4984           (subreg:HI
4985            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4986                         (match_operand:SI 2 "const_int_operand" "")) 2))
4987          (const_int 0)))
4988    (set (match_operand:SI 0 "gpc_reg_operand" "")
4989         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))]
4990   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4991   [(set (match_dup 0)
4992         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))
4993    (set (match_dup 3)
4994         (compare:CC (match_dup 0)
4995                     (const_int 0)))]
4996   "")
4997
4998 (define_insn "ashrsi3"
4999   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5000         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5001                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
5002   ""
5003   "@
5004    sraw %0,%1,%2
5005    srawi %0,%1,%h2"
5006   [(set_attr "type" "shift")
5007    (set_attr "var_shift" "yes,no")])
5008
5009 (define_insn "*ashrsi3_64"
5010   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5011         (sign_extend:DI
5012             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5013                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5014   "TARGET_POWERPC64"
5015   "@
5016    sraw %0,%1,%2
5017    srawi %0,%1,%h2"
5018   [(set_attr "type" "shift")
5019    (set_attr "var_shift" "yes,no")])
5020
5021 (define_insn ""
5022   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5023         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5024                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5025                     (const_int 0)))
5026    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
5027   ""
5028   "@
5029    sraw. %3,%1,%2
5030    srawi. %3,%1,%h2
5031    #
5032    #"
5033   [(set_attr "type" "shift")
5034    (set_attr "var_shift" "yes,no,yes,no")
5035    (set_attr "dot" "yes")
5036    (set_attr "length" "4,4,8,8")])
5037
5038 (define_split
5039   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5040         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5041                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5042                     (const_int 0)))
5043    (clobber (match_scratch:SI 3 ""))]
5044   "reload_completed"
5045   [(set (match_dup 3)
5046         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5047    (set (match_dup 0)
5048         (compare:CC (match_dup 3)
5049                     (const_int 0)))]
5050   "")
5051
5052 (define_insn ""
5053   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5054         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5055                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5056                     (const_int 0)))
5057    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5058         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5059   ""
5060   "@
5061    sraw. %0,%1,%2
5062    srawi. %0,%1,%h2
5063    #
5064    #"
5065   [(set_attr "type" "shift")
5066    (set_attr "var_shift" "yes,no,yes,no")
5067    (set_attr "dot" "yes")
5068    (set_attr "length" "4,4,8,8")])
5069 \f
5070 ;; Builtins to replace a division to generate FRE reciprocal estimate
5071 ;; instructions and the necessary fixup instructions
5072 (define_expand "recip<mode>3"
5073   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5074    (match_operand:RECIPF 1 "gpc_reg_operand" "")
5075    (match_operand:RECIPF 2 "gpc_reg_operand" "")]
5076   "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
5077 {
5078    rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
5079    DONE;
5080 })
5081
5082 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
5083 ;; hardware division.  This is only done before register allocation and with
5084 ;; -ffast-math.  This must appear before the divsf3/divdf3 insns.
5085 (define_split
5086   [(set (match_operand:RECIPF 0 "gpc_reg_operand" "")
5087         (div:RECIPF (match_operand 1 "gpc_reg_operand" "")
5088                     (match_operand 2 "gpc_reg_operand" "")))]
5089   "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
5090    && can_create_pseudo_p () && optimize_insn_for_speed_p ()
5091    && flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math"
5092   [(const_int 0)]
5093 {
5094   rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
5095   DONE;
5096 })
5097
5098 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
5099 ;; appropriate fixup.
5100 (define_expand "rsqrt<mode>2"
5101   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5102    (match_operand:RECIPF 1 "gpc_reg_operand" "")]
5103   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
5104 {
5105   rs6000_emit_swrsqrt (operands[0], operands[1]);
5106   DONE;
5107 })
5108 \f
5109 (define_split
5110   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5111         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5112                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5113                     (const_int 0)))
5114    (set (match_operand:SI 0 "gpc_reg_operand" "")
5115         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5116   "reload_completed"
5117   [(set (match_dup 0)
5118         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5119    (set (match_dup 3)
5120         (compare:CC (match_dup 0)
5121                     (const_int 0)))]
5122   "")
5123
5124 \f
5125 ;; Floating-point insns, excluding normal data motion.  We combine the SF/DF
5126 ;; modes here, and also add in conditional vsx/power8-vector support to access
5127 ;; values in the traditional Altivec registers if the appropriate
5128 ;; -mupper-regs-{df,sf} option is enabled.
5129
5130 (define_expand "abs<mode>2"
5131   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5132         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5133   "TARGET_<MODE>_INSN"
5134   "")
5135
5136 (define_insn "*abs<mode>2_fpr"
5137   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5138         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5139   "TARGET_<MODE>_FPR"
5140   "@
5141    fabs %0,%1
5142    xsabsdp %x0,%x1"
5143   [(set_attr "type" "fp")
5144    (set_attr "fp_type" "fp_addsub_<Fs>")])
5145
5146 (define_insn "*nabs<mode>2_fpr"
5147   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5148         (neg:SFDF
5149          (abs:SFDF
5150           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>"))))]
5151   "TARGET_<MODE>_FPR"
5152   "@
5153    fnabs %0,%1
5154    xsnabsdp %x0,%x1"
5155   [(set_attr "type" "fp")
5156    (set_attr "fp_type" "fp_addsub_<Fs>")])
5157
5158 (define_expand "neg<mode>2"
5159   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5160         (neg:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5161   "TARGET_<MODE>_INSN"
5162   "")
5163
5164 (define_insn "*neg<mode>2_fpr"
5165   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5166         (neg:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5167   "TARGET_<MODE>_FPR"
5168   "@
5169    fneg %0,%1
5170    xsnegdp %x0,%x1"
5171   [(set_attr "type" "fp")
5172    (set_attr "fp_type" "fp_addsub_<Fs>")])
5173
5174 (define_expand "add<mode>3"
5175   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5176         (plus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5177                    (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5178   "TARGET_<MODE>_INSN"
5179   "")
5180
5181 (define_insn "*add<mode>3_fpr"
5182   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5183         (plus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5184                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5185   "TARGET_<MODE>_FPR"
5186   "@
5187    fadd<Ftrad> %0,%1,%2
5188    xsadd<Fvsx> %x0,%x1,%x2"
5189   [(set_attr "type" "fp")
5190    (set_attr "fp_type" "fp_addsub_<Fs>")])
5191
5192 (define_expand "sub<mode>3"
5193   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5194         (minus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5195                     (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5196   "TARGET_<MODE>_INSN"
5197   "")
5198
5199 (define_insn "*sub<mode>3_fpr"
5200   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5201         (minus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5202                     (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5203   "TARGET_<MODE>_FPR"
5204   "@
5205    fsub<Ftrad> %0,%1,%2
5206    xssub<Fvsx> %x0,%x1,%x2"
5207   [(set_attr "type" "fp")
5208    (set_attr "fp_type" "fp_addsub_<Fs>")])
5209
5210 (define_expand "mul<mode>3"
5211   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5212         (mult:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5213                    (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5214   "TARGET_<MODE>_INSN"
5215   "")
5216
5217 (define_insn "*mul<mode>3_fpr"
5218   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5219         (mult:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5220                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5221   "TARGET_<MODE>_FPR"
5222   "@
5223    fmul<Ftrad> %0,%1,%2
5224    xsmul<Fvsx> %x0,%x1,%x2"
5225   [(set_attr "type" "dmul")
5226    (set_attr "fp_type" "fp_mul_<Fs>")])
5227
5228 (define_expand "div<mode>3"
5229   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5230         (div:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5231                   (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5232   "TARGET_<MODE>_INSN && !TARGET_SIMPLE_FPU"
5233   "")
5234
5235 (define_insn "*div<mode>3_fpr"
5236   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5237         (div:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5238                   (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5239   "TARGET_<MODE>_FPR && !TARGET_SIMPLE_FPU"
5240   "@
5241    fdiv<Ftrad> %0,%1,%2
5242    xsdiv<Fvsx> %x0,%x1,%x2"
5243   [(set_attr "type" "<Fs>div")
5244    (set_attr "fp_type" "fp_div_<Fs>")])
5245
5246 (define_insn "sqrt<mode>2"
5247   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5248         (sqrt:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5249   "TARGET_<MODE>_FPR && !TARGET_SIMPLE_FPU
5250    && (TARGET_PPC_GPOPT || (<MODE>mode == SFmode && TARGET_XILINX_FPU))"
5251   "@
5252    fsqrt<Ftrad> %0,%1
5253    xssqrt<Fvsx> %x0,%x1"
5254   [(set_attr "type" "<Fs>sqrt")
5255    (set_attr "fp_type" "fp_sqrt_<Fs>")])
5256
5257 ;; Floating point reciprocal approximation
5258 (define_insn "fre<Fs>"
5259   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5260         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
5261                      UNSPEC_FRES))]
5262   "TARGET_<FFRE>"
5263   "@
5264    fre<Ftrad> %0,%1
5265    xsre<Fvsx> %x0,%x1"
5266   [(set_attr "type" "fp")])
5267
5268 (define_insn "*rsqrt<mode>2"
5269   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5270         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
5271                      UNSPEC_RSQRT))]
5272   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
5273   "@
5274    frsqrte<Ftrad> %0,%1
5275    xsrsqrte<Fvsx> %x0,%x1"
5276   [(set_attr "type" "fp")])
5277
5278 ;; Floating point comparisons
5279 (define_insn "*cmp<mode>_fpr"
5280   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y,y")
5281         (compare:CCFP (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5282                       (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5283   "TARGET_<MODE>_FPR"
5284   "@
5285    fcmpu %0,%1,%2
5286    xscmpudp %0,%x1,%x2"
5287   [(set_attr "type" "fpcompare")])
5288
5289 ;; Floating point conversions
5290 (define_expand "extendsfdf2"
5291   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5292         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5293   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5294   "")
5295
5296 (define_insn_and_split "*extendsfdf2_fpr"
5297   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d,ws,?ws,wv")
5298         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m,0,wy,Z")))]
5299   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5300   "@
5301    #
5302    fmr %0,%1
5303    lfs%U1%X1 %0,%1
5304    #
5305    xxlor %x0,%x1,%x1
5306    lxsspx %x0,%y1"
5307   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5308   [(const_int 0)]
5309 {
5310   emit_note (NOTE_INSN_DELETED);
5311   DONE;
5312 }
5313   [(set_attr "type" "fp,fp,fpload,fp,vecsimple,fpload")])
5314
5315 (define_expand "truncdfsf2"
5316   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5317         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5318   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5319   "")
5320
5321 (define_insn "*truncdfsf2_fpr"
5322   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5323         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5324   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5325   "frsp %0,%1"
5326   [(set_attr "type" "fp")])
5327
5328 ;; This expander is here to avoid FLOAT_WORDS_BIGENDIAN tests in
5329 ;; builtins.c and optabs.c that are not correct for IBM long double
5330 ;; when little-endian.
5331 (define_expand "signbittf2"
5332   [(set (match_dup 2)
5333         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))
5334    (set (match_dup 3)
5335         (subreg:DI (match_dup 2) 0))
5336    (set (match_dup 4)
5337         (match_dup 5))
5338    (set (match_operand:SI 0 "gpc_reg_operand" "")
5339         (match_dup 6))]
5340   "!TARGET_IEEEQUAD
5341    && TARGET_HARD_FLOAT
5342    && (TARGET_FPRS || TARGET_E500_DOUBLE)
5343    && TARGET_LONG_DOUBLE_128"
5344 {
5345   operands[2] = gen_reg_rtx (DFmode);
5346   operands[3] = gen_reg_rtx (DImode);
5347   if (TARGET_POWERPC64)
5348     {
5349       operands[4] = gen_reg_rtx (DImode);
5350       operands[5] = gen_rtx_LSHIFTRT (DImode, operands[3], GEN_INT (63));
5351       operands[6] = gen_rtx_SUBREG (SImode, operands[4],
5352                                     WORDS_BIG_ENDIAN ? 4 : 0);
5353     }
5354   else
5355     {
5356       operands[4] = gen_reg_rtx (SImode);
5357       operands[5] = gen_rtx_SUBREG (SImode, operands[3],
5358                                     WORDS_BIG_ENDIAN ? 0 : 4);
5359       operands[6] = gen_rtx_LSHIFTRT (SImode, operands[4], GEN_INT (31));
5360     }
5361 })
5362
5363 (define_expand "copysign<mode>3"
5364   [(set (match_dup 3)
5365         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))
5366    (set (match_dup 4)
5367         (neg:SFDF (abs:SFDF (match_dup 1))))
5368    (set (match_operand:SFDF 0 "gpc_reg_operand" "")
5369         (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand" "")
5370                                (match_dup 5))
5371                          (match_dup 3)
5372                          (match_dup 4)))]
5373   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5374    && ((TARGET_PPC_GFXOPT
5375         && !HONOR_NANS (<MODE>mode)
5376         && !HONOR_SIGNED_ZEROS (<MODE>mode))
5377        || TARGET_CMPB
5378        || VECTOR_UNIT_VSX_P (<MODE>mode))"
5379 {
5380   if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
5381     {
5382       emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
5383                                              operands[2]));
5384       DONE;
5385     }
5386
5387    operands[3] = gen_reg_rtx (<MODE>mode);
5388    operands[4] = gen_reg_rtx (<MODE>mode);
5389    operands[5] = CONST0_RTX (<MODE>mode);
5390   })
5391
5392 ;; Use an unspec rather providing an if-then-else in RTL, to prevent the
5393 ;; compiler from optimizing -0.0
5394 (define_insn "copysign<mode>3_fcpsgn"
5395   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5396         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5397                       (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")]
5398                      UNSPEC_COPYSIGN))]
5399   "TARGET_<MODE>_FPR && TARGET_CMPB"
5400   "@
5401    fcpsgn %0,%2,%1
5402    xscpsgn<Fvsx> %x0,%x2,%x1"
5403   [(set_attr "type" "fp")])
5404
5405 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5406 ;; fsel instruction and some auxiliary computations.  Then we just have a
5407 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5408 ;; combine.
5409 ;; For MIN, MAX on non-VSX machines, and conditional move all of the time, we
5410 ;; use DEFINE_EXPAND's that involve a fsel instruction and some auxiliary
5411 ;; computations.  Then we just have a single DEFINE_INSN for fsel and the
5412 ;; define_splits to make them if made by combine.  On VSX machines we have the
5413 ;; min/max instructions.
5414 ;;
5415 ;; On VSX, we only check for TARGET_VSX instead of checking for a vsx/p8 vector
5416 ;; to allow either DF/SF to use only traditional registers.
5417
5418 (define_expand "smax<mode>3"
5419   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5420         (if_then_else:SFDF (ge (match_operand:SFDF 1 "gpc_reg_operand" "")
5421                                (match_operand:SFDF 2 "gpc_reg_operand" ""))
5422                            (match_dup 1)
5423                            (match_dup 2)))]
5424   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math"
5425 {
5426   rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
5427   DONE;
5428 })
5429
5430 (define_insn "*smax<mode>3_vsx"
5431   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5432         (smax:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5433                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5434   "TARGET_<MODE>_FPR && TARGET_VSX"
5435   "xsmaxdp %x0,%x1,%x2"
5436   [(set_attr "type" "fp")])
5437
5438 (define_expand "smin<mode>3"
5439   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5440         (if_then_else:SFDF (ge (match_operand:SFDF 1 "gpc_reg_operand" "")
5441                                (match_operand:SFDF 2 "gpc_reg_operand" ""))
5442                            (match_dup 2)
5443                            (match_dup 1)))]
5444   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math"
5445 {
5446   rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
5447   DONE;
5448 })
5449
5450 (define_insn "*smin<mode>3_vsx"
5451   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5452         (smin:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5453                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5454   "TARGET_<MODE>_FPR && TARGET_VSX"
5455   "xsmindp %x0,%x1,%x2"
5456   [(set_attr "type" "fp")])
5457
5458 (define_split
5459   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5460         (match_operator:SFDF 3 "min_max_operator"
5461          [(match_operand:SFDF 1 "gpc_reg_operand" "")
5462           (match_operand:SFDF 2 "gpc_reg_operand" "")]))]
5463   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math
5464    && !TARGET_VSX"
5465   [(const_int 0)]
5466 {
5467   rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), operands[1],
5468                       operands[2]);
5469   DONE;
5470 })
5471
5472 (define_split
5473   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5474         (match_operator:SF 3 "min_max_operator"
5475          [(match_operand:SF 1 "gpc_reg_operand" "")
5476           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5477   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
5478    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
5479   [(const_int 0)]
5480   "
5481 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5482                       operands[1], operands[2]);
5483   DONE;
5484 }")
5485
5486 (define_expand "mov<mode>cc"
5487    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
5488          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
5489                            (match_operand:GPR 2 "gpc_reg_operand" "")
5490                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
5491   "TARGET_ISEL<sel>"
5492   "
5493 {
5494   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5495     DONE;
5496   else
5497     FAIL;
5498 }")
5499
5500 ;; We use the BASE_REGS for the isel input operands because, if rA is
5501 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5502 ;; because we may switch the operands and rB may end up being rA.
5503 ;;
5504 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5505 ;; leave out the mode in operand 4 and use one pattern, but reload can
5506 ;; change the mode underneath our feet and then gets confused trying
5507 ;; to reload the value.
5508 (define_insn "isel_signed_<mode>"
5509   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5510         (if_then_else:GPR
5511          (match_operator 1 "scc_comparison_operator"
5512                          [(match_operand:CC 4 "cc_reg_operand" "y,y")
5513                           (const_int 0)])
5514          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
5515          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5516   "TARGET_ISEL<sel>"
5517   "*
5518 { return output_isel (operands); }"
5519   [(set_attr "type" "isel")
5520    (set_attr "length" "4")])
5521
5522 (define_insn "isel_unsigned_<mode>"
5523   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5524         (if_then_else:GPR
5525          (match_operator 1 "scc_comparison_operator"
5526                          [(match_operand:CCUNS 4 "cc_reg_operand" "y,y")
5527                           (const_int 0)])
5528          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
5529          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5530   "TARGET_ISEL<sel>"
5531   "*
5532 { return output_isel (operands); }"
5533   [(set_attr "type" "isel")
5534    (set_attr "length" "4")])
5535
5536 ;; These patterns can be useful for combine; they let combine know that
5537 ;; isel can handle reversed comparisons so long as the operands are
5538 ;; registers.
5539
5540 (define_insn "*isel_reversed_signed_<mode>"
5541   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5542         (if_then_else:GPR
5543          (match_operator 1 "scc_rev_comparison_operator"
5544                          [(match_operand:CC 4 "cc_reg_operand" "y")
5545                           (const_int 0)])
5546          (match_operand:GPR 2 "gpc_reg_operand" "b")
5547          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
5548   "TARGET_ISEL<sel>"
5549   "*
5550 { return output_isel (operands); }"
5551   [(set_attr "type" "isel")
5552    (set_attr "length" "4")])
5553
5554 (define_insn "*isel_reversed_unsigned_<mode>"
5555   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5556         (if_then_else:GPR
5557          (match_operator 1 "scc_rev_comparison_operator"
5558                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5559                           (const_int 0)])
5560          (match_operand:GPR 2 "gpc_reg_operand" "b")
5561          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
5562   "TARGET_ISEL<sel>"
5563   "*
5564 { return output_isel (operands); }"
5565   [(set_attr "type" "isel")
5566    (set_attr "length" "4")])
5567
5568 (define_expand "movsfcc"
5569    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5570          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5571                           (match_operand:SF 2 "gpc_reg_operand" "")
5572                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5573   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5574   "
5575 {
5576   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5577     DONE;
5578   else
5579     FAIL;
5580 }")
5581
5582 (define_insn "*fselsfsf4"
5583   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5584         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5585                              (match_operand:SF 4 "zero_fp_constant" "F"))
5586                          (match_operand:SF 2 "gpc_reg_operand" "f")
5587                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5588   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5589   "fsel %0,%1,%2,%3"
5590   [(set_attr "type" "fp")])
5591
5592 (define_insn "*fseldfsf4"
5593   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5594         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5595                              (match_operand:DF 4 "zero_fp_constant" "F"))
5596                          (match_operand:SF 2 "gpc_reg_operand" "f")
5597                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5598   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5599   "fsel %0,%1,%2,%3"
5600   [(set_attr "type" "fp")])
5601
5602 ;; The conditional move instructions allow us to perform max and min
5603 ;; operations even when
5604
5605 (define_split
5606   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5607         (match_operator:DF 3 "min_max_operator"
5608          [(match_operand:DF 1 "gpc_reg_operand" "")
5609           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5610   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5611    && !flag_trapping_math"
5612   [(const_int 0)]
5613   "
5614 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5615                       operands[1], operands[2]);
5616   DONE;
5617 }")
5618
5619 (define_expand "movdfcc"
5620    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5621          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5622                           (match_operand:DF 2 "gpc_reg_operand" "")
5623                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5624   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5625   "
5626 {
5627   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5628     DONE;
5629   else
5630     FAIL;
5631 }")
5632
5633 (define_insn "*fseldfdf4"
5634   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5635         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5636                              (match_operand:DF 4 "zero_fp_constant" "F"))
5637                          (match_operand:DF 2 "gpc_reg_operand" "d")
5638                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5639   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5640   "fsel %0,%1,%2,%3"
5641   [(set_attr "type" "fp")])
5642
5643 (define_insn "*fselsfdf4"
5644   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5645         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5646                              (match_operand:SF 4 "zero_fp_constant" "F"))
5647                          (match_operand:DF 2 "gpc_reg_operand" "d")
5648                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5649   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5650   "fsel %0,%1,%2,%3"
5651   [(set_attr "type" "fp")])
5652 \f
5653 ;; Conversions to and from floating-point.
5654
5655 ; We don't define lfiwax/lfiwzx with the normal definition, because we
5656 ; don't want to support putting SImode in FPR registers.
5657 (define_insn "lfiwax"
5658   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wm,!wm")
5659         (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r")]
5660                    UNSPEC_LFIWAX))]
5661   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX"
5662   "@
5663    lfiwax %0,%y1
5664    lxsiwax %x0,%y1
5665    mtvsrwa %x0,%1"
5666   [(set_attr "type" "fpload,fpload,mffgpr")])
5667
5668 ; This split must be run before register allocation because it allocates the
5669 ; memory slot that is needed to move values to/from the FPR.  We don't allocate
5670 ; it earlier to allow for the combiner to merge insns together where it might
5671 ; not be needed and also in case the insns are deleted as dead code.
5672
5673 (define_insn_and_split "floatsi<mode>2_lfiwax"
5674   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5675         (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5676    (clobber (match_scratch:DI 2 "=d"))]
5677   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5678    && <SI_CONVERT_FP> && can_create_pseudo_p ()"
5679   "#"
5680   ""
5681   [(pc)]
5682   "
5683 {
5684   rtx dest = operands[0];
5685   rtx src = operands[1];
5686   rtx tmp;
5687
5688   if (!MEM_P (src) && TARGET_POWERPC64
5689       && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
5690     tmp = convert_to_mode (DImode, src, false);
5691   else
5692     {
5693       tmp = operands[2];
5694       if (GET_CODE (tmp) == SCRATCH)
5695         tmp = gen_reg_rtx (DImode);
5696       if (MEM_P (src))
5697         {
5698           src = rs6000_address_for_fpconvert (src);
5699           emit_insn (gen_lfiwax (tmp, src));
5700         }
5701       else
5702         {
5703           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5704           emit_move_insn (stack, src);
5705           emit_insn (gen_lfiwax (tmp, stack));
5706         }
5707     }
5708   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5709   DONE;
5710 }"
5711   [(set_attr "length" "12")
5712    (set_attr "type" "fpload")])
5713
5714 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
5715   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5716         (float:SFDF
5717          (sign_extend:DI
5718           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5719    (clobber (match_scratch:DI 2 "=0,d"))]
5720   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5721    && <SI_CONVERT_FP>"
5722   "#"
5723   ""
5724   [(pc)]
5725   "
5726 {
5727   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5728   if (GET_CODE (operands[2]) == SCRATCH)
5729     operands[2] = gen_reg_rtx (DImode);
5730   emit_insn (gen_lfiwax (operands[2], operands[1]));
5731   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5732   DONE;
5733 }"
5734   [(set_attr "length" "8")
5735    (set_attr "type" "fpload")])
5736
5737 (define_insn "lfiwzx"
5738   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wm,!wm")
5739         (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r")]
5740                    UNSPEC_LFIWZX))]
5741   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX"
5742   "@
5743    lfiwzx %0,%y1
5744    lxsiwzx %x0,%y1
5745    mtvsrwz %x0,%1"
5746   [(set_attr "type" "fpload,fpload,mftgpr")])
5747
5748 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
5749   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5750         (unsigned_float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5751    (clobber (match_scratch:DI 2 "=d"))]
5752   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5753    && <SI_CONVERT_FP>"
5754   "#"
5755   ""
5756   [(pc)]
5757   "
5758 {
5759   rtx dest = operands[0];
5760   rtx src = operands[1];
5761   rtx tmp;
5762
5763   if (!MEM_P (src) && TARGET_POWERPC64
5764       && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
5765     tmp = convert_to_mode (DImode, src, true);
5766   else
5767     {
5768       tmp = operands[2];
5769       if (GET_CODE (tmp) == SCRATCH)
5770         tmp = gen_reg_rtx (DImode);
5771       if (MEM_P (src))
5772         {
5773           src = rs6000_address_for_fpconvert (src);
5774           emit_insn (gen_lfiwzx (tmp, src));
5775         }
5776       else
5777         {
5778           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5779           emit_move_insn (stack, src);
5780           emit_insn (gen_lfiwzx (tmp, stack));
5781         }
5782     }
5783   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5784   DONE;
5785 }"
5786   [(set_attr "length" "12")
5787    (set_attr "type" "fpload")])
5788
5789 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
5790   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5791         (unsigned_float:SFDF
5792          (zero_extend:DI
5793           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5794    (clobber (match_scratch:DI 2 "=0,d"))]
5795   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5796    && <SI_CONVERT_FP>"
5797   "#"
5798   ""
5799   [(pc)]
5800   "
5801 {
5802   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5803   if (GET_CODE (operands[2]) == SCRATCH)
5804     operands[2] = gen_reg_rtx (DImode);
5805   emit_insn (gen_lfiwzx (operands[2], operands[1]));
5806   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5807   DONE;
5808 }"
5809   [(set_attr "length" "8")
5810    (set_attr "type" "fpload")])
5811
5812 ; For each of these conversions, there is a define_expand, a define_insn
5813 ; with a '#' template, and a define_split (with C code).  The idea is
5814 ; to allow constant folding with the template of the define_insn,
5815 ; then to have the insns split later (between sched1 and final).
5816
5817 (define_expand "floatsidf2"
5818   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5819                    (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5820               (use (match_dup 2))
5821               (use (match_dup 3))
5822               (clobber (match_dup 4))
5823               (clobber (match_dup 5))
5824               (clobber (match_dup 6))])]
5825   "TARGET_HARD_FLOAT 
5826    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5827   "
5828 {
5829   if (TARGET_E500_DOUBLE)
5830     {
5831       if (!REG_P (operands[1]))
5832         operands[1] = force_reg (SImode, operands[1]);
5833       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5834       DONE;
5835     }
5836   else if (TARGET_LFIWAX && TARGET_FCFID)
5837     {
5838       emit_insn (gen_floatsidf2_lfiwax (operands[0], operands[1]));
5839       DONE;
5840     }
5841   else if (TARGET_FCFID)
5842     {
5843       rtx dreg = operands[1];
5844       if (!REG_P (dreg))
5845         dreg = force_reg (SImode, dreg);
5846       dreg = convert_to_mode (DImode, dreg, false);
5847       emit_insn (gen_floatdidf2 (operands[0], dreg));
5848       DONE;
5849     }
5850
5851   if (!REG_P (operands[1]))
5852     operands[1] = force_reg (SImode, operands[1]);
5853   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5854   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5855   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5856   operands[5] = gen_reg_rtx (DFmode);
5857   operands[6] = gen_reg_rtx (SImode);
5858 }")
5859
5860 (define_insn_and_split "*floatsidf2_internal"
5861   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5862         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5863    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5864    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5865    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5866    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
5867    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5868   "! TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5869   "#"
5870   ""
5871   [(pc)]
5872   "
5873 {
5874   rtx lowword, highword;
5875   gcc_assert (MEM_P (operands[4]));
5876   highword = adjust_address (operands[4], SImode, 0);
5877   lowword = adjust_address (operands[4], SImode, 4);
5878   if (! WORDS_BIG_ENDIAN)
5879     {
5880       rtx tmp;
5881       tmp = highword; highword = lowword; lowword = tmp;
5882     }
5883
5884   emit_insn (gen_xorsi3 (operands[6], operands[1],
5885                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5886   emit_move_insn (lowword, operands[6]);
5887   emit_move_insn (highword, operands[2]);
5888   emit_move_insn (operands[5], operands[4]);
5889   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5890   DONE;
5891 }"
5892   [(set_attr "length" "24")
5893    (set_attr "type" "fp")])
5894
5895 ;; If we don't have a direct conversion to single precision, don't enable this
5896 ;; conversion for 32-bit without fast math, because we don't have the insn to
5897 ;; generate the fixup swizzle to avoid double rounding problems.
5898 (define_expand "floatunssisf2"
5899   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5900         (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5901   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
5902    && (!TARGET_FPRS
5903        || (TARGET_FPRS
5904            && ((TARGET_FCFIDUS && TARGET_LFIWZX)
5905                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
5906                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
5907   "
5908 {
5909   if (!TARGET_FPRS)
5910     {
5911       if (!REG_P (operands[1]))
5912         operands[1] = force_reg (SImode, operands[1]);
5913     }
5914   else if (TARGET_LFIWZX && TARGET_FCFIDUS)
5915     {
5916       emit_insn (gen_floatunssisf2_lfiwzx (operands[0], operands[1]));
5917       DONE;
5918     }
5919   else
5920     {
5921       rtx dreg = operands[1];
5922       if (!REG_P (dreg))
5923         dreg = force_reg (SImode, dreg);
5924       dreg = convert_to_mode (DImode, dreg, true);
5925       emit_insn (gen_floatdisf2 (operands[0], dreg));
5926       DONE;
5927     }
5928 }")
5929
5930 (define_expand "floatunssidf2"
5931   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5932                    (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5933               (use (match_dup 2))
5934               (use (match_dup 3))
5935               (clobber (match_dup 4))
5936               (clobber (match_dup 5))])]
5937   "TARGET_HARD_FLOAT
5938    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5939   "
5940 {
5941   if (TARGET_E500_DOUBLE)
5942     {
5943       if (!REG_P (operands[1]))
5944         operands[1] = force_reg (SImode, operands[1]);
5945       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5946       DONE;
5947     }
5948   else if (TARGET_LFIWZX && TARGET_FCFID)
5949     {
5950       emit_insn (gen_floatunssidf2_lfiwzx (operands[0], operands[1]));
5951       DONE;
5952     }
5953   else if (TARGET_FCFID)
5954     {
5955       rtx dreg = operands[1];
5956       if (!REG_P (dreg))
5957         dreg = force_reg (SImode, dreg);
5958       dreg = convert_to_mode (DImode, dreg, true);
5959       emit_insn (gen_floatdidf2 (operands[0], dreg));
5960       DONE;
5961     }
5962
5963   if (!REG_P (operands[1]))
5964     operands[1] = force_reg (SImode, operands[1]);
5965   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5966   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5967   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5968   operands[5] = gen_reg_rtx (DFmode);
5969 }")
5970
5971 (define_insn_and_split "*floatunssidf2_internal"
5972   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5973         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5974    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5975    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5976    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5977    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
5978   "! TARGET_FCFIDU && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5979    && !(TARGET_FCFID && TARGET_POWERPC64)"
5980   "#"
5981   ""
5982   [(pc)]
5983   "
5984 {
5985   rtx lowword, highword;
5986   gcc_assert (MEM_P (operands[4]));
5987   highword = adjust_address (operands[4], SImode, 0);
5988   lowword = adjust_address (operands[4], SImode, 4);
5989   if (! WORDS_BIG_ENDIAN)
5990     {
5991       rtx tmp;
5992       tmp = highword; highword = lowword; lowword = tmp;
5993     }
5994
5995   emit_move_insn (lowword, operands[1]);
5996   emit_move_insn (highword, operands[2]);
5997   emit_move_insn (operands[5], operands[4]);
5998   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5999   DONE;
6000 }"
6001   [(set_attr "length" "20")
6002    (set_attr "type" "fp")])
6003
6004 (define_expand "fix_trunc<mode>si2"
6005   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6006         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6007   "TARGET_HARD_FLOAT && ((TARGET_FPRS && <TARGET_FLOAT>) || <E500_CONVERT>)"
6008   "
6009 {
6010   if (!<E500_CONVERT>)
6011     {
6012       rtx tmp, stack;
6013
6014       if (TARGET_STFIWX)
6015         emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6016       else
6017         {
6018           tmp = gen_reg_rtx (DImode);
6019           stack = rs6000_allocate_stack_temp (DImode, true, false);
6020           emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], operands[1],
6021                                                       tmp, stack));
6022         }
6023       DONE;
6024     }
6025 }")
6026
6027 ; Like the convert to float patterns, this insn must be split before
6028 ; register allocation so that it can allocate the memory slot if it
6029 ; needed
6030 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
6031   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6032         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6033    (clobber (match_scratch:DI 2 "=d"))]
6034   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6035    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
6036    && TARGET_STFIWX && can_create_pseudo_p ()"
6037   "#"
6038   ""
6039   [(pc)]
6040 {
6041   rtx dest = operands[0];
6042   rtx src = operands[1];
6043   rtx tmp = operands[2];
6044
6045   if (GET_CODE (tmp) == SCRATCH)
6046     tmp = gen_reg_rtx (DImode);
6047
6048   emit_insn (gen_fctiwz_<mode> (tmp, src));
6049   if (MEM_P (dest))
6050     {
6051       dest = rs6000_address_for_fpconvert (dest);
6052       emit_insn (gen_stfiwx (dest, tmp));
6053       DONE;
6054     }
6055   else if (TARGET_POWERPC64 && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
6056     {
6057       dest = gen_lowpart (DImode, dest);
6058       emit_move_insn (dest, tmp);
6059       DONE;
6060     }
6061   else
6062     {
6063       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6064       emit_insn (gen_stfiwx (stack, tmp));
6065       emit_move_insn (dest, stack);
6066       DONE;
6067     }
6068 }
6069   [(set_attr "length" "12")
6070    (set_attr "type" "fp")])
6071
6072 (define_insn_and_split "fix_trunc<mode>si2_internal"
6073   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,?r")
6074         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,<rreg>")))
6075    (clobber (match_operand:DI 2 "gpc_reg_operand" "=1,d"))
6076    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o,o"))]
6077   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6078   "#"
6079   ""
6080   [(pc)]
6081   "
6082 {
6083   rtx lowword;
6084   gcc_assert (MEM_P (operands[3]));
6085   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6086
6087   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
6088   emit_move_insn (operands[3], operands[2]);
6089   emit_move_insn (operands[0], lowword);
6090   DONE;
6091 }"
6092   [(set_attr "length" "16")
6093    (set_attr "type" "fp")])
6094
6095 (define_expand "fix_trunc<mode>di2"
6096   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6097         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6098   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6099    && TARGET_FCFID"
6100   "")
6101
6102 (define_insn "*fix_trunc<mode>di2_fctidz"
6103   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6104         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6105   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6106     && TARGET_FCFID && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6107   "fctidz %0,%1"
6108   [(set_attr "type" "fp")])
6109
6110 (define_expand "fixuns_trunc<mode>si2"
6111   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6112         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6113   "TARGET_HARD_FLOAT
6114    && ((TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ && TARGET_STFIWX)
6115        || <E500_CONVERT>)"
6116   "
6117 {
6118   if (!<E500_CONVERT>)
6119     {
6120       emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6121       DONE;
6122     }
6123 }")
6124
6125 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
6126   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6127         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6128    (clobber (match_scratch:DI 2 "=d"))]
6129   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
6130    && TARGET_STFIWX && can_create_pseudo_p ()"
6131   "#"
6132   ""
6133   [(pc)]
6134 {
6135   rtx dest = operands[0];
6136   rtx src = operands[1];
6137   rtx tmp = operands[2];
6138
6139   if (GET_CODE (tmp) == SCRATCH)
6140     tmp = gen_reg_rtx (DImode);
6141
6142   emit_insn (gen_fctiwuz_<mode> (tmp, src));
6143   if (MEM_P (dest))
6144     {
6145       dest = rs6000_address_for_fpconvert (dest);
6146       emit_insn (gen_stfiwx (dest, tmp));
6147       DONE;
6148     }
6149   else if (TARGET_POWERPC64 && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
6150     {
6151       dest = gen_lowpart (DImode, dest);
6152       emit_move_insn (dest, tmp);
6153       DONE;
6154     }
6155   else
6156     {
6157       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6158       emit_insn (gen_stfiwx (stack, tmp));
6159       emit_move_insn (dest, stack);
6160       DONE;
6161     }
6162 }
6163   [(set_attr "length" "12")
6164    (set_attr "type" "fp")])
6165
6166 (define_expand "fixuns_trunc<mode>di2"
6167   [(set (match_operand:DI 0 "register_operand" "")
6168         (unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
6169   "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
6170   "")
6171
6172 (define_insn "*fixuns_trunc<mode>di2_fctiduz"
6173   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6174         (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6175   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6176     && TARGET_FCTIDUZ && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6177   "fctiduz %0,%1"
6178   [(set_attr "type" "fp")])
6179
6180 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6181 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
6182 ; because the first makes it clear that operand 0 is not live
6183 ; before the instruction.
6184 (define_insn "fctiwz_<mode>"
6185   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6186         (unspec:DI [(fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))]
6187                    UNSPEC_FCTIWZ))]
6188   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6189   "fctiwz %0,%1"
6190   [(set_attr "type" "fp")])
6191
6192 (define_insn "fctiwuz_<mode>"
6193   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6194         (unspec:DI [(unsigned_fix:SI
6195                      (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>"))]
6196                    UNSPEC_FCTIWUZ))]
6197   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ"
6198   "fctiwuz %0,%1"
6199   [(set_attr "type" "fp")])
6200
6201 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
6202 ;; since the friz instruction does not truncate the value if the floating
6203 ;; point value is < LONG_MIN or > LONG_MAX.
6204 (define_insn "*friz"
6205   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6206         (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d"))))]
6207   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_FPRND
6208    && !VECTOR_UNIT_VSX_P (DFmode) && flag_unsafe_math_optimizations
6209    && !flag_trapping_math && TARGET_FRIZ"
6210   "friz %0,%1"
6211   [(set_attr "type" "fp")])
6212
6213 ;; Since FCTIWZ doesn't sign extend the upper bits, we have to do a store and a
6214 ;; load to properly sign extend the value, but at least doing a store, load
6215 ;; into a GPR to sign extend, a store from the GPR and a load back into the FPR
6216 ;; if we have 32-bit memory ops
6217 (define_insn_and_split "*round32<mode>2_fprs"
6218   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6219         (float:SFDF
6220          (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6221    (clobber (match_scratch:DI 2 "=d"))
6222    (clobber (match_scratch:DI 3 "=d"))]
6223   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6224    && <SI_CONVERT_FP> && TARGET_LFIWAX && TARGET_STFIWX && TARGET_FCFID
6225    && can_create_pseudo_p ()"
6226   "#"
6227   ""
6228   [(pc)]
6229 {
6230   rtx dest = operands[0];
6231   rtx src = operands[1];
6232   rtx tmp1 = operands[2];
6233   rtx tmp2 = operands[3];
6234   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6235
6236   if (GET_CODE (tmp1) == SCRATCH)
6237     tmp1 = gen_reg_rtx (DImode);
6238   if (GET_CODE (tmp2) == SCRATCH)
6239     tmp2 = gen_reg_rtx (DImode);
6240
6241   emit_insn (gen_fctiwz_<mode> (tmp1, src));
6242   emit_insn (gen_stfiwx (stack, tmp1));
6243   emit_insn (gen_lfiwax (tmp2, stack));
6244   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6245   DONE;
6246 }
6247   [(set_attr "type" "fpload")
6248    (set_attr "length" "16")])
6249
6250 (define_insn_and_split "*roundu32<mode>2_fprs"
6251   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6252         (unsigned_float:SFDF
6253          (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6254    (clobber (match_scratch:DI 2 "=d"))
6255    (clobber (match_scratch:DI 3 "=d"))]
6256   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6257    && TARGET_LFIWZX && TARGET_STFIWX && TARGET_FCFIDU
6258    && can_create_pseudo_p ()"
6259   "#"
6260   ""
6261   [(pc)]
6262 {
6263   rtx dest = operands[0];
6264   rtx src = operands[1];
6265   rtx tmp1 = operands[2];
6266   rtx tmp2 = operands[3];
6267   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6268
6269   if (GET_CODE (tmp1) == SCRATCH)
6270     tmp1 = gen_reg_rtx (DImode);
6271   if (GET_CODE (tmp2) == SCRATCH)
6272     tmp2 = gen_reg_rtx (DImode);
6273
6274   emit_insn (gen_fctiwuz_<mode> (tmp1, src));
6275   emit_insn (gen_stfiwx (stack, tmp1));
6276   emit_insn (gen_lfiwzx (tmp2, stack));
6277   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6278   DONE;
6279 }
6280   [(set_attr "type" "fpload")
6281    (set_attr "length" "16")])
6282
6283 ;; No VSX equivalent to fctid
6284 (define_insn "lrint<mode>di2"
6285   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6286         (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6287                    UNSPEC_FCTID))]
6288   "TARGET_<MODE>_FPR && TARGET_FPRND"
6289   "fctid %0,%1"
6290   [(set_attr "type" "fp")])
6291
6292 (define_insn "btrunc<mode>2"
6293   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6294         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6295                      UNSPEC_FRIZ))]
6296   "TARGET_<MODE>_FPR && TARGET_FPRND"
6297   "@
6298    friz %0,%1
6299    xsrdpiz %x0,%x1"
6300   [(set_attr "type" "fp")
6301    (set_attr "fp_type" "fp_addsub_<Fs>")])
6302
6303 (define_insn "ceil<mode>2"
6304   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6305         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6306                      UNSPEC_FRIP))]
6307   "TARGET_<MODE>_FPR && TARGET_FPRND"
6308   "@
6309    frip %0,%1
6310    xsrdpip %x0,%x1"
6311   [(set_attr "type" "fp")
6312    (set_attr "fp_type" "fp_addsub_<Fs>")])
6313
6314 (define_insn "floor<mode>2"
6315   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6316         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6317                      UNSPEC_FRIM))]
6318   "TARGET_<MODE>_FPR && TARGET_FPRND"
6319   "@
6320    frim %0,%1
6321    xsrdpim %x0,%x1"
6322   [(set_attr "type" "fp")
6323    (set_attr "fp_type" "fp_addsub_<Fs>")])
6324
6325 ;; No VSX equivalent to frin
6326 (define_insn "round<mode>2"
6327   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6328         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6329                      UNSPEC_FRIN))]
6330   "TARGET_<MODE>_FPR && TARGET_FPRND"
6331   "frin %0,%1"
6332   [(set_attr "type" "fp")
6333    (set_attr "fp_type" "fp_addsub_<Fs>")])
6334
6335 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6336 (define_insn "stfiwx"
6337   [(set (match_operand:SI 0 "memory_operand" "=Z")
6338         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
6339                    UNSPEC_STFIWX))]
6340   "TARGET_PPC_GFXOPT"
6341   "stfiwx %1,%y0"
6342   [(set_attr "type" "fpstore")])
6343
6344 ;; If we don't have a direct conversion to single precision, don't enable this
6345 ;; conversion for 32-bit without fast math, because we don't have the insn to
6346 ;; generate the fixup swizzle to avoid double rounding problems.
6347 (define_expand "floatsisf2"
6348   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6349         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
6350   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
6351    && (!TARGET_FPRS
6352        || (TARGET_FPRS
6353            && ((TARGET_FCFIDS && TARGET_LFIWAX)
6354                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
6355                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
6356   "
6357 {
6358   if (!TARGET_FPRS)
6359     {
6360       if (!REG_P (operands[1]))
6361         operands[1] = force_reg (SImode, operands[1]);
6362     }
6363   else if (TARGET_FCFIDS && TARGET_LFIWAX)
6364     {
6365       emit_insn (gen_floatsisf2_lfiwax (operands[0], operands[1]));
6366       DONE;
6367     }
6368   else if (TARGET_FCFID && TARGET_LFIWAX)
6369     {
6370       rtx dfreg = gen_reg_rtx (DFmode);
6371       emit_insn (gen_floatsidf2_lfiwax (dfreg, operands[1]));
6372       emit_insn (gen_truncdfsf2 (operands[0], dfreg));
6373       DONE;
6374     }
6375   else
6376     {
6377       rtx dreg = operands[1];
6378       if (!REG_P (dreg))
6379         dreg = force_reg (SImode, dreg);
6380       dreg = convert_to_mode (DImode, dreg, false);
6381       emit_insn (gen_floatdisf2 (operands[0], dreg));
6382       DONE;
6383     }
6384 }")
6385
6386 (define_expand "floatdidf2"
6387   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6388         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
6389   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
6390   "")
6391
6392 (define_insn "*floatdidf2_fpr"
6393   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6394         (float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6395   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6396    && !VECTOR_UNIT_VSX_P (DFmode)"
6397   "fcfid %0,%1"
6398   [(set_attr "type" "fp")])
6399
6400 ; Allow the combiner to merge source memory operands to the conversion so that
6401 ; the optimizer/register allocator doesn't try to load the value too early in a
6402 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
6403 ; hit.  We will split after reload to avoid the trip through the GPRs
6404
6405 (define_insn_and_split "*floatdidf2_mem"
6406   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6407         (float:DF (match_operand:DI 1 "memory_operand" "m")))
6408    (clobber (match_scratch:DI 2 "=d"))]
6409   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCFID"
6410   "#"
6411   "&& reload_completed"
6412   [(set (match_dup 2) (match_dup 1))
6413    (set (match_dup 0) (float:DF (match_dup 2)))]
6414   ""
6415   [(set_attr "length" "8")
6416    (set_attr "type" "fpload")])
6417
6418 (define_expand "floatunsdidf2"
6419   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6420         (unsigned_float:DF
6421          (match_operand:DI 1 "gpc_reg_operand" "")))]
6422   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
6423   "")
6424
6425 (define_insn "*floatunsdidf2_fcfidu"
6426   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6427         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6428   "TARGET_HARD_FLOAT && TARGET_FCFIDU && !VECTOR_UNIT_VSX_P (DFmode)"
6429   "fcfidu %0,%1"
6430   [(set_attr "type" "fp")
6431    (set_attr "length" "4")])
6432
6433 (define_insn_and_split "*floatunsdidf2_mem"
6434   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6435         (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m")))
6436    (clobber (match_scratch:DI 2 "=d"))]
6437   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
6438   "#"
6439   "&& reload_completed"
6440   [(set (match_dup 2) (match_dup 1))
6441    (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
6442   ""
6443   [(set_attr "length" "8")
6444    (set_attr "type" "fpload")])
6445
6446 (define_expand "floatdisf2"
6447   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6448         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6449   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6450    && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
6451   "
6452 {
6453   if (!TARGET_FCFIDS)
6454     {
6455       rtx val = operands[1];
6456       if (!flag_unsafe_math_optimizations)
6457         {
6458           rtx label = gen_label_rtx ();
6459           val = gen_reg_rtx (DImode);
6460           emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
6461           emit_label (label);
6462         }
6463       emit_insn (gen_floatdisf2_internal1 (operands[0], val));
6464       DONE;
6465     }
6466 }")
6467
6468 (define_insn "floatdisf2_fcfids"
6469   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6470         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6471   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6472    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
6473   "fcfids %0,%1"
6474   [(set_attr "type" "fp")])
6475
6476 (define_insn_and_split "*floatdisf2_mem"
6477   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6478         (float:SF (match_operand:DI 1 "memory_operand" "m")))
6479    (clobber (match_scratch:DI 2 "=f"))]
6480   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6481    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
6482   "#"
6483   "&& reload_completed"
6484   [(pc)]
6485   "
6486 {
6487   emit_move_insn (operands[2], operands[1]);
6488   emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
6489   DONE;
6490 }"
6491   [(set_attr "length" "8")])
6492
6493 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6494 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6495 ;; from double rounding.
6496 ;; Instead of creating a new cpu type for two FP operations, just use fp
6497 (define_insn_and_split "floatdisf2_internal1"
6498   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6499         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
6500    (clobber (match_scratch:DF 2 "=d"))]
6501   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6502   "#"
6503   "&& reload_completed"
6504   [(set (match_dup 2)
6505         (float:DF (match_dup 1)))
6506    (set (match_dup 0)
6507         (float_truncate:SF (match_dup 2)))]
6508   ""
6509   [(set_attr "length" "8")
6510    (set_attr "type" "fp")])
6511
6512 ;; Twiddles bits to avoid double rounding.
6513 ;; Bits that might be truncated when converting to DFmode are replaced
6514 ;; by a bit that won't be lost at that stage, but is below the SFmode
6515 ;; rounding position.
6516 (define_expand "floatdisf2_internal2"
6517   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6518                                    (const_int 53)))
6519    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6520                                                       (const_int 2047)))
6521               (clobber (scratch:CC))])
6522    (set (match_dup 3) (plus:DI (match_dup 3)
6523                                (const_int 1)))
6524    (set (match_dup 0) (plus:DI (match_dup 0)
6525                                (const_int 2047)))
6526    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6527                                      (const_int 2)))
6528    (set (match_dup 0) (ior:DI (match_dup 0)
6529                               (match_dup 1)))
6530    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6531                                          (const_int -2048)))
6532               (clobber (scratch:CC))])
6533    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6534                            (label_ref (match_operand:DI 2 "" ""))
6535                            (pc)))
6536    (set (match_dup 0) (match_dup 1))]
6537   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6538   "
6539 {
6540   operands[3] = gen_reg_rtx (DImode);
6541   operands[4] = gen_reg_rtx (CCUNSmode);
6542 }")
6543
6544 (define_expand "floatunsdisf2"
6545   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6546         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6547   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6548    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6549   "")
6550
6551 (define_insn "floatunsdisf2_fcfidus"
6552   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6553         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6554   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6555    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6556   "fcfidus %0,%1"
6557   [(set_attr "type" "fp")])
6558
6559 (define_insn_and_split "*floatunsdisf2_mem"
6560   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6561         (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m")))
6562    (clobber (match_scratch:DI 2 "=f"))]
6563   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6564    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6565   "#"
6566   "&& reload_completed"
6567   [(pc)]
6568   "
6569 {
6570   emit_move_insn (operands[2], operands[1]);
6571   emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
6572   DONE;
6573 }"
6574   [(set_attr "length" "8")
6575    (set_attr "type" "fpload")])
6576 \f
6577 ;; Define the TImode operations that can be done in a small number
6578 ;; of instructions.  The & constraints are to prevent the register
6579 ;; allocator from allocating registers that overlap with the inputs
6580 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6581 ;; also allow for the output being the same as one of the inputs.
6582
6583 (define_insn "addti3"
6584   [(set (match_operand:TI 0 "gpc_reg_operand" "=&r,&r,r,r")
6585         (plus:TI (match_operand:TI 1 "gpc_reg_operand" "%r,r,0,0")
6586                  (match_operand:TI 2 "reg_or_short_operand" "r,I,r,I")))]
6587   "TARGET_64BIT"
6588 {
6589   if (WORDS_BIG_ENDIAN)
6590     return (GET_CODE (operands[2])) != CONST_INT
6591             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6592             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6593   else
6594     return (GET_CODE (operands[2])) != CONST_INT
6595             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6596             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6597 }
6598   [(set_attr "type" "two")
6599    (set_attr "length" "8")])
6600
6601 (define_insn "subti3"
6602   [(set (match_operand:TI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6603         (minus:TI (match_operand:TI 1 "reg_or_short_operand" "r,I,0,r,I")
6604                   (match_operand:TI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6605   "TARGET_64BIT"
6606 {
6607   if (WORDS_BIG_ENDIAN)
6608     return (GET_CODE (operands[1]) != CONST_INT)
6609             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6610             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6611   else
6612     return (GET_CODE (operands[1]) != CONST_INT)
6613             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6614             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6615 }
6616   [(set_attr "type" "two")
6617    (set_attr "length" "8")])
6618
6619
6620 ;; Define the DImode operations that can be done in a small number
6621 ;; of instructions.  The & constraints are to prevent the register
6622 ;; allocator from allocating registers that overlap with the inputs
6623 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6624 ;; also allow for the output being the same as one of the inputs.
6625
6626 (define_insn "*adddi3_noppc64"
6627   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6628         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6629                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6630   "! TARGET_POWERPC64"
6631   "*
6632 {
6633   if (WORDS_BIG_ENDIAN)
6634     return (GET_CODE (operands[2])) != CONST_INT
6635             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6636             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6637   else
6638     return (GET_CODE (operands[2])) != CONST_INT
6639             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6640             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6641 }"
6642   [(set_attr "type" "two")
6643    (set_attr "length" "8")])
6644
6645 (define_insn "*subdi3_noppc64"
6646   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6647         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6648                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6649   "! TARGET_POWERPC64"
6650   "*
6651 {
6652   if (WORDS_BIG_ENDIAN)
6653     return (GET_CODE (operands[1]) != CONST_INT)
6654             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6655             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6656   else
6657     return (GET_CODE (operands[1]) != CONST_INT)
6658             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6659             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6660 }"
6661   [(set_attr "type" "two")
6662    (set_attr "length" "8")])
6663
6664 (define_insn "*negdi2_noppc64"
6665   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6666         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6667   "! TARGET_POWERPC64"
6668   "*
6669 {
6670   return (WORDS_BIG_ENDIAN)
6671     ? \"subfic %L0,%L1,0\;subfze %0,%1\"
6672     : \"subfic %0,%1,0\;subfze %L0,%L1\";
6673 }"
6674   [(set_attr "type" "two")
6675    (set_attr "length" "8")])
6676
6677 (define_insn "mulsidi3"
6678   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6679         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6680                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6681   "! TARGET_POWERPC64"
6682 {
6683   return (WORDS_BIG_ENDIAN)
6684     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6685     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6686 }
6687   [(set_attr "type" "mul")
6688    (set_attr "length" "8")])
6689
6690 (define_split
6691   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6692         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6693                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6694   "! TARGET_POWERPC64 && reload_completed"
6695   [(set (match_dup 3)
6696         (truncate:SI
6697          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6698                                (sign_extend:DI (match_dup 2)))
6699                       (const_int 32))))
6700    (set (match_dup 4)
6701         (mult:SI (match_dup 1)
6702                  (match_dup 2)))]
6703   "
6704 {
6705   int endian = (WORDS_BIG_ENDIAN == 0);
6706   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6707   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6708 }")
6709
6710 (define_insn "umulsidi3"
6711   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6712         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6713                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6714   "! TARGET_POWERPC64"
6715   "*
6716 {
6717   return (WORDS_BIG_ENDIAN)
6718     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6719     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6720 }"
6721   [(set_attr "type" "mul")
6722    (set_attr "length" "8")])
6723
6724 (define_split
6725   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6726         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6727                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6728   "! TARGET_POWERPC64 && reload_completed"
6729   [(set (match_dup 3)
6730         (truncate:SI
6731          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6732                                (zero_extend:DI (match_dup 2)))
6733                       (const_int 32))))
6734    (set (match_dup 4)
6735         (mult:SI (match_dup 1)
6736                  (match_dup 2)))]
6737   "
6738 {
6739   int endian = (WORDS_BIG_ENDIAN == 0);
6740   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6741   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6742 }")
6743
6744 (define_insn "smulsi3_highpart"
6745   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6746         (truncate:SI
6747          (lshiftrt:DI (mult:DI (sign_extend:DI
6748                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6749                                (sign_extend:DI
6750                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6751                       (const_int 32))))]
6752   ""
6753   "mulhw %0,%1,%2"
6754   [(set_attr "type" "mul")])
6755
6756 (define_insn "umulsi3_highpart"
6757   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6758         (truncate:SI
6759          (lshiftrt:DI (mult:DI (zero_extend:DI
6760                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6761                                (zero_extend:DI
6762                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6763                       (const_int 32))))]
6764   ""
6765   "mulhwu %0,%1,%2"
6766   [(set_attr "type" "mul")])
6767
6768 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6769 ;; just handle shifts by constants.
6770 (define_insn "ashrdi3_no_power"
6771   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6772         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6773                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6774   "!TARGET_POWERPC64"
6775   "*
6776 {
6777   switch (which_alternative)
6778     {
6779     default:
6780       gcc_unreachable ();
6781     case 0:
6782       if (WORDS_BIG_ENDIAN)
6783         return \"srawi %0,%1,31\;srawi %L0,%1,%h2\";
6784       else
6785         return \"srawi %L0,%L1,31\;srawi %0,%L1,%h2\";
6786     case 1:
6787       if (WORDS_BIG_ENDIAN)
6788         return \"srwi %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;srawi %0,%1,%h2\";
6789       else
6790         return \"srwi %0,%1,%h2\;insrwi %0,%L1,%h2,0\;srawi %L0,%L1,%h2\";
6791     }
6792 }"
6793   [(set_attr "type" "two,three")
6794    (set_attr "length" "8,12")])
6795
6796 (define_insn "*ashrdisi3_noppc64be"
6797   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6798         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6799                                 (const_int 32)) 4))]
6800   "TARGET_32BIT && !TARGET_POWERPC64 && WORDS_BIG_ENDIAN"
6801   "*
6802 {
6803   if (REGNO (operands[0]) == REGNO (operands[1]))
6804     return \"\";
6805   else
6806     return \"mr %0,%1\";
6807 }"
6808    [(set_attr "length" "4")])
6809
6810 \f
6811 ;; PowerPC64 DImode operations.
6812
6813 (define_insn "muldi3"
6814   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6815         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6816                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6817   "TARGET_POWERPC64"
6818   "@
6819    mulld %0,%1,%2
6820    mulli %0,%1,%2"
6821    [(set_attr "type" "mul")
6822     (set (attr "size")
6823       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6824                 (const_string "8")
6825              (match_operand:SI 2 "short_cint_operand" "")
6826                 (const_string "16")]
6827         (const_string "64")))])
6828
6829 (define_insn "*muldi3_internal1"
6830   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6831         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6832                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6833                     (const_int 0)))
6834    (clobber (match_scratch:DI 3 "=r,r"))]
6835   "TARGET_POWERPC64"
6836   "@
6837    mulld. %3,%1,%2
6838    #"
6839   [(set_attr "type" "mul")
6840    (set_attr "size" "64")
6841    (set_attr "dot" "yes")
6842    (set_attr "length" "4,8")])
6843
6844 (define_split
6845   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6846         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6847                              (match_operand:DI 2 "gpc_reg_operand" ""))
6848                     (const_int 0)))
6849    (clobber (match_scratch:DI 3 ""))]
6850   "TARGET_POWERPC64 && reload_completed"
6851   [(set (match_dup 3)
6852         (mult:DI (match_dup 1) (match_dup 2)))
6853    (set (match_dup 0)
6854         (compare:CC (match_dup 3)
6855                     (const_int 0)))]
6856   "")
6857
6858 (define_insn "*muldi3_internal2"
6859   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6860         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6861                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6862                     (const_int 0)))
6863    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6864         (mult:DI (match_dup 1) (match_dup 2)))]
6865   "TARGET_POWERPC64"
6866   "@
6867    mulld. %0,%1,%2
6868    #"
6869   [(set_attr "type" "mul")
6870    (set_attr "size" "64")
6871    (set_attr "dot" "yes")
6872    (set_attr "length" "4,8")])
6873
6874 (define_split
6875   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6876         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6877                              (match_operand:DI 2 "gpc_reg_operand" ""))
6878                     (const_int 0)))
6879    (set (match_operand:DI 0 "gpc_reg_operand" "")
6880         (mult:DI (match_dup 1) (match_dup 2)))]
6881   "TARGET_POWERPC64 && reload_completed"
6882   [(set (match_dup 0)
6883         (mult:DI (match_dup 1) (match_dup 2)))
6884    (set (match_dup 3)
6885         (compare:CC (match_dup 0)
6886                     (const_int 0)))]
6887   "")
6888
6889 (define_insn "smuldi3_highpart"
6890   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6891         (truncate:DI
6892          (lshiftrt:TI (mult:TI (sign_extend:TI
6893                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6894                                (sign_extend:TI
6895                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6896                       (const_int 64))))]
6897   "TARGET_POWERPC64"
6898   "mulhd %0,%1,%2"
6899   [(set_attr "type" "mul")
6900    (set_attr "size" "64")])
6901
6902 (define_insn "umuldi3_highpart"
6903   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6904         (truncate:DI
6905          (lshiftrt:TI (mult:TI (zero_extend:TI
6906                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6907                                (zero_extend:TI
6908                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6909                       (const_int 64))))]
6910   "TARGET_POWERPC64"
6911   "mulhdu %0,%1,%2"
6912   [(set_attr "type" "mul")
6913    (set_attr "size" "64")])
6914
6915 (define_expand "mulditi3"
6916   [(set (match_operand:TI 0 "gpc_reg_operand")
6917         (mult:TI (sign_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6918                  (sign_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6919   "TARGET_POWERPC64"
6920 {
6921   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6922   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6923   emit_insn (gen_smuldi3_highpart (h, operands[1], operands[2]));
6924   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6925   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6926   DONE;
6927 })
6928
6929 (define_expand "umulditi3"
6930   [(set (match_operand:TI 0 "gpc_reg_operand")
6931         (mult:TI (zero_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6932                  (zero_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6933   "TARGET_POWERPC64"
6934 {
6935   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6936   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6937   emit_insn (gen_umuldi3_highpart (h, operands[1], operands[2]));
6938   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6939   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6940   DONE;
6941 })
6942
6943 (define_insn "rotldi3"
6944   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6945         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6946                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
6947   "TARGET_POWERPC64"
6948   "@
6949    rldcl %0,%1,%2,0
6950    rldicl %0,%1,%H2,0"
6951   [(set_attr "type" "shift,integer")
6952    (set_attr "var_shift" "yes,no")])
6953
6954 (define_insn "*rotldi3_internal2"
6955   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6956         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6957                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6958                     (const_int 0)))
6959    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6960   "TARGET_64BIT"
6961   "@
6962    rldcl. %3,%1,%2,0
6963    rldicl. %3,%1,%H2,0
6964    #
6965    #"
6966   [(set_attr "type" "shift")
6967    (set_attr "var_shift" "yes,no,yes,no")
6968    (set_attr "dot" "yes")
6969    (set_attr "length" "4,4,8,8")])
6970
6971 (define_split
6972   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6973         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6974                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6975                     (const_int 0)))
6976    (clobber (match_scratch:DI 3 ""))]
6977   "TARGET_POWERPC64 && reload_completed"
6978   [(set (match_dup 3)
6979         (rotate:DI (match_dup 1) (match_dup 2)))
6980    (set (match_dup 0)
6981         (compare:CC (match_dup 3)
6982                     (const_int 0)))]
6983   "")
6984
6985 (define_insn "*rotldi3_internal3"
6986   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6987         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6988                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6989                     (const_int 0)))
6990    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6991         (rotate:DI (match_dup 1) (match_dup 2)))]
6992   "TARGET_64BIT"
6993   "@
6994    rldcl. %0,%1,%2,0
6995    rldicl. %0,%1,%H2,0
6996    #
6997    #"
6998   [(set_attr "type" "shift")
6999    (set_attr "var_shift" "yes,no,yes,no")
7000    (set_attr "dot" "yes")
7001    (set_attr "length" "4,4,8,8")])
7002
7003 (define_split
7004   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7005         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7006                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7007                     (const_int 0)))
7008    (set (match_operand:DI 0 "gpc_reg_operand" "")
7009         (rotate:DI (match_dup 1) (match_dup 2)))]
7010   "TARGET_POWERPC64 && reload_completed"
7011   [(set (match_dup 0)
7012         (rotate:DI (match_dup 1) (match_dup 2)))
7013    (set (match_dup 3)
7014         (compare:CC (match_dup 0)
7015                     (const_int 0)))]
7016   "")
7017
7018 (define_insn "*rotldi3_internal4"
7019   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7020         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7021                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
7022                 (match_operand:DI 3 "mask64_operand" "n,n")))]
7023   "TARGET_POWERPC64"
7024   "@
7025    rldc%B3 %0,%1,%2,%S3
7026    rldic%B3 %0,%1,%H2,%S3"
7027   [(set_attr "type" "shift,integer")
7028    (set_attr "var_shift" "yes,no")])
7029
7030 (define_insn "*rotldi3_internal5"
7031   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7032         (compare:CC (and:DI
7033                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7034                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7035                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7036                     (const_int 0)))
7037    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
7038   "TARGET_64BIT"
7039   "@
7040    rldc%B3. %4,%1,%2,%S3
7041    rldic%B3. %4,%1,%H2,%S3
7042    #
7043    #"
7044   [(set_attr "type" "shift")
7045    (set_attr "var_shift" "yes,no,yes,no")
7046    (set_attr "dot" "yes")
7047    (set_attr "length" "4,4,8,8")])
7048
7049 (define_split
7050   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7051         (compare:CC (and:DI
7052                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7053                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7054                      (match_operand:DI 3 "mask64_operand" ""))
7055                     (const_int 0)))
7056    (clobber (match_scratch:DI 4 ""))]
7057   "TARGET_POWERPC64 && reload_completed"
7058   [(set (match_dup 4)
7059         (and:DI (rotate:DI (match_dup 1)
7060                                 (match_dup 2))
7061                      (match_dup 3)))
7062    (set (match_dup 0)
7063         (compare:CC (match_dup 4)
7064                     (const_int 0)))]
7065   "")
7066
7067 (define_insn "*rotldi3_internal6"
7068   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
7069         (compare:CC (and:DI
7070                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7071                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7072                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7073                     (const_int 0)))
7074    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7075         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7076   "TARGET_64BIT"
7077   "@
7078    rldc%B3. %0,%1,%2,%S3
7079    rldic%B3. %0,%1,%H2,%S3
7080    #
7081    #"
7082   [(set_attr "type" "shift")
7083    (set_attr "var_shift" "yes,no,yes,no")
7084    (set_attr "dot" "yes")
7085    (set_attr "length" "4,4,8,8")])
7086
7087 (define_split
7088   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7089         (compare:CC (and:DI
7090                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7091                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7092                      (match_operand:DI 3 "mask64_operand" ""))
7093                     (const_int 0)))
7094    (set (match_operand:DI 0 "gpc_reg_operand" "")
7095         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7096   "TARGET_POWERPC64 && reload_completed"
7097   [(set (match_dup 0)
7098         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
7099    (set (match_dup 4)
7100         (compare:CC (match_dup 0)
7101                     (const_int 0)))]
7102   "")
7103
7104 (define_insn "*rotldi3_internal7le"
7105   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7106         (zero_extend:DI
7107          (subreg:QI
7108           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7109                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7110   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7111   "@
7112    rldcl %0,%1,%2,56
7113    rldicl %0,%1,%H2,56"
7114   [(set_attr "type" "shift,integer")
7115    (set_attr "var_shift" "yes,no")])
7116
7117 (define_insn "*rotldi3_internal7be"
7118   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7119         (zero_extend:DI
7120          (subreg:QI
7121           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7122                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 7)))]
7123   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7124   "@
7125    rldcl %0,%1,%2,56
7126    rldicl %0,%1,%H2,56"
7127   [(set_attr "type" "shift,integer")
7128    (set_attr "var_shift" "yes,no")])
7129
7130 (define_insn "*rotldi3_internal8le"
7131   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7132         (compare:CC (zero_extend:DI
7133                      (subreg:QI
7134                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7135                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7136                     (const_int 0)))
7137    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7138   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7139   "@
7140    rldcl. %3,%1,%2,56
7141    rldicl. %3,%1,%H2,56
7142    #
7143    #"
7144   [(set_attr "type" "shift")
7145    (set_attr "var_shift" "yes,no,yes,no")
7146    (set_attr "dot" "yes")
7147    (set_attr "length" "4,4,8,8")])
7148
7149 (define_insn "*rotldi3_internal8be"
7150   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7151         (compare:CC (zero_extend:DI
7152                      (subreg:QI
7153                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7154                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 7))
7155                     (const_int 0)))
7156    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7157   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7158   "@
7159    rldcl. %3,%1,%2,56
7160    rldicl. %3,%1,%H2,56
7161    #
7162    #"
7163   [(set_attr "type" "shift")
7164    (set_attr "var_shift" "yes,no,yes,no")
7165    (set_attr "dot" "yes")
7166    (set_attr "length" "4,4,8,8")])
7167
7168 (define_split
7169   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7170         (compare:CC (zero_extend:DI
7171                      (subreg:QI
7172                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7173                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7174                     (const_int 0)))
7175    (clobber (match_scratch:DI 3 ""))]
7176   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7177   [(set (match_dup 3)
7178         (zero_extend:DI (subreg:QI
7179                       (rotate:DI (match_dup 1)
7180                                  (match_dup 2)) 0)))
7181    (set (match_dup 0)
7182         (compare:CC (match_dup 3)
7183                     (const_int 0)))]
7184   "")
7185
7186 (define_split
7187   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7188         (compare:CC (zero_extend:DI
7189                      (subreg:QI
7190                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7191                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 7))
7192                     (const_int 0)))
7193    (clobber (match_scratch:DI 3 ""))]
7194   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7195   [(set (match_dup 3)
7196         (zero_extend:DI (subreg:QI
7197                       (rotate:DI (match_dup 1)
7198                                  (match_dup 2)) 7)))
7199    (set (match_dup 0)
7200         (compare:CC (match_dup 3)
7201                     (const_int 0)))]
7202   "")
7203
7204 (define_insn "*rotldi3_internal9le"
7205   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7206         (compare:CC (zero_extend:DI
7207                      (subreg:QI
7208                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7209                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7210                     (const_int 0)))
7211    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7212         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7213   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7214   "@
7215    rldcl. %0,%1,%2,56
7216    rldicl. %0,%1,%H2,56
7217    #
7218    #"
7219   [(set_attr "type" "shift")
7220    (set_attr "var_shift" "yes,no,yes,no")
7221    (set_attr "dot" "yes")
7222    (set_attr "length" "4,4,8,8")])
7223
7224 (define_insn "*rotldi3_internal9be"
7225   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7226         (compare:CC (zero_extend:DI
7227                      (subreg:QI
7228                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7229                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 7))
7230                     (const_int 0)))
7231    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7232         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))]
7233   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7234   "@
7235    rldcl. %0,%1,%2,56
7236    rldicl. %0,%1,%H2,56
7237    #
7238    #"
7239   [(set_attr "type" "shift")
7240    (set_attr "var_shift" "yes,no,yes,no")
7241    (set_attr "dot" "yes")
7242    (set_attr "length" "4,4,8,8")])
7243
7244 (define_split
7245   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7246         (compare:CC (zero_extend:DI
7247                      (subreg:QI
7248                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7249                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7250                     (const_int 0)))
7251    (set (match_operand:DI 0 "gpc_reg_operand" "")
7252         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7253   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7254   [(set (match_dup 0)
7255         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7256    (set (match_dup 3)
7257         (compare:CC (match_dup 0)
7258                     (const_int 0)))]
7259   "")
7260
7261 (define_split
7262   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7263         (compare:CC (zero_extend:DI
7264                      (subreg:QI
7265                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7266                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 7))
7267                     (const_int 0)))
7268    (set (match_operand:DI 0 "gpc_reg_operand" "")
7269         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))]
7270   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7271   [(set (match_dup 0)
7272         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))
7273    (set (match_dup 3)
7274         (compare:CC (match_dup 0)
7275                     (const_int 0)))]
7276   "")
7277
7278 (define_insn "*rotldi3_internal10le"
7279   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7280         (zero_extend:DI
7281          (subreg:HI
7282           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7283                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7284   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7285   "@
7286    rldcl %0,%1,%2,48
7287    rldicl %0,%1,%H2,48"
7288   [(set_attr "type" "shift,integer")
7289    (set_attr "var_shift" "yes,no")])
7290
7291 (define_insn "*rotldi3_internal10be"
7292   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7293         (zero_extend:DI
7294          (subreg:HI
7295           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7296                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 6)))]
7297   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7298   "@
7299    rldcl %0,%1,%2,48
7300    rldicl %0,%1,%H2,48"
7301   [(set_attr "type" "shift,integer")
7302    (set_attr "var_shift" "yes,no")])
7303
7304 (define_insn "*rotldi3_internal11le"
7305   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7306         (compare:CC (zero_extend:DI
7307                      (subreg:HI
7308                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7309                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7310                     (const_int 0)))
7311    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7312   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7313   "@
7314    rldcl. %3,%1,%2,48
7315    rldicl. %3,%1,%H2,48
7316    #
7317    #"
7318   [(set_attr "type" "shift")
7319    (set_attr "var_shift" "yes,no,yes,no")
7320    (set_attr "dot" "yes")
7321    (set_attr "length" "4,4,8,8")])
7322
7323 (define_insn "*rotldi3_internal11be"
7324   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7325         (compare:CC (zero_extend:DI
7326                      (subreg:HI
7327                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7328                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 6))
7329                     (const_int 0)))
7330    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7331   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7332   "@
7333    rldcl. %3,%1,%2,48
7334    rldicl. %3,%1,%H2,48
7335    #
7336    #"
7337   [(set_attr "type" "shift")
7338    (set_attr "var_shift" "yes,no,yes,no")
7339    (set_attr "dot" "yes")
7340    (set_attr "length" "4,4,8,8")])
7341
7342 (define_split
7343   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7344         (compare:CC (zero_extend:DI
7345                      (subreg:HI
7346                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7347                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7348                     (const_int 0)))
7349    (clobber (match_scratch:DI 3 ""))]
7350   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7351   [(set (match_dup 3)
7352         (zero_extend:DI (subreg:HI
7353                       (rotate:DI (match_dup 1)
7354                                  (match_dup 2)) 0)))
7355    (set (match_dup 0)
7356         (compare:CC (match_dup 3)
7357                     (const_int 0)))]
7358   "")
7359
7360 (define_split
7361   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7362         (compare:CC (zero_extend:DI
7363                      (subreg:HI
7364                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7365                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 6))
7366                     (const_int 0)))
7367    (clobber (match_scratch:DI 3 ""))]
7368   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7369   [(set (match_dup 3)
7370         (zero_extend:DI (subreg:HI
7371                       (rotate:DI (match_dup 1)
7372                                  (match_dup 2)) 6)))
7373    (set (match_dup 0)
7374         (compare:CC (match_dup 3)
7375                     (const_int 0)))]
7376   "")
7377
7378 (define_insn "*rotldi3_internal12le"
7379   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7380         (compare:CC (zero_extend:DI
7381                      (subreg:HI
7382                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7383                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7384                     (const_int 0)))
7385    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7386         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7387   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7388   "@
7389    rldcl. %0,%1,%2,48
7390    rldicl. %0,%1,%H2,48
7391    #
7392    #"
7393   [(set_attr "type" "shift")
7394    (set_attr "var_shift" "yes,no,yes,no")
7395    (set_attr "dot" "yes")
7396    (set_attr "length" "4,4,8,8")])
7397
7398 (define_insn "*rotldi3_internal12be"
7399   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7400         (compare:CC (zero_extend:DI
7401                      (subreg:HI
7402                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7403                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 6))
7404                     (const_int 0)))
7405    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7406         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))]
7407   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7408   "@
7409    rldcl. %0,%1,%2,48
7410    rldicl. %0,%1,%H2,48
7411    #
7412    #"
7413   [(set_attr "type" "shift")
7414    (set_attr "var_shift" "yes,no,yes,no")
7415    (set_attr "dot" "yes")
7416    (set_attr "length" "4,4,8,8")])
7417
7418 (define_split
7419   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7420         (compare:CC (zero_extend:DI
7421                      (subreg:HI
7422                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7423                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7424                     (const_int 0)))
7425    (set (match_operand:DI 0 "gpc_reg_operand" "")
7426         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7427   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7428   [(set (match_dup 0)
7429         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7430    (set (match_dup 3)
7431         (compare:CC (match_dup 0)
7432                     (const_int 0)))]
7433   "")
7434
7435 (define_split
7436   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7437         (compare:CC (zero_extend:DI
7438                      (subreg:HI
7439                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7440                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 6))
7441                     (const_int 0)))
7442    (set (match_operand:DI 0 "gpc_reg_operand" "")
7443         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))]
7444   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7445   [(set (match_dup 0)
7446         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))
7447    (set (match_dup 3)
7448         (compare:CC (match_dup 0)
7449                     (const_int 0)))]
7450   "")
7451
7452 (define_insn "*rotldi3_internal13le"
7453   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7454         (zero_extend:DI
7455          (subreg:SI
7456           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7457                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7458   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7459   "@
7460    rldcl %0,%1,%2,32
7461    rldicl %0,%1,%H2,32"
7462   [(set_attr "type" "shift,integer")
7463    (set_attr "var_shift" "yes,no")])
7464
7465 (define_insn "*rotldi3_internal13be"
7466   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7467         (zero_extend:DI
7468          (subreg:SI
7469           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7470                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 4)))]
7471   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7472   "@
7473    rldcl %0,%1,%2,32
7474    rldicl %0,%1,%H2,32"
7475   [(set_attr "type" "shift,integer")
7476    (set_attr "var_shift" "yes,no")])
7477
7478 (define_insn "*rotldi3_internal14le"
7479   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7480         (compare:CC (zero_extend:DI
7481                      (subreg:SI
7482                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7483                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7484                     (const_int 0)))
7485    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7486   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7487   "@
7488    rldcl. %3,%1,%2,32
7489    rldicl. %3,%1,%H2,32
7490    #
7491    #"
7492   [(set_attr "type" "shift")
7493    (set_attr "var_shift" "yes,no,yes,no")
7494    (set_attr "dot" "yes")
7495    (set_attr "length" "4,4,8,8")])
7496
7497 (define_insn "*rotldi3_internal14be"
7498   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7499         (compare:CC (zero_extend:DI
7500                      (subreg:SI
7501                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7502                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 4))
7503                     (const_int 0)))
7504    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7505   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7506   "@
7507    rldcl. %3,%1,%2,32
7508    rldicl. %3,%1,%H2,32
7509    #
7510    #"
7511   [(set_attr "type" "shift")
7512    (set_attr "var_shift" "yes,no,yes,no")
7513    (set_attr "dot" "yes")
7514    (set_attr "length" "4,4,8,8")])
7515
7516 (define_split
7517   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7518         (compare:CC (zero_extend:DI
7519                      (subreg:SI
7520                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7521                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7522                     (const_int 0)))
7523    (clobber (match_scratch:DI 3 ""))]
7524   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7525   [(set (match_dup 3)
7526         (zero_extend:DI (subreg:SI
7527                       (rotate:DI (match_dup 1)
7528                                  (match_dup 2)) 0)))
7529    (set (match_dup 0)
7530         (compare:CC (match_dup 3)
7531                     (const_int 0)))]
7532   "")
7533
7534 (define_split
7535   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7536         (compare:CC (zero_extend:DI
7537                      (subreg:SI
7538                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7539                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 4))
7540                     (const_int 0)))
7541    (clobber (match_scratch:DI 3 ""))]
7542   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7543   [(set (match_dup 3)
7544         (zero_extend:DI (subreg:SI
7545                       (rotate:DI (match_dup 1)
7546                                  (match_dup 2)) 4)))
7547    (set (match_dup 0)
7548         (compare:CC (match_dup 3)
7549                     (const_int 0)))]
7550   "")
7551
7552 (define_insn "*rotldi3_internal15le"
7553   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7554         (compare:CC (zero_extend:DI
7555                      (subreg:SI
7556                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7557                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7558                     (const_int 0)))
7559    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7560         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7561   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7562   "@
7563    rldcl. %0,%1,%2,32
7564    rldicl. %0,%1,%H2,32
7565    #
7566    #"
7567   [(set_attr "type" "shift")
7568    (set_attr "var_shift" "yes,no,yes,no")
7569    (set_attr "dot" "yes")
7570    (set_attr "length" "4,4,8,8")])
7571
7572 (define_insn "*rotldi3_internal15be"
7573   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7574         (compare:CC (zero_extend:DI
7575                      (subreg:SI
7576                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7577                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 4))
7578                     (const_int 0)))
7579    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7580         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))]
7581   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7582   "@
7583    rldcl. %0,%1,%2,32
7584    rldicl. %0,%1,%H2,32
7585    #
7586    #"
7587   [(set_attr "type" "shift")
7588    (set_attr "var_shift" "yes,no,yes,no")
7589    (set_attr "dot" "yes")
7590    (set_attr "length" "4,4,8,8")])
7591
7592 (define_split
7593   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7594         (compare:CC (zero_extend:DI
7595                      (subreg:SI
7596                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7597                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7598                     (const_int 0)))
7599    (set (match_operand:DI 0 "gpc_reg_operand" "")
7600         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7601   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7602   [(set (match_dup 0)
7603         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7604    (set (match_dup 3)
7605         (compare:CC (match_dup 0)
7606                     (const_int 0)))]
7607   "")
7608
7609 (define_split
7610   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7611         (compare:CC (zero_extend:DI
7612                      (subreg:SI
7613                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7614                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 4))
7615                     (const_int 0)))
7616    (set (match_operand:DI 0 "gpc_reg_operand" "")
7617         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))]
7618   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7619   [(set (match_dup 0)
7620         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))
7621    (set (match_dup 3)
7622         (compare:CC (match_dup 0)
7623                     (const_int 0)))]
7624   "")
7625
7626 (define_expand "ashldi3"
7627   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7628         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7629                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
7630   "TARGET_POWERPC64"
7631   "")
7632
7633 (define_insn "*ashldi3_internal1"
7634   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7635         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7636                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7637   "TARGET_POWERPC64"
7638   "@
7639    sld %0,%1,%2
7640    sldi %0,%1,%H2"
7641   [(set_attr "type" "shift")
7642    (set_attr "var_shift" "yes,no")])
7643
7644 (define_insn "*ashldi3_internal2"
7645   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7646         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7647                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7648                     (const_int 0)))
7649    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7650   "TARGET_64BIT"
7651   "@
7652    sld. %3,%1,%2
7653    sldi. %3,%1,%H2
7654    #
7655    #"
7656   [(set_attr "type" "shift")
7657    (set_attr "var_shift" "yes,no,yes,no")
7658    (set_attr "dot" "yes")
7659    (set_attr "length" "4,4,8,8")])
7660
7661 (define_split
7662   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7663         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7664                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7665                     (const_int 0)))
7666    (clobber (match_scratch:DI 3 ""))]
7667   "TARGET_POWERPC64 && reload_completed"
7668   [(set (match_dup 3)
7669         (ashift:DI (match_dup 1) (match_dup 2)))
7670    (set (match_dup 0)
7671         (compare:CC (match_dup 3)
7672                     (const_int 0)))]
7673   "")
7674
7675 (define_insn "*ashldi3_internal3"
7676   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7677         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7678                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7679                     (const_int 0)))
7680    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7681         (ashift:DI (match_dup 1) (match_dup 2)))]
7682   "TARGET_64BIT"
7683   "@
7684    sld. %0,%1,%2
7685    sldi. %0,%1,%H2
7686    #
7687    #"
7688   [(set_attr "type" "shift")
7689    (set_attr "var_shift" "yes,no,yes,no")
7690    (set_attr "dot" "yes")
7691    (set_attr "length" "4,4,8,8")])
7692
7693 (define_split
7694   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7695         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7696                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7697                     (const_int 0)))
7698    (set (match_operand:DI 0 "gpc_reg_operand" "")
7699         (ashift:DI (match_dup 1) (match_dup 2)))]
7700   "TARGET_POWERPC64 && reload_completed"
7701   [(set (match_dup 0)
7702         (ashift:DI (match_dup 1) (match_dup 2)))
7703    (set (match_dup 3)
7704         (compare:CC (match_dup 0)
7705                     (const_int 0)))]
7706   "")
7707
7708 (define_insn "*ashldi3_internal4"
7709   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7710         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7711                            (match_operand:SI 2 "const_int_operand" "i"))
7712                 (match_operand:DI 3 "const_int_operand" "n")))]
7713   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7714   "rldic %0,%1,%H2,%W3")
7715
7716 (define_insn "ashldi3_internal5"
7717   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7718         (compare:CC
7719          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7720                             (match_operand:SI 2 "const_int_operand" "i,i"))
7721                  (match_operand:DI 3 "const_int_operand" "n,n"))
7722          (const_int 0)))
7723    (clobber (match_scratch:DI 4 "=r,r"))]
7724   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7725   "@
7726    rldic. %4,%1,%H2,%W3
7727    #"
7728   [(set_attr "type" "compare")
7729    (set_attr "length" "4,8")])
7730
7731 (define_split
7732   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7733         (compare:CC
7734          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7735                             (match_operand:SI 2 "const_int_operand" ""))
7736                  (match_operand:DI 3 "const_int_operand" ""))
7737          (const_int 0)))
7738    (clobber (match_scratch:DI 4 ""))]
7739   "TARGET_POWERPC64 && reload_completed
7740    && includes_rldic_lshift_p (operands[2], operands[3])"
7741   [(set (match_dup 4)
7742         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7743                 (match_dup 3)))
7744    (set (match_dup 0)
7745         (compare:CC (match_dup 4)
7746                     (const_int 0)))]
7747   "")
7748
7749 (define_insn "*ashldi3_internal6"
7750   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7751         (compare:CC
7752          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7753                             (match_operand:SI 2 "const_int_operand" "i,i"))
7754                     (match_operand:DI 3 "const_int_operand" "n,n"))
7755          (const_int 0)))
7756    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7757         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7758   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7759   "@
7760    rldic. %0,%1,%H2,%W3
7761    #"
7762   [(set_attr "type" "compare")
7763    (set_attr "length" "4,8")])
7764
7765 (define_split
7766   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7767         (compare:CC
7768          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7769                             (match_operand:SI 2 "const_int_operand" ""))
7770                  (match_operand:DI 3 "const_int_operand" ""))
7771          (const_int 0)))
7772    (set (match_operand:DI 0 "gpc_reg_operand" "")
7773         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7774   "TARGET_POWERPC64 && reload_completed
7775    && includes_rldic_lshift_p (operands[2], operands[3])"
7776   [(set (match_dup 0)
7777         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7778                 (match_dup 3)))
7779    (set (match_dup 4)
7780         (compare:CC (match_dup 0)
7781                     (const_int 0)))]
7782   "")
7783
7784 (define_insn "*ashldi3_internal7"
7785   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7786         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7787                            (match_operand:SI 2 "const_int_operand" "i"))
7788                 (match_operand:DI 3 "mask64_operand" "n")))]
7789   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7790   "rldicr %0,%1,%H2,%S3")
7791
7792 (define_insn "ashldi3_internal8"
7793   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7794         (compare:CC
7795          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7796                             (match_operand:SI 2 "const_int_operand" "i,i"))
7797                  (match_operand:DI 3 "mask64_operand" "n,n"))
7798          (const_int 0)))
7799    (clobber (match_scratch:DI 4 "=r,r"))]
7800   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7801   "@
7802    rldicr. %4,%1,%H2,%S3
7803    #"
7804   [(set_attr "type" "compare")
7805    (set_attr "length" "4,8")])
7806
7807 (define_split
7808   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7809         (compare:CC
7810          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7811                             (match_operand:SI 2 "const_int_operand" ""))
7812                  (match_operand:DI 3 "mask64_operand" ""))
7813          (const_int 0)))
7814    (clobber (match_scratch:DI 4 ""))]
7815   "TARGET_POWERPC64 && reload_completed
7816    && includes_rldicr_lshift_p (operands[2], operands[3])"
7817   [(set (match_dup 4)
7818         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7819                 (match_dup 3)))
7820    (set (match_dup 0)
7821         (compare:CC (match_dup 4)
7822                     (const_int 0)))]
7823   "")
7824
7825 (define_insn "*ashldi3_internal9"
7826   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7827         (compare:CC
7828          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7829                             (match_operand:SI 2 "const_int_operand" "i,i"))
7830                     (match_operand:DI 3 "mask64_operand" "n,n"))
7831          (const_int 0)))
7832    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7833         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7834   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7835   "@
7836    rldicr. %0,%1,%H2,%S3
7837    #"
7838   [(set_attr "type" "compare")
7839    (set_attr "length" "4,8")])
7840
7841 (define_split
7842   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7843         (compare:CC
7844          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7845                             (match_operand:SI 2 "const_int_operand" ""))
7846                  (match_operand:DI 3 "mask64_operand" ""))
7847          (const_int 0)))
7848    (set (match_operand:DI 0 "gpc_reg_operand" "")
7849         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7850   "TARGET_POWERPC64 && reload_completed
7851    && includes_rldicr_lshift_p (operands[2], operands[3])"
7852   [(set (match_dup 0)
7853         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7854                 (match_dup 3)))
7855    (set (match_dup 4)
7856         (compare:CC (match_dup 0)
7857                     (const_int 0)))]
7858   "")
7859
7860 (define_expand "lshrdi3"
7861   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7862         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7863                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7864   "TARGET_POWERPC64"
7865   "")
7866
7867 (define_insn "*lshrdi3_internal1"
7868   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7869         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7870                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7871   "TARGET_POWERPC64"
7872   "@
7873    srd %0,%1,%2
7874    srdi %0,%1,%H2"
7875   [(set_attr "type" "shift")
7876    (set_attr "var_shift" "yes,no")])
7877
7878 (define_insn "*lshrdi3_internal2"
7879   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7880         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7881                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7882                     (const_int 0)))
7883    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7884   "TARGET_64BIT "
7885   "@
7886    srd. %3,%1,%2
7887    srdi. %3,%1,%H2
7888    #
7889    #"
7890   [(set_attr "type" "shift")
7891    (set_attr "var_shift" "yes,no,yes,no")
7892    (set_attr "dot" "yes")
7893    (set_attr "length" "4,4,8,8")])
7894
7895 (define_split
7896   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7897         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7898                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7899                     (const_int 0)))
7900    (clobber (match_scratch:DI 3 ""))]
7901   "TARGET_POWERPC64 && reload_completed"
7902   [(set (match_dup 3)
7903         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7904    (set (match_dup 0)
7905         (compare:CC (match_dup 3)
7906                     (const_int 0)))]
7907   "")
7908
7909 (define_insn "*lshrdi3_internal3"
7910   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7911         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7912                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7913                     (const_int 0)))
7914    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7915         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7916   "TARGET_64BIT"
7917   "@
7918    srd. %0,%1,%2
7919    srdi. %0,%1,%H2
7920    #
7921    #"
7922   [(set_attr "type" "shift")
7923    (set_attr "var_shift" "yes,no,yes,no")
7924    (set_attr "dot" "yes")
7925    (set_attr "length" "4,4,8,8")])
7926
7927 (define_split
7928   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7929         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7930                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7931                     (const_int 0)))
7932    (set (match_operand:DI 0 "gpc_reg_operand" "")
7933         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7934   "TARGET_POWERPC64 && reload_completed"
7935   [(set (match_dup 0)
7936         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7937    (set (match_dup 3)
7938         (compare:CC (match_dup 0)
7939                     (const_int 0)))]
7940   "")
7941
7942 (define_expand "ashrdi3"
7943   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7944         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7945                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7946   ""
7947   "
7948 {
7949   if (TARGET_POWERPC64)
7950     ;
7951   else if (GET_CODE (operands[2]) == CONST_INT)
7952     {
7953       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7954       DONE;
7955     }
7956   else
7957     FAIL;
7958 }")
7959
7960 (define_insn "*ashrdi3_internal1"
7961   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7962         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7963                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7964   "TARGET_POWERPC64"
7965   "@
7966    srad %0,%1,%2
7967    sradi %0,%1,%H2"
7968   [(set_attr "type" "shift")
7969    (set_attr "var_shift" "yes,no")])
7970
7971 (define_insn "*ashrdi3_internal2"
7972   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7973         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7974                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7975                     (const_int 0)))
7976    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7977   "TARGET_64BIT"
7978   "@
7979    srad. %3,%1,%2
7980    sradi. %3,%1,%H2
7981    #
7982    #"
7983   [(set_attr "type" "shift")
7984    (set_attr "var_shift" "yes,no,yes,no")
7985    (set_attr "dot" "yes")
7986    (set_attr "length" "4,4,8,8")])
7987
7988 (define_split
7989   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7990         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7991                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7992                     (const_int 0)))
7993    (clobber (match_scratch:DI 3 ""))]
7994   "TARGET_POWERPC64 && reload_completed"
7995   [(set (match_dup 3)
7996         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7997    (set (match_dup 0)
7998         (compare:CC (match_dup 3)
7999                     (const_int 0)))]
8000   "")
8001
8002 (define_insn "*ashrdi3_internal3"
8003   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8004         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8005                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8006                     (const_int 0)))
8007    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8008         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8009   "TARGET_64BIT"
8010   "@
8011    srad. %0,%1,%2
8012    sradi. %0,%1,%H2
8013    #
8014    #"
8015   [(set_attr "type" "shift")
8016    (set_attr "var_shift" "yes,no,yes,no")
8017    (set_attr "dot" "yes")
8018    (set_attr "length" "4,4,8,8")])
8019
8020 (define_split
8021   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
8022         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8023                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8024                     (const_int 0)))
8025    (set (match_operand:DI 0 "gpc_reg_operand" "")
8026         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8027   "TARGET_POWERPC64 && reload_completed"
8028   [(set (match_dup 0)
8029         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8030    (set (match_dup 3)
8031         (compare:CC (match_dup 0)
8032                     (const_int 0)))]
8033   "")
8034
8035 (define_expand "anddi3"
8036   [(parallel
8037     [(set (match_operand:DI 0 "gpc_reg_operand" "")
8038           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8039                   (match_operand:DI 2 "reg_or_cint_operand" "")))
8040      (clobber (match_scratch:CC 3 ""))])]
8041   ""
8042 {
8043   if (!TARGET_POWERPC64)
8044     {
8045       rtx cc = gen_rtx_SCRATCH (CCmode);
8046       rs6000_split_logical (operands, AND, false, false, false, cc);
8047       DONE;
8048     }
8049   else if (!and64_2_operand (operands[2], DImode))
8050     operands[2] = force_reg (DImode, operands[2]);
8051 })
8052
8053 (define_insn "anddi3_mc"
8054   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
8055         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
8056                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
8057    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
8058   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
8059   "@
8060    and %0,%1,%2
8061    rldic%B2 %0,%1,0,%S2
8062    rlwinm %0,%1,0,%m2,%M2
8063    andi. %0,%1,%b2
8064    andis. %0,%1,%u2
8065    #"
8066   [(set_attr "type" "*,*,*,fast_compare,fast_compare,*")
8067    (set_attr "length" "4,4,4,4,4,8")])
8068
8069 (define_insn "anddi3_nomc"
8070   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8071         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
8072                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
8073    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
8074   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
8075   "@
8076    and %0,%1,%2
8077    rldic%B2 %0,%1,0,%S2
8078    rlwinm %0,%1,0,%m2,%M2
8079    #"
8080   [(set_attr "length" "4,4,4,8")])
8081
8082 (define_split
8083   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8084         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8085                 (match_operand:DI 2 "mask64_2_operand" "")))
8086    (clobber (match_scratch:CC 3 ""))]
8087   "TARGET_POWERPC64
8088     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8089     && !mask_operand (operands[2], DImode)
8090     && !mask64_operand (operands[2], DImode)"
8091   [(set (match_dup 0)
8092         (and:DI (rotate:DI (match_dup 1)
8093                            (match_dup 4))
8094                 (match_dup 5)))
8095    (set (match_dup 0)
8096         (and:DI (rotate:DI (match_dup 0)
8097                            (match_dup 6))
8098                 (match_dup 7)))]
8099 {
8100   build_mask64_2_operands (operands[2], &operands[4]);
8101 })
8102
8103 (define_insn "*anddi3_internal2_mc"
8104   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8105         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8106                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8107                     (const_int 0)))
8108    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
8109    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8110   "TARGET_64BIT && rs6000_gen_cell_microcode"
8111   "@
8112    and. %3,%1,%2
8113    rldic%B2. %3,%1,0,%S2
8114    rlwinm. %3,%1,0,%m2,%M2
8115    andi. %3,%1,%b2
8116    andis. %3,%1,%u2
8117    #
8118    #
8119    #
8120    #
8121    #
8122    #
8123    #"
8124   [(set_attr "type" "fast_compare,compare,shift,fast_compare,\
8125                      fast_compare,compare,compare,compare,compare,compare,\
8126                      compare,compare")
8127    (set_attr "dot" "yes")
8128    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8129
8130 (define_split
8131   [(set (match_operand:CC 0 "cc_reg_operand" "")
8132         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8133                             (match_operand:DI 2 "mask64_2_operand" ""))
8134                     (const_int 0)))
8135    (clobber (match_scratch:DI 3 ""))
8136    (clobber (match_scratch:CC 4 ""))]
8137   "TARGET_64BIT && reload_completed
8138     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8139     && !mask_operand (operands[2], DImode)
8140     && !mask64_operand (operands[2], DImode)"
8141   [(set (match_dup 3)
8142         (and:DI (rotate:DI (match_dup 1)
8143                            (match_dup 5))
8144                 (match_dup 6)))
8145    (parallel [(set (match_dup 0)
8146                    (compare:CC (and:DI (rotate:DI (match_dup 3)
8147                                                   (match_dup 7))
8148                                        (match_dup 8))
8149                                (const_int 0)))
8150               (clobber (match_dup 3))])]
8151   "
8152 {
8153   build_mask64_2_operands (operands[2], &operands[5]);
8154 }")
8155
8156 (define_insn "*anddi3_internal3_mc"
8157   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8158         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8159                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8160                     (const_int 0)))
8161    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
8162         (and:DI (match_dup 1) (match_dup 2)))
8163    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8164   "TARGET_64BIT && rs6000_gen_cell_microcode"
8165   "@
8166    and. %0,%1,%2
8167    rldic%B2. %0,%1,0,%S2
8168    rlwinm. %0,%1,0,%m2,%M2
8169    andi. %0,%1,%b2
8170    andis. %0,%1,%u2
8171    #
8172    #
8173    #
8174    #
8175    #
8176    #
8177    #"
8178   [(set_attr "type" "fast_compare,compare,shift,fast_compare,\
8179                      fast_compare,compare,compare,compare,compare,compare,\
8180                      compare,compare")
8181    (set_attr "dot" "yes")
8182    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8183
8184 (define_split
8185   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8186         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8187                             (match_operand:DI 2 "and64_2_operand" ""))
8188                     (const_int 0)))
8189    (set (match_operand:DI 0 "gpc_reg_operand" "")
8190         (and:DI (match_dup 1) (match_dup 2)))
8191    (clobber (match_scratch:CC 4 ""))]
8192   "TARGET_64BIT && reload_completed"
8193   [(parallel [(set (match_dup 0)
8194                     (and:DI (match_dup 1) (match_dup 2)))
8195                (clobber (match_dup 4))])
8196    (set (match_dup 3)
8197         (compare:CC (match_dup 0)
8198                     (const_int 0)))]
8199   "")
8200
8201 (define_split
8202   [(set (match_operand:CC 3 "cc_reg_operand" "")
8203         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8204                             (match_operand:DI 2 "mask64_2_operand" ""))
8205                     (const_int 0)))
8206    (set (match_operand:DI 0 "gpc_reg_operand" "")
8207         (and:DI (match_dup 1) (match_dup 2)))
8208    (clobber (match_scratch:CC 4 ""))]
8209   "TARGET_64BIT && reload_completed
8210     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8211     && !mask_operand (operands[2], DImode)
8212     && !mask64_operand (operands[2], DImode)"
8213   [(set (match_dup 0)
8214         (and:DI (rotate:DI (match_dup 1)
8215                            (match_dup 5))
8216                 (match_dup 6)))
8217    (parallel [(set (match_dup 3)
8218                    (compare:CC (and:DI (rotate:DI (match_dup 0)
8219                                                   (match_dup 7))
8220                                        (match_dup 8))
8221                                (const_int 0)))
8222               (set (match_dup 0)
8223                    (and:DI (rotate:DI (match_dup 0)
8224                                       (match_dup 7))
8225                            (match_dup 8)))])]
8226   "
8227 {
8228   build_mask64_2_operands (operands[2], &operands[5]);
8229 }")
8230
8231 (define_expand "iordi3"
8232   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8233         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
8234                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
8235   ""
8236 {
8237   if (!TARGET_POWERPC64)
8238     {
8239       rs6000_split_logical (operands, IOR, false, false, false, NULL_RTX);
8240       DONE;
8241     }
8242   else if (!reg_or_logical_cint_operand (operands[2], DImode))
8243     operands[2] = force_reg (DImode, operands[2]);
8244   else if (non_logical_cint_operand (operands[2], DImode))
8245     {
8246       HOST_WIDE_INT value;
8247       rtx tmp = ((!can_create_pseudo_p ()
8248                   || rtx_equal_p (operands[0], operands[1]))
8249                  ? operands[0] : gen_reg_rtx (DImode));
8250
8251       value = INTVAL (operands[2]);
8252       emit_insn (gen_iordi3 (tmp, operands[1],
8253                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8254
8255       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8256       DONE;
8257     }
8258 })
8259
8260 (define_expand "xordi3"
8261   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8262         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
8263                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
8264   ""
8265 {
8266   if (!TARGET_POWERPC64)
8267     {
8268       rs6000_split_logical (operands, XOR, false, false, false, NULL_RTX);
8269       DONE;
8270     }
8271   else if (!reg_or_logical_cint_operand (operands[2], DImode))
8272     operands[2] = force_reg (DImode, operands[2]);
8273   if (non_logical_cint_operand (operands[2], DImode))
8274     {
8275       HOST_WIDE_INT value;
8276       rtx tmp = ((!can_create_pseudo_p ()
8277                   || rtx_equal_p (operands[0], operands[1]))
8278                  ? operands[0] : gen_reg_rtx (DImode));
8279
8280       value = INTVAL (operands[2]);
8281       emit_insn (gen_xordi3 (tmp, operands[1],
8282                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8283
8284       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8285       DONE;
8286     }
8287 })
8288
8289 (define_insn "*booldi3_internal1"
8290   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
8291         (match_operator:DI 3 "boolean_or_operator"
8292          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
8293           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
8294   "TARGET_POWERPC64"
8295   "@
8296    %q3 %0,%1,%2
8297    %q3i %0,%1,%b2
8298    %q3is %0,%1,%u2")
8299
8300 (define_insn "*booldi3_internal2"
8301   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8302         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8303          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8304           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8305          (const_int 0)))
8306    (clobber (match_scratch:DI 3 "=r,r"))]
8307   "TARGET_64BIT"
8308   "@
8309    %q4. %3,%1,%2
8310    #"
8311   [(set_attr "type" "fast_compare,compare")
8312    (set_attr "length" "4,8")])
8313
8314 (define_split
8315   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8316         (compare:CC (match_operator:DI 4 "boolean_operator"
8317          [(match_operand:DI 1 "gpc_reg_operand" "")
8318           (match_operand:DI 2 "gpc_reg_operand" "")])
8319          (const_int 0)))
8320    (clobber (match_scratch:DI 3 ""))]
8321   "TARGET_POWERPC64 && reload_completed"
8322   [(set (match_dup 3) (match_dup 4))
8323    (set (match_dup 0)
8324         (compare:CC (match_dup 3)
8325                     (const_int 0)))]
8326   "")
8327
8328 (define_insn "*booldi3_internal3"
8329   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8330         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8331          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8332           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8333          (const_int 0)))
8334    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8335         (match_dup 4))]
8336   "TARGET_64BIT"
8337   "@
8338    %q4. %0,%1,%2
8339    #"
8340   [(set_attr "type" "fast_compare,compare")
8341    (set_attr "length" "4,8")])
8342
8343 (define_split
8344   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8345         (compare:CC (match_operator:DI 4 "boolean_operator"
8346          [(match_operand:DI 1 "gpc_reg_operand" "")
8347           (match_operand:DI 2 "gpc_reg_operand" "")])
8348          (const_int 0)))
8349    (set (match_operand:DI 0 "gpc_reg_operand" "")
8350         (match_dup 4))]
8351   "TARGET_POWERPC64 && reload_completed"
8352   [(set (match_dup 0) (match_dup 4))
8353    (set (match_dup 3)
8354         (compare:CC (match_dup 0)
8355                     (const_int 0)))]
8356   "")
8357
8358 ;; Split a logical operation that we can't do in one insn into two insns,
8359 ;; each of which does one 16-bit part.  This is used by combine.
8360
8361 (define_split
8362   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8363         (match_operator:DI 3 "boolean_or_operator"
8364          [(match_operand:DI 1 "gpc_reg_operand" "")
8365           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
8366   "TARGET_POWERPC64"
8367   [(set (match_dup 0) (match_dup 4))
8368    (set (match_dup 0) (match_dup 5))]
8369 "
8370 {
8371   rtx i3,i4;
8372
8373   i3 = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
8374   i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
8375   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8376                                 operands[1], i3);
8377   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8378                                 operands[0], i4);
8379 }")
8380
8381 (define_insn "*boolcdi3_internal1"
8382   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8383         (match_operator:DI 3 "boolean_operator"
8384          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8385           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
8386   "TARGET_POWERPC64"
8387   "%q3 %0,%2,%1")
8388
8389 (define_insn "*boolcdi3_internal2"
8390   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8391         (compare:CC (match_operator:DI 4 "boolean_operator"
8392          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8393           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8394          (const_int 0)))
8395    (clobber (match_scratch:DI 3 "=r,r"))]
8396   "TARGET_64BIT"
8397   "@
8398    %q4. %3,%2,%1
8399    #"
8400   [(set_attr "type" "fast_compare,compare")
8401    (set_attr "length" "4,8")])
8402
8403 (define_split
8404   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8405         (compare:CC (match_operator:DI 4 "boolean_operator"
8406          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8407           (match_operand:DI 2 "gpc_reg_operand" "")])
8408          (const_int 0)))
8409    (clobber (match_scratch:DI 3 ""))]
8410   "TARGET_POWERPC64 && reload_completed"
8411   [(set (match_dup 3) (match_dup 4))
8412    (set (match_dup 0)
8413         (compare:CC (match_dup 3)
8414                     (const_int 0)))]
8415   "")
8416
8417 (define_insn "*boolcdi3_internal3"
8418   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8419         (compare:CC (match_operator:DI 4 "boolean_operator"
8420          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8421           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8422          (const_int 0)))
8423    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8424         (match_dup 4))]
8425   "TARGET_64BIT"
8426   "@
8427    %q4. %0,%2,%1
8428    #"
8429   [(set_attr "type" "fast_compare,compare")
8430    (set_attr "length" "4,8")])
8431
8432 (define_split
8433   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8434         (compare:CC (match_operator:DI 4 "boolean_operator"
8435          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8436           (match_operand:DI 2 "gpc_reg_operand" "")])
8437          (const_int 0)))
8438    (set (match_operand:DI 0 "gpc_reg_operand" "")
8439         (match_dup 4))]
8440   "TARGET_POWERPC64 && reload_completed"
8441   [(set (match_dup 0) (match_dup 4))
8442    (set (match_dup 3)
8443         (compare:CC (match_dup 0)
8444                     (const_int 0)))]
8445   "")
8446
8447 (define_insn "*boolccdi3_internal1"
8448   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8449         (match_operator:DI 3 "boolean_operator"
8450          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8451           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
8452   "TARGET_POWERPC64"
8453   "%q3 %0,%1,%2")
8454
8455 (define_insn "*boolccdi3_internal2"
8456   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8457         (compare:CC (match_operator:DI 4 "boolean_operator"
8458          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8459           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8460          (const_int 0)))
8461    (clobber (match_scratch:DI 3 "=r,r"))]
8462   "TARGET_64BIT"
8463   "@
8464    %q4. %3,%1,%2
8465    #"
8466   [(set_attr "type" "fast_compare,compare")
8467    (set_attr "length" "4,8")])
8468
8469 (define_split
8470   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8471         (compare:CC (match_operator:DI 4 "boolean_operator"
8472          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8473           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8474          (const_int 0)))
8475    (clobber (match_scratch:DI 3 ""))]
8476   "TARGET_POWERPC64 && reload_completed"
8477   [(set (match_dup 3) (match_dup 4))
8478    (set (match_dup 0)
8479         (compare:CC (match_dup 3)
8480                     (const_int 0)))]
8481   "")
8482
8483 (define_insn "*boolccdi3_internal3"
8484   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8485         (compare:CC (match_operator:DI 4 "boolean_operator"
8486          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8487           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8488          (const_int 0)))
8489    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8490         (match_dup 4))]
8491   "TARGET_64BIT"
8492   "@
8493    %q4. %0,%1,%2
8494    #"
8495   [(set_attr "type" "fast_compare,compare")
8496    (set_attr "length" "4,8")])
8497
8498 (define_split
8499   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8500         (compare:CC (match_operator:DI 4 "boolean_operator"
8501          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8502           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8503          (const_int 0)))
8504    (set (match_operand:DI 0 "gpc_reg_operand" "")
8505         (match_dup 4))]
8506   "TARGET_POWERPC64 && reload_completed"
8507   [(set (match_dup 0) (match_dup 4))
8508    (set (match_dup 3)
8509         (compare:CC (match_dup 0)
8510                     (const_int 0)))]
8511   "")
8512
8513 ;; Eqv operation.
8514 (define_insn "*eqv<mode>3"
8515   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
8516         (not:GPR
8517          (xor:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
8518                   (match_operand:GPR 2 "gpc_reg_operand" "r"))))]
8519   ""
8520   "eqv %0,%1,%2"
8521   [(set_attr "type" "integer")
8522    (set_attr "length" "4")])
8523
8524 \f
8525 ;; 128-bit logical operations expanders
8526
8527 (define_expand "and<mode>3"
8528   [(parallel [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8529                    (and:BOOL_128
8530                     (match_operand:BOOL_128 1 "vlogical_operand" "")
8531                     (match_operand:BOOL_128 2 "vlogical_operand" "")))
8532               (clobber (match_scratch:CC 3 ""))])]
8533   ""
8534   "")
8535
8536 (define_expand "ior<mode>3"
8537   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8538         (ior:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8539                       (match_operand:BOOL_128 2 "vlogical_operand" "")))]
8540   ""
8541   "")
8542
8543 (define_expand "xor<mode>3"
8544   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8545         (xor:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8546                       (match_operand:BOOL_128 2 "vlogical_operand" "")))]
8547   ""
8548   "")
8549
8550 (define_expand "one_cmpl<mode>2"
8551   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8552         (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8553   ""
8554   "")
8555
8556 (define_expand "nor<mode>3"
8557   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8558         (and:BOOL_128
8559          (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" ""))
8560          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8561   ""
8562   "")
8563
8564 (define_expand "andc<mode>3"
8565   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8566         (and:BOOL_128
8567          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))
8568          (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8569   ""
8570   "")
8571
8572 ;; Power8 vector logical instructions.
8573 (define_expand "eqv<mode>3"
8574   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8575         (not:BOOL_128
8576          (xor:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8577                        (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8578   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8579   "")
8580
8581 ;; Rewrite nand into canonical form
8582 (define_expand "nand<mode>3"
8583   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8584         (ior:BOOL_128
8585          (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" ""))
8586          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8587   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8588   "")
8589
8590 ;; The canonical form is to have the negated element first, so we need to
8591 ;; reverse arguments.
8592 (define_expand "orc<mode>3"
8593   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8594         (ior:BOOL_128
8595          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))
8596          (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8597   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8598   "")
8599
8600 ;; 128-bit logical operations insns and split operations
8601 (define_insn_and_split "*and<mode>3_internal"
8602   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8603         (and:BOOL_128
8604          (match_operand:BOOL_128 1 "vlogical_operand" "%<BOOL_REGS_OP1>")
8605          (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>")))
8606    (clobber (match_scratch:CC 3 "<BOOL_REGS_AND_CR0>"))]
8607   ""
8608 {
8609   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8610     return "xxland %x0,%x1,%x2";
8611
8612   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8613     return "vand %0,%1,%2";
8614
8615   return "#";
8616 }
8617   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8618   [(const_int 0)]
8619 {
8620   rs6000_split_logical (operands, AND, false, false, false, operands[3]);
8621   DONE;
8622 }
8623   [(set (attr "type")
8624       (if_then_else
8625         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8626         (const_string "vecsimple")
8627         (const_string "integer")))
8628    (set (attr "length")
8629       (if_then_else
8630         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8631         (const_string "4")
8632         (if_then_else
8633          (match_test "TARGET_POWERPC64")
8634          (const_string "8")
8635          (const_string "16"))))])
8636
8637 ;; 128-bit IOR/XOR
8638 (define_insn_and_split "*bool<mode>3_internal"
8639   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8640         (match_operator:BOOL_128 3 "boolean_or_operator"
8641          [(match_operand:BOOL_128 1 "vlogical_operand" "%<BOOL_REGS_OP1>")
8642           (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>")]))]
8643   ""
8644 {
8645   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8646     return "xxl%q3 %x0,%x1,%x2";
8647
8648   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8649     return "v%q3 %0,%1,%2";
8650
8651   return "#";
8652 }
8653   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8654   [(const_int 0)]
8655 {
8656   rs6000_split_logical (operands, GET_CODE (operands[3]), false, false, false,
8657                         NULL_RTX);
8658   DONE;
8659 }
8660   [(set (attr "type")
8661       (if_then_else
8662         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8663         (const_string "vecsimple")
8664         (const_string "integer")))
8665    (set (attr "length")
8666       (if_then_else
8667         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8668         (const_string "4")
8669         (if_then_else
8670          (match_test "TARGET_POWERPC64")
8671          (const_string "8")
8672          (const_string "16"))))])
8673
8674 ;; 128-bit ANDC/ORC
8675 (define_insn_and_split "*boolc<mode>3_internal1"
8676   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8677         (match_operator:BOOL_128 3 "boolean_operator"
8678          [(not:BOOL_128
8679            (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP1>"))
8680           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP2>")]))]
8681   "TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND)"
8682 {
8683   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8684     return "xxl%q3 %x0,%x1,%x2";
8685
8686   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8687     return "v%q3 %0,%1,%2";
8688
8689   return "#";
8690 }
8691   "(TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND))
8692    && reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8693   [(const_int 0)]
8694 {
8695   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, false,
8696                         NULL_RTX);
8697   DONE;
8698 }
8699   [(set (attr "type")
8700       (if_then_else
8701         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8702         (const_string "vecsimple")
8703         (const_string "integer")))
8704    (set (attr "length")
8705       (if_then_else
8706         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8707         (const_string "4")
8708         (if_then_else
8709          (match_test "TARGET_POWERPC64")
8710          (const_string "8")
8711          (const_string "16"))))])
8712
8713 (define_insn_and_split "*boolc<mode>3_internal2"
8714   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8715         (match_operator:TI2 3 "boolean_operator"
8716          [(not:TI2
8717            (match_operand:TI2 1 "int_reg_operand" "r,0,r"))
8718           (match_operand:TI2 2 "int_reg_operand" "r,r,0")]))]
8719   "!TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8720   "#"
8721   "reload_completed && !TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8722   [(const_int 0)]
8723 {
8724   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, false,
8725                         NULL_RTX);
8726   DONE;
8727 }
8728   [(set_attr "type" "integer")
8729    (set (attr "length")
8730         (if_then_else
8731          (match_test "TARGET_POWERPC64")
8732          (const_string "8")
8733          (const_string "16")))])
8734
8735 ;; 128-bit NAND/NOR
8736 (define_insn_and_split "*boolcc<mode>3_internal1"
8737   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8738         (match_operator:BOOL_128 3 "boolean_operator"
8739          [(not:BOOL_128
8740            (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>"))
8741           (not:BOOL_128
8742            (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))]))]
8743   "TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND)"
8744 {
8745   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8746     return "xxl%q3 %x0,%x1,%x2";
8747
8748   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8749     return "v%q3 %0,%1,%2";
8750
8751   return "#";
8752 }
8753   "(TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND))
8754    && reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8755   [(const_int 0)]
8756 {
8757   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, true,
8758                         NULL_RTX);
8759   DONE;
8760 }
8761   [(set (attr "type")
8762       (if_then_else
8763         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8764         (const_string "vecsimple")
8765         (const_string "integer")))
8766    (set (attr "length")
8767       (if_then_else
8768         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8769         (const_string "4")
8770         (if_then_else
8771          (match_test "TARGET_POWERPC64")
8772          (const_string "8")
8773          (const_string "16"))))])
8774
8775 (define_insn_and_split "*boolcc<mode>3_internal2"
8776   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8777         (match_operator:TI2 3 "boolean_operator"
8778          [(not:TI2
8779            (match_operand:TI2 1 "int_reg_operand" "r,0,r"))
8780           (not:TI2
8781            (match_operand:TI2 2 "int_reg_operand" "r,r,0"))]))]
8782   "!TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8783   "#"
8784   "reload_completed && !TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8785   [(const_int 0)]
8786 {
8787   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, true,
8788                         NULL_RTX);
8789   DONE;
8790 }
8791   [(set_attr "type" "integer")
8792    (set (attr "length")
8793         (if_then_else
8794          (match_test "TARGET_POWERPC64")
8795          (const_string "8")
8796          (const_string "16")))])
8797
8798
8799 ;; 128-bit EQV
8800 (define_insn_and_split "*eqv<mode>3_internal1"
8801   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8802         (not:BOOL_128
8803          (xor:BOOL_128
8804           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>")
8805           (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))))]
8806   "TARGET_P8_VECTOR"
8807 {
8808   if (vsx_register_operand (operands[0], <MODE>mode))
8809     return "xxleqv %x0,%x1,%x2";
8810
8811   return "#";
8812 }
8813   "TARGET_P8_VECTOR && reload_completed
8814    && int_reg_operand (operands[0], <MODE>mode)"
8815   [(const_int 0)]
8816 {
8817   rs6000_split_logical (operands, XOR, true, false, false, NULL_RTX);
8818   DONE;
8819 }
8820   [(set (attr "type")
8821       (if_then_else
8822         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8823         (const_string "vecsimple")
8824         (const_string "integer")))
8825    (set (attr "length")
8826       (if_then_else
8827         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8828         (const_string "4")
8829         (if_then_else
8830          (match_test "TARGET_POWERPC64")
8831          (const_string "8")
8832          (const_string "16"))))])
8833
8834 (define_insn_and_split "*eqv<mode>3_internal2"
8835   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8836         (not:TI2
8837          (xor:TI2
8838           (match_operand:TI2 1 "int_reg_operand" "r,0,r")
8839           (match_operand:TI2 2 "int_reg_operand" "r,r,0"))))]
8840   "!TARGET_P8_VECTOR"
8841   "#"
8842   "reload_completed && !TARGET_P8_VECTOR"
8843   [(const_int 0)]
8844 {
8845   rs6000_split_logical (operands, XOR, true, false, false, NULL_RTX);
8846   DONE;
8847 }
8848   [(set_attr "type" "integer")
8849    (set (attr "length")
8850         (if_then_else
8851          (match_test "TARGET_POWERPC64")
8852          (const_string "8")
8853          (const_string "16")))])
8854
8855 ;; 128-bit one's complement
8856 (define_insn_and_split "*one_cmpl<mode>3_internal"
8857   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8858         (not:BOOL_128
8859           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_UNARY>")))]
8860   ""
8861 {
8862   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8863     return "xxlnor %x0,%x1,%x1";
8864
8865   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8866     return "vnor %0,%1,%1";
8867
8868   return "#";
8869 }
8870   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8871   [(const_int 0)]
8872 {
8873   rs6000_split_logical (operands, NOT, false, false, false, NULL_RTX);
8874   DONE;
8875 }
8876   [(set (attr "type")
8877       (if_then_else
8878         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8879         (const_string "vecsimple")
8880         (const_string "integer")))
8881    (set (attr "length")
8882       (if_then_else
8883         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8884         (const_string "4")
8885         (if_then_else
8886          (match_test "TARGET_POWERPC64")
8887          (const_string "8")
8888          (const_string "16"))))])
8889
8890 \f
8891 ;; Now define ways of moving data around.
8892
8893 ;; Set up a register with a value from the GOT table
8894
8895 (define_expand "movsi_got"
8896   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8897         (unspec:SI [(match_operand:SI 1 "got_operand" "")
8898                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
8899   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8900   "
8901 {
8902   if (GET_CODE (operands[1]) == CONST)
8903     {
8904       rtx offset = const0_rtx;
8905       HOST_WIDE_INT value;
8906
8907       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
8908       value = INTVAL (offset);
8909       if (value != 0)
8910         {
8911           rtx tmp = (!can_create_pseudo_p ()
8912                      ? operands[0]
8913                      : gen_reg_rtx (Pmode));
8914           emit_insn (gen_movsi_got (tmp, operands[1]));
8915           emit_insn (gen_addsi3 (operands[0], tmp, offset));
8916           DONE;
8917         }
8918     }
8919
8920   operands[2] = rs6000_got_register (operands[1]);
8921 }")
8922
8923 (define_insn "*movsi_got_internal"
8924   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8925         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8926                     (match_operand:SI 2 "gpc_reg_operand" "b")]
8927                    UNSPEC_MOVSI_GOT))]
8928   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8929   "lwz %0,%a1@got(%2)"
8930   [(set_attr "type" "load")])
8931
8932 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
8933 ;; didn't get allocated to a hard register.
8934 (define_split
8935   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8936         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8937                     (match_operand:SI 2 "memory_operand" "")]
8938                    UNSPEC_MOVSI_GOT))]
8939   "DEFAULT_ABI == ABI_V4
8940     && flag_pic == 1
8941     && (reload_in_progress || reload_completed)"
8942   [(set (match_dup 0) (match_dup 2))
8943    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
8944                                  UNSPEC_MOVSI_GOT))]
8945   "")
8946
8947 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8948 ;; do the load 16-bits at a time.  We could do this by loading from memory,
8949 ;; and this is even supposed to be faster, but it is simpler not to get
8950 ;; integers in the TOC.
8951 (define_insn "movsi_low"
8952   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8953         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8954                            (match_operand 2 "" ""))))]
8955   "TARGET_MACHO && ! TARGET_64BIT"
8956   "lwz %0,lo16(%2)(%1)"
8957   [(set_attr "type" "load")
8958    (set_attr "length" "4")])
8959
8960 (define_insn "*movsi_internal1"
8961   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h")
8962         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0"))]
8963   "!TARGET_SINGLE_FPU &&
8964    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8965   "@
8966    mr %0,%1
8967    la %0,%a1
8968    lwz%U1%X1 %0,%1
8969    stw%U0%X0 %1,%0
8970    li %0,%1
8971    lis %0,%v1
8972    #
8973    mf%1 %0
8974    mt%0 %1
8975    mt%0 %1
8976    nop"
8977   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*")
8978    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4")])
8979
8980 (define_insn "*movsi_internal1_single"
8981   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h,m,*f")
8982         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0,f,m"))]
8983   "TARGET_SINGLE_FPU &&
8984    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8985   "@
8986    mr %0,%1
8987    la %0,%a1
8988    lwz%U1%X1 %0,%1
8989    stw%U0%X0 %1,%0
8990    li %0,%1
8991    lis %0,%v1
8992    #
8993    mf%1 %0
8994    mt%0 %1
8995    mt%0 %1
8996    nop
8997    stfs%U0%X0 %1,%0
8998    lfs%U1%X1 %0,%1"
8999   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*,fpstore,fpload")
9000    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
9001
9002 ;; Split a load of a large constant into the appropriate two-insn
9003 ;; sequence.
9004
9005 (define_split
9006   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9007         (match_operand:SI 1 "const_int_operand" ""))]
9008   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
9009    && (INTVAL (operands[1]) & 0xffff) != 0"
9010   [(set (match_dup 0)
9011         (match_dup 2))
9012    (set (match_dup 0)
9013         (ior:SI (match_dup 0)
9014                 (match_dup 3)))]
9015   "
9016 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
9017
9018   if (tem == operands[0])
9019     DONE;
9020   else
9021     FAIL;
9022 }")
9023
9024 (define_insn "*mov<mode>_internal2"
9025   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
9026         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
9027                     (const_int 0)))
9028    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
9029   ""
9030   "@
9031    cmp<wd>i %2,%0,0
9032    mr. %0,%1
9033    #"
9034   [(set_attr "type" "cmp,fast_compare,cmp")
9035    (set_attr "length" "4,4,8")])
9036
9037 (define_split
9038   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
9039         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
9040                     (const_int 0)))
9041    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
9042   "reload_completed"
9043   [(set (match_dup 0) (match_dup 1))
9044    (set (match_dup 2)
9045         (compare:CC (match_dup 0)
9046                     (const_int 0)))]
9047   "")
9048 \f
9049 (define_insn "*movhi_internal"
9050   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
9051         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,0"))]
9052   "gpc_reg_operand (operands[0], HImode)
9053    || gpc_reg_operand (operands[1], HImode)"
9054   "@
9055    mr %0,%1
9056    lhz%U1%X1 %0,%1
9057    sth%U0%X0 %1,%0
9058    li %0,%w1
9059    mf%1 %0
9060    mt%0 %1
9061    nop"
9062   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
9063
9064 (define_expand "mov<mode>"
9065   [(set (match_operand:INT 0 "general_operand" "")
9066         (match_operand:INT 1 "any_operand" ""))]
9067   ""
9068   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9069
9070 (define_insn "*movqi_internal"
9071   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
9072         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,0"))]
9073   "gpc_reg_operand (operands[0], QImode)
9074    || gpc_reg_operand (operands[1], QImode)"
9075   "@
9076    mr %0,%1
9077    lbz%U1%X1 %0,%1
9078    stb%U0%X0 %1,%0
9079    li %0,%1
9080    mf%1 %0
9081    mt%0 %1
9082    nop"
9083   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
9084 \f
9085 ;; Here is how to move condition codes around.  When we store CC data in
9086 ;; an integer register or memory, we store just the high-order 4 bits.
9087 ;; This lets us not shift in the most common case of CR0.
9088 (define_expand "movcc"
9089   [(set (match_operand:CC 0 "nonimmediate_operand" "")
9090         (match_operand:CC 1 "nonimmediate_operand" ""))]
9091   ""
9092   "")
9093
9094 (define_insn "*movcc_internal1"
9095   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,cl,r,m")
9096         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,m,r"))]
9097   "register_operand (operands[0], CCmode)
9098    || register_operand (operands[1], CCmode)"
9099   "@
9100    mcrf %0,%1
9101    mtcrf 128,%1
9102    rlwinm %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;rlwinm %1,%1,%f0,0xffffffff
9103    crxor %0,%0,%0
9104    mfcr %0%Q1
9105    mfcr %0%Q1\;rlwinm %0,%0,%f1,0xf0000000
9106    mr %0,%1
9107    li %0,%1
9108    mf%1 %0
9109    mt%0 %1
9110    lwz%U1%X1 %0,%1
9111    stw%U0%X0 %1,%0"
9112   [(set (attr "type")
9113      (cond [(eq_attr "alternative" "0,3")
9114                 (const_string "cr_logical")
9115             (eq_attr "alternative" "1,2")
9116                 (const_string "mtcr")
9117             (eq_attr "alternative" "6,7")
9118                 (const_string "integer")
9119             (eq_attr "alternative" "8")
9120                 (const_string "mfjmpr")
9121             (eq_attr "alternative" "9")
9122                 (const_string "mtjmpr")
9123             (eq_attr "alternative" "10")
9124                 (const_string "load")
9125             (eq_attr "alternative" "11")
9126                 (const_string "store")
9127             (match_test "TARGET_MFCRF")
9128                 (const_string "mfcrf")
9129            ]
9130         (const_string "mfcr")))
9131    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4")])
9132 \f
9133 ;; For floating-point, we normally deal with the floating-point registers
9134 ;; unless -msoft-float is used.  The sole exception is that parameter passing
9135 ;; can produce floating-point values in fixed-point registers.  Unless the
9136 ;; value is a simple constant or already in memory, we deal with this by
9137 ;; allocating memory and copying the value explicitly via that memory location.
9138
9139 ;; Move 32-bit binary/decimal floating point
9140 (define_expand "mov<mode>"
9141   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "")
9142         (match_operand:FMOVE32 1 "any_operand" ""))]
9143   "<fmove_ok>"
9144   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9145
9146 (define_split
9147   [(set (match_operand:FMOVE32 0 "gpc_reg_operand" "")
9148         (match_operand:FMOVE32 1 "const_double_operand" ""))]
9149   "reload_completed
9150    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9151        || (GET_CODE (operands[0]) == SUBREG
9152            && GET_CODE (SUBREG_REG (operands[0])) == REG
9153            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9154   [(set (match_dup 2) (match_dup 3))]
9155   "
9156 {
9157   long l;
9158   REAL_VALUE_TYPE rv;
9159
9160   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9161   <real_value_to_target> (rv, l);
9162
9163   if (! TARGET_POWERPC64)
9164     operands[2] = operand_subword (operands[0], 0, 0, <MODE>mode);
9165   else
9166     operands[2] = gen_lowpart (SImode, operands[0]);
9167
9168   operands[3] = gen_int_mode (l, SImode);
9169 }")
9170
9171 (define_insn "mov<mode>_hardfloat"
9172   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "=!r,!r,m,f,wa,wa,<f32_lr>,<f32_sm>,wu,Z,?<f32_dm>,?r,*c*l,!r,*h,!r,!r")
9173         (match_operand:FMOVE32 1 "input_operand" "r,m,r,f,wa,j,<f32_lm>,<f32_sr>,Z,wu,r,<f32_dm>,r,h,0,G,Fn"))]
9174   "(gpc_reg_operand (operands[0], <MODE>mode)
9175    || gpc_reg_operand (operands[1], <MODE>mode))
9176    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
9177   "@
9178    mr %0,%1
9179    lwz%U1%X1 %0,%1
9180    stw%U0%X0 %1,%0
9181    fmr %0,%1
9182    xxlor %x0,%x1,%x1
9183    xxlxor %x0,%x0,%x0
9184    <f32_li>
9185    <f32_si>
9186    <f32_lv>
9187    <f32_sv>
9188    mtvsrwz %x0,%1
9189    mfvsrwz %0,%x1
9190    mt%0 %1
9191    mf%1 %0
9192    nop
9193    #
9194    #"
9195   [(set_attr "type" "*,load,store,fp,vecsimple,vecsimple,fpload,fpstore,fpload,fpstore,mftgpr,mffgpr,mtjmpr,mfjmpr,*,*,*")
9196    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8")])
9197
9198 (define_insn "*mov<mode>_softfloat"
9199   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "=r,cl,r,r,m,r,r,r,r,*h")
9200         (match_operand:FMOVE32 1 "input_operand" "r,r,h,m,r,I,L,G,Fn,0"))]
9201   "(gpc_reg_operand (operands[0], <MODE>mode)
9202    || gpc_reg_operand (operands[1], <MODE>mode))
9203    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
9204   "@
9205    mr %0,%1
9206    mt%0 %1
9207    mf%1 %0
9208    lwz%U1%X1 %0,%1
9209    stw%U0%X0 %1,%0
9210    li %0,%1
9211    lis %0,%v1
9212    #
9213    #
9214    nop"
9215   [(set_attr "type" "*,mtjmpr,mfjmpr,load,store,*,*,*,*,*")
9216    (set_attr "length" "4,4,4,4,4,4,4,4,8,4")])
9217
9218 \f
9219 ;; Move 64-bit binary/decimal floating point
9220 (define_expand "mov<mode>"
9221   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "")
9222         (match_operand:FMOVE64 1 "any_operand" ""))]
9223   ""
9224   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9225
9226 (define_split
9227   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
9228         (match_operand:FMOVE64 1 "const_int_operand" ""))]
9229   "! TARGET_POWERPC64 && reload_completed
9230    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9231        || (GET_CODE (operands[0]) == SUBREG
9232            && GET_CODE (SUBREG_REG (operands[0])) == REG
9233            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9234   [(set (match_dup 2) (match_dup 4))
9235    (set (match_dup 3) (match_dup 1))]
9236   "
9237 {
9238   int endian = (WORDS_BIG_ENDIAN == 0);
9239   HOST_WIDE_INT value = INTVAL (operands[1]);
9240
9241   operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
9242   operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
9243   operands[4] = GEN_INT (value >> 32);
9244   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9245 }")
9246
9247 (define_split
9248   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
9249         (match_operand:FMOVE64 1 "const_double_operand" ""))]
9250   "! TARGET_POWERPC64 && reload_completed
9251    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9252        || (GET_CODE (operands[0]) == SUBREG
9253            && GET_CODE (SUBREG_REG (operands[0])) == REG
9254            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9255   [(set (match_dup 2) (match_dup 4))
9256    (set (match_dup 3) (match_dup 5))]
9257   "
9258 {
9259   int endian = (WORDS_BIG_ENDIAN == 0);
9260   long l[2];
9261   REAL_VALUE_TYPE rv;
9262
9263   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9264   <real_value_to_target> (rv, l);
9265
9266   operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
9267   operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
9268   operands[4] = gen_int_mode (l[endian], SImode);
9269   operands[5] = gen_int_mode (l[1 - endian], SImode);
9270 }")
9271
9272 (define_split
9273   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
9274         (match_operand:FMOVE64 1 "const_double_operand" ""))]
9275   "TARGET_POWERPC64 && reload_completed
9276    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9277        || (GET_CODE (operands[0]) == SUBREG
9278            && GET_CODE (SUBREG_REG (operands[0])) == REG
9279            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9280   [(set (match_dup 2) (match_dup 3))]
9281   "
9282 {
9283   int endian = (WORDS_BIG_ENDIAN == 0);
9284   long l[2];
9285   REAL_VALUE_TYPE rv;
9286   HOST_WIDE_INT val;
9287
9288   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9289   <real_value_to_target> (rv, l);
9290
9291   operands[2] = gen_lowpart (DImode, operands[0]);
9292   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
9293   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
9294          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
9295
9296   operands[3] = gen_int_mode (val, DImode);
9297 }")
9298
9299 ;; Don't have reload use general registers to load a constant.  It is
9300 ;; less efficient than loading the constant into an FP register, since
9301 ;; it will probably be used there.
9302
9303 ;; The move constraints are ordered to prefer floating point registers before
9304 ;; general purpose registers to avoid doing a store and a load to get the value
9305 ;; into a floating point register when it is needed for a floating point
9306 ;; operation.  Prefer traditional floating point registers over VSX registers,
9307 ;; since the D-form version of the memory instructions does not need a GPR for
9308 ;; reloading.
9309
9310 (define_insn "*mov<mode>_hardfloat32"
9311   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=m,d,d,wv,Z,wa,wa,Y,r,!r,!r,!r,!r")
9312         (match_operand:FMOVE64 1 "input_operand" "d,m,d,Z,wv,wa,j,r,Y,r,G,H,F"))]
9313   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9314    && (gpc_reg_operand (operands[0], <MODE>mode)
9315        || gpc_reg_operand (operands[1], <MODE>mode))"
9316   "@
9317    stfd%U0%X0 %1,%0
9318    lfd%U1%X1 %0,%1
9319    fmr %0,%1
9320    lxsd%U1x %x0,%y1
9321    stxsd%U0x %x1,%y0
9322    xxlor %x0,%x1,%x1
9323    xxlxor %x0,%x0,%x0
9324    #
9325    #
9326    #
9327    #
9328    #
9329    #"
9330   [(set_attr "type" "fpstore,fpload,fp,fpload,fpstore,vecsimple,vecsimple,store,load,two,fp,fp,*")
9331    (set_attr "length" "4,4,4,4,4,4,4,8,8,8,8,12,16")])
9332
9333 (define_insn "*mov<mode>_softfloat32"
9334   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=Y,r,r,r,r,r")
9335         (match_operand:FMOVE64 1 "input_operand" "r,Y,r,G,H,F"))]
9336   "! TARGET_POWERPC64 
9337    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
9338        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE
9339        || (<MODE>mode == DDmode && TARGET_E500_DOUBLE))
9340    && (gpc_reg_operand (operands[0], <MODE>mode)
9341        || gpc_reg_operand (operands[1], <MODE>mode))"
9342   "#"
9343   [(set_attr "type" "store,load,two,*,*,*")
9344    (set_attr "length" "8,8,8,8,12,16")])
9345
9346 ; ld/std require word-aligned displacements -> 'Y' constraint.
9347 ; List Y->r and r->Y before r->r for reload.
9348 (define_insn "*mov<mode>_hardfloat64"
9349   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=m,d,d,wv,Z,wa,wa,Y,r,!r,*c*l,!r,*h,!r,!r,!r,r,wg,r,wm")
9350         (match_operand:FMOVE64 1 "input_operand" "d,m,d,Z,wv,wa,j,r,Y,r,r,h,0,G,H,F,wg,r,wm,r"))]
9351   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
9352    && (gpc_reg_operand (operands[0], <MODE>mode)
9353        || gpc_reg_operand (operands[1], <MODE>mode))"
9354   "@
9355    stfd%U0%X0 %1,%0
9356    lfd%U1%X1 %0,%1
9357    fmr %0,%1
9358    lxsd%U1x %x0,%y1
9359    stxsd%U0x %x1,%y0
9360    xxlor %x0,%x1,%x1
9361    xxlxor %x0,%x0,%x0
9362    std%U0%X0 %1,%0
9363    ld%U1%X1 %0,%1
9364    mr %0,%1
9365    mt%0 %1
9366    mf%1 %0
9367    nop
9368    #
9369    #
9370    #
9371    mftgpr %0,%1
9372    mffgpr %0,%1
9373    mfvsrd %0,%x1
9374    mtvsrd %x0,%1"
9375   [(set_attr "type" "fpstore,fpload,fp,fpload,fpstore,vecsimple,vecsimple,store,load,*,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr,mftgpr,mffgpr")
9376    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4,4,4")])
9377
9378 (define_insn "*mov<mode>_softfloat64"
9379   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=Y,r,r,cl,r,r,r,r,*h")
9380         (match_operand:FMOVE64 1 "input_operand" "r,Y,r,r,h,G,H,F,0"))]
9381   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
9382    && (gpc_reg_operand (operands[0], <MODE>mode)
9383        || gpc_reg_operand (operands[1], <MODE>mode))"
9384   "@
9385    std%U0%X0 %1,%0
9386    ld%U1%X1 %0,%1
9387    mr %0,%1
9388    mt%0 %1
9389    mf%1 %0
9390    #
9391    #
9392    #
9393    nop"
9394   [(set_attr "type" "store,load,*,mtjmpr,mfjmpr,*,*,*,*")
9395    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
9396 \f
9397 (define_expand "mov<mode>"
9398   [(set (match_operand:FMOVE128 0 "general_operand" "")
9399         (match_operand:FMOVE128 1 "any_operand" ""))]
9400   ""
9401   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9402
9403 ;; It's important to list Y->r and r->Y before r->r because otherwise
9404 ;; reload, given m->r, will try to pick r->r and reload it, which
9405 ;; doesn't make progress.
9406
9407 ;; We can't split little endian direct moves of TDmode, because the words are
9408 ;; not swapped like they are for TImode or TFmode.  Subregs therefore are
9409 ;; problematical.  Don't allow direct move for this case.
9410
9411 (define_insn_and_split "*mov<mode>_64bit_dm"
9412   [(set (match_operand:FMOVE128 0 "nonimmediate_operand" "=m,d,d,Y,r,r,r,wm")
9413         (match_operand:FMOVE128 1 "input_operand" "d,m,d,r,YGHF,r,wm,r"))]
9414   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_POWERPC64
9415    && (<MODE>mode != TDmode || WORDS_BIG_ENDIAN)
9416    && (gpc_reg_operand (operands[0], <MODE>mode)
9417        || gpc_reg_operand (operands[1], <MODE>mode))"
9418   "#"
9419   "&& reload_completed"
9420   [(pc)]
9421 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9422   [(set_attr "length" "8,8,8,12,12,8,8,8")])
9423
9424 (define_insn_and_split "*movtd_64bit_nodm"
9425   [(set (match_operand:TD 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
9426         (match_operand:TD 1 "input_operand" "d,m,d,r,YGHF,r"))]
9427   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_POWERPC64 && !WORDS_BIG_ENDIAN
9428    && (gpc_reg_operand (operands[0], TDmode)
9429        || gpc_reg_operand (operands[1], TDmode))"
9430   "#"
9431   "&& reload_completed"
9432   [(pc)]
9433 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9434   [(set_attr "length" "8,8,8,12,12,8")])
9435
9436 (define_insn_and_split "*mov<mode>_32bit"
9437   [(set (match_operand:FMOVE128 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
9438         (match_operand:FMOVE128 1 "input_operand" "d,m,d,r,YGHF,r"))]
9439   "TARGET_HARD_FLOAT && TARGET_FPRS && !TARGET_POWERPC64
9440    && (gpc_reg_operand (operands[0], <MODE>mode)
9441        || gpc_reg_operand (operands[1], <MODE>mode))"
9442   "#"
9443   "&& reload_completed"
9444   [(pc)]
9445 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9446   [(set_attr "length" "8,8,8,20,20,16")])
9447
9448 (define_insn_and_split "*mov<mode>_softfloat"
9449   [(set (match_operand:FMOVE128 0 "rs6000_nonimmediate_operand" "=Y,r,r")
9450         (match_operand:FMOVE128 1 "input_operand" "r,YGHF,r"))]
9451   "(TARGET_SOFT_FLOAT || !TARGET_FPRS)
9452    && (gpc_reg_operand (operands[0], <MODE>mode)
9453        || gpc_reg_operand (operands[1], <MODE>mode))"
9454   "#"
9455   "&& reload_completed"
9456   [(pc)]
9457 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9458   [(set_attr "length" "20,20,16")])
9459
9460 (define_expand "extenddftf2"
9461   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9462         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
9463   "!TARGET_IEEEQUAD
9464    && TARGET_HARD_FLOAT
9465    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9466    && TARGET_LONG_DOUBLE_128"
9467 {
9468   if (TARGET_E500_DOUBLE)
9469     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
9470   else
9471     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
9472   DONE;
9473 })
9474
9475 (define_expand "extenddftf2_fprs"
9476   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9477                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
9478               (use (match_dup 2))])]
9479   "!TARGET_IEEEQUAD
9480    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9481    && TARGET_LONG_DOUBLE_128"
9482 {
9483   operands[2] = CONST0_RTX (DFmode);
9484   /* Generate GOT reference early for SVR4 PIC.  */
9485   if (DEFAULT_ABI == ABI_V4 && flag_pic)
9486     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
9487 })
9488
9489 (define_insn_and_split "*extenddftf2_internal"
9490   [(set (match_operand:TF 0 "nonimmediate_operand" "=m,Y,d,&d,r")
9491        (float_extend:TF (match_operand:DF 1 "input_operand" "d,r,md,md,rmGHF")))
9492    (use (match_operand:DF 2 "zero_reg_mem_operand" "d,r,m,d,n"))]
9493   "!TARGET_IEEEQUAD
9494    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9495    && TARGET_LONG_DOUBLE_128"
9496   "#"
9497   "&& reload_completed"
9498   [(pc)]
9499 {
9500   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9501   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9502   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
9503                   operands[1]);
9504   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
9505                   operands[2]);
9506   DONE;
9507 })
9508
9509 (define_expand "extendsftf2"
9510   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9511         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
9512   "!TARGET_IEEEQUAD
9513    && TARGET_HARD_FLOAT
9514    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9515    && TARGET_LONG_DOUBLE_128"
9516 {
9517   rtx tmp = gen_reg_rtx (DFmode);
9518   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
9519   emit_insn (gen_extenddftf2 (operands[0], tmp));
9520   DONE;
9521 })
9522
9523 (define_expand "trunctfdf2"
9524   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9525         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
9526   "!TARGET_IEEEQUAD
9527    && TARGET_HARD_FLOAT
9528    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9529    && TARGET_LONG_DOUBLE_128"
9530   "")
9531
9532 (define_insn_and_split "trunctfdf2_internal1"
9533   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
9534         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
9535   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
9536    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9537   "@
9538    #
9539    fmr %0,%1"
9540   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
9541   [(const_int 0)]
9542 {
9543   emit_note (NOTE_INSN_DELETED);
9544   DONE;
9545 }
9546   [(set_attr "type" "fp")])
9547
9548 (define_insn "trunctfdf2_internal2"
9549   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9550         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9551   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
9552    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9553    && TARGET_LONG_DOUBLE_128"
9554   "fadd %0,%1,%L1"
9555   [(set_attr "type" "fp")
9556    (set_attr "fp_type" "fp_addsub_d")])
9557
9558 (define_expand "trunctfsf2"
9559   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9560         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
9561   "!TARGET_IEEEQUAD
9562    && TARGET_HARD_FLOAT
9563    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9564    && TARGET_LONG_DOUBLE_128"
9565 {
9566   if (TARGET_E500_DOUBLE)
9567     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
9568   else
9569     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
9570   DONE;
9571 })
9572
9573 (define_insn_and_split "trunctfsf2_fprs"
9574   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
9575         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
9576    (clobber (match_scratch:DF 2 "=d"))]
9577   "!TARGET_IEEEQUAD
9578    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
9579    && TARGET_LONG_DOUBLE_128"
9580   "#"
9581   "&& reload_completed"
9582   [(set (match_dup 2)
9583         (float_truncate:DF (match_dup 1)))
9584    (set (match_dup 0)
9585         (float_truncate:SF (match_dup 2)))]
9586   "")
9587
9588 (define_expand "floatsitf2"
9589   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9590         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
9591   "!TARGET_IEEEQUAD
9592    && TARGET_HARD_FLOAT
9593    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9594    && TARGET_LONG_DOUBLE_128"
9595 {
9596   rtx tmp = gen_reg_rtx (DFmode);
9597   expand_float (tmp, operands[1], false);
9598   emit_insn (gen_extenddftf2 (operands[0], tmp));
9599   DONE;
9600 })
9601
9602 ; fadd, but rounding towards zero.
9603 ; This is probably not the optimal code sequence.
9604 (define_insn "fix_trunc_helper"
9605   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9606         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
9607                    UNSPEC_FIX_TRUNC_TF))
9608    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
9609   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
9610   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
9611   [(set_attr "type" "fp")
9612    (set_attr "length" "20")])
9613
9614 (define_expand "fix_trunctfsi2"
9615   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9616         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
9617   "!TARGET_IEEEQUAD && TARGET_HARD_FLOAT
9618    && (TARGET_FPRS || TARGET_E500_DOUBLE) && TARGET_LONG_DOUBLE_128"
9619 {
9620   if (TARGET_E500_DOUBLE)
9621     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
9622   else
9623     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
9624   DONE;
9625 })
9626
9627 (define_expand "fix_trunctfsi2_fprs"
9628   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
9629                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
9630               (clobber (match_dup 2))
9631               (clobber (match_dup 3))
9632               (clobber (match_dup 4))
9633               (clobber (match_dup 5))])]
9634   "!TARGET_IEEEQUAD
9635    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9636 {
9637   operands[2] = gen_reg_rtx (DFmode);
9638   operands[3] = gen_reg_rtx (DFmode);
9639   operands[4] = gen_reg_rtx (DImode);
9640   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode));
9641 })
9642
9643 (define_insn_and_split "*fix_trunctfsi2_internal"
9644   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9645         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
9646    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
9647    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
9648    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
9649    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
9650   "!TARGET_IEEEQUAD
9651    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9652   "#"
9653   ""
9654   [(pc)]
9655 {
9656   rtx lowword;
9657   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
9658
9659   gcc_assert (MEM_P (operands[5]));
9660   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
9661
9662   emit_insn (gen_fctiwz_df (operands[4], operands[2]));
9663   emit_move_insn (operands[5], operands[4]);
9664   emit_move_insn (operands[0], lowword);
9665   DONE;
9666 })
9667
9668 (define_expand "negtf2"
9669   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9670         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9671   "!TARGET_IEEEQUAD
9672    && TARGET_HARD_FLOAT
9673    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9674    && TARGET_LONG_DOUBLE_128"
9675   "")
9676
9677 (define_insn "negtf2_internal"
9678   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
9679         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9680   "!TARGET_IEEEQUAD
9681    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9682   "*
9683 {
9684   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9685     return \"fneg %L0,%L1\;fneg %0,%1\";
9686   else
9687     return \"fneg %0,%1\;fneg %L0,%L1\";
9688 }"
9689   [(set_attr "type" "fp")
9690    (set_attr "length" "8")])
9691
9692 (define_expand "abstf2"
9693   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9694         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9695   "!TARGET_IEEEQUAD
9696    && TARGET_HARD_FLOAT
9697    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9698    && TARGET_LONG_DOUBLE_128"
9699   "
9700 {
9701   rtx label = gen_label_rtx ();
9702   if (TARGET_E500_DOUBLE)
9703     {
9704       if (flag_finite_math_only && !flag_trapping_math)
9705         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
9706       else
9707         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
9708     }
9709   else
9710     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
9711   emit_label (label);
9712   DONE;
9713 }")
9714
9715 (define_expand "abstf2_internal"
9716   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9717         (match_operand:TF 1 "gpc_reg_operand" ""))
9718    (set (match_dup 3) (match_dup 5))
9719    (set (match_dup 5) (abs:DF (match_dup 5)))
9720    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
9721    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
9722                            (label_ref (match_operand 2 "" ""))
9723                            (pc)))
9724    (set (match_dup 6) (neg:DF (match_dup 6)))]
9725   "!TARGET_IEEEQUAD
9726    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9727    && TARGET_LONG_DOUBLE_128"
9728   "
9729 {
9730   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9731   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9732   operands[3] = gen_reg_rtx (DFmode);
9733   operands[4] = gen_reg_rtx (CCFPmode);
9734   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
9735   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
9736 }")
9737 \f
9738 ;; Reload helper functions used by rs6000_secondary_reload.  The patterns all
9739 ;; must have 3 arguments, and scratch register constraint must be a single
9740 ;; constraint.
9741
9742 ;; Reload patterns to support gpr load/store with misaligned mem.
9743 ;; and multiple gpr load/store at offset >= 0xfffc
9744 (define_expand "reload_<mode>_store"
9745   [(parallel [(match_operand 0 "memory_operand" "=m")
9746               (match_operand 1 "gpc_reg_operand" "r")
9747               (match_operand:GPR 2 "register_operand" "=&b")])]
9748   ""
9749 {
9750   rs6000_secondary_reload_gpr (operands[1], operands[0], operands[2], true);
9751   DONE;
9752 })
9753
9754 (define_expand "reload_<mode>_load"
9755   [(parallel [(match_operand 0 "gpc_reg_operand" "=r")
9756               (match_operand 1 "memory_operand" "m")
9757               (match_operand:GPR 2 "register_operand" "=b")])]
9758   ""
9759 {
9760   rs6000_secondary_reload_gpr (operands[0], operands[1], operands[2], false);
9761   DONE;
9762 })
9763
9764 \f
9765 ;; Power8 merge instructions to allow direct move to/from floating point
9766 ;; registers in 32-bit mode.  We use TF mode to get two registers to move the
9767 ;; individual 32-bit parts across.  Subreg doesn't work too well on the TF
9768 ;; value, since it is allocated in reload and not all of the flow information
9769 ;; is setup for it.  We have two patterns to do the two moves between gprs and
9770 ;; fprs.  There isn't a dependancy between the two, but we could potentially
9771 ;; schedule other instructions between the two instructions.  TFmode is
9772 ;; currently limited to traditional FPR registers.  If/when this is changed, we
9773 ;; will need to revist %L to make sure it works with VSX registers, or add an
9774 ;; %x version of %L.
9775
9776 (define_insn "p8_fmrgow_<mode>"
9777   [(set (match_operand:FMOVE64X 0 "register_operand" "=d")
9778         (unspec:FMOVE64X [(match_operand:TF 1 "register_operand" "d")]
9779                          UNSPEC_P8V_FMRGOW))]
9780   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9781   "fmrgow %0,%1,%L1"
9782   [(set_attr "type" "vecperm")])
9783
9784 (define_insn "p8_mtvsrwz_1"
9785   [(set (match_operand:TF 0 "register_operand" "=d")
9786         (unspec:TF [(match_operand:SI 1 "register_operand" "r")]
9787                    UNSPEC_P8V_MTVSRWZ))]
9788   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9789   "mtvsrwz %x0,%1"
9790   [(set_attr "type" "mftgpr")])
9791
9792 (define_insn "p8_mtvsrwz_2"
9793   [(set (match_operand:TF 0 "register_operand" "+d")
9794         (unspec:TF [(match_dup 0)
9795                     (match_operand:SI 1 "register_operand" "r")]
9796                    UNSPEC_P8V_MTVSRWZ))]
9797   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9798   "mtvsrwz %L0,%1"
9799   [(set_attr "type" "mftgpr")])
9800
9801 (define_insn_and_split "reload_fpr_from_gpr<mode>"
9802   [(set (match_operand:FMOVE64X 0 "register_operand" "=ws")
9803         (unspec:FMOVE64X [(match_operand:FMOVE64X 1 "register_operand" "r")]
9804                          UNSPEC_P8V_RELOAD_FROM_GPR))
9805    (clobber (match_operand:TF 2 "register_operand" "=d"))]
9806   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9807   "#"
9808   "&& reload_completed"
9809   [(const_int 0)]
9810 {
9811   rtx dest = operands[0];
9812   rtx src = operands[1];
9813   rtx tmp = operands[2];
9814   rtx gpr_hi_reg = gen_highpart (SImode, src);
9815   rtx gpr_lo_reg = gen_lowpart (SImode, src);
9816
9817   emit_insn (gen_p8_mtvsrwz_1 (tmp, gpr_hi_reg));
9818   emit_insn (gen_p8_mtvsrwz_2 (tmp, gpr_lo_reg));
9819   emit_insn (gen_p8_fmrgow_<mode> (dest, tmp));
9820   DONE;
9821 }
9822   [(set_attr "length" "12")
9823    (set_attr "type" "three")])
9824
9825 ;; Move 128 bit values from GPRs to VSX registers in 64-bit mode
9826 (define_insn "p8_mtvsrd_1"
9827   [(set (match_operand:TF 0 "register_operand" "=ws")
9828         (unspec:TF [(match_operand:DI 1 "register_operand" "r")]
9829                    UNSPEC_P8V_MTVSRD))]
9830   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9831   "mtvsrd %0,%1"
9832   [(set_attr "type" "mftgpr")])
9833
9834 (define_insn "p8_mtvsrd_2"
9835   [(set (match_operand:TF 0 "register_operand" "+ws")
9836         (unspec:TF [(match_dup 0)
9837                     (match_operand:DI 1 "register_operand" "r")]
9838                    UNSPEC_P8V_MTVSRD))]
9839   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9840   "mtvsrd %L0,%1"
9841   [(set_attr "type" "mftgpr")])
9842
9843 (define_insn "p8_xxpermdi_<mode>"
9844   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9845         (unspec:FMOVE128_GPR [(match_operand:TF 1 "register_operand" "ws")]
9846                              UNSPEC_P8V_XXPERMDI))]
9847   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9848   "xxpermdi %x0,%1,%L1,0"
9849   [(set_attr "type" "vecperm")])
9850
9851 (define_insn_and_split "reload_vsx_from_gpr<mode>"
9852   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9853         (unspec:FMOVE128_GPR
9854          [(match_operand:FMOVE128_GPR 1 "register_operand" "r")]
9855          UNSPEC_P8V_RELOAD_FROM_GPR))
9856    (clobber (match_operand:TF 2 "register_operand" "=ws"))]
9857   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9858   "#"
9859   "&& reload_completed"
9860   [(const_int 0)]
9861 {
9862   rtx dest = operands[0];
9863   rtx src = operands[1];
9864   rtx tmp = operands[2];
9865   rtx gpr_hi_reg = gen_highpart (DImode, src);
9866   rtx gpr_lo_reg = gen_lowpart (DImode, src);
9867
9868   emit_insn (gen_p8_mtvsrd_1 (tmp, gpr_hi_reg));
9869   emit_insn (gen_p8_mtvsrd_2 (tmp, gpr_lo_reg));
9870   emit_insn (gen_p8_xxpermdi_<mode> (dest, tmp));
9871 }
9872   [(set_attr "length" "12")
9873    (set_attr "type" "three")])
9874
9875 (define_split
9876   [(set (match_operand:FMOVE128_GPR 0 "nonimmediate_operand" "")
9877         (match_operand:FMOVE128_GPR 1 "input_operand" ""))]
9878   "reload_completed
9879    && (int_reg_operand (operands[0], <MODE>mode)
9880        || int_reg_operand (operands[1], <MODE>mode))"
9881   [(pc)]
9882 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9883
9884 ;; Move SFmode to a VSX from a GPR register.  Because scalar floating point
9885 ;; type is stored internally as double precision in the VSX registers, we have
9886 ;; to convert it from the vector format.
9887
9888 (define_insn_and_split "reload_vsx_from_gprsf"
9889   [(set (match_operand:SF 0 "register_operand" "=wa")
9890         (unspec:SF [(match_operand:SF 1 "register_operand" "r")]
9891                    UNSPEC_P8V_RELOAD_FROM_GPR))
9892    (clobber (match_operand:DI 2 "register_operand" "=r"))]
9893   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9894   "#"
9895   "&& reload_completed"
9896   [(const_int 0)]
9897 {
9898   rtx op0 = operands[0];
9899   rtx op1 = operands[1];
9900   rtx op2 = operands[2];
9901   /* Also use the destination register to hold the unconverted DImode value.
9902      This is conceptually a separate value from OP0, so we use gen_rtx_REG
9903      rather than simplify_gen_subreg.  */
9904   rtx op0_di = gen_rtx_REG (DImode, REGNO (op0));
9905   rtx op1_di = simplify_gen_subreg (DImode, op1, SFmode, 0);
9906
9907   /* Move SF value to upper 32-bits for xscvspdpn.  */
9908   emit_insn (gen_ashldi3 (op2, op1_di, GEN_INT (32)));
9909   emit_move_insn (op0_di, op2);
9910   emit_insn (gen_vsx_xscvspdpn_directmove (op0, op0_di));
9911   DONE;
9912 }
9913   [(set_attr "length" "8")
9914    (set_attr "type" "two")])
9915
9916 ;; Move 128 bit values from VSX registers to GPRs in 64-bit mode by doing a
9917 ;; normal 64-bit move, followed by an xxpermdi to get the bottom 64-bit value,
9918 ;; and then doing a move of that.
9919 (define_insn "p8_mfvsrd_3_<mode>"
9920   [(set (match_operand:DF 0 "register_operand" "=r")
9921         (unspec:DF [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9922                    UNSPEC_P8V_RELOAD_FROM_VSX))]
9923   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9924   "mfvsrd %0,%x1"
9925   [(set_attr "type" "mftgpr")])
9926
9927 (define_insn_and_split "reload_gpr_from_vsx<mode>"
9928   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=r")
9929         (unspec:FMOVE128_GPR
9930          [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9931          UNSPEC_P8V_RELOAD_FROM_VSX))
9932    (clobber (match_operand:FMOVE128_GPR 2 "register_operand" "=wa"))]
9933   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9934   "#"
9935   "&& reload_completed"
9936   [(const_int 0)]
9937 {
9938   rtx dest = operands[0];
9939   rtx src = operands[1];
9940   rtx tmp = operands[2];
9941   rtx gpr_hi_reg = gen_highpart (DFmode, dest);
9942   rtx gpr_lo_reg = gen_lowpart (DFmode, dest);
9943
9944   emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_hi_reg, src));
9945   emit_insn (gen_vsx_xxpermdi_<mode> (tmp, src, src, GEN_INT (3)));
9946   emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_lo_reg, tmp));
9947 }
9948   [(set_attr "length" "12")
9949    (set_attr "type" "three")])
9950
9951 ;; Move SFmode to a GPR from a VSX register.  Because scalar floating point
9952 ;; type is stored internally as double precision, we have to convert it to the
9953 ;; vector format.
9954
9955 (define_insn_and_split "reload_gpr_from_vsxsf"
9956   [(set (match_operand:SF 0 "register_operand" "=r")
9957         (unspec:SF [(match_operand:SF 1 "register_operand" "wa")]
9958                    UNSPEC_P8V_RELOAD_FROM_VSX))
9959    (clobber (match_operand:V4SF 2 "register_operand" "=wa"))]
9960   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9961   "#"
9962   "&& reload_completed"
9963   [(const_int 0)]
9964 {
9965   rtx op0 = operands[0];
9966   rtx op1 = operands[1];
9967   rtx op2 = operands[2];
9968   rtx diop0 = simplify_gen_subreg (DImode, op0, SFmode, 0);
9969
9970   emit_insn (gen_vsx_xscvdpspn_scalar (op2, op1));
9971   emit_insn (gen_p8_mfvsrd_4_disf (diop0, op2));
9972   emit_insn (gen_lshrdi3 (diop0, diop0, GEN_INT (32)));
9973   DONE;
9974 }
9975   [(set_attr "length" "12")
9976    (set_attr "type" "three")])
9977
9978 (define_insn "p8_mfvsrd_4_disf"
9979   [(set (match_operand:DI 0 "register_operand" "=r")
9980         (unspec:DI [(match_operand:V4SF 1 "register_operand" "wa")]
9981                    UNSPEC_P8V_RELOAD_FROM_VSX))]
9982   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9983   "mfvsrd %0,%x1"
9984   [(set_attr "type" "mftgpr")])
9985
9986 \f
9987 ;; Next come the multi-word integer load and store and the load and store
9988 ;; multiple insns.
9989
9990 ;; List r->r after r->Y, otherwise reload will try to reload a
9991 ;; non-offsettable address by using r->r which won't make progress.
9992 ;; Use of fprs is disparaged slightly otherwise reload prefers to reload
9993 ;; a gpr into a fpr instead of reloading an invalid 'Y' address
9994 (define_insn "*movdi_internal32"
9995   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=Y,r,r,?m,?*d,?*d,r")
9996         (match_operand:DI 1 "input_operand" "r,Y,r,d,m,d,IJKnGHF"))]
9997   "! TARGET_POWERPC64
9998    && (gpc_reg_operand (operands[0], DImode)
9999        || gpc_reg_operand (operands[1], DImode))"
10000   "@
10001    #
10002    #
10003    #
10004    stfd%U0%X0 %1,%0
10005    lfd%U1%X1 %0,%1
10006    fmr %0,%1
10007    #"
10008   [(set_attr "type" "store,load,*,fpstore,fpload,fp,*")])
10009
10010 (define_split
10011   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10012         (match_operand:DI 1 "const_int_operand" ""))]
10013   "! TARGET_POWERPC64 && reload_completed
10014    && gpr_or_gpr_p (operands[0], operands[1])
10015    && !direct_move_p (operands[0], operands[1])"
10016   [(set (match_dup 2) (match_dup 4))
10017    (set (match_dup 3) (match_dup 1))]
10018   "
10019 {
10020   HOST_WIDE_INT value = INTVAL (operands[1]);
10021   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10022                                        DImode);
10023   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10024                                        DImode);
10025   operands[4] = GEN_INT (value >> 32);
10026   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
10027 }")
10028
10029 (define_split
10030   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
10031         (match_operand:DIFD 1 "input_operand" ""))]
10032   "reload_completed && !TARGET_POWERPC64
10033    && gpr_or_gpr_p (operands[0], operands[1])
10034    && !direct_move_p (operands[0], operands[1])"
10035   [(pc)]
10036 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10037
10038 (define_insn "*movdi_internal64"
10039   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,r,r,r,r,?m,?*d,?*d,r,*h,*h,r,?*wg,r,?*wm")
10040         (match_operand:DI 1 "input_operand" "r,Y,r,I,L,nF,d,m,d,*h,r,0,*wg,r,*wm,r"))]
10041   "TARGET_POWERPC64
10042    && (gpc_reg_operand (operands[0], DImode)
10043        || gpc_reg_operand (operands[1], DImode))"
10044   "@
10045    std%U0%X0 %1,%0
10046    ld%U1%X1 %0,%1
10047    mr %0,%1
10048    li %0,%1
10049    lis %0,%v1
10050    #
10051    stfd%U0%X0 %1,%0
10052    lfd%U1%X1 %0,%1
10053    fmr %0,%1
10054    mf%1 %0
10055    mt%0 %1
10056    nop
10057    mftgpr %0,%1
10058    mffgpr %0,%1
10059    mfvsrd %0,%x1
10060    mtvsrd %x0,%1"
10061   [(set_attr "type" "store,load,*,*,*,*,fpstore,fpload,fp,mfjmpr,mtjmpr,*,mftgpr,mffgpr,mftgpr,mffgpr")
10062    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4,4")])
10063
10064 ;; Generate all one-bits and clear left or right.
10065 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
10066 (define_split
10067   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10068         (match_operand:DI 1 "mask64_operand" ""))]
10069   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10070   [(set (match_dup 0) (const_int -1))
10071    (set (match_dup 0)
10072         (and:DI (rotate:DI (match_dup 0)
10073                            (const_int 0))
10074                 (match_dup 1)))]
10075   "")
10076
10077 ;; Split a load of a large constant into the appropriate five-instruction
10078 ;; sequence.  Handle anything in a constant number of insns.
10079 ;; When non-easy constants can go in the TOC, this should use
10080 ;; easy_fp_constant predicate.
10081 (define_split
10082   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10083         (match_operand:DI 1 "const_int_operand" ""))]
10084   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10085   [(set (match_dup 0) (match_dup 2))
10086    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
10087   "
10088 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
10089
10090   if (tem == operands[0])
10091     DONE;
10092   else
10093     FAIL;
10094 }")
10095
10096 (define_split
10097   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10098         (match_operand:DI 1 "const_scalar_int_operand" ""))]
10099   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10100   [(set (match_dup 0) (match_dup 2))
10101    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
10102   "
10103 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
10104
10105   if (tem == operands[0])
10106     DONE;
10107   else
10108     FAIL;
10109 }")
10110 \f
10111 ;; TImode/PTImode is similar, except that we usually want to compute the
10112 ;; address into a register and use lsi/stsi (the exception is during reload).
10113
10114 (define_insn "*mov<mode>_string"
10115   [(set (match_operand:TI2 0 "reg_or_mem_operand" "=Q,Y,????r,????r,????r,r")
10116         (match_operand:TI2 1 "input_operand" "r,r,Q,Y,r,n"))]
10117   "! TARGET_POWERPC64
10118    && (<MODE>mode != TImode || VECTOR_MEM_NONE_P (TImode))
10119    && (gpc_reg_operand (operands[0], <MODE>mode)
10120        || gpc_reg_operand (operands[1], <MODE>mode))"
10121   "*
10122 {
10123   switch (which_alternative)
10124     {
10125     default:
10126       gcc_unreachable ();
10127     case 0:
10128       if (TARGET_STRING)
10129         return \"stswi %1,%P0,16\";
10130     case 1:
10131       return \"#\";
10132     case 2:
10133       /* If the address is not used in the output, we can use lsi.  Otherwise,
10134          fall through to generating four loads.  */
10135       if (TARGET_STRING
10136           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
10137         return \"lswi %0,%P1,16\";
10138       /* ... fall through ...  */
10139     case 3:
10140     case 4:
10141     case 5:
10142       return \"#\";
10143     }
10144 }"
10145   [(set_attr "type" "store,store,load,load,*,*")
10146    (set_attr "update" "yes")
10147    (set_attr "indexed" "yes")
10148    (set (attr "cell_micro") (if_then_else (match_test "TARGET_STRING")
10149                                           (const_string "always")
10150                                           (const_string "conditional")))])
10151
10152 (define_insn "*mov<mode>_ppc64"
10153   [(set (match_operand:TI2 0 "nonimmediate_operand" "=wQ,Y,r,r,r,r")
10154         (match_operand:TI2 1 "input_operand" "r,r,wQ,Y,r,n"))]
10155   "(TARGET_POWERPC64 && VECTOR_MEM_NONE_P (<MODE>mode)
10156    && (gpc_reg_operand (operands[0], <MODE>mode)
10157        || gpc_reg_operand (operands[1], <MODE>mode)))"
10158 {
10159   return rs6000_output_move_128bit (operands);
10160 }
10161   [(set_attr "type" "store,store,load,load,*,*")
10162    (set_attr "length" "8")])
10163
10164 (define_split
10165   [(set (match_operand:TI2 0 "int_reg_operand" "")
10166         (match_operand:TI2 1 "const_scalar_int_operand" ""))]
10167   "TARGET_POWERPC64
10168    && (VECTOR_MEM_NONE_P (<MODE>mode)
10169        || (reload_completed && INT_REGNO_P (REGNO (operands[0]))))"
10170   [(set (match_dup 2) (match_dup 4))
10171    (set (match_dup 3) (match_dup 5))]
10172   "
10173 {
10174   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10175                                        <MODE>mode);
10176   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10177                                        <MODE>mode);
10178   if (CONST_WIDE_INT_P (operands[1]))
10179     {
10180       operands[4] = GEN_INT (CONST_WIDE_INT_ELT (operands[1], 1));
10181       operands[5] = GEN_INT (CONST_WIDE_INT_ELT (operands[1], 0));
10182     }
10183   else if (CONST_INT_P (operands[1]))
10184     {
10185       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
10186       operands[5] = operands[1];
10187     }
10188   else
10189     FAIL;
10190 }")
10191
10192 (define_split
10193   [(set (match_operand:TI2 0 "nonimmediate_operand" "")
10194         (match_operand:TI2 1 "input_operand" ""))]
10195   "reload_completed
10196    && gpr_or_gpr_p (operands[0], operands[1])
10197    && !direct_move_p (operands[0], operands[1])
10198    && !quad_load_store_p (operands[0], operands[1])"
10199   [(pc)]
10200 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10201 \f
10202 (define_expand "load_multiple"
10203   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10204                           (match_operand:SI 1 "" ""))
10205                      (use (match_operand:SI 2 "" ""))])]
10206   "TARGET_STRING && !TARGET_POWERPC64"
10207   "
10208 {
10209   int regno;
10210   int count;
10211   rtx op1;
10212   int i;
10213
10214   /* Support only loading a constant number of fixed-point registers from
10215      memory and only bother with this if more than two; the machine
10216      doesn't support more than eight.  */
10217   if (GET_CODE (operands[2]) != CONST_INT
10218       || INTVAL (operands[2]) <= 2
10219       || INTVAL (operands[2]) > 8
10220       || GET_CODE (operands[1]) != MEM
10221       || GET_CODE (operands[0]) != REG
10222       || REGNO (operands[0]) >= 32)
10223     FAIL;
10224
10225   count = INTVAL (operands[2]);
10226   regno = REGNO (operands[0]);
10227
10228   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
10229   op1 = replace_equiv_address (operands[1],
10230                                force_reg (SImode, XEXP (operands[1], 0)));
10231
10232   for (i = 0; i < count; i++)
10233     XVECEXP (operands[3], 0, i)
10234       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
10235                      adjust_address_nv (op1, SImode, i * 4));
10236 }")
10237
10238 (define_insn "*ldmsi8"
10239   [(match_parallel 0 "load_multiple_operation"
10240     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10241           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10242      (set (match_operand:SI 3 "gpc_reg_operand" "")
10243           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10244      (set (match_operand:SI 4 "gpc_reg_operand" "")
10245           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10246      (set (match_operand:SI 5 "gpc_reg_operand" "")
10247           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10248      (set (match_operand:SI 6 "gpc_reg_operand" "")
10249           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10250      (set (match_operand:SI 7 "gpc_reg_operand" "")
10251           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10252      (set (match_operand:SI 8 "gpc_reg_operand" "")
10253           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
10254      (set (match_operand:SI 9 "gpc_reg_operand" "")
10255           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
10256   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10257   "*
10258 { return rs6000_output_load_multiple (operands); }"
10259   [(set_attr "type" "load")
10260    (set_attr "update" "yes")
10261    (set_attr "indexed" "yes")
10262    (set_attr "length" "32")])
10263
10264 (define_insn "*ldmsi7"
10265   [(match_parallel 0 "load_multiple_operation"
10266     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10267           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10268      (set (match_operand:SI 3 "gpc_reg_operand" "")
10269           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10270      (set (match_operand:SI 4 "gpc_reg_operand" "")
10271           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10272      (set (match_operand:SI 5 "gpc_reg_operand" "")
10273           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10274      (set (match_operand:SI 6 "gpc_reg_operand" "")
10275           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10276      (set (match_operand:SI 7 "gpc_reg_operand" "")
10277           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10278      (set (match_operand:SI 8 "gpc_reg_operand" "")
10279           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
10280   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10281   "*
10282 { return rs6000_output_load_multiple (operands); }"
10283   [(set_attr "type" "load")
10284    (set_attr "update" "yes")
10285    (set_attr "indexed" "yes")
10286    (set_attr "length" "32")])
10287
10288 (define_insn "*ldmsi6"
10289   [(match_parallel 0 "load_multiple_operation"
10290     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10291           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10292      (set (match_operand:SI 3 "gpc_reg_operand" "")
10293           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10294      (set (match_operand:SI 4 "gpc_reg_operand" "")
10295           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10296      (set (match_operand:SI 5 "gpc_reg_operand" "")
10297           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10298      (set (match_operand:SI 6 "gpc_reg_operand" "")
10299           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10300      (set (match_operand:SI 7 "gpc_reg_operand" "")
10301           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
10302   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10303   "*
10304 { return rs6000_output_load_multiple (operands); }"
10305   [(set_attr "type" "load")
10306    (set_attr "update" "yes")
10307    (set_attr "indexed" "yes")
10308    (set_attr "length" "32")])
10309
10310 (define_insn "*ldmsi5"
10311   [(match_parallel 0 "load_multiple_operation"
10312     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10313           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10314      (set (match_operand:SI 3 "gpc_reg_operand" "")
10315           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10316      (set (match_operand:SI 4 "gpc_reg_operand" "")
10317           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10318      (set (match_operand:SI 5 "gpc_reg_operand" "")
10319           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10320      (set (match_operand:SI 6 "gpc_reg_operand" "")
10321           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
10322   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10323   "*
10324 { return rs6000_output_load_multiple (operands); }"
10325   [(set_attr "type" "load")
10326    (set_attr "update" "yes")
10327    (set_attr "indexed" "yes")
10328    (set_attr "length" "32")])
10329
10330 (define_insn "*ldmsi4"
10331   [(match_parallel 0 "load_multiple_operation"
10332     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10333           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10334      (set (match_operand:SI 3 "gpc_reg_operand" "")
10335           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10336      (set (match_operand:SI 4 "gpc_reg_operand" "")
10337           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10338      (set (match_operand:SI 5 "gpc_reg_operand" "")
10339           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
10340   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10341   "*
10342 { return rs6000_output_load_multiple (operands); }"
10343   [(set_attr "type" "load")
10344    (set_attr "update" "yes")
10345    (set_attr "indexed" "yes")
10346    (set_attr "length" "32")])
10347
10348 (define_insn "*ldmsi3"
10349   [(match_parallel 0 "load_multiple_operation"
10350     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10351           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10352      (set (match_operand:SI 3 "gpc_reg_operand" "")
10353           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10354      (set (match_operand:SI 4 "gpc_reg_operand" "")
10355           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
10356   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
10357   "*
10358 { return rs6000_output_load_multiple (operands); }"
10359   [(set_attr "type" "load")
10360    (set_attr "update" "yes")
10361    (set_attr "indexed" "yes")
10362    (set_attr "length" "32")])
10363
10364 (define_expand "store_multiple"
10365   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10366                           (match_operand:SI 1 "" ""))
10367                      (clobber (scratch:SI))
10368                      (use (match_operand:SI 2 "" ""))])]
10369   "TARGET_STRING && !TARGET_POWERPC64"
10370   "
10371 {
10372   int regno;
10373   int count;
10374   rtx to;
10375   rtx op0;
10376   int i;
10377
10378   /* Support only storing a constant number of fixed-point registers to
10379      memory and only bother with this if more than two; the machine
10380      doesn't support more than eight.  */
10381   if (GET_CODE (operands[2]) != CONST_INT
10382       || INTVAL (operands[2]) <= 2
10383       || INTVAL (operands[2]) > 8
10384       || GET_CODE (operands[0]) != MEM
10385       || GET_CODE (operands[1]) != REG
10386       || REGNO (operands[1]) >= 32)
10387     FAIL;
10388
10389   count = INTVAL (operands[2]);
10390   regno = REGNO (operands[1]);
10391
10392   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
10393   to = force_reg (SImode, XEXP (operands[0], 0));
10394   op0 = replace_equiv_address (operands[0], to);
10395
10396   XVECEXP (operands[3], 0, 0)
10397     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
10398   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
10399                                                  gen_rtx_SCRATCH (SImode));
10400
10401   for (i = 1; i < count; i++)
10402     XVECEXP (operands[3], 0, i + 1)
10403       = gen_rtx_SET (VOIDmode,
10404                      adjust_address_nv (op0, SImode, i * 4),
10405                      gen_rtx_REG (SImode, regno + i));
10406 }")
10407
10408 (define_insn "*stmsi8"
10409   [(match_parallel 0 "store_multiple_operation"
10410     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10411           (match_operand:SI 2 "gpc_reg_operand" "r"))
10412      (clobber (match_scratch:SI 3 "=X"))
10413      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10414           (match_operand:SI 4 "gpc_reg_operand" "r"))
10415      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10416           (match_operand:SI 5 "gpc_reg_operand" "r"))
10417      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10418           (match_operand:SI 6 "gpc_reg_operand" "r"))
10419      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10420           (match_operand:SI 7 "gpc_reg_operand" "r"))
10421      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10422           (match_operand:SI 8 "gpc_reg_operand" "r"))
10423      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10424           (match_operand:SI 9 "gpc_reg_operand" "r"))
10425      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10426           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10427   "TARGET_STRING && XVECLEN (operands[0], 0) == 9"
10428   "stswi %2,%1,%O0"
10429   [(set_attr "type" "store")
10430    (set_attr "update" "yes")
10431    (set_attr "indexed" "yes")
10432    (set_attr "cell_micro" "always")])
10433
10434 (define_insn "*stmsi7"
10435   [(match_parallel 0 "store_multiple_operation"
10436     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10437           (match_operand:SI 2 "gpc_reg_operand" "r"))
10438      (clobber (match_scratch:SI 3 "=X"))
10439      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10440           (match_operand:SI 4 "gpc_reg_operand" "r"))
10441      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10442           (match_operand:SI 5 "gpc_reg_operand" "r"))
10443      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10444           (match_operand:SI 6 "gpc_reg_operand" "r"))
10445      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10446           (match_operand:SI 7 "gpc_reg_operand" "r"))
10447      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10448           (match_operand:SI 8 "gpc_reg_operand" "r"))
10449      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10450           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10451   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10452   "stswi %2,%1,%O0"
10453   [(set_attr "type" "store")
10454    (set_attr "update" "yes")
10455    (set_attr "indexed" "yes")
10456    (set_attr "cell_micro" "always")])
10457
10458 (define_insn "*stmsi6"
10459   [(match_parallel 0 "store_multiple_operation"
10460     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10461           (match_operand:SI 2 "gpc_reg_operand" "r"))
10462      (clobber (match_scratch:SI 3 "=X"))
10463      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10464           (match_operand:SI 4 "gpc_reg_operand" "r"))
10465      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10466           (match_operand:SI 5 "gpc_reg_operand" "r"))
10467      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10468           (match_operand:SI 6 "gpc_reg_operand" "r"))
10469      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10470           (match_operand:SI 7 "gpc_reg_operand" "r"))
10471      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10472           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10473   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10474   "stswi %2,%1,%O0"
10475   [(set_attr "type" "store")
10476    (set_attr "update" "yes")
10477    (set_attr "indexed" "yes")
10478    (set_attr "cell_micro" "always")])
10479
10480 (define_insn "*stmsi5"
10481   [(match_parallel 0 "store_multiple_operation"
10482     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10483           (match_operand:SI 2 "gpc_reg_operand" "r"))
10484      (clobber (match_scratch:SI 3 "=X"))
10485      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10486           (match_operand:SI 4 "gpc_reg_operand" "r"))
10487      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10488           (match_operand:SI 5 "gpc_reg_operand" "r"))
10489      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10490           (match_operand:SI 6 "gpc_reg_operand" "r"))
10491      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10492           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10493   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10494   "stswi %2,%1,%O0"
10495   [(set_attr "type" "store")
10496    (set_attr "update" "yes")
10497    (set_attr "indexed" "yes")
10498    (set_attr "cell_micro" "always")])
10499
10500 (define_insn "*stmsi4"
10501   [(match_parallel 0 "store_multiple_operation"
10502     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10503           (match_operand:SI 2 "gpc_reg_operand" "r"))
10504      (clobber (match_scratch:SI 3 "=X"))
10505      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10506           (match_operand:SI 4 "gpc_reg_operand" "r"))
10507      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10508           (match_operand:SI 5 "gpc_reg_operand" "r"))
10509      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10510           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10511   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10512   "stswi %2,%1,%O0"
10513   [(set_attr "type" "store")
10514    (set_attr "update" "yes")
10515    (set_attr "indexed" "yes")
10516    (set_attr "cell_micro" "always")])
10517
10518 (define_insn "*stmsi3"
10519   [(match_parallel 0 "store_multiple_operation"
10520     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10521           (match_operand:SI 2 "gpc_reg_operand" "r"))
10522      (clobber (match_scratch:SI 3 "=X"))
10523      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10524           (match_operand:SI 4 "gpc_reg_operand" "r"))
10525      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10526           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10527   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10528   "stswi %2,%1,%O0"
10529   [(set_attr "type" "store")
10530    (set_attr "update" "yes")
10531    (set_attr "indexed" "yes")
10532    (set_attr "cell_micro" "always")])
10533 \f
10534 (define_expand "setmemsi"
10535   [(parallel [(set (match_operand:BLK 0 "" "")
10536                    (match_operand 2 "const_int_operand" ""))
10537               (use (match_operand:SI 1 "" ""))
10538               (use (match_operand:SI 3 "" ""))])]
10539   ""
10540   "
10541 {
10542   /* If value to set is not zero, use the library routine.  */
10543   if (operands[2] != const0_rtx)
10544     FAIL;
10545
10546   if (expand_block_clear (operands))
10547     DONE;
10548   else
10549     FAIL;
10550 }")
10551
10552 ;; String/block move insn.
10553 ;; Argument 0 is the destination
10554 ;; Argument 1 is the source
10555 ;; Argument 2 is the length
10556 ;; Argument 3 is the alignment
10557
10558 (define_expand "movmemsi"
10559   [(parallel [(set (match_operand:BLK 0 "" "")
10560                    (match_operand:BLK 1 "" ""))
10561               (use (match_operand:SI 2 "" ""))
10562               (use (match_operand:SI 3 "" ""))])]
10563   ""
10564   "
10565 {
10566   if (expand_block_move (operands))
10567     DONE;
10568   else
10569     FAIL;
10570 }")
10571
10572 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
10573 ;; register allocator doesn't have a clue about allocating 8 word registers.
10574 ;; rD/rS = r5 is preferred, efficient form.
10575 (define_expand "movmemsi_8reg"
10576   [(parallel [(set (match_operand 0 "" "")
10577                    (match_operand 1 "" ""))
10578               (use (match_operand 2 "" ""))
10579               (use (match_operand 3 "" ""))
10580               (clobber (reg:SI  5))
10581               (clobber (reg:SI  6))
10582               (clobber (reg:SI  7))
10583               (clobber (reg:SI  8))
10584               (clobber (reg:SI  9))
10585               (clobber (reg:SI 10))
10586               (clobber (reg:SI 11))
10587               (clobber (reg:SI 12))
10588               (clobber (match_scratch:SI 4 ""))])]
10589   "TARGET_STRING"
10590   "")
10591
10592 (define_insn ""
10593   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10594         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10595    (use (match_operand:SI 2 "immediate_operand" "i"))
10596    (use (match_operand:SI 3 "immediate_operand" "i"))
10597    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10598    (clobber (reg:SI  6))
10599    (clobber (reg:SI  7))
10600    (clobber (reg:SI  8))
10601    (clobber (reg:SI  9))
10602    (clobber (reg:SI 10))
10603    (clobber (reg:SI 11))
10604    (clobber (reg:SI 12))
10605    (clobber (match_scratch:SI 5 "=X"))]
10606   "TARGET_STRING
10607    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10608        || INTVAL (operands[2]) == 0)
10609    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10610    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10611    && REGNO (operands[4]) == 5"
10612   "lswi %4,%1,%2\;stswi %4,%0,%2"
10613   [(set_attr "type" "store")
10614    (set_attr "update" "yes")
10615    (set_attr "indexed" "yes")
10616    (set_attr "cell_micro" "always")
10617    (set_attr "length" "8")])
10618
10619 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
10620 ;; register allocator doesn't have a clue about allocating 6 word registers.
10621 ;; rD/rS = r5 is preferred, efficient form.
10622 (define_expand "movmemsi_6reg"
10623   [(parallel [(set (match_operand 0 "" "")
10624                    (match_operand 1 "" ""))
10625               (use (match_operand 2 "" ""))
10626               (use (match_operand 3 "" ""))
10627               (clobber (reg:SI  5))
10628               (clobber (reg:SI  6))
10629               (clobber (reg:SI  7))
10630               (clobber (reg:SI  8))
10631               (clobber (reg:SI  9))
10632               (clobber (reg:SI 10))
10633               (clobber (match_scratch:SI 4 ""))])]
10634   "TARGET_STRING"
10635   "")
10636
10637 (define_insn ""
10638   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10639         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10640    (use (match_operand:SI 2 "immediate_operand" "i"))
10641    (use (match_operand:SI 3 "immediate_operand" "i"))
10642    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10643    (clobber (reg:SI  6))
10644    (clobber (reg:SI  7))
10645    (clobber (reg:SI  8))
10646    (clobber (reg:SI  9))
10647    (clobber (reg:SI 10))
10648    (clobber (match_scratch:SI 5 "=X"))]
10649   "TARGET_STRING
10650    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
10651    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10652    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10653    && REGNO (operands[4]) == 5"
10654   "lswi %4,%1,%2\;stswi %4,%0,%2"
10655   [(set_attr "type" "store")
10656    (set_attr "update" "yes")
10657    (set_attr "indexed" "yes")
10658    (set_attr "cell_micro" "always")
10659    (set_attr "length" "8")])
10660
10661 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
10662 ;; problems with TImode.
10663 ;; rD/rS = r5 is preferred, efficient form.
10664 (define_expand "movmemsi_4reg"
10665   [(parallel [(set (match_operand 0 "" "")
10666                    (match_operand 1 "" ""))
10667               (use (match_operand 2 "" ""))
10668               (use (match_operand 3 "" ""))
10669               (clobber (reg:SI 5))
10670               (clobber (reg:SI 6))
10671               (clobber (reg:SI 7))
10672               (clobber (reg:SI 8))
10673               (clobber (match_scratch:SI 4 ""))])]
10674   "TARGET_STRING"
10675   "")
10676
10677 (define_insn ""
10678   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10679         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10680    (use (match_operand:SI 2 "immediate_operand" "i"))
10681    (use (match_operand:SI 3 "immediate_operand" "i"))
10682    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10683    (clobber (reg:SI 6))
10684    (clobber (reg:SI 7))
10685    (clobber (reg:SI 8))
10686    (clobber (match_scratch:SI 5 "=X"))]
10687   "TARGET_STRING
10688    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
10689    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
10690    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
10691    && REGNO (operands[4]) == 5"
10692   "lswi %4,%1,%2\;stswi %4,%0,%2"
10693   [(set_attr "type" "store")
10694    (set_attr "update" "yes")
10695    (set_attr "indexed" "yes")
10696    (set_attr "cell_micro" "always")
10697    (set_attr "length" "8")])
10698
10699 ;; Move up to 8 bytes at a time.
10700 (define_expand "movmemsi_2reg"
10701   [(parallel [(set (match_operand 0 "" "")
10702                    (match_operand 1 "" ""))
10703               (use (match_operand 2 "" ""))
10704               (use (match_operand 3 "" ""))
10705               (clobber (match_scratch:DI 4 ""))
10706               (clobber (match_scratch:SI 5 ""))])]
10707   "TARGET_STRING && ! TARGET_POWERPC64"
10708   "")
10709
10710 (define_insn ""
10711   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10712         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10713    (use (match_operand:SI 2 "immediate_operand" "i"))
10714    (use (match_operand:SI 3 "immediate_operand" "i"))
10715    (clobber (match_scratch:DI 4 "=&r"))
10716    (clobber (match_scratch:SI 5 "=X"))]
10717   "TARGET_STRING && ! TARGET_POWERPC64
10718    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
10719   "lswi %4,%1,%2\;stswi %4,%0,%2"
10720   [(set_attr "type" "store")
10721    (set_attr "update" "yes")
10722    (set_attr "indexed" "yes")
10723    (set_attr "cell_micro" "always")
10724    (set_attr "length" "8")])
10725
10726 ;; Move up to 4 bytes at a time.
10727 (define_expand "movmemsi_1reg"
10728   [(parallel [(set (match_operand 0 "" "")
10729                    (match_operand 1 "" ""))
10730               (use (match_operand 2 "" ""))
10731               (use (match_operand 3 "" ""))
10732               (clobber (match_scratch:SI 4 ""))
10733               (clobber (match_scratch:SI 5 ""))])]
10734   "TARGET_STRING"
10735   "")
10736
10737 (define_insn ""
10738   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10739         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10740    (use (match_operand:SI 2 "immediate_operand" "i"))
10741    (use (match_operand:SI 3 "immediate_operand" "i"))
10742    (clobber (match_scratch:SI 4 "=&r"))
10743    (clobber (match_scratch:SI 5 "=X"))]
10744   "TARGET_STRING && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
10745   "lswi %4,%1,%2\;stswi %4,%0,%2"
10746   [(set_attr "type" "store")
10747    (set_attr "update" "yes")
10748    (set_attr "indexed" "yes")
10749    (set_attr "cell_micro" "always")
10750    (set_attr "length" "8")])
10751 \f
10752 ;; Define insns that do load or store with update.  Some of these we can
10753 ;; get by using pre-decrement or pre-increment, but the hardware can also
10754 ;; do cases where the increment is not the size of the object.
10755 ;;
10756 ;; In all these cases, we use operands 0 and 1 for the register being
10757 ;; incremented because those are the operands that local-alloc will
10758 ;; tie and these are the pair most likely to be tieable (and the ones
10759 ;; that will benefit the most).
10760
10761 (define_insn "*movdi_update1"
10762   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
10763         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
10764                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
10765    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
10766         (plus:DI (match_dup 1) (match_dup 2)))]
10767   "TARGET_POWERPC64 && TARGET_UPDATE
10768    && (!avoiding_indexed_address_p (DImode)
10769        || !gpc_reg_operand (operands[2], DImode))"
10770   "@
10771    ldux %3,%0,%2
10772    ldu %3,%2(%0)"
10773   [(set_attr "type" "load")
10774    (set_attr "update" "yes")
10775    (set_attr "indexed" "yes,no")])
10776
10777 (define_insn "movdi_<mode>_update"
10778   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10779                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10780         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10781    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10782         (plus:P (match_dup 1) (match_dup 2)))]
10783   "TARGET_POWERPC64 && TARGET_UPDATE
10784    && (!avoiding_indexed_address_p (Pmode)
10785        || !gpc_reg_operand (operands[2], Pmode)
10786        || (REG_P (operands[0])
10787            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10788   "@
10789    stdux %3,%0,%2
10790    stdu %3,%2(%0)"
10791   [(set_attr "type" "store")
10792    (set_attr "update" "yes")
10793    (set_attr "indexed" "yes,no")])
10794
10795 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
10796 ;; needed for stack allocation, even if the user passes -mno-update.
10797 (define_insn "movdi_<mode>_update_stack"
10798   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10799                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10800         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10801    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10802         (plus:P (match_dup 1) (match_dup 2)))]
10803   "TARGET_POWERPC64"
10804   "@
10805    stdux %3,%0,%2
10806    stdu %3,%2(%0)"
10807   [(set_attr "type" "store")
10808    (set_attr "update" "yes")
10809    (set_attr "indexed" "yes,no")])
10810
10811 (define_insn "*movsi_update1"
10812   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10813         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10814                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10815    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10816         (plus:SI (match_dup 1) (match_dup 2)))]
10817   "TARGET_UPDATE
10818    && (!avoiding_indexed_address_p (SImode)
10819        || !gpc_reg_operand (operands[2], SImode))"
10820   "@
10821    lwzux %3,%0,%2
10822    lwzu %3,%2(%0)"
10823   [(set_attr "type" "load")
10824    (set_attr "update" "yes")
10825    (set_attr "indexed" "yes,no")])
10826
10827 (define_insn "*movsi_update2"
10828   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
10829         (sign_extend:DI
10830          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
10831                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
10832    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
10833         (plus:DI (match_dup 1) (match_dup 2)))]
10834   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
10835    && !avoiding_indexed_address_p (DImode)"
10836   "lwaux %3,%0,%2"
10837   [(set_attr "type" "load")
10838    (set_attr "sign_extend" "yes")
10839    (set_attr "update" "yes")
10840    (set_attr "indexed" "yes")])
10841
10842 (define_insn "movsi_update"
10843   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10844                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10845         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10846    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10847         (plus:SI (match_dup 1) (match_dup 2)))]
10848   "TARGET_UPDATE
10849    && (!avoiding_indexed_address_p (SImode)
10850        || !gpc_reg_operand (operands[2], SImode)
10851        || (REG_P (operands[0])
10852            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10853   "@
10854    stwux %3,%0,%2
10855    stwu %3,%2(%0)"
10856   [(set_attr "type" "store")
10857    (set_attr "update" "yes")
10858    (set_attr "indexed" "yes,no")])
10859
10860 ;; This is an unconditional pattern; needed for stack allocation, even
10861 ;; if the user passes -mno-update.
10862 (define_insn "movsi_update_stack"
10863   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10864                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10865         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10866    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10867         (plus:SI (match_dup 1) (match_dup 2)))]
10868   ""
10869   "@
10870    stwux %3,%0,%2
10871    stwu %3,%2(%0)"
10872   [(set_attr "type" "store")
10873    (set_attr "update" "yes")
10874    (set_attr "indexed" "yes,no")])
10875
10876 (define_insn "*movhi_update1"
10877   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
10878         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10879                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10880    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10881         (plus:SI (match_dup 1) (match_dup 2)))]
10882   "TARGET_UPDATE
10883    && (!avoiding_indexed_address_p (SImode)
10884        || !gpc_reg_operand (operands[2], SImode))"
10885   "@
10886    lhzux %3,%0,%2
10887    lhzu %3,%2(%0)"
10888   [(set_attr "type" "load")
10889    (set_attr "update" "yes")
10890    (set_attr "indexed" "yes,no")])
10891
10892 (define_insn "*movhi_update2"
10893   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10894         (zero_extend:SI
10895          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10896                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10897    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10898         (plus:SI (match_dup 1) (match_dup 2)))]
10899   "TARGET_UPDATE
10900    && (!avoiding_indexed_address_p (SImode)
10901        || !gpc_reg_operand (operands[2], SImode))"
10902   "@
10903    lhzux %3,%0,%2
10904    lhzu %3,%2(%0)"
10905   [(set_attr "type" "load")
10906    (set_attr "update" "yes")
10907    (set_attr "indexed" "yes,no")])
10908
10909 (define_insn "*movhi_update3"
10910   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10911         (sign_extend:SI
10912          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10913                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10914    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10915         (plus:SI (match_dup 1) (match_dup 2)))]
10916   "TARGET_UPDATE && rs6000_gen_cell_microcode
10917    && (!avoiding_indexed_address_p (SImode)
10918        || !gpc_reg_operand (operands[2], SImode))"
10919   "@
10920    lhaux %3,%0,%2
10921    lhau %3,%2(%0)"
10922   [(set_attr "type" "load")
10923    (set_attr "sign_extend" "yes")
10924    (set_attr "update" "yes")
10925    (set_attr "indexed" "yes,no")])
10926
10927 (define_insn "*movhi_update4"
10928   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10929                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10930         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
10931    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10932         (plus:SI (match_dup 1) (match_dup 2)))]
10933   "TARGET_UPDATE
10934    && (!avoiding_indexed_address_p (SImode)
10935        || !gpc_reg_operand (operands[2], SImode))"
10936   "@
10937    sthux %3,%0,%2
10938    sthu %3,%2(%0)"
10939   [(set_attr "type" "store")
10940    (set_attr "update" "yes")
10941    (set_attr "indexed" "yes,no")])
10942
10943 (define_insn "*movqi_update1"
10944   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
10945         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10946                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10947    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10948         (plus:SI (match_dup 1) (match_dup 2)))]
10949   "TARGET_UPDATE
10950    && (!avoiding_indexed_address_p (SImode)
10951        || !gpc_reg_operand (operands[2], SImode))"
10952   "@
10953    lbzux %3,%0,%2
10954    lbzu %3,%2(%0)"
10955   [(set_attr "type" "load")
10956    (set_attr "update" "yes")
10957    (set_attr "indexed" "yes,no")])
10958
10959 (define_insn "*movqi_update2"
10960   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10961         (zero_extend:SI
10962          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10963                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10964    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10965         (plus:SI (match_dup 1) (match_dup 2)))]
10966   "TARGET_UPDATE
10967    && (!avoiding_indexed_address_p (SImode)
10968        || !gpc_reg_operand (operands[2], SImode))"
10969   "@
10970    lbzux %3,%0,%2
10971    lbzu %3,%2(%0)"
10972   [(set_attr "type" "load")
10973    (set_attr "update" "yes")
10974    (set_attr "indexed" "yes,no")])
10975
10976 (define_insn "*movqi_update3"
10977   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10978                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10979         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
10980    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10981         (plus:SI (match_dup 1) (match_dup 2)))]
10982   "TARGET_UPDATE
10983    && (!avoiding_indexed_address_p (SImode)
10984        || !gpc_reg_operand (operands[2], SImode))"
10985   "@
10986    stbux %3,%0,%2
10987    stbu %3,%2(%0)"
10988   [(set_attr "type" "store")
10989    (set_attr "update" "yes")
10990    (set_attr "indexed" "yes,no")])
10991
10992 (define_insn "*movsf_update1"
10993   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
10994         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10995                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10996    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10997         (plus:SI (match_dup 1) (match_dup 2)))]
10998   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10999    && (!avoiding_indexed_address_p (SImode)
11000        || !gpc_reg_operand (operands[2], SImode))"
11001   "@
11002    lfsux %3,%0,%2
11003    lfsu %3,%2(%0)"
11004   [(set_attr "type" "fpload")
11005    (set_attr "update" "yes")
11006    (set_attr "indexed" "yes,no")])
11007
11008 (define_insn "*movsf_update2"
11009   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11010                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11011         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
11012    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11013         (plus:SI (match_dup 1) (match_dup 2)))]
11014   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
11015    && (!avoiding_indexed_address_p (SImode)
11016        || !gpc_reg_operand (operands[2], SImode))"
11017   "@
11018    stfsux %3,%0,%2
11019    stfsu %3,%2(%0)"
11020   [(set_attr "type" "fpstore")
11021    (set_attr "update" "yes")
11022    (set_attr "indexed" "yes,no")])
11023
11024 (define_insn "*movsf_update3"
11025   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
11026         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11027                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11028    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11029         (plus:SI (match_dup 1) (match_dup 2)))]
11030   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
11031    && (!avoiding_indexed_address_p (SImode)
11032        || !gpc_reg_operand (operands[2], SImode))"
11033   "@
11034    lwzux %3,%0,%2
11035    lwzu %3,%2(%0)"
11036   [(set_attr "type" "load")
11037    (set_attr "update" "yes")
11038    (set_attr "indexed" "yes,no")])
11039
11040 (define_insn "*movsf_update4"
11041   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11042                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11043         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
11044    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11045         (plus:SI (match_dup 1) (match_dup 2)))]
11046   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
11047    && (!avoiding_indexed_address_p (SImode)
11048        || !gpc_reg_operand (operands[2], SImode))"
11049   "@
11050    stwux %3,%0,%2
11051    stwu %3,%2(%0)"
11052   [(set_attr "type" "store")
11053    (set_attr "update" "yes")
11054    (set_attr "indexed" "yes,no")])
11055
11056 (define_insn "*movdf_update1"
11057   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
11058         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11059                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11060    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11061         (plus:SI (match_dup 1) (match_dup 2)))]
11062   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
11063    && (!avoiding_indexed_address_p (SImode)
11064        || !gpc_reg_operand (operands[2], SImode))"
11065   "@
11066    lfdux %3,%0,%2
11067    lfdu %3,%2(%0)"
11068   [(set_attr "type" "fpload")
11069    (set_attr "update" "yes")
11070    (set_attr "indexed" "yes,no")])
11071
11072 (define_insn "*movdf_update2"
11073   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11074                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11075         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
11076    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11077         (plus:SI (match_dup 1) (match_dup 2)))]
11078   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
11079    && (!avoiding_indexed_address_p (SImode)
11080        || !gpc_reg_operand (operands[2], SImode))"
11081   "@
11082    stfdux %3,%0,%2
11083    stfdu %3,%2(%0)"
11084   [(set_attr "type" "fpstore")
11085    (set_attr "update" "yes")
11086    (set_attr "indexed" "yes,no")])
11087
11088
11089 ;; After inserting conditional returns we can sometimes have
11090 ;; unnecessary register moves.  Unfortunately we cannot have a
11091 ;; modeless peephole here, because some single SImode sets have early
11092 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
11093 ;; sequences, using get_attr_length here will smash the operands
11094 ;; array.  Neither is there an early_cobbler_p predicate.
11095 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
11096 (define_peephole2
11097   [(set (match_operand:DF 0 "gpc_reg_operand" "")
11098         (match_operand:DF 1 "any_operand" ""))
11099    (set (match_operand:DF 2 "gpc_reg_operand" "")
11100         (match_dup 0))]
11101   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
11102    && peep2_reg_dead_p (2, operands[0])"
11103   [(set (match_dup 2) (match_dup 1))])
11104
11105 (define_peephole2
11106   [(set (match_operand:SF 0 "gpc_reg_operand" "")
11107         (match_operand:SF 1 "any_operand" ""))
11108    (set (match_operand:SF 2 "gpc_reg_operand" "")
11109         (match_dup 0))]
11110   "peep2_reg_dead_p (2, operands[0])"
11111   [(set (match_dup 2) (match_dup 1))])
11112
11113 \f
11114 ;; TLS support.
11115
11116 ;; Mode attributes for different ABIs.
11117 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
11118 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
11119 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
11120 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
11121
11122 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
11123   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11124         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11125               (match_operand 4 "" "g")))
11126    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11127                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11128                    UNSPEC_TLSGD)
11129    (clobber (reg:SI LR_REGNO))]
11130   "HAVE_AS_TLS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11131 {
11132   if (TARGET_CMODEL != CMODEL_SMALL)
11133     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;"
11134            "bl %z3\;nop";
11135   else
11136     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;nop";
11137 }
11138   "&& TARGET_TLS_MARKERS"
11139   [(set (match_dup 0)
11140         (unspec:TLSmode [(match_dup 1)
11141                          (match_dup 2)]
11142                         UNSPEC_TLSGD))
11143    (parallel [(set (match_dup 0)
11144                    (call (mem:TLSmode (match_dup 3))
11145                          (match_dup 4)))
11146               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11147               (clobber (reg:SI LR_REGNO))])]
11148   ""
11149   [(set_attr "type" "two")
11150    (set (attr "length")
11151      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11152                    (const_int 16)
11153                    (const_int 12)))])
11154
11155 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
11156   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11157         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11158               (match_operand 4 "" "g")))
11159    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11160                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11161                    UNSPEC_TLSGD)
11162    (clobber (reg:SI LR_REGNO))]
11163   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11164 {
11165   if (flag_pic)
11166     {
11167       if (TARGET_SECURE_PLT && flag_pic == 2)
11168         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
11169       else
11170         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
11171     }
11172   else
11173     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
11174 }
11175   "&& TARGET_TLS_MARKERS"
11176   [(set (match_dup 0)
11177         (unspec:TLSmode [(match_dup 1)
11178                          (match_dup 2)]
11179                         UNSPEC_TLSGD))
11180    (parallel [(set (match_dup 0)
11181                    (call (mem:TLSmode (match_dup 3))
11182                          (match_dup 4)))
11183               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11184               (clobber (reg:SI LR_REGNO))])]
11185   ""
11186   [(set_attr "type" "two")
11187    (set_attr "length" "8")])
11188
11189 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
11190   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11191         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11192                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11193                         UNSPEC_TLSGD))]
11194   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11195   "addi %0,%1,%2@got@tlsgd"
11196   "&& TARGET_CMODEL != CMODEL_SMALL"
11197   [(set (match_dup 3)
11198         (high:TLSmode
11199             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))
11200    (set (match_dup 0)
11201         (lo_sum:TLSmode (match_dup 3)
11202             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))]
11203   "
11204 {
11205   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11206 }"
11207   [(set (attr "length")
11208      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11209                    (const_int 8)
11210                    (const_int 4)))])
11211
11212 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
11213   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11214      (high:TLSmode
11215        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11216                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11217                        UNSPEC_TLSGD)))]
11218   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11219   "addis %0,%1,%2@got@tlsgd@ha"
11220   [(set_attr "length" "4")])
11221
11222 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
11223   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11224      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11225        (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
11226                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11227                        UNSPEC_TLSGD)))]
11228   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11229   "addi %0,%1,%2@got@tlsgd@l"
11230   [(set_attr "length" "4")])
11231
11232 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
11233   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11234         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11235               (match_operand 2 "" "g")))
11236    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11237                    UNSPEC_TLSGD)
11238    (clobber (reg:SI LR_REGNO))]
11239   "HAVE_AS_TLS && TARGET_TLS_MARKERS
11240    && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11241   "bl %z1(%3@tlsgd)\;nop"
11242   [(set_attr "type" "branch")
11243    (set_attr "length" "8")])
11244
11245 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
11246   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11247         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11248               (match_operand 2 "" "g")))
11249    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11250                    UNSPEC_TLSGD)
11251    (clobber (reg:SI LR_REGNO))]
11252   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11253 {
11254   if (flag_pic)
11255     {
11256       if (TARGET_SECURE_PLT && flag_pic == 2)
11257         return "bl %z1+32768(%3@tlsgd)@plt";
11258       return "bl %z1(%3@tlsgd)@plt";
11259     }
11260   return "bl %z1(%3@tlsgd)";
11261 }
11262   [(set_attr "type" "branch")
11263    (set_attr "length" "4")])
11264
11265 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
11266   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11267         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11268               (match_operand 3 "" "g")))
11269    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11270                    UNSPEC_TLSLD)
11271    (clobber (reg:SI LR_REGNO))]
11272   "HAVE_AS_TLS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11273 {
11274   if (TARGET_CMODEL != CMODEL_SMALL)
11275     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;"
11276            "bl %z2\;nop";
11277   else
11278     return "addi %0,%1,%&@got@tlsld\;bl %z2\;nop";
11279 }
11280   "&& TARGET_TLS_MARKERS"
11281   [(set (match_dup 0)
11282         (unspec:TLSmode [(match_dup 1)]
11283                         UNSPEC_TLSLD))
11284    (parallel [(set (match_dup 0)
11285                    (call (mem:TLSmode (match_dup 2))
11286                          (match_dup 3)))
11287               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11288               (clobber (reg:SI LR_REGNO))])]
11289   ""
11290   [(set_attr "type" "two")
11291    (set (attr "length")
11292      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11293                    (const_int 16)
11294                    (const_int 12)))])
11295
11296 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
11297   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11298         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11299               (match_operand 3 "" "g")))
11300    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11301                    UNSPEC_TLSLD)
11302    (clobber (reg:SI LR_REGNO))]
11303   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11304 {
11305   if (flag_pic)
11306     {
11307       if (TARGET_SECURE_PLT && flag_pic == 2)
11308         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11309       else
11310         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11311     }
11312   else
11313     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11314 }
11315   "&& TARGET_TLS_MARKERS"
11316   [(set (match_dup 0)
11317         (unspec:TLSmode [(match_dup 1)]
11318                         UNSPEC_TLSLD))
11319    (parallel [(set (match_dup 0)
11320                    (call (mem:TLSmode (match_dup 2))
11321                          (match_dup 3)))
11322               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11323               (clobber (reg:SI LR_REGNO))])]
11324   ""
11325   [(set_attr "length" "8")])
11326
11327 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
11328   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11329         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11330                         UNSPEC_TLSLD))]
11331   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11332   "addi %0,%1,%&@got@tlsld"
11333   "&& TARGET_CMODEL != CMODEL_SMALL"
11334   [(set (match_dup 2)
11335         (high:TLSmode
11336             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))
11337    (set (match_dup 0)
11338         (lo_sum:TLSmode (match_dup 2)
11339             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))]
11340   "
11341 {
11342   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11343 }"
11344   [(set (attr "length")
11345      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11346                    (const_int 8)
11347                    (const_int 4)))])
11348
11349 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
11350   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11351      (high:TLSmode
11352        (unspec:TLSmode [(const_int 0)
11353                         (match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11354                        UNSPEC_TLSLD)))]
11355   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11356   "addis %0,%1,%&@got@tlsld@ha"
11357   [(set_attr "length" "4")])
11358
11359 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
11360   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11361      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11362        (unspec:TLSmode [(const_int 0)
11363                         (match_operand:TLSmode 2 "gpc_reg_operand" "b")]
11364                        UNSPEC_TLSLD)))]
11365   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11366   "addi %0,%1,%&@got@tlsld@l"
11367   [(set_attr "length" "4")])
11368
11369 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11370   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11371         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11372               (match_operand 2 "" "g")))
11373    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11374    (clobber (reg:SI LR_REGNO))]
11375   "HAVE_AS_TLS && TARGET_TLS_MARKERS
11376    && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11377   "bl %z1(%&@tlsld)\;nop"
11378   [(set_attr "type" "branch")
11379    (set_attr "length" "8")])
11380
11381 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11382   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11383         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11384               (match_operand 2 "" "g")))
11385    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11386    (clobber (reg:SI LR_REGNO))]
11387   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11388 {
11389   if (flag_pic)
11390     {
11391       if (TARGET_SECURE_PLT && flag_pic == 2)
11392         return "bl %z1+32768(%&@tlsld)@plt";
11393       return "bl %z1(%&@tlsld)@plt";
11394     }
11395   return "bl %z1(%&@tlsld)";
11396 }
11397   [(set_attr "type" "branch")
11398    (set_attr "length" "4")])
11399
11400 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11401   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11402         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11403                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11404                         UNSPEC_TLSDTPREL))]
11405   "HAVE_AS_TLS"
11406   "addi %0,%1,%2@dtprel")
11407
11408 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11409   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11410         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11411                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11412                         UNSPEC_TLSDTPRELHA))]
11413   "HAVE_AS_TLS"
11414   "addis %0,%1,%2@dtprel@ha")
11415
11416 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11417   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11418         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11419                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11420                         UNSPEC_TLSDTPRELLO))]
11421   "HAVE_AS_TLS"
11422   "addi %0,%1,%2@dtprel@l")
11423
11424 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11425   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11426         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11427                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11428                         UNSPEC_TLSGOTDTPREL))]
11429   "HAVE_AS_TLS"
11430   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
11431   "&& TARGET_CMODEL != CMODEL_SMALL"
11432   [(set (match_dup 3)
11433         (high:TLSmode
11434             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))
11435    (set (match_dup 0)
11436         (lo_sum:TLSmode (match_dup 3)
11437             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
11438   "
11439 {
11440   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11441 }"
11442   [(set (attr "length")
11443      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11444                    (const_int 8)
11445                    (const_int 4)))])
11446
11447 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
11448   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11449      (high:TLSmode
11450        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11451                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11452                        UNSPEC_TLSGOTDTPREL)))]
11453   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11454   "addis %0,%1,%2@got@dtprel@ha"
11455   [(set_attr "length" "4")])
11456
11457 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
11458   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11459      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11460          (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
11461                           (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11462                          UNSPEC_TLSGOTDTPREL)))]
11463   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11464   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
11465   [(set_attr "length" "4")])
11466
11467 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11468   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11469         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11470                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11471                         UNSPEC_TLSTPREL))]
11472   "HAVE_AS_TLS"
11473   "addi %0,%1,%2@tprel")
11474
11475 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11476   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11477         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11478                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11479                         UNSPEC_TLSTPRELHA))]
11480   "HAVE_AS_TLS"
11481   "addis %0,%1,%2@tprel@ha")
11482
11483 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11484   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11485         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11486                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11487                         UNSPEC_TLSTPRELLO))]
11488   "HAVE_AS_TLS"
11489   "addi %0,%1,%2@tprel@l")
11490
11491 ;; "b" output constraint here and on tls_tls input to support linker tls
11492 ;; optimization.  The linker may edit the instructions emitted by a
11493 ;; tls_got_tprel/tls_tls pair to addis,addi.
11494 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11495   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11496         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11497                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11498                         UNSPEC_TLSGOTTPREL))]
11499   "HAVE_AS_TLS"
11500   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
11501   "&& TARGET_CMODEL != CMODEL_SMALL"
11502   [(set (match_dup 3)
11503         (high:TLSmode
11504             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))
11505    (set (match_dup 0)
11506         (lo_sum:TLSmode (match_dup 3)
11507             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))]
11508   "
11509 {
11510   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11511 }"
11512   [(set (attr "length")
11513      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11514                    (const_int 8)
11515                    (const_int 4)))])
11516
11517 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
11518   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11519      (high:TLSmode
11520        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11521                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11522                        UNSPEC_TLSGOTTPREL)))]
11523   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11524   "addis %0,%1,%2@got@tprel@ha"
11525   [(set_attr "length" "4")])
11526
11527 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
11528   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11529      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11530          (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
11531                           (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11532                          UNSPEC_TLSGOTTPREL)))]
11533   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11534   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
11535   [(set_attr "length" "4")])
11536
11537 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11538   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11539         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11540                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11541                         UNSPEC_TLSTLS))]
11542   "TARGET_ELF && HAVE_AS_TLS"
11543   "add %0,%1,%2@tls")
11544
11545 (define_expand "tls_get_tpointer"
11546   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11547         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))]
11548   "TARGET_XCOFF && HAVE_AS_TLS"
11549   "
11550 {
11551   emit_insn (gen_tls_get_tpointer_internal ());
11552   emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
11553   DONE;
11554 }")
11555
11556 (define_insn "tls_get_tpointer_internal"
11557   [(set (reg:SI 3)
11558         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))
11559    (clobber (reg:SI LR_REGNO))]
11560   "TARGET_XCOFF && HAVE_AS_TLS"
11561   "bla __get_tpointer")
11562
11563 (define_expand "tls_get_addr<mode>"
11564   [(set (match_operand:P 0 "gpc_reg_operand" "")
11565         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "")
11566                    (match_operand:P 2 "gpc_reg_operand" "")] UNSPEC_TLSTLS))]
11567   "TARGET_XCOFF && HAVE_AS_TLS"
11568   "
11569 {
11570   emit_move_insn (gen_rtx_REG (Pmode, 3), operands[1]);
11571   emit_move_insn (gen_rtx_REG (Pmode, 4), operands[2]);
11572   emit_insn (gen_tls_get_addr_internal<mode> ());
11573   emit_move_insn (operands[0], gen_rtx_REG (Pmode, 3));
11574   DONE;
11575 }")
11576
11577 (define_insn "tls_get_addr_internal<mode>"
11578   [(set (reg:P 3)
11579         (unspec:P [(reg:P 3) (reg:P 4)] UNSPEC_TLSTLS))
11580    (clobber (reg:P 0))
11581    (clobber (reg:P 4))
11582    (clobber (reg:P 5))
11583    (clobber (reg:P 11))
11584    (clobber (reg:CC CR0_REGNO))
11585    (clobber (reg:P LR_REGNO))]
11586   "TARGET_XCOFF && HAVE_AS_TLS"
11587   "bla __tls_get_addr")
11588 \f
11589 ;; Next come insns related to the calling sequence.
11590 ;;
11591 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11592 ;; We move the back-chain and decrement the stack pointer.
11593
11594 (define_expand "allocate_stack"
11595   [(set (match_operand 0 "gpc_reg_operand" "")
11596         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11597    (set (reg 1)
11598         (minus (reg 1) (match_dup 1)))]
11599   ""
11600   "
11601 { rtx chain = gen_reg_rtx (Pmode);
11602   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11603   rtx neg_op0;
11604   rtx insn, par, set, mem;
11605
11606   emit_move_insn (chain, stack_bot);
11607
11608   /* Check stack bounds if necessary.  */
11609   if (crtl->limit_stack)
11610     {
11611       rtx available;
11612       available = expand_binop (Pmode, sub_optab,
11613                                 stack_pointer_rtx, stack_limit_rtx,
11614                                 NULL_RTX, 1, OPTAB_WIDEN);
11615       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11616     }
11617
11618   if (GET_CODE (operands[1]) != CONST_INT
11619       || INTVAL (operands[1]) < -32767
11620       || INTVAL (operands[1]) > 32768)
11621     {
11622       neg_op0 = gen_reg_rtx (Pmode);
11623       if (TARGET_32BIT)
11624         emit_insn (gen_negsi2 (neg_op0, operands[1]));
11625       else
11626         emit_insn (gen_negdi2 (neg_op0, operands[1]));
11627     }
11628   else
11629     neg_op0 = GEN_INT (- INTVAL (operands[1]));
11630
11631   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
11632                                        : gen_movdi_di_update_stack))
11633                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
11634                          chain));
11635   /* Since we didn't use gen_frame_mem to generate the MEM, grab
11636      it now and set the alias set/attributes. The above gen_*_update
11637      calls will generate a PARALLEL with the MEM set being the first
11638      operation. */
11639   par = PATTERN (insn);
11640   gcc_assert (GET_CODE (par) == PARALLEL);
11641   set = XVECEXP (par, 0, 0);
11642   gcc_assert (GET_CODE (set) == SET);
11643   mem = SET_DEST (set);
11644   gcc_assert (MEM_P (mem));
11645   MEM_NOTRAP_P (mem) = 1;
11646   set_mem_alias_set (mem, get_frame_alias_set ());
11647
11648   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
11649   DONE;
11650 }")
11651
11652 ;; These patterns say how to save and restore the stack pointer.  We need not
11653 ;; save the stack pointer at function level since we are careful to
11654 ;; preserve the backchain.  At block level, we have to restore the backchain
11655 ;; when we restore the stack pointer.
11656 ;;
11657 ;; For nonlocal gotos, we must save both the stack pointer and its
11658 ;; backchain and restore both.  Note that in the nonlocal case, the
11659 ;; save area is a memory location.
11660
11661 (define_expand "save_stack_function"
11662   [(match_operand 0 "any_operand" "")
11663    (match_operand 1 "any_operand" "")]
11664   ""
11665   "DONE;")
11666
11667 (define_expand "restore_stack_function"
11668   [(match_operand 0 "any_operand" "")
11669    (match_operand 1 "any_operand" "")]
11670   ""
11671   "DONE;")
11672
11673 ;; Adjust stack pointer (op0) to a new value (op1).
11674 ;; First copy old stack backchain to new location, and ensure that the
11675 ;; scheduler won't reorder the sp assignment before the backchain write.
11676 (define_expand "restore_stack_block"
11677   [(set (match_dup 2) (match_dup 3))
11678    (set (match_dup 4) (match_dup 2))
11679    (match_dup 5)
11680    (set (match_operand 0 "register_operand" "")
11681         (match_operand 1 "register_operand" ""))]
11682   ""
11683   "
11684 {
11685   rtvec p;
11686
11687   operands[1] = force_reg (Pmode, operands[1]);
11688   operands[2] = gen_reg_rtx (Pmode);
11689   operands[3] = gen_frame_mem (Pmode, operands[0]);
11690   operands[4] = gen_frame_mem (Pmode, operands[1]);
11691   p = rtvec_alloc (1);
11692   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
11693                                   gen_frame_mem (BLKmode, operands[0]),
11694                                   const0_rtx);
11695   operands[5] = gen_rtx_PARALLEL (VOIDmode, p);
11696 }")
11697
11698 (define_expand "save_stack_nonlocal"
11699   [(set (match_dup 3) (match_dup 4))
11700    (set (match_operand 0 "memory_operand" "") (match_dup 3))
11701    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
11702   ""
11703   "
11704 {
11705   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11706
11707   /* Copy the backchain to the first word, sp to the second.  */
11708   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
11709   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
11710   operands[3] = gen_reg_rtx (Pmode);
11711   operands[4] = gen_frame_mem (Pmode, operands[1]);
11712 }")
11713
11714 (define_expand "restore_stack_nonlocal"
11715   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
11716    (set (match_dup 3) (match_dup 4))
11717    (set (match_dup 5) (match_dup 2))
11718    (match_dup 6)
11719    (set (match_operand 0 "register_operand" "") (match_dup 3))]
11720   ""
11721   "
11722 {
11723   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11724   rtvec p;
11725
11726   /* Restore the backchain from the first word, sp from the second.  */
11727   operands[2] = gen_reg_rtx (Pmode);
11728   operands[3] = gen_reg_rtx (Pmode);
11729   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
11730   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
11731   operands[5] = gen_frame_mem (Pmode, operands[3]);
11732   p = rtvec_alloc (1);
11733   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
11734                                   gen_frame_mem (BLKmode, operands[0]),
11735                                   const0_rtx);
11736   operands[6] = gen_rtx_PARALLEL (VOIDmode, p);
11737 }")
11738 \f
11739 ;; TOC register handling.
11740
11741 ;; Code to initialize the TOC register...
11742
11743 (define_insn "load_toc_aix_si"
11744   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11745                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
11746               (use (reg:SI 2))])]
11747   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && TARGET_32BIT"
11748   "*
11749 {
11750   char buf[30];
11751   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11752   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11753   operands[2] = gen_rtx_REG (Pmode, 2);
11754   return \"lwz %0,%1(%2)\";
11755 }"
11756   [(set_attr "type" "load")
11757    (set_attr "update" "no")
11758    (set_attr "indexed" "no")])
11759
11760 (define_insn "load_toc_aix_di"
11761   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11762                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
11763               (use (reg:DI 2))])]
11764   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && TARGET_64BIT"
11765   "*
11766 {
11767   char buf[30];
11768 #ifdef TARGET_RELOCATABLE
11769   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
11770                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
11771 #else
11772   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11773 #endif
11774   if (TARGET_ELF)
11775     strcat (buf, \"@toc\");
11776   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11777   operands[2] = gen_rtx_REG (Pmode, 2);
11778   return \"ld %0,%1(%2)\";
11779 }"
11780   [(set_attr "type" "load")
11781    (set_attr "update" "no")
11782    (set_attr "indexed" "no")])
11783
11784 (define_insn "load_toc_v4_pic_si"
11785   [(set (reg:SI LR_REGNO)
11786         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
11787   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
11788   "bl _GLOBAL_OFFSET_TABLE_@local-4"
11789   [(set_attr "type" "branch")
11790    (set_attr "length" "4")])
11791
11792 (define_expand "load_toc_v4_PIC_1"
11793   [(parallel [(set (reg:SI LR_REGNO)
11794                    (match_operand:SI 0 "immediate_operand" "s"))
11795               (use (unspec [(match_dup 0)] UNSPEC_TOC))])]
11796   "TARGET_ELF && DEFAULT_ABI == ABI_V4
11797    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11798   "")
11799
11800 (define_insn "load_toc_v4_PIC_1_normal"
11801   [(set (reg:SI LR_REGNO)
11802         (match_operand:SI 0 "immediate_operand" "s"))
11803    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11804   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4
11805    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11806   "bcl 20,31,%0\\n%0:"
11807   [(set_attr "type" "branch")
11808    (set_attr "length" "4")])
11809
11810 (define_insn "load_toc_v4_PIC_1_476"
11811   [(set (reg:SI LR_REGNO)
11812         (match_operand:SI 0 "immediate_operand" "s"))
11813    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11814   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4
11815    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11816   "*
11817 {
11818   char name[32];
11819   static char templ[32];
11820
11821   get_ppc476_thunk_name (name);
11822   sprintf (templ, \"bl %s\\n%%0:\", name);
11823   return templ;
11824 }"
11825   [(set_attr "type" "branch")
11826    (set_attr "length" "4")])
11827
11828 (define_expand "load_toc_v4_PIC_1b"
11829   [(parallel [(set (reg:SI LR_REGNO)
11830                    (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11831                                (label_ref (match_operand 1 "" ""))]
11832                            UNSPEC_TOCPTR))
11833               (match_dup 1)])]
11834   "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11835   "")
11836
11837 (define_insn "load_toc_v4_PIC_1b_normal"
11838   [(set (reg:SI LR_REGNO)
11839         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11840                     (label_ref (match_operand 1 "" ""))]
11841                 UNSPEC_TOCPTR))
11842    (match_dup 1)]
11843   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11844   "bcl 20,31,$+8\;.long %0-$"
11845   [(set_attr "type" "branch")
11846    (set_attr "length" "8")])
11847
11848 (define_insn "load_toc_v4_PIC_1b_476"
11849   [(set (reg:SI LR_REGNO)
11850         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11851                     (label_ref (match_operand 1 "" ""))]
11852                 UNSPEC_TOCPTR))
11853    (match_dup 1)]
11854   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11855   "*
11856 {
11857   char name[32];
11858   static char templ[32];
11859
11860   get_ppc476_thunk_name (name);
11861   sprintf (templ, \"bl %s\\n\\tb $+8\\n\\t.long %%0-$\", name);
11862   return templ;
11863 }"
11864   [(set_attr "type" "branch")
11865    (set_attr "length" "16")])
11866
11867 (define_insn "load_toc_v4_PIC_2"
11868   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11869         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11870                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
11871                              (match_operand:SI 3 "immediate_operand" "s")))))]
11872   "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11873   "lwz %0,%2-%3(%1)"
11874   [(set_attr "type" "load")])
11875
11876 (define_insn "load_toc_v4_PIC_3b"
11877   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11878         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11879                  (high:SI
11880                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11881                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
11882   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
11883   "addis %0,%1,%2-%3@ha")
11884
11885 (define_insn "load_toc_v4_PIC_3c"
11886   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11887         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11888                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11889                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
11890   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
11891   "addi %0,%1,%2-%3@l")
11892
11893 ;; If the TOC is shared over a translation unit, as happens with all
11894 ;; the kinds of PIC that we support, we need to restore the TOC
11895 ;; pointer only when jumping over units of translation.
11896 ;; On Darwin, we need to reload the picbase.
11897
11898 (define_expand "builtin_setjmp_receiver"
11899   [(use (label_ref (match_operand 0 "" "")))]
11900   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11901    || (TARGET_TOC && TARGET_MINIMAL_TOC)
11902    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
11903   "
11904 {
11905 #if TARGET_MACHO
11906   if (DEFAULT_ABI == ABI_DARWIN)
11907     {
11908       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
11909       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
11910       rtx tmplabrtx;
11911       char tmplab[20];
11912
11913       crtl->uses_pic_offset_table = 1;
11914       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
11915                                   CODE_LABEL_NUMBER (operands[0]));
11916       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
11917
11918       emit_insn (gen_load_macho_picbase (tmplabrtx));
11919       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
11920       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
11921     }
11922   else
11923 #endif
11924     rs6000_emit_load_toc_table (FALSE);
11925   DONE;
11926 }")
11927
11928 ;; Largetoc support
11929 (define_insn "*largetoc_high"
11930   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11931         (high:DI
11932           (unspec [(match_operand:DI 1 "" "")
11933                    (match_operand:DI 2 "gpc_reg_operand" "b")]
11934                   UNSPEC_TOCREL)))]
11935    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11936    "addis %0,%2,%1@toc@ha")
11937
11938 (define_insn "*largetoc_high_aix<mode>"
11939   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11940         (high:P
11941           (unspec [(match_operand:P 1 "" "")
11942                    (match_operand:P 2 "gpc_reg_operand" "b")]
11943                   UNSPEC_TOCREL)))]
11944    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11945    "addis %0,%1@u(%2)")
11946
11947 (define_insn "*largetoc_high_plus"
11948   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11949         (high:DI
11950           (plus:DI
11951             (unspec [(match_operand:DI 1 "" "")
11952                      (match_operand:DI 2 "gpc_reg_operand" "b")]
11953                     UNSPEC_TOCREL)
11954             (match_operand:DI 3 "add_cint_operand" "n"))))]
11955    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11956    "addis %0,%2,%1+%3@toc@ha")
11957
11958 (define_insn "*largetoc_high_plus_aix<mode>"
11959   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11960         (high:P
11961           (plus:P
11962             (unspec [(match_operand:P 1 "" "")
11963                      (match_operand:P 2 "gpc_reg_operand" "b")]
11964                     UNSPEC_TOCREL)
11965             (match_operand:P 3 "add_cint_operand" "n"))))]
11966    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11967    "addis %0,%1+%3@u(%2)")
11968
11969 (define_insn "*largetoc_low"
11970   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11971         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,!*r")
11972                    (match_operand:DI 2 "" "")))]
11973    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11974    "@
11975     addi %0,%1,%2@l
11976     addic %0,%1,%2@l")
11977
11978 (define_insn "*largetoc_low_aix<mode>"
11979   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11980         (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
11981                    (match_operand:P 2 "" "")))]
11982    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11983    "la %0,%2@l(%1)")
11984
11985 (define_insn_and_split "*tocref<mode>"
11986   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11987         (match_operand:P 1 "small_toc_ref" "R"))]
11988    "TARGET_TOC"
11989    "la %0,%a1"
11990    "&& TARGET_CMODEL != CMODEL_SMALL && reload_completed"
11991   [(set (match_dup 0) (high:P (match_dup 1)))
11992    (set (match_dup 0) (lo_sum:P (match_dup 0) (match_dup 1)))])
11993
11994 ;; Elf specific ways of loading addresses for non-PIC code.
11995 ;; The output of this could be r0, but we make a very strong
11996 ;; preference for a base register because it will usually
11997 ;; be needed there.
11998 (define_insn "elf_high"
11999   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
12000         (high:SI (match_operand 1 "" "")))]
12001   "TARGET_ELF && ! TARGET_64BIT"
12002   "lis %0,%1@ha")
12003
12004 (define_insn "elf_low"
12005   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12006         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
12007                    (match_operand 2 "" "")))]
12008    "TARGET_ELF && ! TARGET_64BIT"
12009    "@
12010     la %0,%2@l(%1)
12011     addic %0,%1,%K2")
12012 \f
12013 ;; Call and call_value insns
12014 (define_expand "call"
12015   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12016                     (match_operand 1 "" ""))
12017               (use (match_operand 2 "" ""))
12018               (clobber (reg:SI LR_REGNO))])]
12019   ""
12020   "
12021 {
12022 #if TARGET_MACHO
12023   if (MACHOPIC_INDIRECT)
12024     operands[0] = machopic_indirect_call_target (operands[0]);
12025 #endif
12026
12027   gcc_assert (GET_CODE (operands[0]) == MEM);
12028   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12029
12030   operands[0] = XEXP (operands[0], 0);
12031
12032   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12033     {
12034       rs6000_call_aix (NULL_RTX, operands[0], operands[1], operands[2]);
12035       DONE;
12036     }
12037
12038   if (GET_CODE (operands[0]) != SYMBOL_REF
12039       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
12040     {
12041       if (INTVAL (operands[2]) & CALL_LONG)
12042         operands[0] = rs6000_longcall_ref (operands[0]);
12043
12044       switch (DEFAULT_ABI)
12045         {
12046         case ABI_V4:
12047         case ABI_DARWIN:
12048           operands[0] = force_reg (Pmode, operands[0]);
12049           break;
12050
12051         default:
12052           gcc_unreachable ();
12053         }
12054     }
12055 }")
12056
12057 (define_expand "call_value"
12058   [(parallel [(set (match_operand 0 "" "")
12059                    (call (mem:SI (match_operand 1 "address_operand" ""))
12060                          (match_operand 2 "" "")))
12061               (use (match_operand 3 "" ""))
12062               (clobber (reg:SI LR_REGNO))])]
12063   ""
12064   "
12065 {
12066 #if TARGET_MACHO
12067   if (MACHOPIC_INDIRECT)
12068     operands[1] = machopic_indirect_call_target (operands[1]);
12069 #endif
12070
12071   gcc_assert (GET_CODE (operands[1]) == MEM);
12072   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12073
12074   operands[1] = XEXP (operands[1], 0);
12075
12076   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12077     {
12078       rs6000_call_aix (operands[0], operands[1], operands[2], operands[3]);
12079       DONE;
12080     }
12081
12082   if (GET_CODE (operands[1]) != SYMBOL_REF
12083       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
12084     {
12085       if (INTVAL (operands[3]) & CALL_LONG)
12086         operands[1] = rs6000_longcall_ref (operands[1]);
12087
12088       switch (DEFAULT_ABI)
12089         {
12090         case ABI_V4:
12091         case ABI_DARWIN:
12092           operands[1] = force_reg (Pmode, operands[1]);
12093           break;
12094
12095         default:
12096           gcc_unreachable ();
12097         }
12098     }
12099 }")
12100
12101 ;; Call to function in current module.  No TOC pointer reload needed.
12102 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12103 ;; either the function was not prototyped, or it was prototyped as a
12104 ;; variable argument function.  It is > 0 if FP registers were passed
12105 ;; and < 0 if they were not.
12106
12107 (define_insn "*call_local32"
12108   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12109          (match_operand 1 "" "g,g"))
12110    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12111    (clobber (reg:SI LR_REGNO))]
12112   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12113   "*
12114 {
12115   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12116     output_asm_insn (\"crxor 6,6,6\", operands);
12117
12118   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12119     output_asm_insn (\"creqv 6,6,6\", operands);
12120
12121   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12122 }"
12123   [(set_attr "type" "branch")
12124    (set_attr "length" "4,8")])
12125
12126 (define_insn "*call_local64"
12127   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12128          (match_operand 1 "" "g,g"))
12129    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12130    (clobber (reg:SI LR_REGNO))]
12131   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12132   "*
12133 {
12134   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12135     output_asm_insn (\"crxor 6,6,6\", operands);
12136
12137   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12138     output_asm_insn (\"creqv 6,6,6\", operands);
12139
12140   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12141 }"
12142   [(set_attr "type" "branch")
12143    (set_attr "length" "4,8")])
12144
12145 (define_insn "*call_value_local32"
12146   [(set (match_operand 0 "" "")
12147         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12148               (match_operand 2 "" "g,g")))
12149    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12150    (clobber (reg:SI LR_REGNO))]
12151   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12152   "*
12153 {
12154   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12155     output_asm_insn (\"crxor 6,6,6\", operands);
12156
12157   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12158     output_asm_insn (\"creqv 6,6,6\", operands);
12159
12160   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12161 }"
12162   [(set_attr "type" "branch")
12163    (set_attr "length" "4,8")])
12164
12165
12166 (define_insn "*call_value_local64"
12167   [(set (match_operand 0 "" "")
12168         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12169               (match_operand 2 "" "g,g")))
12170    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12171    (clobber (reg:SI LR_REGNO))]
12172   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12173   "*
12174 {
12175   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12176     output_asm_insn (\"crxor 6,6,6\", operands);
12177
12178   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12179     output_asm_insn (\"creqv 6,6,6\", operands);
12180
12181   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12182 }"
12183   [(set_attr "type" "branch")
12184    (set_attr "length" "4,8")])
12185
12186
12187 ;; A function pointer under System V is just a normal pointer
12188 ;; operands[0] is the function pointer
12189 ;; operands[1] is the stack size to clean up
12190 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12191 ;; which indicates how to set cr1
12192
12193 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12194   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12195          (match_operand 1 "" "g,g,g,g"))
12196    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12197    (clobber (reg:SI LR_REGNO))]
12198   "DEFAULT_ABI == ABI_V4
12199    || DEFAULT_ABI == ABI_DARWIN"
12200 {
12201   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12202     output_asm_insn ("crxor 6,6,6", operands);
12203
12204   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12205     output_asm_insn ("creqv 6,6,6", operands);
12206
12207   return "b%T0l";
12208 }
12209   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12210    (set_attr "length" "4,4,8,8")])
12211
12212 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12213   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12214          (match_operand 1 "" "g,g"))
12215    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12216    (clobber (reg:SI LR_REGNO))]
12217   "(DEFAULT_ABI == ABI_DARWIN
12218    || (DEFAULT_ABI == ABI_V4
12219        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12220 {
12221   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12222     output_asm_insn ("crxor 6,6,6", operands);
12223
12224   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12225     output_asm_insn ("creqv 6,6,6", operands);
12226
12227 #if TARGET_MACHO
12228   return output_call(insn, operands, 0, 2);
12229 #else
12230   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12231     {
12232       gcc_assert (!TARGET_SECURE_PLT);
12233       return "bl %z0@plt";
12234     }
12235   else
12236     return "bl %z0";
12237 #endif
12238 }
12239   "DEFAULT_ABI == ABI_V4
12240    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12241    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12242   [(parallel [(call (mem:SI (match_dup 0))
12243                     (match_dup 1))
12244               (use (match_dup 2))
12245               (use (match_dup 3))
12246               (clobber (reg:SI LR_REGNO))])]
12247 {
12248   operands[3] = pic_offset_table_rtx;
12249 }
12250   [(set_attr "type" "branch,branch")
12251    (set_attr "length" "4,8")])
12252
12253 (define_insn "*call_nonlocal_sysv_secure<mode>"
12254   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12255          (match_operand 1 "" "g,g"))
12256    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12257    (use (match_operand:SI 3 "register_operand" "r,r"))
12258    (clobber (reg:SI LR_REGNO))]
12259   "(DEFAULT_ABI == ABI_V4
12260     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12261     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
12262 {
12263   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12264     output_asm_insn ("crxor 6,6,6", operands);
12265
12266   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12267     output_asm_insn ("creqv 6,6,6", operands);
12268
12269   if (flag_pic == 2)
12270     /* The magic 32768 offset here and in the other sysv call insns
12271        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12272        See sysv4.h:toc_section.  */
12273     return "bl %z0+32768@plt";
12274   else
12275     return "bl %z0@plt";
12276 }
12277   [(set_attr "type" "branch,branch")
12278    (set_attr "length" "4,8")])
12279
12280 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12281   [(set (match_operand 0 "" "")
12282         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12283               (match_operand 2 "" "g,g,g,g")))
12284    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12285    (clobber (reg:SI LR_REGNO))]
12286   "DEFAULT_ABI == ABI_V4
12287    || DEFAULT_ABI == ABI_DARWIN"
12288 {
12289   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12290     output_asm_insn ("crxor 6,6,6", operands);
12291
12292   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12293     output_asm_insn ("creqv 6,6,6", operands);
12294
12295   return "b%T1l";
12296 }
12297   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12298    (set_attr "length" "4,4,8,8")])
12299
12300 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12301   [(set (match_operand 0 "" "")
12302         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12303               (match_operand 2 "" "g,g")))
12304    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12305    (clobber (reg:SI LR_REGNO))]
12306   "(DEFAULT_ABI == ABI_DARWIN
12307    || (DEFAULT_ABI == ABI_V4
12308        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12309 {
12310   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12311     output_asm_insn ("crxor 6,6,6", operands);
12312
12313   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12314     output_asm_insn ("creqv 6,6,6", operands);
12315
12316 #if TARGET_MACHO
12317   return output_call(insn, operands, 1, 3);
12318 #else
12319   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12320     {
12321       gcc_assert (!TARGET_SECURE_PLT);
12322       return "bl %z1@plt";
12323     }
12324   else
12325     return "bl %z1";
12326 #endif
12327 }
12328   "DEFAULT_ABI == ABI_V4
12329    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12330    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12331   [(parallel [(set (match_dup 0)
12332                    (call (mem:SI (match_dup 1))
12333                          (match_dup 2)))
12334               (use (match_dup 3))
12335               (use (match_dup 4))
12336               (clobber (reg:SI LR_REGNO))])]
12337 {
12338   operands[4] = pic_offset_table_rtx;
12339 }
12340   [(set_attr "type" "branch,branch")
12341    (set_attr "length" "4,8")])
12342
12343 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12344   [(set (match_operand 0 "" "")
12345         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12346               (match_operand 2 "" "g,g")))
12347    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12348    (use (match_operand:SI 4 "register_operand" "r,r"))
12349    (clobber (reg:SI LR_REGNO))]
12350   "(DEFAULT_ABI == ABI_V4
12351     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12352     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12353 {
12354   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12355     output_asm_insn ("crxor 6,6,6", operands);
12356
12357   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12358     output_asm_insn ("creqv 6,6,6", operands);
12359
12360   if (flag_pic == 2)
12361     return "bl %z1+32768@plt";
12362   else
12363     return "bl %z1@plt";
12364 }
12365   [(set_attr "type" "branch,branch")
12366    (set_attr "length" "4,8")])
12367
12368
12369 ;; Call to AIX abi function in the same module.
12370
12371 (define_insn "*call_local_aix<mode>"
12372   [(call (mem:SI (match_operand:P 0 "current_file_function_operand" "s"))
12373          (match_operand 1 "" "g"))
12374    (clobber (reg:P LR_REGNO))]
12375   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12376   "bl %z0"
12377   [(set_attr "type" "branch")
12378    (set_attr "length" "4")])
12379
12380 (define_insn "*call_value_local_aix<mode>"
12381   [(set (match_operand 0 "" "")
12382         (call (mem:SI (match_operand:P 1 "current_file_function_operand" "s"))
12383               (match_operand 2 "" "g")))
12384    (clobber (reg:P LR_REGNO))]
12385   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12386   "bl %z1"
12387   [(set_attr "type" "branch")
12388    (set_attr "length" "4")])
12389
12390 ;; Call to AIX abi function which may be in another module.
12391 ;; Restore the TOC pointer (r2) after the call.
12392
12393 (define_insn "*call_nonlocal_aix<mode>"
12394   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s"))
12395          (match_operand 1 "" "g"))
12396    (clobber (reg:P LR_REGNO))]
12397   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12398   "bl %z0\;nop"
12399   [(set_attr "type" "branch")
12400    (set_attr "length" "8")])
12401
12402 (define_insn "*call_value_nonlocal_aix<mode>"
12403   [(set (match_operand 0 "" "")
12404         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s"))
12405               (match_operand 2 "" "g")))
12406    (clobber (reg:P LR_REGNO))]
12407   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12408   "bl %z1\;nop"
12409   [(set_attr "type" "branch")
12410    (set_attr "length" "8")])
12411
12412 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
12413 ;; Operand0 is the addresss of the function to call
12414 ;; Operand2 is the location in the function descriptor to load r2 from
12415 ;; Operand3 is the stack location to hold the current TOC pointer
12416
12417 (define_insn "*call_indirect_aix<mode>"
12418   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12419          (match_operand 1 "" "g,g"))
12420    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
12421    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12422    (clobber (reg:P LR_REGNO))]
12423   "DEFAULT_ABI == ABI_AIX"
12424   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
12425   [(set_attr "type" "jmpreg")
12426    (set_attr "length" "12")])
12427
12428 (define_insn "*call_value_indirect_aix<mode>"
12429   [(set (match_operand 0 "" "")
12430         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12431               (match_operand 2 "" "g,g")))
12432    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12433    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
12434    (clobber (reg:P LR_REGNO))]
12435   "DEFAULT_ABI == ABI_AIX"
12436   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12437   [(set_attr "type" "jmpreg")
12438    (set_attr "length" "12")])
12439
12440 ;; Call to indirect functions with the ELFv2 ABI.
12441 ;; Operand0 is the addresss of the function to call
12442 ;; Operand2 is the stack location to hold the current TOC pointer
12443
12444 (define_insn "*call_indirect_elfv2<mode>"
12445   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12446          (match_operand 1 "" "g,g"))
12447    (set (reg:P TOC_REGNUM) (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
12448    (clobber (reg:P LR_REGNO))]
12449   "DEFAULT_ABI == ABI_ELFv2"
12450   "b%T0l\;<ptrload> 2,%2"
12451   [(set_attr "type" "jmpreg")
12452    (set_attr "length" "8")])
12453
12454 (define_insn "*call_value_indirect_elfv2<mode>"
12455   [(set (match_operand 0 "" "")
12456         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12457               (match_operand 2 "" "g,g")))
12458    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12459    (clobber (reg:P LR_REGNO))]
12460   "DEFAULT_ABI == ABI_ELFv2"
12461   "b%T1l\;<ptrload> 2,%3"
12462   [(set_attr "type" "jmpreg")
12463    (set_attr "length" "8")])
12464
12465
12466 ;; Call subroutine returning any type.
12467 (define_expand "untyped_call"
12468   [(parallel [(call (match_operand 0 "" "")
12469                     (const_int 0))
12470               (match_operand 1 "" "")
12471               (match_operand 2 "" "")])]
12472   ""
12473   "
12474 {
12475   int i;
12476
12477   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12478
12479   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12480     {
12481       rtx set = XVECEXP (operands[2], 0, i);
12482       emit_move_insn (SET_DEST (set), SET_SRC (set));
12483     }
12484
12485   /* The optimizer does not know that the call sets the function value
12486      registers we stored in the result block.  We avoid problems by
12487      claiming that all hard registers are used and clobbered at this
12488      point.  */
12489   emit_insn (gen_blockage ());
12490
12491   DONE;
12492 }")
12493
12494 ;; sibling call patterns
12495 (define_expand "sibcall"
12496   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12497                     (match_operand 1 "" ""))
12498               (use (match_operand 2 "" ""))
12499               (use (reg:SI LR_REGNO))
12500               (simple_return)])]
12501   ""
12502   "
12503 {
12504 #if TARGET_MACHO
12505   if (MACHOPIC_INDIRECT)
12506     operands[0] = machopic_indirect_call_target (operands[0]);
12507 #endif
12508
12509   gcc_assert (GET_CODE (operands[0]) == MEM);
12510   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12511
12512   operands[0] = XEXP (operands[0], 0);
12513
12514   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12515     {
12516       rs6000_sibcall_aix (NULL_RTX, operands[0], operands[1], operands[2]);
12517       DONE;
12518     }
12519 }")
12520
12521 (define_expand "sibcall_value"
12522   [(parallel [(set (match_operand 0 "register_operand" "")
12523                 (call (mem:SI (match_operand 1 "address_operand" ""))
12524                       (match_operand 2 "" "")))
12525               (use (match_operand 3 "" ""))
12526               (use (reg:SI LR_REGNO))
12527               (simple_return)])]
12528   ""
12529   "
12530 {
12531 #if TARGET_MACHO
12532   if (MACHOPIC_INDIRECT)
12533     operands[1] = machopic_indirect_call_target (operands[1]);
12534 #endif
12535
12536   gcc_assert (GET_CODE (operands[1]) == MEM);
12537   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12538
12539   operands[1] = XEXP (operands[1], 0);
12540
12541   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12542     {
12543       rs6000_sibcall_aix (operands[0], operands[1], operands[2], operands[3]);
12544       DONE;
12545     }
12546 }")
12547
12548 ;; this and similar patterns must be marked as using LR, otherwise
12549 ;; dataflow will try to delete the store into it.  This is true
12550 ;; even when the actual reg to jump to is in CTR, when LR was
12551 ;; saved and restored around the PIC-setting BCL.
12552 (define_insn "*sibcall_local32"
12553   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12554          (match_operand 1 "" "g,g"))
12555    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12556    (use (reg:SI LR_REGNO))
12557    (simple_return)]
12558   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12559   "*
12560 {
12561   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12562     output_asm_insn (\"crxor 6,6,6\", operands);
12563
12564   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12565     output_asm_insn (\"creqv 6,6,6\", operands);
12566
12567   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12568 }"
12569   [(set_attr "type" "branch")
12570    (set_attr "length" "4,8")])
12571
12572 (define_insn "*sibcall_local64"
12573   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12574          (match_operand 1 "" "g,g"))
12575    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12576    (use (reg:SI LR_REGNO))
12577    (simple_return)]
12578   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12579   "*
12580 {
12581   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12582     output_asm_insn (\"crxor 6,6,6\", operands);
12583
12584   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12585     output_asm_insn (\"creqv 6,6,6\", operands);
12586
12587   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12588 }"
12589   [(set_attr "type" "branch")
12590    (set_attr "length" "4,8")])
12591
12592 (define_insn "*sibcall_value_local32"
12593   [(set (match_operand 0 "" "")
12594         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12595               (match_operand 2 "" "g,g")))
12596    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12597    (use (reg:SI LR_REGNO))
12598    (simple_return)]
12599   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12600   "*
12601 {
12602   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12603     output_asm_insn (\"crxor 6,6,6\", operands);
12604
12605   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12606     output_asm_insn (\"creqv 6,6,6\", operands);
12607
12608   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12609 }"
12610   [(set_attr "type" "branch")
12611    (set_attr "length" "4,8")])
12612
12613 (define_insn "*sibcall_value_local64"
12614   [(set (match_operand 0 "" "")
12615         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12616               (match_operand 2 "" "g,g")))
12617    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12618    (use (reg:SI LR_REGNO))
12619    (simple_return)]
12620   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12621   "*
12622 {
12623   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12624     output_asm_insn (\"crxor 6,6,6\", operands);
12625
12626   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12627     output_asm_insn (\"creqv 6,6,6\", operands);
12628
12629   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12630 }"
12631   [(set_attr "type" "branch")
12632    (set_attr "length" "4,8")])
12633
12634 (define_insn "*sibcall_nonlocal_sysv<mode>"
12635   [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c"))
12636          (match_operand 1 "" ""))
12637    (use (match_operand 2 "immediate_operand" "O,n,O,n"))
12638    (use (reg:SI LR_REGNO))
12639    (simple_return)]
12640   "(DEFAULT_ABI == ABI_DARWIN
12641     || DEFAULT_ABI == ABI_V4)
12642    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12643   "*
12644 {
12645   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12646     output_asm_insn (\"crxor 6,6,6\", operands);
12647
12648   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12649     output_asm_insn (\"creqv 6,6,6\", operands);
12650
12651   if (which_alternative >= 2)
12652     return \"b%T0\";
12653   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12654     {
12655       gcc_assert (!TARGET_SECURE_PLT);
12656       return \"b %z0@plt\";
12657     }
12658   else
12659     return \"b %z0\";
12660 }"
12661   [(set_attr "type" "branch")
12662    (set_attr "length" "4,8,4,8")])
12663
12664 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
12665   [(set (match_operand 0 "" "")
12666         (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c"))
12667               (match_operand 2 "" "")))
12668    (use (match_operand:SI 3 "immediate_operand" "O,n,O,n"))
12669    (use (reg:SI LR_REGNO))
12670    (simple_return)]
12671   "(DEFAULT_ABI == ABI_DARWIN
12672     || DEFAULT_ABI == ABI_V4)
12673    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12674   "*
12675 {
12676   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12677     output_asm_insn (\"crxor 6,6,6\", operands);
12678
12679   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12680     output_asm_insn (\"creqv 6,6,6\", operands);
12681
12682   if (which_alternative >= 2)
12683     return \"b%T1\";
12684   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12685     {
12686       gcc_assert (!TARGET_SECURE_PLT);
12687       return \"b %z1@plt\";
12688     }
12689   else
12690     return \"b %z1\";
12691 }"
12692   [(set_attr "type" "branch")
12693    (set_attr "length" "4,8,4,8")])
12694
12695 ;; AIX ABI sibling call patterns.
12696
12697 (define_insn "*sibcall_aix<mode>"
12698   [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
12699          (match_operand 1 "" "g,g"))
12700    (simple_return)]
12701   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12702   "@
12703    b %z0
12704    b%T0"
12705   [(set_attr "type" "branch")
12706    (set_attr "length" "4")])
12707
12708 (define_insn "*sibcall_value_aix<mode>"
12709   [(set (match_operand 0 "" "")
12710         (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
12711               (match_operand 2 "" "g,g")))
12712    (simple_return)]
12713   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12714   "@
12715    b %z1
12716    b%T1"
12717   [(set_attr "type" "branch")
12718    (set_attr "length" "4")])
12719
12720 (define_expand "sibcall_epilogue"
12721   [(use (const_int 0))]
12722   ""
12723 {
12724   if (!TARGET_SCHED_PROLOG)
12725     emit_insn (gen_blockage ());
12726   rs6000_emit_epilogue (TRUE);
12727   DONE;
12728 })
12729
12730 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12731 ;; all of memory.  This blocks insns from being moved across this point.
12732
12733 (define_insn "blockage"
12734   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
12735   ""
12736   "")
12737
12738 (define_expand "probe_stack"
12739   [(set (match_operand 0 "memory_operand" "=m")
12740         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
12741   ""
12742 {
12743   if (TARGET_64BIT)
12744     emit_insn (gen_probe_stack_di (operands[0]));
12745   else
12746     emit_insn (gen_probe_stack_si (operands[0]));
12747   DONE;
12748 })
12749
12750 (define_insn "probe_stack_<mode>"
12751   [(set (match_operand:P 0 "memory_operand" "=m")
12752         (unspec:P [(const_int 0)] UNSPEC_PROBE_STACK))]
12753   ""
12754 {
12755   operands[1] = gen_rtx_REG (Pmode, 0);
12756   return "st<wd>%U0%X0 %1,%0";
12757 }
12758   [(set_attr "type" "store")
12759    (set (attr "update")
12760         (if_then_else (match_operand 0 "update_address_mem")
12761                       (const_string "yes")
12762                       (const_string "no")))
12763    (set (attr "indexed")
12764         (if_then_else (match_operand 0 "indexed_address_mem")
12765                       (const_string "yes")
12766                       (const_string "no")))
12767    (set_attr "length" "4")])
12768
12769 (define_insn "probe_stack_range<P:mode>"
12770   [(set (match_operand:P 0 "register_operand" "=r")
12771         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
12772                             (match_operand:P 2 "register_operand" "r")]
12773                            UNSPECV_PROBE_STACK_RANGE))]
12774   ""
12775   "* return output_probe_stack_range (operands[0], operands[2]);"
12776   [(set_attr "type" "three")])
12777 \f
12778 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
12779 ;; signed & unsigned, and one type of branch.
12780 ;;
12781 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
12782 ;; insns, and branches.
12783
12784 (define_expand "cbranch<mode>4"
12785   [(use (match_operator 0 "rs6000_cbranch_operator"
12786          [(match_operand:GPR 1 "gpc_reg_operand" "")
12787           (match_operand:GPR 2 "reg_or_short_operand" "")]))
12788    (use (match_operand 3 ""))]
12789   ""
12790   "
12791 {
12792   /* Take care of the possibility that operands[2] might be negative but
12793      this might be a logical operation.  That insn doesn't exist.  */
12794   if (GET_CODE (operands[2]) == CONST_INT
12795       && INTVAL (operands[2]) < 0)
12796     {
12797       operands[2] = force_reg (<MODE>mode, operands[2]);
12798       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
12799                                     GET_MODE (operands[0]),
12800                                     operands[1], operands[2]);
12801    }
12802
12803   rs6000_emit_cbranch (<MODE>mode, operands);
12804   DONE;
12805 }")
12806
12807 (define_expand "cbranch<mode>4"
12808   [(use (match_operator 0 "rs6000_cbranch_operator"
12809          [(match_operand:FP 1 "gpc_reg_operand" "")
12810           (match_operand:FP 2 "gpc_reg_operand" "")]))
12811    (use (match_operand 3 ""))]
12812   ""
12813   "
12814 {
12815   rs6000_emit_cbranch (<MODE>mode, operands);
12816   DONE;
12817 }")
12818
12819 (define_expand "cstore<mode>4"
12820   [(use (match_operator 1 "rs6000_cbranch_operator"
12821          [(match_operand:GPR 2 "gpc_reg_operand" "")
12822           (match_operand:GPR 3 "reg_or_short_operand" "")]))
12823    (clobber (match_operand:SI 0 "register_operand"))]
12824   ""
12825   "
12826 {
12827   /* Take care of the possibility that operands[3] might be negative but
12828      this might be a logical operation.  That insn doesn't exist.  */
12829   if (GET_CODE (operands[3]) == CONST_INT
12830       && INTVAL (operands[3]) < 0)
12831     {
12832       operands[3] = force_reg (<MODE>mode, operands[3]);
12833       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
12834                                     GET_MODE (operands[1]),
12835                                     operands[2], operands[3]);
12836     }
12837
12838   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
12839      For SEQ, likewise, except that comparisons with zero should be done
12840      with an scc insns.  However, due to the order that combine see the
12841      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
12842      the cases we don't want to handle or are best handled by portable
12843      code.  */
12844   if (GET_CODE (operands[1]) == NE)
12845     FAIL;
12846   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
12847        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
12848       && operands[3] == const0_rtx)
12849     FAIL;
12850   rs6000_emit_sCOND (<MODE>mode, operands);
12851   DONE;
12852 }")
12853
12854 (define_expand "cstore<mode>4"
12855   [(use (match_operator 1 "rs6000_cbranch_operator"
12856          [(match_operand:FP 2 "gpc_reg_operand" "")
12857           (match_operand:FP 3 "gpc_reg_operand" "")]))
12858    (clobber (match_operand:SI 0 "register_operand"))]
12859   ""
12860   "
12861 {
12862   rs6000_emit_sCOND (<MODE>mode, operands);
12863   DONE;
12864 }")
12865
12866
12867 (define_expand "stack_protect_set"
12868   [(match_operand 0 "memory_operand" "")
12869    (match_operand 1 "memory_operand" "")]
12870   ""
12871 {
12872 #ifdef TARGET_THREAD_SSP_OFFSET
12873   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12874   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12875   operands[1] = gen_rtx_MEM (Pmode, addr);
12876 #endif
12877   if (TARGET_64BIT)
12878     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
12879   else
12880     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
12881   DONE;
12882 })
12883
12884 (define_insn "stack_protect_setsi"
12885   [(set (match_operand:SI 0 "memory_operand" "=m")
12886         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12887    (set (match_scratch:SI 2 "=&r") (const_int 0))]
12888   "TARGET_32BIT"
12889   "lwz%U1%X1 %2,%1\;stw%U0%X0 %2,%0\;li %2,0"
12890   [(set_attr "type" "three")
12891    (set_attr "length" "12")])
12892
12893 (define_insn "stack_protect_setdi"
12894   [(set (match_operand:DI 0 "memory_operand" "=Y")
12895         (unspec:DI [(match_operand:DI 1 "memory_operand" "Y")] UNSPEC_SP_SET))
12896    (set (match_scratch:DI 2 "=&r") (const_int 0))]
12897   "TARGET_64BIT"
12898   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;li %2,0"
12899   [(set_attr "type" "three")
12900    (set_attr "length" "12")])
12901
12902 (define_expand "stack_protect_test"
12903   [(match_operand 0 "memory_operand" "")
12904    (match_operand 1 "memory_operand" "")
12905    (match_operand 2 "" "")]
12906   ""
12907 {
12908   rtx test, op0, op1;
12909 #ifdef TARGET_THREAD_SSP_OFFSET
12910   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12911   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12912   operands[1] = gen_rtx_MEM (Pmode, addr);
12913 #endif
12914   op0 = operands[0];
12915   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
12916   test = gen_rtx_EQ (VOIDmode, op0, op1);
12917   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
12918   DONE;
12919 })
12920
12921 (define_insn "stack_protect_testsi"
12922   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12923         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
12924                       (match_operand:SI 2 "memory_operand" "m,m")]
12925                      UNSPEC_SP_TEST))
12926    (set (match_scratch:SI 4 "=r,r") (const_int 0))
12927    (clobber (match_scratch:SI 3 "=&r,&r"))]
12928   "TARGET_32BIT"
12929   "@
12930    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
12931    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;cmplw %0,%3,%4\;li %3,0\;li %4,0"
12932   [(set_attr "length" "16,20")])
12933
12934 (define_insn "stack_protect_testdi"
12935   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12936         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "Y,Y")
12937                       (match_operand:DI 2 "memory_operand" "Y,Y")]
12938                      UNSPEC_SP_TEST))
12939    (set (match_scratch:DI 4 "=r,r") (const_int 0))
12940    (clobber (match_scratch:DI 3 "=&r,&r"))]
12941   "TARGET_64BIT"
12942   "@
12943    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
12944    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;li %3,0\;li %4,0"
12945   [(set_attr "length" "16,20")])
12946
12947 \f
12948 ;; Here are the actual compare insns.
12949 (define_insn "*cmp<mode>_internal1"
12950   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
12951         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
12952                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
12953   ""
12954   "cmp<wd>%I2 %0,%1,%2"
12955   [(set_attr "type" "cmp")])
12956
12957 ;; If we are comparing a register for equality with a large constant,
12958 ;; we can do this with an XOR followed by a compare.  But this is profitable
12959 ;; only if the large constant is only used for the comparison (and in this
12960 ;; case we already have a register to reuse as scratch).
12961 ;;
12962 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
12963 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
12964
12965 (define_peephole2
12966   [(set (match_operand:SI 0 "register_operand")
12967         (match_operand:SI 1 "logical_const_operand" ""))
12968    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
12969                        [(match_dup 0)
12970                         (match_operand:SI 2 "logical_const_operand" "")]))
12971    (set (match_operand:CC 4 "cc_reg_operand" "")
12972         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
12973                     (match_dup 0)))
12974    (set (pc)
12975         (if_then_else (match_operator 6 "equality_operator"
12976                        [(match_dup 4) (const_int 0)])
12977                       (match_operand 7 "" "")
12978                       (match_operand 8 "" "")))]
12979   "peep2_reg_dead_p (3, operands[0])
12980    && peep2_reg_dead_p (4, operands[4])"
12981  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
12982   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
12983   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
12984  
12985 {
12986   /* Get the constant we are comparing against, and see what it looks like
12987      when sign-extended from 16 to 32 bits.  Then see what constant we could
12988      XOR with SEXTC to get the sign-extended value.  */
12989   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
12990                                               SImode,
12991                                               operands[1], operands[2]);
12992   HOST_WIDE_INT c = INTVAL (cnst);
12993   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
12994   HOST_WIDE_INT xorv = c ^ sextc;
12995
12996   operands[9] = GEN_INT (xorv);
12997   operands[10] = GEN_INT (sextc);
12998 })
12999
13000 (define_insn "*cmpsi_internal2"
13001   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13002         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13003                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
13004   ""
13005   "cmplw%I2 %0,%1,%b2"
13006   [(set_attr "type" "cmp")])
13007
13008 (define_insn "*cmpdi_internal2"
13009   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13010         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
13011                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
13012   ""
13013   "cmpld%I2 %0,%1,%b2"
13014   [(set_attr "type" "cmp")])
13015
13016 ;; The following two insns don't exist as single insns, but if we provide
13017 ;; them, we can swap an add and compare, which will enable us to overlap more
13018 ;; of the required delay between a compare and branch.  We generate code for
13019 ;; them by splitting.
13020
13021 (define_insn ""
13022   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13023         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
13024                     (match_operand:SI 2 "short_cint_operand" "i")))
13025    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13026         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13027   ""
13028   "#"
13029   [(set_attr "length" "8")])
13030
13031 (define_insn ""
13032   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
13033         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13034                        (match_operand:SI 2 "u_short_cint_operand" "i")))
13035    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13036         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13037   ""
13038   "#"
13039   [(set_attr "length" "8")])
13040
13041 (define_split
13042   [(set (match_operand:CC 3 "cc_reg_operand" "")
13043         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
13044                     (match_operand:SI 2 "short_cint_operand" "")))
13045    (set (match_operand:SI 0 "gpc_reg_operand" "")
13046         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13047   ""
13048   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
13049    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13050
13051 (define_split
13052   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
13053         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
13054                        (match_operand:SI 2 "u_short_cint_operand" "")))
13055    (set (match_operand:SI 0 "gpc_reg_operand" "")
13056         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13057   ""
13058   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
13059    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13060
13061 ;; Only need to compare second words if first words equal
13062 (define_insn "*cmptf_internal1"
13063   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13064         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13065                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
13066   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
13067    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13068   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
13069   [(set_attr "type" "fpcompare")
13070    (set_attr "length" "12")])
13071
13072 (define_insn_and_split "*cmptf_internal2"
13073   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13074         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13075                       (match_operand:TF 2 "gpc_reg_operand" "d")))
13076     (clobber (match_scratch:DF 3 "=d"))
13077     (clobber (match_scratch:DF 4 "=d"))
13078     (clobber (match_scratch:DF 5 "=d"))
13079     (clobber (match_scratch:DF 6 "=d"))
13080     (clobber (match_scratch:DF 7 "=d"))
13081     (clobber (match_scratch:DF 8 "=d"))
13082     (clobber (match_scratch:DF 9 "=d"))
13083     (clobber (match_scratch:DF 10 "=d"))
13084     (clobber (match_scratch:GPR 11 "=b"))]
13085   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
13086    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13087   "#"
13088   "&& reload_completed"
13089   [(set (match_dup 3) (match_dup 14))
13090    (set (match_dup 4) (match_dup 15))
13091    (set (match_dup 9) (abs:DF (match_dup 5)))
13092    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
13093    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
13094                            (label_ref (match_dup 12))
13095                            (pc)))
13096    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
13097    (set (pc) (label_ref (match_dup 13)))
13098    (match_dup 12)
13099    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
13100    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
13101    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
13102    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
13103    (match_dup 13)]
13104 {
13105   REAL_VALUE_TYPE rv;
13106   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
13107   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
13108
13109   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
13110   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
13111   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
13112   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
13113   operands[12] = gen_label_rtx ();
13114   operands[13] = gen_label_rtx ();
13115   real_inf (&rv);
13116   operands[14] = force_const_mem (DFmode,
13117                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
13118   operands[15] = force_const_mem (DFmode,
13119                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
13120                                                                 DFmode));
13121   if (TARGET_TOC)
13122     {
13123       rtx tocref;
13124       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
13125       operands[14] = gen_const_mem (DFmode, tocref);
13126       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
13127       operands[15] = gen_const_mem (DFmode, tocref);
13128       set_mem_alias_set (operands[14], get_TOC_alias_set ());
13129       set_mem_alias_set (operands[15], get_TOC_alias_set ());
13130     }
13131 })
13132 \f
13133 ;; Now we have the scc insns.  We can do some combinations because of the
13134 ;; way the machine works.
13135 ;;
13136 ;; Note that this is probably faster if we can put an insn between the
13137 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
13138 ;; cases the insns below which don't use an intermediate CR field will
13139 ;; be used instead.
13140 (define_insn ""
13141   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13142         (match_operator:SI 1 "scc_comparison_operator"
13143                            [(match_operand 2 "cc_reg_operand" "y")
13144                             (const_int 0)]))]
13145   ""
13146   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
13147   [(set (attr "type")
13148      (cond [(match_test "TARGET_MFCRF")
13149                 (const_string "mfcrf")
13150            ]
13151         (const_string "mfcr")))
13152    (set_attr "length" "8")])
13153
13154 ;; Same as above, but get the GT bit.
13155 (define_insn "move_from_CR_gt_bit"
13156   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13157         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
13158   "TARGET_HARD_FLOAT && !TARGET_FPRS"
13159   "mfcr %0\;rlwinm %0,%0,%D1,31,31"
13160   [(set_attr "type" "mfcr")
13161    (set_attr "length" "8")])
13162
13163 ;; Same as above, but get the OV/ORDERED bit.
13164 (define_insn "move_from_CR_ov_bit"
13165   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13166         (unspec:SI [(match_operand:CC 1 "cc_reg_operand" "y")]
13167                    UNSPEC_MV_CR_OV))]
13168   "TARGET_ISEL"
13169   "mfcr %0\;rlwinm %0,%0,%t1,1"
13170   [(set_attr "type" "mfcr")
13171    (set_attr "length" "8")])
13172
13173 (define_insn ""
13174   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13175         (match_operator:DI 1 "scc_comparison_operator"
13176                            [(match_operand 2 "cc_reg_operand" "y")
13177                             (const_int 0)]))]
13178   "TARGET_POWERPC64"
13179   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
13180   [(set (attr "type")
13181      (cond [(match_test "TARGET_MFCRF")
13182                 (const_string "mfcrf")
13183            ]
13184         (const_string "mfcr")))
13185    (set_attr "length" "8")])
13186
13187 (define_insn ""
13188   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13189         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13190                                        [(match_operand 2 "cc_reg_operand" "y,y")
13191                                         (const_int 0)])
13192                     (const_int 0)))
13193    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
13194         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13195   "TARGET_32BIT"
13196   "@
13197    mfcr %3%Q2\;rlwinm. %3,%3,%J1,1
13198    #"
13199   [(set_attr "type" "shift")
13200    (set_attr "dot" "yes")
13201    (set_attr "length" "8,16")])
13202
13203 (define_split
13204   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13205         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13206                                        [(match_operand 2 "cc_reg_operand" "")
13207                                         (const_int 0)])
13208                     (const_int 0)))
13209    (set (match_operand:SI 3 "gpc_reg_operand" "")
13210         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13211   "TARGET_32BIT && reload_completed"
13212   [(set (match_dup 3)
13213         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
13214    (set (match_dup 0)
13215         (compare:CC (match_dup 3)
13216                     (const_int 0)))]
13217   "")
13218
13219 (define_insn ""
13220   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13221         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13222                                       [(match_operand 2 "cc_reg_operand" "y")
13223                                        (const_int 0)])
13224                    (match_operand:SI 3 "const_int_operand" "n")))]
13225   ""
13226   "*
13227 {
13228   int is_bit = ccr_bit (operands[1], 1);
13229   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13230   int count;
13231
13232   if (is_bit >= put_bit)
13233     count = is_bit - put_bit;
13234   else
13235     count = 32 - (put_bit - is_bit);
13236
13237   operands[4] = GEN_INT (count);
13238   operands[5] = GEN_INT (put_bit);
13239
13240   return \"mfcr %0%Q2\;rlwinm %0,%0,%4,%5,%5\";
13241 }"
13242   [(set (attr "type")
13243      (cond [(match_test "TARGET_MFCRF")
13244                 (const_string "mfcrf")
13245            ]
13246         (const_string "mfcr")))
13247    (set_attr "length" "8")])
13248
13249 (define_insn ""
13250   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13251         (compare:CC
13252          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13253                                        [(match_operand 2 "cc_reg_operand" "y,y")
13254                                         (const_int 0)])
13255                     (match_operand:SI 3 "const_int_operand" "n,n"))
13256          (const_int 0)))
13257    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
13258         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13259                    (match_dup 3)))]
13260   ""
13261   "*
13262 {
13263   int is_bit = ccr_bit (operands[1], 1);
13264   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13265   int count;
13266
13267   /* Force split for non-cc0 compare.  */
13268   if (which_alternative == 1)
13269      return \"#\";
13270
13271   if (is_bit >= put_bit)
13272     count = is_bit - put_bit;
13273   else
13274     count = 32 - (put_bit - is_bit);
13275
13276   operands[5] = GEN_INT (count);
13277   operands[6] = GEN_INT (put_bit);
13278
13279   return \"mfcr %4%Q2\;rlwinm. %4,%4,%5,%6,%6\";
13280 }"
13281   [(set_attr "type" "shift")
13282    (set_attr "dot" "yes")
13283    (set_attr "length" "8,16")])
13284
13285 (define_split
13286   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13287         (compare:CC
13288          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13289                                        [(match_operand 2 "cc_reg_operand" "")
13290                                         (const_int 0)])
13291                     (match_operand:SI 3 "const_int_operand" ""))
13292          (const_int 0)))
13293    (set (match_operand:SI 4 "gpc_reg_operand" "")
13294         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13295                    (match_dup 3)))]
13296   "reload_completed"
13297   [(set (match_dup 4)
13298         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13299                    (match_dup 3)))
13300    (set (match_dup 0)
13301         (compare:CC (match_dup 4)
13302                     (const_int 0)))]
13303   "")
13304
13305 ;; There is a 3 cycle delay between consecutive mfcr instructions
13306 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13307
13308 (define_peephole
13309   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13310         (match_operator:SI 1 "scc_comparison_operator"
13311                            [(match_operand 2 "cc_reg_operand" "y")
13312                             (const_int 0)]))
13313    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13314         (match_operator:SI 4 "scc_comparison_operator"
13315                            [(match_operand 5 "cc_reg_operand" "y")
13316                             (const_int 0)]))]
13317   "REGNO (operands[2]) != REGNO (operands[5])"
13318   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
13319   [(set_attr "type" "mfcr")
13320    (set_attr "length" "12")])
13321
13322 (define_peephole
13323   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13324         (match_operator:DI 1 "scc_comparison_operator"
13325                            [(match_operand 2 "cc_reg_operand" "y")
13326                             (const_int 0)]))
13327    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13328         (match_operator:DI 4 "scc_comparison_operator"
13329                            [(match_operand 5 "cc_reg_operand" "y")
13330                             (const_int 0)]))]
13331   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13332   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
13333   [(set_attr "type" "mfcr")
13334    (set_attr "length" "12")])
13335
13336 ;; There are some scc insns that can be done directly, without a compare.
13337 ;; These are faster because they don't involve the communications between
13338 ;; the FXU and branch units.   In fact, we will be replacing all of the
13339 ;; integer scc insns here or in the portable methods in emit_store_flag.
13340 ;;
13341 ;; Also support (neg (scc ..)) since that construct is used to replace
13342 ;; branches, (plus (scc ..) ..) since that construct is common and
13343 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13344 ;; cases where it is no more expensive than (neg (scc ..)).
13345
13346 ;; Have reload force a constant into a register for the simple insns that
13347 ;; otherwise won't accept constants.  We do this because it is faster than
13348 ;; the cmp/mfcr sequence we would otherwise generate.
13349
13350 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13351                               (DI "rKJI")])
13352
13353 (define_insn_and_split "*eq<mode>"
13354   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13355         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13356                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13357   ""
13358   "#"
13359   ""
13360   [(set (match_dup 0)
13361         (clz:GPR (match_dup 3)))
13362    (set (match_dup 0)
13363         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13364   {
13365     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13366       {
13367         /* Use output operand as intermediate.  */
13368         operands[3] = operands[0];
13369
13370         if (logical_operand (operands[2], <MODE>mode))
13371           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13372                                   gen_rtx_XOR (<MODE>mode,
13373                                                operands[1], operands[2])));
13374         else
13375           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13376                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13377                                                 negate_rtx (<MODE>mode,
13378                                                             operands[2]))));
13379       }
13380     else
13381       operands[3] = operands[1];
13382
13383     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13384   })
13385
13386 (define_insn_and_split "*eq<mode>_compare"
13387   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13388         (compare:CC
13389          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13390                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13391          (const_int 0)))
13392    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13393         (eq:P (match_dup 1) (match_dup 2)))]
13394   "optimize_size"
13395   "#"
13396   "optimize_size"
13397   [(set (match_dup 0)
13398         (clz:P (match_dup 4)))
13399    (parallel [(set (match_dup 3)
13400                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13401                                (const_int 0)))
13402               (set (match_dup 0)
13403                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13404   {
13405     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13406       {
13407         /* Use output operand as intermediate.  */
13408         operands[4] = operands[0];
13409
13410         if (logical_operand (operands[2], <MODE>mode))
13411           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13412                                   gen_rtx_XOR (<MODE>mode,
13413                                                operands[1], operands[2])));
13414         else
13415           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13416                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13417                                                 negate_rtx (<MODE>mode,
13418                                                             operands[2]))));
13419       }
13420     else
13421       operands[4] = operands[1];
13422
13423     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13424   })
13425
13426 ;; We have insns of the form shown by the first define_insn below.  If
13427 ;; there is something inside the comparison operation, we must split it.
13428 (define_split
13429   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13430         (plus:SI (match_operator 1 "comparison_operator"
13431                                  [(match_operand:SI 2 "" "")
13432                                   (match_operand:SI 3
13433                                                     "reg_or_cint_operand" "")])
13434                  (match_operand:SI 4 "gpc_reg_operand" "")))
13435    (clobber (match_operand:SI 5 "register_operand" ""))]
13436   "! gpc_reg_operand (operands[2], SImode)"
13437   [(set (match_dup 5) (match_dup 2))
13438    (set (match_dup 0) (plus:SI (match_op_dup 1 [(match_dup 5) (match_dup 3)])
13439                                (match_dup 4)))])
13440
13441 (define_insn "*plus_eqsi"
13442   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13443         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13444                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13445                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13446   "TARGET_32BIT"
13447   "@
13448    xor %0,%1,%2\;subfic %0,%0,0\;addze %0,%3
13449    subfic %0,%1,0\;addze %0,%3
13450    xori %0,%1,%b2\;subfic %0,%0,0\;addze %0,%3
13451    xoris %0,%1,%u2\;subfic %0,%0,0\;addze %0,%3
13452    subfic %0,%1,%2\;subfic %0,%0,0\;addze %0,%3"
13453   [(set_attr "type" "three,two,three,three,three")
13454    (set_attr "length" "12,8,12,12,12")])
13455
13456 (define_insn "*compare_plus_eqsi"
13457   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13458         (compare:CC
13459          (plus:SI
13460           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13461                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13462           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13463          (const_int 0)))
13464    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13465   "TARGET_32BIT && optimize_size"
13466   "@
13467    xor %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
13468    subfic %4,%1,0\;addze. %4,%3
13469    xori %4,%1,%b2\;subfic %4,%4,0\;addze. %4,%3
13470    xoris %4,%1,%u2\;subfic %4,%4,0\;addze. %4,%3
13471    subfic %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
13472    #
13473    #
13474    #
13475    #
13476    #"
13477   [(set_attr "type" "compare")
13478    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13479
13480 (define_split
13481   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13482         (compare:CC
13483          (plus:SI
13484           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13485                  (match_operand:SI 2 "scc_eq_operand" ""))
13486           (match_operand:SI 3 "gpc_reg_operand" ""))
13487          (const_int 0)))
13488    (clobber (match_scratch:SI 4 ""))]
13489   "TARGET_32BIT && optimize_size && reload_completed"
13490   [(set (match_dup 4)
13491         (plus:SI (eq:SI (match_dup 1)
13492                  (match_dup 2))
13493           (match_dup 3)))
13494    (set (match_dup 0)
13495         (compare:CC (match_dup 4)
13496                     (const_int 0)))]
13497   "")
13498
13499 (define_insn "*plus_eqsi_compare"
13500   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13501         (compare:CC
13502          (plus:SI
13503           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13504                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13505           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13506          (const_int 0)))
13507    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13508         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13509   "TARGET_32BIT && optimize_size"
13510   "@
13511    xor %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
13512    subfic %0,%1,0\;addze. %0,%3
13513    xori %0,%1,%b2\;subfic %0,%0,0\;addze. %0,%3
13514    xoris %0,%1,%u2\;subfic %0,%0,0\;addze. %0,%3
13515    subfic %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
13516    #
13517    #
13518    #
13519    #
13520    #"
13521   [(set_attr "type" "compare")
13522    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13523
13524 (define_split
13525   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13526         (compare:CC
13527          (plus:SI
13528           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13529                  (match_operand:SI 2 "scc_eq_operand" ""))
13530           (match_operand:SI 3 "gpc_reg_operand" ""))
13531          (const_int 0)))
13532    (set (match_operand:SI 0 "gpc_reg_operand" "")
13533         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13534   "TARGET_32BIT && optimize_size && reload_completed"
13535   [(set (match_dup 0)
13536         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13537    (set (match_dup 4)
13538         (compare:CC (match_dup 0)
13539                     (const_int 0)))]
13540   "")
13541
13542 (define_insn "*neg_eq0<mode>"
13543   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13544         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13545                      (const_int 0))))]
13546   ""
13547   "addic %0,%1,-1\;subfe %0,%0,%0"
13548   [(set_attr "type" "two")
13549    (set_attr "length" "8")])
13550
13551 (define_insn_and_split "*neg_eq<mode>"
13552   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13553         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
13554                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
13555   ""
13556   "#"
13557   ""
13558   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
13559   {
13560     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13561       {
13562         /* Use output operand as intermediate.  */
13563         operands[3] = operands[0];
13564
13565         if (logical_operand (operands[2], <MODE>mode))
13566           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13567                                   gen_rtx_XOR (<MODE>mode,
13568                                                operands[1], operands[2])));
13569         else
13570           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13571                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13572                                                 negate_rtx (<MODE>mode,
13573                                                             operands[2]))));
13574       }
13575     else
13576       operands[3] = operands[1];
13577   })
13578
13579 (define_insn "*ne0_<mode>"
13580   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13581         (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13582               (const_int 0)))
13583    (clobber (match_scratch:P 2 "=&r"))]
13584   "!(TARGET_32BIT && TARGET_ISEL)"
13585   "addic %2,%1,-1\;subfe %0,%2,%1"
13586   [(set_attr "type" "two")
13587    (set_attr "length" "8")])
13588
13589 (define_insn "*plus_ne0_<mode>"
13590   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13591         (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13592                       (const_int 0))
13593                 (match_operand:P 2 "gpc_reg_operand" "r")))
13594    (clobber (match_scratch:P 3 "=&r"))]
13595   ""
13596   "addic %3,%1,-1\;addze %0,%2"
13597   [(set_attr "type" "two")
13598    (set_attr "length" "8")])
13599
13600 (define_insn "*compare_plus_ne0_<mode>"
13601   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13602         (compare:CC (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13603                                   (const_int 0))
13604                             (match_operand:P 2 "gpc_reg_operand" "r,r"))
13605                     (const_int 0)))
13606    (clobber (match_scratch:P 3 "=&r,&r"))
13607    (clobber (match_scratch:P 4 "=X,&r"))]
13608   ""
13609   "@
13610    addic %3,%1,-1\;addze. %3,%2
13611    #"
13612   [(set_attr "type" "compare")
13613    (set_attr "length" "8,12")])
13614
13615 (define_split
13616   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13617         (compare:CC (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
13618                           (const_int 0))
13619                     (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
13620    (clobber (match_scratch:P 3 ""))
13621    (clobber (match_scratch:P 4 ""))]
13622   "reload_completed"
13623   [(parallel [(set (match_dup 3)
13624                    (plus:P (ne:P (match_dup 1)
13625                                  (const_int 0))
13626                            (match_dup 2)))
13627               (clobber (match_dup 4))])
13628    (set (match_dup 0)
13629         (compare:CC (match_dup 3)
13630                     (const_int 0)))]
13631   "")
13632
13633 ; For combine.
13634 (define_insn "*compare_plus_ne0_<mode>_1"
13635   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13636         (compare:CCEQ (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13637                             (const_int 0))
13638                       (neg:P (match_operand:P 2 "gpc_reg_operand" "r,r"))))
13639    (clobber (match_scratch:P 3 "=&r,&r"))
13640    (clobber (match_scratch:P 4 "=X,&r"))]
13641   ""
13642   "@
13643    addic %3,%1,-1\;addze. %3,%2
13644    #"
13645   [(set_attr "type" "compare")
13646    (set_attr "length" "8,12")])
13647
13648 (define_split
13649   [(set (match_operand:CCEQ 0 "cc_reg_not_micro_cr0_operand" "")
13650         (compare:CCEQ (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
13651                             (const_int 0))
13652                       (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
13653    (clobber (match_scratch:P 3 ""))
13654    (clobber (match_scratch:P 4 ""))]
13655   "reload_completed"
13656   [(parallel [(set (match_dup 3)
13657                    (plus:P (ne:P (match_dup 1)
13658                                  (const_int 0))
13659                            (match_dup 2)))
13660               (clobber (match_dup 4))])
13661    (set (match_dup 0)
13662         (compare:CC (match_dup 3)
13663                     (const_int 0)))]
13664   "")
13665
13666 (define_insn "*plus_ne0_<mode>_compare"
13667   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13668         (compare:CC
13669          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13670                        (const_int 0))
13671                  (match_operand:P 2 "gpc_reg_operand" "r,r"))
13672          (const_int 0)))
13673    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13674         (plus:P (ne:P (match_dup 1)
13675                       (const_int 0))
13676                 (match_dup 2)))
13677    (clobber (match_scratch:P 3 "=&r,&r"))]
13678   ""
13679   "@
13680    addic %3,%1,-1\;addze. %0,%2
13681    #"
13682   [(set_attr "type" "compare")
13683    (set_attr "length" "8,12")])
13684
13685 (define_split
13686   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
13687         (compare:CC
13688          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "")
13689                        (const_int 0))
13690                  (match_operand:P 2 "gpc_reg_operand" ""))
13691          (const_int 0)))
13692    (set (match_operand:P 0 "gpc_reg_operand" "")
13693         (plus:P (ne:P (match_dup 1)
13694                       (const_int 0))
13695                 (match_dup 2)))
13696    (clobber (match_scratch:P 3 ""))]
13697   "reload_completed"
13698   [(parallel [(set (match_dup 0)
13699                    (plus:P (ne:P (match_dup 1)
13700                                  (const_int 0))
13701                            (match_dup 2)))
13702               (clobber (match_dup 3))])
13703    (set (match_dup 4)
13704         (compare:CC (match_dup 0)
13705                     (const_int 0)))]
13706   "")
13707
13708 (define_insn "*leu<mode>"
13709   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13710         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13711                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13712   ""
13713   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
13714   [(set_attr "type" "three")
13715    (set_attr "length" "12")])
13716
13717 (define_insn "*leu<mode>_compare"
13718   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13719         (compare:CC
13720          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13721                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13722          (const_int 0)))
13723    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13724         (leu:P (match_dup 1) (match_dup 2)))]
13725   ""
13726   "@
13727    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
13728    #"
13729   [(set_attr "type" "compare")
13730    (set_attr "length" "12,16")])
13731
13732 (define_split
13733   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13734         (compare:CC
13735          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
13736                 (match_operand:P 2 "reg_or_short_operand" ""))
13737          (const_int 0)))
13738    (set (match_operand:P 0 "gpc_reg_operand" "")
13739         (leu:P (match_dup 1) (match_dup 2)))]
13740   "reload_completed"
13741   [(set (match_dup 0)
13742         (leu:P (match_dup 1) (match_dup 2)))
13743    (set (match_dup 3)
13744         (compare:CC (match_dup 0)
13745                     (const_int 0)))]
13746   "")
13747
13748 (define_insn "*plus_leu<mode>"
13749   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13750         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13751                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13752                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13753   ""
13754   "subf%I2c %0,%1,%2\;addze %0,%3"
13755   [(set_attr "type" "two")
13756    (set_attr "length" "8")])
13757
13758 (define_insn ""
13759   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13760         (compare:CC
13761          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13762                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13763                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13764          (const_int 0)))
13765    (clobber (match_scratch:SI 4 "=&r,&r"))]
13766   "TARGET_32BIT"
13767   "@
13768    subf%I2c %4,%1,%2\;addze. %4,%3
13769    #"
13770   [(set_attr "type" "compare")
13771    (set_attr "length" "8,12")])
13772
13773 (define_split
13774   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13775         (compare:CC
13776          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13777                           (match_operand:SI 2 "reg_or_short_operand" ""))
13778                   (match_operand:SI 3 "gpc_reg_operand" ""))
13779          (const_int 0)))
13780    (clobber (match_scratch:SI 4 ""))]
13781   "TARGET_32BIT && reload_completed"
13782   [(set (match_dup 4)
13783         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
13784                   (match_dup 3)))
13785    (set (match_dup 0)
13786         (compare:CC (match_dup 4)
13787                     (const_int 0)))]
13788   "")
13789
13790 (define_insn ""
13791   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13792         (compare:CC
13793          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13794                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13795                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13796          (const_int 0)))
13797    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13798         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13799   "TARGET_32BIT"
13800   "@
13801    subf%I2c %0,%1,%2\;addze. %0,%3
13802    #"
13803   [(set_attr "type" "compare")
13804    (set_attr "length" "8,12")])
13805
13806 (define_split
13807   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13808         (compare:CC
13809          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13810                           (match_operand:SI 2 "reg_or_short_operand" ""))
13811                   (match_operand:SI 3 "gpc_reg_operand" ""))
13812          (const_int 0)))
13813    (set (match_operand:SI 0 "gpc_reg_operand" "")
13814         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13815   "TARGET_32BIT && reload_completed"
13816   [(set (match_dup 0)
13817         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13818    (set (match_dup 4)
13819         (compare:CC (match_dup 0)
13820                     (const_int 0)))]
13821   "")
13822
13823 (define_insn "*neg_leu<mode>"
13824   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13825         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13826                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13827   ""
13828   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;nand %0,%0,%0"
13829    [(set_attr "type" "three")
13830     (set_attr "length" "12")])
13831
13832 (define_insn "*and_neg_leu<mode>"
13833   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13834         (and:P (neg:P
13835                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13836                         (match_operand:P 2 "reg_or_short_operand" "rI")))
13837                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13838   ""
13839   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc %0,%3,%0"
13840   [(set_attr "type" "three")
13841    (set_attr "length" "12")])
13842
13843 (define_insn ""
13844   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13845         (compare:CC
13846          (and:SI (neg:SI
13847                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13848                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13849                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13850          (const_int 0)))
13851    (clobber (match_scratch:SI 4 "=&r,&r"))]
13852   "TARGET_32BIT"
13853   "@
13854    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;andc. %4,%3,%4
13855    #"
13856   [(set_attr "type" "compare")
13857    (set_attr "length" "12,16")])
13858
13859 (define_split
13860   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13861         (compare:CC
13862          (and:SI (neg:SI
13863                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13864                           (match_operand:SI 2 "reg_or_short_operand" "")))
13865                  (match_operand:SI 3 "gpc_reg_operand" ""))
13866          (const_int 0)))
13867    (clobber (match_scratch:SI 4 ""))]
13868   "TARGET_32BIT && reload_completed"
13869   [(set (match_dup 4)
13870         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13871                 (match_dup 3)))
13872    (set (match_dup 0)
13873         (compare:CC (match_dup 4)
13874                     (const_int 0)))]
13875   "")
13876
13877 (define_insn ""
13878   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13879         (compare:CC
13880          (and:SI (neg:SI
13881                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13882                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13883                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13884          (const_int 0)))
13885    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13886         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13887   "TARGET_32BIT"
13888   "@
13889    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc. %0,%3,%0
13890    #"
13891   [(set_attr "type" "compare")
13892    (set_attr "length" "12,16")])
13893
13894 (define_split
13895   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13896         (compare:CC
13897          (and:SI (neg:SI
13898                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13899                           (match_operand:SI 2 "reg_or_short_operand" "")))
13900                  (match_operand:SI 3 "gpc_reg_operand" ""))
13901          (const_int 0)))
13902    (set (match_operand:SI 0 "gpc_reg_operand" "")
13903         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13904   "TARGET_32BIT && reload_completed"
13905   [(set (match_dup 0)
13906         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13907                 (match_dup 3)))
13908    (set (match_dup 4)
13909         (compare:CC (match_dup 0)
13910                     (const_int 0)))]
13911   "")
13912
13913 (define_insn_and_split "*ltu<mode>"
13914   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13915         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13916                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13917   ""
13918   "#"
13919   ""
13920   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13921    (set (match_dup 0) (neg:P (match_dup 0)))]
13922   "")
13923
13924 (define_insn_and_split "*ltu<mode>_compare"
13925   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13926         (compare:CC
13927          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13928                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13929          (const_int 0)))
13930    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13931         (ltu:P (match_dup 1) (match_dup 2)))]
13932   ""
13933   "#"
13934   ""
13935   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13936    (parallel [(set (match_dup 3)
13937                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13938               (set (match_dup 0) (neg:P (match_dup 0)))])]
13939   "")
13940
13941 (define_insn_and_split "*plus_ltu<mode>"
13942   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
13943         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13944                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13945                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
13946   ""
13947   "#"
13948   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13949   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13950    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13951   "")
13952
13953 (define_insn_and_split "*plus_ltu<mode>_compare"
13954   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13955         (compare:CC
13956          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13957                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13958                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13959          (const_int 0)))
13960    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13961         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13962   ""
13963   "#"
13964   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13965   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13966    (parallel [(set (match_dup 4)
13967                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13968                                (const_int 0)))
13969               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13970   "")
13971
13972 (define_insn "*neg_ltu<mode>"
13973   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13974         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13975                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
13976   ""
13977   "@
13978    subfc %0,%2,%1\;subfe %0,%0,%0
13979    addic %0,%1,%n2\;subfe %0,%0,%0"
13980   [(set_attr "type" "two")
13981    (set_attr "length" "8")])
13982
13983 (define_insn "*geu<mode>"
13984   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13985         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13986                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13987   ""
13988   "@
13989    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
13990    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
13991   [(set_attr "type" "three")
13992    (set_attr "length" "12")])
13993
13994 (define_insn "*geu<mode>_compare"
13995   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13996         (compare:CC
13997          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13998                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13999          (const_int 0)))
14000    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14001         (geu:P (match_dup 1) (match_dup 2)))]
14002   ""
14003   "@
14004    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
14005    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
14006    #
14007    #"
14008   [(set_attr "type" "compare")
14009    (set_attr "length" "12,12,16,16")])
14010
14011 (define_split
14012   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14013         (compare:CC
14014          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
14015                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
14016          (const_int 0)))
14017    (set (match_operand:P 0 "gpc_reg_operand" "")
14018         (geu:P (match_dup 1) (match_dup 2)))]
14019   "reload_completed"
14020   [(set (match_dup 0)
14021         (geu:P (match_dup 1) (match_dup 2)))
14022    (set (match_dup 3)
14023         (compare:CC (match_dup 0)
14024                     (const_int 0)))]
14025   "")
14026
14027 (define_insn "*plus_geu<mode>"
14028   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14029         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14030                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14031                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14032   ""
14033   "@
14034    subfc %0,%2,%1\;addze %0,%3
14035    addic %0,%1,%n2\;addze %0,%3"
14036   [(set_attr "type" "two")
14037    (set_attr "length" "8")])
14038
14039 (define_insn ""
14040   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14041         (compare:CC
14042          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14043                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14044                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14045          (const_int 0)))
14046    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14047   "TARGET_32BIT"
14048   "@
14049    subfc %4,%2,%1\;addze. %4,%3
14050    addic %4,%1,%n2\;addze. %4,%3
14051    #
14052    #"
14053   [(set_attr "type" "compare")
14054    (set_attr "length" "8,8,12,12")])
14055
14056 (define_split
14057   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14058         (compare:CC
14059          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14060                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14061                   (match_operand:SI 3 "gpc_reg_operand" ""))
14062          (const_int 0)))
14063    (clobber (match_scratch:SI 4 ""))]
14064   "TARGET_32BIT && reload_completed"
14065   [(set (match_dup 4)
14066         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
14067                   (match_dup 3)))
14068    (set (match_dup 0)
14069         (compare:CC (match_dup 4)
14070                     (const_int 0)))]
14071   "")
14072
14073 (define_insn ""
14074   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14075         (compare:CC
14076          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14077                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14078                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14079          (const_int 0)))
14080    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14081         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14082   "TARGET_32BIT"
14083   "@
14084    subfc %0,%2,%1\;addze. %0,%3
14085    addic %0,%1,%n2\;addze. %0,%3
14086    #
14087    #"
14088   [(set_attr "type" "compare")
14089    (set_attr "length" "8,8,12,12")])
14090
14091 (define_split
14092   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14093         (compare:CC
14094          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14095                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14096                   (match_operand:SI 3 "gpc_reg_operand" ""))
14097          (const_int 0)))
14098    (set (match_operand:SI 0 "gpc_reg_operand" "")
14099         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14100   "TARGET_32BIT && reload_completed"
14101   [(set (match_dup 0)
14102         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14103    (set (match_dup 4)
14104         (compare:CC (match_dup 0)
14105                     (const_int 0)))]
14106   "")
14107
14108 (define_insn "*neg_geu<mode>"
14109   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14110         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14111                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
14112   ""
14113   "@
14114    subfc %0,%2,%1\;subfe %0,%0,%0\;nand %0,%0,%0
14115    subfic %0,%1,-1\;add%I2c %0,%0,%2\;subfe %0,%0,%0"
14116   [(set_attr "type" "three")
14117    (set_attr "length" "12")])
14118
14119 (define_insn "*and_neg_geu<mode>"
14120   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14121         (and:P (neg:P
14122                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14123                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
14124                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14125   ""
14126   "@
14127    subfc %0,%2,%1\;subfe %0,%0,%0\;andc %0,%3,%0
14128    addic %0,%1,%n2\;subfe %0,%0,%0\;andc %0,%3,%0"
14129   [(set_attr "type" "three")
14130    (set_attr "length" "12")])
14131
14132 (define_insn ""
14133   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14134         (compare:CC
14135          (and:SI (neg:SI
14136                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14137                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14138                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14139          (const_int 0)))
14140    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14141   "TARGET_32BIT"
14142   "@
14143    subfc %4,%2,%1\;subfe %4,%4,%4\;andc. %4,%3,%4
14144    addic %4,%1,%n2\;subfe %4,%4,%4\;andc. %4,%3,%4
14145    #
14146    #"
14147   [(set_attr "type" "compare")
14148    (set_attr "length" "12,12,16,16")])
14149
14150 (define_split
14151   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14152         (compare:CC
14153          (and:SI (neg:SI
14154                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14155                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14156                  (match_operand:SI 3 "gpc_reg_operand" ""))
14157          (const_int 0)))
14158    (clobber (match_scratch:SI 4 ""))]
14159   "TARGET_32BIT && reload_completed"
14160   [(set (match_dup 4)
14161         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
14162                 (match_dup 3)))
14163    (set (match_dup 0)
14164         (compare:CC (match_dup 4)
14165                     (const_int 0)))]
14166   "")
14167
14168 (define_insn ""
14169   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14170         (compare:CC
14171          (and:SI (neg:SI
14172                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14173                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14174                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14175          (const_int 0)))
14176    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14177         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14178   "TARGET_32BIT"
14179   "@
14180    subfc %0,%2,%1\;subfe %0,%0,%0\;andc. %0,%3,%0
14181    addic %0,%1,%n2\;subfe %0,%0,%0\;andc. %0,%3,%0
14182    #
14183    #"
14184   [(set_attr "type" "compare")
14185    (set_attr "length" "12,12,16,16")])
14186
14187 (define_split
14188   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14189         (compare:CC
14190          (and:SI (neg:SI
14191                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14192                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14193                  (match_operand:SI 3 "gpc_reg_operand" ""))
14194          (const_int 0)))
14195    (set (match_operand:SI 0 "gpc_reg_operand" "")
14196         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14197   "TARGET_32BIT && reload_completed"
14198   [(set (match_dup 0)
14199         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
14200    (set (match_dup 4)
14201         (compare:CC (match_dup 0)
14202                     (const_int 0)))]
14203   "")
14204
14205 (define_insn "*plus_gt0<mode>"
14206   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14207         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
14208                       (const_int 0))
14209                  (match_operand:P 2 "gpc_reg_operand" "r")))]
14210   ""
14211   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
14212   [(set_attr "type" "three")
14213    (set_attr "length" "12")])
14214
14215 (define_insn ""
14216   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14217         (compare:CC
14218          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14219                          (const_int 0))
14220                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14221          (const_int 0)))
14222    (clobber (match_scratch:SI 3 "=&r,&r"))]
14223   "TARGET_32BIT"
14224   "@
14225    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14226    #"
14227   [(set_attr "type" "compare")
14228    (set_attr "length" "12,16")])
14229
14230 (define_split
14231   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14232         (compare:CC
14233          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14234                          (const_int 0))
14235                   (match_operand:SI 2 "gpc_reg_operand" ""))
14236          (const_int 0)))
14237    (clobber (match_scratch:SI 3 ""))]
14238   "TARGET_32BIT && reload_completed"
14239   [(set (match_dup 3)
14240         (plus:SI (gt:SI (match_dup 1) (const_int 0))
14241                   (match_dup 2)))
14242    (set (match_dup 0)
14243         (compare:CC (match_dup 3)
14244                     (const_int 0)))]
14245   "")
14246
14247 (define_insn ""
14248   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14249         (compare:CC
14250          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14251                          (const_int 0))
14252                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14253          (const_int 0)))
14254    (clobber (match_scratch:DI 3 "=&r,&r"))]
14255   "TARGET_64BIT"
14256   "@
14257    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14258    #"
14259   [(set_attr "type" "compare")
14260    (set_attr "length" "12,16")])
14261
14262 (define_split
14263   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14264         (compare:CC
14265          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14266                          (const_int 0))
14267                   (match_operand:DI 2 "gpc_reg_operand" ""))
14268          (const_int 0)))
14269    (clobber (match_scratch:DI 3 ""))]
14270   "TARGET_64BIT && reload_completed"
14271   [(set (match_dup 3)
14272         (plus:DI (gt:DI (match_dup 1) (const_int 0))
14273                  (match_dup 2)))
14274    (set (match_dup 0)
14275         (compare:CC (match_dup 3)
14276                     (const_int 0)))]
14277   "")
14278
14279 (define_insn ""
14280   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14281         (compare:CC
14282          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14283                          (const_int 0))
14284                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14285          (const_int 0)))
14286    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14287         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14288   "TARGET_32BIT"
14289   "@
14290    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14291    #"
14292   [(set_attr "type" "compare")
14293    (set_attr "length" "12,16")])
14294
14295 (define_split
14296   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14297         (compare:CC
14298          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14299                          (const_int 0))
14300                   (match_operand:SI 2 "gpc_reg_operand" ""))
14301          (const_int 0)))
14302    (set (match_operand:SI 0 "gpc_reg_operand" "")
14303         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14304   "TARGET_32BIT && reload_completed"
14305   [(set (match_dup 0)
14306         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
14307    (set (match_dup 3)
14308         (compare:CC (match_dup 0)
14309                     (const_int 0)))]
14310   "")
14311
14312 (define_insn ""
14313   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14314         (compare:CC
14315          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14316                          (const_int 0))
14317                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14318          (const_int 0)))
14319    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
14320         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14321   "TARGET_64BIT"
14322   "@
14323    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14324    #"
14325   [(set_attr "type" "compare")
14326    (set_attr "length" "12,16")])
14327
14328 (define_split
14329   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14330         (compare:CC
14331          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14332                          (const_int 0))
14333                   (match_operand:DI 2 "gpc_reg_operand" ""))
14334          (const_int 0)))
14335    (set (match_operand:DI 0 "gpc_reg_operand" "")
14336         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14337   "TARGET_64BIT && reload_completed"
14338   [(set (match_dup 0)
14339         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
14340    (set (match_dup 3)
14341         (compare:CC (match_dup 0)
14342                     (const_int 0)))]
14343   "")
14344
14345 (define_insn_and_split "*gtu<mode>"
14346   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14347         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14348                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14349   ""
14350   "#"
14351   ""
14352   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14353    (set (match_dup 0) (neg:P (match_dup 0)))]
14354   "")
14355
14356 (define_insn_and_split "*gtu<mode>_compare"
14357   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14358         (compare:CC
14359          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14360                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14361          (const_int 0)))
14362    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14363         (gtu:P (match_dup 1) (match_dup 2)))]
14364   ""
14365   "#"
14366   ""
14367   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14368    (parallel [(set (match_dup 3)
14369                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14370               (set (match_dup 0) (neg:P (match_dup 0)))])]
14371   "")
14372
14373 (define_insn_and_split "*plus_gtu<mode>"
14374   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14375         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14376                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14377                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
14378   ""
14379   "#"
14380   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14381   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14382    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14383   "")
14384
14385 (define_insn_and_split "*plus_gtu<mode>_compare"
14386   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14387         (compare:CC
14388          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14389                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
14390                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14391          (const_int 0)))
14392    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14393         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14394   ""
14395   "#"
14396   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14397   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14398    (parallel [(set (match_dup 4)
14399                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14400                                (const_int 0)))
14401               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14402   "")
14403
14404 (define_insn "*neg_gtu<mode>"
14405   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14406         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14407                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14408   ""
14409   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
14410   [(set_attr "type" "two")
14411    (set_attr "length" "8")])
14412
14413 \f
14414 ;; Define both directions of branch and return.  If we need a reload
14415 ;; register, we'd rather use CR0 since it is much easier to copy a
14416 ;; register CC value to there.
14417
14418 (define_insn ""
14419   [(set (pc)
14420         (if_then_else (match_operator 1 "branch_comparison_operator"
14421                                       [(match_operand 2
14422                                                       "cc_reg_operand" "y")
14423                                        (const_int 0)])
14424                       (label_ref (match_operand 0 "" ""))
14425                       (pc)))]
14426   ""
14427   "*
14428 {
14429   return output_cbranch (operands[1], \"%l0\", 0, insn);
14430 }"
14431   [(set_attr "type" "branch")])
14432
14433 (define_insn ""
14434   [(set (pc)
14435         (if_then_else (match_operator 0 "branch_comparison_operator"
14436                                       [(match_operand 1
14437                                                       "cc_reg_operand" "y")
14438                                        (const_int 0)])
14439                       (any_return)
14440                       (pc)))]
14441   "<return_pred>"
14442   "*
14443 {
14444   return output_cbranch (operands[0], NULL, 0, insn);
14445 }"
14446   [(set_attr "type" "jmpreg")
14447    (set_attr "length" "4")])
14448
14449 (define_insn ""
14450   [(set (pc)
14451         (if_then_else (match_operator 1 "branch_comparison_operator"
14452                                       [(match_operand 2
14453                                                       "cc_reg_operand" "y")
14454                                        (const_int 0)])
14455                       (pc)
14456                       (label_ref (match_operand 0 "" ""))))]
14457   ""
14458   "*
14459 {
14460   return output_cbranch (operands[1], \"%l0\", 1, insn);
14461 }"
14462   [(set_attr "type" "branch")])
14463
14464 (define_insn ""
14465   [(set (pc)
14466         (if_then_else (match_operator 0 "branch_comparison_operator"
14467                                       [(match_operand 1
14468                                                       "cc_reg_operand" "y")
14469                                        (const_int 0)])
14470                       (pc)
14471                       (any_return)))]
14472   "<return_pred>"
14473   "*
14474 {
14475   return output_cbranch (operands[0], NULL, 1, insn);
14476 }"
14477   [(set_attr "type" "jmpreg")
14478    (set_attr "length" "4")])
14479
14480 ;; Logic on condition register values.
14481
14482 ; This pattern matches things like
14483 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
14484 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
14485 ;                                  (const_int 1)))
14486 ; which are generated by the branch logic.
14487 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
14488
14489 (define_insn "*cceq_ior_compare"
14490   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14491         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
14492                         [(match_operator:SI 2
14493                                       "branch_positive_comparison_operator"
14494                                       [(match_operand 3
14495                                                       "cc_reg_operand" "y,y")
14496                                        (const_int 0)])
14497                          (match_operator:SI 4
14498                                       "branch_positive_comparison_operator"
14499                                       [(match_operand 5
14500                                                       "cc_reg_operand" "0,y")
14501                                        (const_int 0)])])
14502                       (const_int 1)))]
14503   ""
14504   "cr%q1 %E0,%j2,%j4"
14505   [(set_attr "type" "cr_logical,delayed_cr")])
14506
14507 ; Why is the constant -1 here, but 1 in the previous pattern?
14508 ; Because ~1 has all but the low bit set.
14509 (define_insn ""
14510   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14511         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
14512                         [(not:SI (match_operator:SI 2
14513                                       "branch_positive_comparison_operator"
14514                                       [(match_operand 3
14515                                                       "cc_reg_operand" "y,y")
14516                                        (const_int 0)]))
14517                          (match_operator:SI 4
14518                                 "branch_positive_comparison_operator"
14519                                 [(match_operand 5
14520                                                 "cc_reg_operand" "0,y")
14521                                  (const_int 0)])])
14522                       (const_int -1)))]
14523   ""
14524   "cr%q1 %E0,%j2,%j4"
14525   [(set_attr "type" "cr_logical,delayed_cr")])
14526
14527 (define_insn "*cceq_rev_compare"
14528   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14529         (compare:CCEQ (match_operator:SI 1
14530                                       "branch_positive_comparison_operator"
14531                                       [(match_operand 2
14532                                                       "cc_reg_operand" "0,y")
14533                                        (const_int 0)])
14534                       (const_int 0)))]
14535   ""
14536   "crnot %E0,%j1"
14537   [(set_attr "type" "cr_logical,delayed_cr")])
14538
14539 ;; If we are comparing the result of two comparisons, this can be done
14540 ;; using creqv or crxor.
14541
14542 (define_insn_and_split ""
14543   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
14544         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
14545                               [(match_operand 2 "cc_reg_operand" "y")
14546                                (const_int 0)])
14547                       (match_operator 3 "branch_comparison_operator"
14548                               [(match_operand 4 "cc_reg_operand" "y")
14549                                (const_int 0)])))]
14550   ""
14551   "#"
14552   ""
14553   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
14554                                     (match_dup 5)))]
14555   "
14556 {
14557   int positive_1, positive_2;
14558
14559   positive_1 = branch_positive_comparison_operator (operands[1],
14560                                                     GET_MODE (operands[1]));
14561   positive_2 = branch_positive_comparison_operator (operands[3],
14562                                                     GET_MODE (operands[3]));
14563
14564   if (! positive_1)
14565     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
14566                                                             GET_CODE (operands[1])),
14567                                   SImode,
14568                                   operands[2], const0_rtx);
14569   else if (GET_MODE (operands[1]) != SImode)
14570     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
14571                                   operands[2], const0_rtx);
14572
14573   if (! positive_2)
14574     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
14575                                                             GET_CODE (operands[3])),
14576                                   SImode,
14577                                   operands[4], const0_rtx);
14578   else if (GET_MODE (operands[3]) != SImode)
14579     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
14580                                   operands[4], const0_rtx);
14581
14582   if (positive_1 == positive_2)
14583     {
14584       operands[1] = gen_rtx_NOT (SImode, operands[1]);
14585       operands[5] = constm1_rtx;
14586     }
14587   else
14588     {
14589       operands[5] = const1_rtx;
14590     }
14591 }")
14592
14593 ;; Unconditional branch and return.
14594
14595 (define_insn "jump"
14596   [(set (pc)
14597         (label_ref (match_operand 0 "" "")))]
14598   ""
14599   "b %l0"
14600   [(set_attr "type" "branch")])
14601
14602 (define_insn "<return_str>return"
14603   [(any_return)]
14604   "<return_pred>"
14605   "blr"
14606   [(set_attr "type" "jmpreg")])
14607
14608 (define_expand "indirect_jump"
14609   [(set (pc) (match_operand 0 "register_operand" ""))])
14610
14611 (define_insn "*indirect_jump<mode>"
14612   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
14613   ""
14614   "@
14615    bctr
14616    blr"
14617   [(set_attr "type" "jmpreg")])
14618
14619 ;; Table jump for switch statements:
14620 (define_expand "tablejump"
14621   [(use (match_operand 0 "" ""))
14622    (use (label_ref (match_operand 1 "" "")))]
14623   ""
14624   "
14625 {
14626   if (TARGET_32BIT)
14627     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
14628   else
14629     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
14630   DONE;
14631 }")
14632
14633 (define_expand "tablejumpsi"
14634   [(set (match_dup 3)
14635         (plus:SI (match_operand:SI 0 "" "")
14636                  (match_dup 2)))
14637    (parallel [(set (pc) (match_dup 3))
14638               (use (label_ref (match_operand 1 "" "")))])]
14639   "TARGET_32BIT"
14640   "
14641 { operands[0] = force_reg (SImode, operands[0]);
14642   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
14643   operands[3] = gen_reg_rtx (SImode);
14644 }")
14645
14646 (define_expand "tablejumpdi"
14647   [(set (match_dup 4)
14648         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
14649    (set (match_dup 3)
14650         (plus:DI (match_dup 4)
14651                  (match_dup 2)))
14652    (parallel [(set (pc) (match_dup 3))
14653               (use (label_ref (match_operand 1 "" "")))])]
14654   "TARGET_64BIT"
14655   "
14656 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
14657   operands[3] = gen_reg_rtx (DImode);
14658   operands[4] = gen_reg_rtx (DImode);
14659 }")
14660
14661 (define_insn "*tablejump<mode>_internal1"
14662   [(set (pc)
14663         (match_operand:P 0 "register_operand" "c,*l"))
14664    (use (label_ref (match_operand 1 "" "")))]
14665   ""
14666   "@
14667    bctr
14668    blr"
14669   [(set_attr "type" "jmpreg")])
14670
14671 (define_insn "nop"
14672   [(const_int 0)]
14673   ""
14674   "nop")
14675
14676 (define_insn "group_ending_nop"
14677   [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
14678   ""
14679   "*
14680 {
14681   if (rs6000_cpu_attr == CPU_POWER6)
14682     return \"ori 1,1,0\";
14683   return \"ori 2,2,0\";
14684 }")
14685 \f
14686 ;; Define the subtract-one-and-jump insns, starting with the template
14687 ;; so loop.c knows what to generate.
14688
14689 (define_expand "doloop_end"
14690   [(use (match_operand 0 "" ""))        ; loop pseudo
14691    (use (match_operand 1 "" ""))]       ; label
14692   ""
14693   "
14694 {
14695   if (TARGET_64BIT)
14696     {
14697       if (GET_MODE (operands[0]) != DImode)
14698         FAIL;
14699       emit_jump_insn (gen_ctrdi (operands[0], operands[1]));
14700     }
14701   else
14702     {
14703       if (GET_MODE (operands[0]) != SImode)
14704         FAIL;
14705       emit_jump_insn (gen_ctrsi (operands[0], operands[1]));
14706     }
14707   DONE;
14708 }")
14709
14710 (define_expand "ctr<mode>"
14711   [(parallel [(set (pc)
14712                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
14713                                      (const_int 1))
14714                                  (label_ref (match_operand 1 "" ""))
14715                                  (pc)))
14716               (set (match_dup 0)
14717                    (plus:P (match_dup 0)
14718                             (const_int -1)))
14719               (clobber (match_scratch:CC 2 ""))
14720               (clobber (match_scratch:P 3 ""))])]
14721   ""
14722   "")
14723
14724 ;; We need to be able to do this for any operand, including MEM, or we
14725 ;; will cause reload to blow up since we don't allow output reloads on
14726 ;; JUMP_INSNs.
14727 ;; For the length attribute to be calculated correctly, the
14728 ;; label MUST be operand 0.
14729
14730 (define_insn "*ctr<mode>_internal1"
14731   [(set (pc)
14732         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14733                           (const_int 1))
14734                       (label_ref (match_operand 0 "" ""))
14735                       (pc)))
14736    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14737         (plus:P (match_dup 1)
14738                  (const_int -1)))
14739    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14740    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14741   ""
14742   "*
14743 {
14744   if (which_alternative != 0)
14745     return \"#\";
14746   else if (get_attr_length (insn) == 4)
14747     return \"bdnz %l0\";
14748   else
14749     return \"bdz $+8\;b %l0\";
14750 }"
14751   [(set_attr "type" "branch")
14752    (set_attr "length" "*,12,16,16")])
14753
14754 (define_insn "*ctr<mode>_internal2"
14755   [(set (pc)
14756         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14757                           (const_int 1))
14758                       (pc)
14759                       (label_ref (match_operand 0 "" ""))))
14760    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14761         (plus:P (match_dup 1)
14762                  (const_int -1)))
14763    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14764    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14765   ""
14766   "*
14767 {
14768   if (which_alternative != 0)
14769     return \"#\";
14770   else if (get_attr_length (insn) == 4)
14771     return \"bdz %l0\";
14772   else
14773     return \"bdnz $+8\;b %l0\";
14774 }"
14775   [(set_attr "type" "branch")
14776    (set_attr "length" "*,12,16,16")])
14777
14778 ;; Similar but use EQ
14779
14780 (define_insn "*ctr<mode>_internal5"
14781   [(set (pc)
14782         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14783                           (const_int 1))
14784                       (label_ref (match_operand 0 "" ""))
14785                       (pc)))
14786    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14787         (plus:P (match_dup 1)
14788                  (const_int -1)))
14789    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14790    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14791   ""
14792   "*
14793 {
14794   if (which_alternative != 0)
14795     return \"#\";
14796   else if (get_attr_length (insn) == 4)
14797     return \"bdz %l0\";
14798   else
14799     return \"bdnz $+8\;b %l0\";
14800 }"
14801   [(set_attr "type" "branch")
14802    (set_attr "length" "*,12,16,16")])
14803
14804 (define_insn "*ctr<mode>_internal6"
14805   [(set (pc)
14806         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14807                           (const_int 1))
14808                       (pc)
14809                       (label_ref (match_operand 0 "" ""))))
14810    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14811         (plus:P (match_dup 1)
14812                  (const_int -1)))
14813    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14814    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14815   ""
14816   "*
14817 {
14818   if (which_alternative != 0)
14819     return \"#\";
14820   else if (get_attr_length (insn) == 4)
14821     return \"bdnz %l0\";
14822   else
14823     return \"bdz $+8\;b %l0\";
14824 }"
14825   [(set_attr "type" "branch")
14826    (set_attr "length" "*,12,16,16")])
14827
14828 ;; Now the splitters if we could not allocate the CTR register
14829
14830 (define_split
14831   [(set (pc)
14832         (if_then_else (match_operator 2 "comparison_operator"
14833                                       [(match_operand:P 1 "gpc_reg_operand" "")
14834                                        (const_int 1)])
14835                       (match_operand 5 "" "")
14836                       (match_operand 6 "" "")))
14837    (set (match_operand:P 0 "gpc_reg_operand" "")
14838         (plus:P (match_dup 1) (const_int -1)))
14839    (clobber (match_scratch:CC 3 ""))
14840    (clobber (match_scratch:P 4 ""))]
14841   "reload_completed"
14842   [(parallel [(set (match_dup 3)
14843                    (compare:CC (plus:P (match_dup 1)
14844                                         (const_int -1))
14845                                (const_int 0)))
14846               (set (match_dup 0)
14847                    (plus:P (match_dup 1)
14848                             (const_int -1)))])
14849    (set (pc) (if_then_else (match_dup 7)
14850                            (match_dup 5)
14851                            (match_dup 6)))]
14852   "
14853 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14854                                 operands[3], const0_rtx); }")
14855
14856 (define_split
14857   [(set (pc)
14858         (if_then_else (match_operator 2 "comparison_operator"
14859                                       [(match_operand:P 1 "gpc_reg_operand" "")
14860                                        (const_int 1)])
14861                       (match_operand 5 "" "")
14862                       (match_operand 6 "" "")))
14863    (set (match_operand:P 0 "nonimmediate_operand" "")
14864         (plus:P (match_dup 1) (const_int -1)))
14865    (clobber (match_scratch:CC 3 ""))
14866    (clobber (match_scratch:P 4 ""))]
14867   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
14868   [(parallel [(set (match_dup 3)
14869                    (compare:CC (plus:P (match_dup 1)
14870                                         (const_int -1))
14871                                (const_int 0)))
14872               (set (match_dup 4)
14873                    (plus:P (match_dup 1)
14874                             (const_int -1)))])
14875    (set (match_dup 0)
14876         (match_dup 4))
14877    (set (pc) (if_then_else (match_dup 7)
14878                            (match_dup 5)
14879                            (match_dup 6)))]
14880   "
14881 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14882                                 operands[3], const0_rtx); }")
14883 \f
14884 (define_insn "trap"
14885   [(trap_if (const_int 1) (const_int 0))]
14886   ""
14887   "trap"
14888   [(set_attr "type" "trap")])
14889
14890 (define_expand "ctrap<mode>4"
14891   [(trap_if (match_operator 0 "ordered_comparison_operator"
14892                             [(match_operand:GPR 1 "register_operand")
14893                              (match_operand:GPR 2 "reg_or_short_operand")])
14894             (match_operand 3 "zero_constant" ""))]
14895   ""
14896   "")
14897
14898 (define_insn ""
14899   [(trap_if (match_operator 0 "ordered_comparison_operator"
14900                             [(match_operand:GPR 1 "register_operand" "r")
14901                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
14902             (const_int 0))]
14903   ""
14904   "t<wd>%V0%I2 %1,%2"
14905   [(set_attr "type" "trap")])
14906 \f
14907 ;; Insns related to generating the function prologue and epilogue.
14908
14909 (define_expand "prologue"
14910   [(use (const_int 0))]
14911   ""
14912 {
14913   rs6000_emit_prologue ();
14914   if (!TARGET_SCHED_PROLOG)
14915     emit_insn (gen_blockage ());
14916   DONE;
14917 })
14918
14919 (define_insn "*movesi_from_cr_one"
14920   [(match_parallel 0 "mfcr_operation"
14921                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14922                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14923                                      (match_operand 3 "immediate_operand" "n")]
14924                           UNSPEC_MOVESI_FROM_CR))])]
14925   "TARGET_MFCRF"
14926   "*
14927 {
14928   int mask = 0;
14929   int i;
14930   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14931   {
14932     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14933     operands[4] = GEN_INT (mask);
14934     output_asm_insn (\"mfcr %1,%4\", operands);
14935   }
14936   return \"\";
14937 }"
14938   [(set_attr "type" "mfcrf")])
14939
14940 (define_insn "movesi_from_cr"
14941   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14942         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
14943                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
14944                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
14945                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
14946                    UNSPEC_MOVESI_FROM_CR))]
14947   ""
14948   "mfcr %0"
14949   [(set_attr "type" "mfcr")])
14950
14951 (define_insn "*crsave"
14952   [(match_parallel 0 "crsave_operation"
14953                    [(set (match_operand:SI 1 "memory_operand" "=m")
14954                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14955   ""
14956   "stw %2,%1"
14957   [(set_attr "type" "store")])
14958
14959 (define_insn "*stmw"
14960   [(match_parallel 0 "stmw_operation"
14961                    [(set (match_operand:SI 1 "memory_operand" "=m")
14962                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14963   "TARGET_MULTIPLE"
14964   "stmw %2,%1"
14965   [(set_attr "type" "store")
14966    (set_attr "update" "yes")
14967    (set_attr "indexed" "yes")])
14968
14969 ; The following comment applies to:
14970 ;     save_gpregs_*
14971 ;     save_fpregs_*
14972 ;     restore_gpregs*
14973 ;     return_and_restore_gpregs*
14974 ;     return_and_restore_fpregs*
14975 ;     return_and_restore_fpregs_aix*
14976 ;
14977 ; The out-of-line save / restore functions expects one input argument.
14978 ; Since those are not standard call_insn's, we must avoid using
14979 ; MATCH_OPERAND for that argument. That way the register rename
14980 ; optimization will not try to rename this register.
14981 ; Each pattern is repeated for each possible register number used in 
14982 ; various ABIs (r11, r1, and for some functions r12)
14983
14984 (define_insn "*save_gpregs_<mode>_r11"
14985   [(match_parallel 0 "any_parallel_operand"
14986                    [(clobber (reg:P 65))
14987                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14988                     (use (reg:P 11))
14989                     (set (match_operand:P 2 "memory_operand" "=m")
14990                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
14991   ""
14992   "bl %1"
14993   [(set_attr "type" "branch")
14994    (set_attr "length" "4")])
14995
14996 (define_insn "*save_gpregs_<mode>_r12"
14997   [(match_parallel 0 "any_parallel_operand"
14998                    [(clobber (reg:P 65))
14999                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15000                     (use (reg:P 12))
15001                     (set (match_operand:P 2 "memory_operand" "=m")
15002                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
15003   ""
15004   "bl %1"
15005   [(set_attr "type" "branch")
15006    (set_attr "length" "4")])
15007
15008 (define_insn "*save_gpregs_<mode>_r1"
15009   [(match_parallel 0 "any_parallel_operand"
15010                    [(clobber (reg:P 65))
15011                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15012                     (use (reg:P 1))
15013                     (set (match_operand:P 2 "memory_operand" "=m")
15014                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
15015   ""
15016   "bl %1"
15017   [(set_attr "type" "branch")
15018    (set_attr "length" "4")])
15019
15020 (define_insn "*save_fpregs_<mode>_r11"
15021   [(match_parallel 0 "any_parallel_operand"
15022                    [(clobber (reg:P 65))
15023                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15024                     (use (reg:P 11))
15025                     (set (match_operand:DF 2 "memory_operand" "=m")
15026                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15027   ""
15028   "bl %1"
15029   [(set_attr "type" "branch")
15030    (set_attr "length" "4")])
15031
15032 (define_insn "*save_fpregs_<mode>_r12"
15033   [(match_parallel 0 "any_parallel_operand"
15034                    [(clobber (reg:P 65))
15035                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15036                     (use (reg:P 12))
15037                     (set (match_operand:DF 2 "memory_operand" "=m")
15038                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15039   ""
15040   "bl %1"
15041   [(set_attr "type" "branch")
15042    (set_attr "length" "4")])
15043
15044 (define_insn "*save_fpregs_<mode>_r1"
15045   [(match_parallel 0 "any_parallel_operand"
15046                    [(clobber (reg:P 65))
15047                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15048                     (use (reg:P 1))
15049                     (set (match_operand:DF 2 "memory_operand" "=m")
15050                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15051   ""
15052   "bl %1"
15053   [(set_attr "type" "branch")
15054    (set_attr "length" "4")])
15055
15056 ; This is to explain that changes to the stack pointer should
15057 ; not be moved over loads from or stores to stack memory.
15058 (define_insn "stack_tie"
15059   [(match_parallel 0 "tie_operand"
15060                    [(set (mem:BLK (reg 1)) (const_int 0))])]
15061   ""
15062   ""
15063   [(set_attr "length" "0")])
15064
15065 (define_expand "epilogue"
15066   [(use (const_int 0))]
15067   ""
15068 {
15069   if (!TARGET_SCHED_PROLOG)
15070     emit_insn (gen_blockage ());
15071   rs6000_emit_epilogue (FALSE);
15072   DONE;
15073 })
15074
15075 ; On some processors, doing the mtcrf one CC register at a time is
15076 ; faster (like on the 604e).  On others, doing them all at once is
15077 ; faster; for instance, on the 601 and 750.
15078
15079 (define_expand "movsi_to_cr_one"
15080   [(set (match_operand:CC 0 "cc_reg_operand" "")
15081         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
15082                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
15083   ""
15084   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
15085
15086 (define_insn "*movsi_to_cr"
15087   [(match_parallel 0 "mtcrf_operation"
15088                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
15089                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
15090                                      (match_operand 3 "immediate_operand" "n")]
15091                                     UNSPEC_MOVESI_TO_CR))])]
15092  ""
15093  "*
15094 {
15095   int mask = 0;
15096   int i;
15097   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15098     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15099   operands[4] = GEN_INT (mask);
15100   return \"mtcrf %4,%2\";
15101 }"
15102   [(set_attr "type" "mtcr")])
15103
15104 (define_insn "*mtcrfsi"
15105   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
15106         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15107                     (match_operand 2 "immediate_operand" "n")]
15108                    UNSPEC_MOVESI_TO_CR))]
15109   "GET_CODE (operands[0]) == REG
15110    && CR_REGNO_P (REGNO (operands[0]))
15111    && GET_CODE (operands[2]) == CONST_INT
15112    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
15113   "mtcrf %R0,%1"
15114   [(set_attr "type" "mtcr")])
15115
15116 ; The load-multiple instructions have similar properties.
15117 ; Note that "load_multiple" is a name known to the machine-independent
15118 ; code that actually corresponds to the PowerPC load-string.
15119
15120 (define_insn "*lmw"
15121   [(match_parallel 0 "lmw_operation"
15122                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15123                          (match_operand:SI 2 "memory_operand" "m"))])]
15124   "TARGET_MULTIPLE"
15125   "lmw %1,%2"
15126   [(set_attr "type" "load")
15127    (set_attr "update" "yes")
15128    (set_attr "indexed" "yes")
15129    (set_attr "cell_micro" "always")])
15130
15131 (define_insn "*return_internal_<mode>"
15132   [(simple_return)
15133    (use (match_operand:P 0 "register_operand" "lc"))]
15134   ""
15135   "b%T0"
15136   [(set_attr "type" "jmpreg")])
15137
15138 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
15139 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
15140
15141 ; The following comment applies to:
15142 ;     save_gpregs_*
15143 ;     save_fpregs_*
15144 ;     restore_gpregs*
15145 ;     return_and_restore_gpregs*
15146 ;     return_and_restore_fpregs*
15147 ;     return_and_restore_fpregs_aix*
15148 ;
15149 ; The out-of-line save / restore functions expects one input argument.
15150 ; Since those are not standard call_insn's, we must avoid using
15151 ; MATCH_OPERAND for that argument. That way the register rename
15152 ; optimization will not try to rename this register.
15153 ; Each pattern is repeated for each possible register number used in 
15154 ; various ABIs (r11, r1, and for some functions r12)
15155
15156 (define_insn "*restore_gpregs_<mode>_r11"
15157  [(match_parallel 0 "any_parallel_operand"
15158                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15159                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15160                    (use (reg:P 11))
15161                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15162                         (match_operand:P 4 "memory_operand" "m"))])]
15163  ""
15164  "bl %2"
15165  [(set_attr "type" "branch")
15166   (set_attr "length" "4")])
15167
15168 (define_insn "*restore_gpregs_<mode>_r12"
15169  [(match_parallel 0 "any_parallel_operand"
15170                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15171                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15172                    (use (reg:P 12))
15173                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15174                         (match_operand:P 4 "memory_operand" "m"))])]
15175  ""
15176  "bl %2"
15177  [(set_attr "type" "branch")
15178   (set_attr "length" "4")])
15179
15180 (define_insn "*restore_gpregs_<mode>_r1"
15181  [(match_parallel 0 "any_parallel_operand"
15182                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15183                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15184                    (use (reg:P 1))
15185                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15186                         (match_operand:P 4 "memory_operand" "m"))])]
15187  ""
15188  "bl %2"
15189  [(set_attr "type" "branch")
15190   (set_attr "length" "4")])
15191
15192 (define_insn "*return_and_restore_gpregs_<mode>_r11"
15193  [(match_parallel 0 "any_parallel_operand"
15194                   [(return)
15195                    (clobber (match_operand:P 1 "register_operand" "=l"))
15196                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15197                    (use (reg:P 11))
15198                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15199                         (match_operand:P 4 "memory_operand" "m"))])]
15200  ""
15201  "b %2"
15202  [(set_attr "type" "branch")
15203   (set_attr "length" "4")])
15204
15205 (define_insn "*return_and_restore_gpregs_<mode>_r12"
15206  [(match_parallel 0 "any_parallel_operand"
15207                   [(return)
15208                    (clobber (match_operand:P 1 "register_operand" "=l"))
15209                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15210                    (use (reg:P 12))
15211                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15212                         (match_operand:P 4 "memory_operand" "m"))])]
15213  ""
15214  "b %2"
15215  [(set_attr "type" "branch")
15216   (set_attr "length" "4")])
15217
15218 (define_insn "*return_and_restore_gpregs_<mode>_r1"
15219  [(match_parallel 0 "any_parallel_operand"
15220                   [(return)
15221                    (clobber (match_operand:P 1 "register_operand" "=l"))
15222                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15223                    (use (reg:P 1))
15224                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15225                         (match_operand:P 4 "memory_operand" "m"))])]
15226  ""
15227  "b %2"
15228  [(set_attr "type" "branch")
15229   (set_attr "length" "4")])
15230
15231 (define_insn "*return_and_restore_fpregs_<mode>_r11"
15232  [(match_parallel 0 "any_parallel_operand"
15233                   [(return)
15234                    (clobber (match_operand:P 1 "register_operand" "=l"))
15235                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15236                    (use (reg:P 11))
15237                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15238                         (match_operand:DF 4 "memory_operand" "m"))])]
15239  ""
15240  "b %2"
15241  [(set_attr "type" "branch")
15242   (set_attr "length" "4")])
15243
15244 (define_insn "*return_and_restore_fpregs_<mode>_r12"
15245  [(match_parallel 0 "any_parallel_operand"
15246                   [(return)
15247                    (clobber (match_operand:P 1 "register_operand" "=l"))
15248                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15249                    (use (reg:P 12))
15250                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15251                         (match_operand:DF 4 "memory_operand" "m"))])]
15252  ""
15253  "b %2"
15254  [(set_attr "type" "branch")
15255   (set_attr "length" "4")])
15256
15257 (define_insn "*return_and_restore_fpregs_<mode>_r1"
15258  [(match_parallel 0 "any_parallel_operand"
15259                   [(return)
15260                    (clobber (match_operand:P 1 "register_operand" "=l"))
15261                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15262                    (use (reg:P 1))
15263                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15264                         (match_operand:DF 4 "memory_operand" "m"))])]
15265  ""
15266  "b %2"
15267  [(set_attr "type" "branch")
15268   (set_attr "length" "4")])
15269
15270 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
15271  [(match_parallel 0 "any_parallel_operand"
15272                   [(return)
15273                    (use (match_operand:P 1 "register_operand" "l"))
15274                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15275                    (use (reg:P 11))
15276                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15277                         (match_operand:DF 4 "memory_operand" "m"))])]
15278  ""
15279  "b %2"
15280  [(set_attr "type" "branch")
15281   (set_attr "length" "4")])
15282
15283 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
15284  [(match_parallel 0 "any_parallel_operand"
15285                   [(return)
15286                    (use (match_operand:P 1 "register_operand" "l"))
15287                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15288                    (use (reg:P 1))
15289                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15290                         (match_operand:DF 4 "memory_operand" "m"))])]
15291  ""
15292  "b %2"
15293  [(set_attr "type" "branch")
15294   (set_attr "length" "4")])
15295
15296 ; This is used in compiling the unwind routines.
15297 (define_expand "eh_return"
15298   [(use (match_operand 0 "general_operand" ""))]
15299   ""
15300   "
15301 {
15302   if (TARGET_32BIT)
15303     emit_insn (gen_eh_set_lr_si (operands[0]));
15304   else
15305     emit_insn (gen_eh_set_lr_di (operands[0]));
15306   DONE;
15307 }")
15308
15309 ; We can't expand this before we know where the link register is stored.
15310 (define_insn "eh_set_lr_<mode>"
15311   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
15312                     UNSPECV_EH_RR)
15313    (clobber (match_scratch:P 1 "=&b"))]
15314   ""
15315   "#")
15316
15317 (define_split
15318   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
15319    (clobber (match_scratch 1 ""))]
15320   "reload_completed"
15321   [(const_int 0)]
15322   "
15323 {
15324   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
15325   DONE;
15326 }")
15327
15328 (define_insn "prefetch"
15329   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
15330              (match_operand:SI 1 "const_int_operand" "n")
15331              (match_operand:SI 2 "const_int_operand" "n"))]
15332   ""
15333   "*
15334 {
15335   if (GET_CODE (operands[0]) == REG)
15336     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
15337   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
15338 }"
15339   [(set_attr "type" "load")])
15340 \f
15341 (define_insn "bpermd_<mode>"
15342   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15343         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
15344                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
15345   "TARGET_POPCNTD"
15346   "bpermd %0,%1,%2"
15347   [(set_attr "type" "popcnt")])
15348
15349 \f
15350 ;; Builtin fma support.  Handle 
15351 ;; Note that the conditions for expansion are in the FMA_F iterator.
15352
15353 (define_expand "fma<mode>4"
15354   [(set (match_operand:FMA_F 0 "register_operand" "")
15355         (fma:FMA_F
15356           (match_operand:FMA_F 1 "register_operand" "")
15357           (match_operand:FMA_F 2 "register_operand" "")
15358           (match_operand:FMA_F 3 "register_operand" "")))]
15359   ""
15360   "")
15361
15362 (define_insn "*fma<mode>4_fpr"
15363   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15364         (fma:SFDF
15365           (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>,<Fv>")
15366           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15367           (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>")))]
15368   "TARGET_<MODE>_FPR"
15369   "@
15370    fmadd<Ftrad> %0,%1,%2,%3
15371    xsmadda<Fvsx> %x0,%x1,%x2
15372    xsmaddm<Fvsx> %x0,%x1,%x3"
15373   [(set_attr "type" "fp")
15374    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15375
15376 ; Altivec only has fma and nfms.
15377 (define_expand "fms<mode>4"
15378   [(set (match_operand:FMA_F 0 "register_operand" "")
15379         (fma:FMA_F
15380           (match_operand:FMA_F 1 "register_operand" "")
15381           (match_operand:FMA_F 2 "register_operand" "")
15382           (neg:FMA_F (match_operand:FMA_F 3 "register_operand" ""))))]
15383   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15384   "")
15385
15386 (define_insn "*fms<mode>4_fpr"
15387   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15388         (fma:SFDF
15389          (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15390          (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15391          (neg:SFDF (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>"))))]
15392   "TARGET_<MODE>_FPR"
15393   "@
15394    fmsub<Ftrad> %0,%1,%2,%3
15395    xsmsuba<Fvsx> %x0,%x1,%x2
15396    xsmsubm<Fvsx> %x0,%x1,%x3"
15397   [(set_attr "type" "fp")
15398    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15399
15400 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
15401 (define_expand "fnma<mode>4"
15402   [(set (match_operand:FMA_F 0 "register_operand" "")
15403         (neg:FMA_F
15404           (fma:FMA_F
15405             (match_operand:FMA_F 1 "register_operand" "")
15406             (match_operand:FMA_F 2 "register_operand" "")
15407             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
15408   "!HONOR_SIGNED_ZEROS (<MODE>mode)"
15409   "")
15410
15411 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
15412 (define_expand "fnms<mode>4"
15413   [(set (match_operand:FMA_F 0 "register_operand" "")
15414         (neg:FMA_F
15415           (fma:FMA_F
15416             (match_operand:FMA_F 1 "register_operand" "")
15417             (match_operand:FMA_F 2 "register_operand" "")
15418             (match_operand:FMA_F 3 "register_operand" ""))))]
15419   "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15420   "")
15421
15422 ; Not an official optab name, but used from builtins.
15423 (define_expand "nfma<mode>4"
15424   [(set (match_operand:FMA_F 0 "register_operand" "")
15425         (neg:FMA_F
15426           (fma:FMA_F
15427             (match_operand:FMA_F 1 "register_operand" "")
15428             (match_operand:FMA_F 2 "register_operand" "")
15429             (match_operand:FMA_F 3 "register_operand" ""))))]
15430   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15431   "")
15432
15433 (define_insn "*nfma<mode>4_fpr"
15434   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15435         (neg:SFDF
15436          (fma:SFDF
15437           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15438           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15439           (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>"))))]
15440   "TARGET_<MODE>_FPR"
15441   "@
15442    fnmadd<Ftrad> %0,%1,%2,%3
15443    xsnmadda<Fvsx> %x0,%x1,%x2
15444    xsnmaddm<Fvsx> %x0,%x1,%x3"
15445   [(set_attr "type" "fp")
15446    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15447
15448 ; Not an official optab name, but used from builtins.
15449 (define_expand "nfms<mode>4"
15450   [(set (match_operand:FMA_F 0 "register_operand" "")
15451         (neg:FMA_F
15452           (fma:FMA_F
15453             (match_operand:FMA_F 1 "register_operand" "")
15454             (match_operand:FMA_F 2 "register_operand" "")
15455             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
15456   ""
15457   "")
15458
15459 (define_insn "*nfmssf4_fpr"
15460   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15461         (neg:SFDF
15462          (fma:SFDF
15463           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15464           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15465           (neg:SFDF
15466            (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>")))))]
15467   "TARGET_<MODE>_FPR"
15468   "@
15469    fnmsub<Ftrad> %0,%1,%2,%3
15470    xsnmsuba<Fvsx> %x0,%x1,%x2
15471    xsnmsubm<Fvsx> %x0,%x1,%x3"
15472   [(set_attr "type" "fp")
15473    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15474
15475 \f
15476 (define_expand "rs6000_get_timebase"
15477   [(use (match_operand:DI 0 "gpc_reg_operand" ""))]
15478   ""
15479 {
15480   if (TARGET_POWERPC64)
15481     emit_insn (gen_rs6000_mftb_di (operands[0]));
15482   else
15483     emit_insn (gen_rs6000_get_timebase_ppc32 (operands[0]));
15484   DONE;
15485 })
15486
15487 (define_insn "rs6000_get_timebase_ppc32"
15488   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
15489         (unspec_volatile:DI [(const_int 0)] UNSPECV_MFTB))
15490    (clobber (match_scratch:SI 1 "=r"))
15491    (clobber (match_scratch:CC 2 "=y"))]
15492   "!TARGET_POWERPC64"
15493 {
15494   if (WORDS_BIG_ENDIAN)
15495     if (TARGET_MFCRF)
15496       {
15497         return "mfspr %0,269\;"
15498                "mfspr %L0,268\;"
15499                "mfspr %1,269\;"
15500                "cmpw %2,%0,%1\;"
15501                "bne- %2,$-16";
15502       }
15503     else
15504       {
15505         return "mftbu %0\;"
15506                "mftb %L0\;"
15507                "mftbu %1\;"
15508                "cmpw %2,%0,%1\;"
15509                "bne- %2,$-16";
15510       }
15511   else
15512     if (TARGET_MFCRF)
15513       {
15514         return "mfspr %L0,269\;"
15515                "mfspr %0,268\;"
15516                "mfspr %1,269\;"
15517                "cmpw %2,%L0,%1\;"
15518                "bne- %2,$-16";
15519       }
15520     else
15521       {
15522         return "mftbu %L0\;"
15523                "mftb %0\;"
15524                "mftbu %1\;"
15525                "cmpw %2,%L0,%1\;"
15526                "bne- %2,$-16";
15527       }
15528 }
15529   [(set_attr "length" "20")])
15530
15531 (define_insn "rs6000_mftb_<mode>"
15532   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15533         (unspec_volatile:P [(const_int 0)] UNSPECV_MFTB))]
15534   ""
15535 {
15536   if (TARGET_MFCRF)
15537     return "mfspr %0,268";
15538   else
15539     return "mftb %0";
15540 })
15541
15542 \f
15543 (define_insn "rs6000_mffs"
15544   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
15545         (unspec_volatile:DF [(const_int 0)] UNSPECV_MFFS))]
15546   "TARGET_HARD_FLOAT && TARGET_FPRS"
15547   "mffs %0")
15548
15549 (define_insn "rs6000_mtfsf"
15550   [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "i")
15551                      (match_operand:DF 1 "gpc_reg_operand" "d")]
15552                     UNSPECV_MTFSF)]
15553   "TARGET_HARD_FLOAT && TARGET_FPRS"
15554   "mtfsf %0,%1")
15555
15556 \f
15557 ;; Power8 fusion support for fusing an addis instruction with a D-form load of
15558 ;; a GPR.  The addis instruction must be adjacent to the load, and use the same
15559 ;; register that is being loaded.  The fused ops must be physically adjacent.
15560
15561 ;; We use define_peephole for the actual addis/load, and the register used to
15562 ;; hold the addis value must be the same as the register being loaded.  We use
15563 ;; define_peephole2 to change the register used for addis to be the register
15564 ;; being loaded, since we can look at whether it is dead after the load insn.
15565
15566 (define_peephole
15567   [(set (match_operand:P 0 "base_reg_operand" "")
15568         (match_operand:P 1 "fusion_gpr_addis" ""))
15569    (set (match_operand:INT1 2 "base_reg_operand" "")
15570         (match_operand:INT1 3 "fusion_gpr_mem_load" ""))]
15571   "TARGET_P8_FUSION && fusion_gpr_load_p (operands, false)"
15572 {
15573   return emit_fusion_gpr_load (operands);
15574 }
15575   [(set_attr "type" "load")
15576    (set_attr "length" "8")])
15577
15578 (define_peephole2
15579   [(set (match_operand:P 0 "base_reg_operand" "")
15580         (match_operand:P 1 "fusion_gpr_addis" ""))
15581    (set (match_operand:INT1 2 "base_reg_operand" "")
15582         (match_operand:INT1 3 "fusion_gpr_mem_load" ""))]
15583   "TARGET_P8_FUSION
15584    && (REGNO (operands[0]) != REGNO (operands[2])
15585        || GET_CODE (operands[3]) == SIGN_EXTEND)
15586    && fusion_gpr_load_p (operands, true)"
15587   [(const_int 0)]
15588 {
15589   expand_fusion_gpr_load (operands);
15590   DONE;
15591 })
15592
15593 \f
15594 ;; Miscellaneous ISA 2.06 (power7) instructions
15595 (define_insn "addg6s"
15596   [(set (match_operand:SI 0 "register_operand" "=r")
15597         (unspec:SI [(match_operand:SI 1 "register_operand" "r")
15598                     (match_operand:SI 2 "register_operand" "r")]
15599                    UNSPEC_ADDG6S))]
15600   "TARGET_POPCNTD"
15601   "addg6s %0,%1,%2"
15602   [(set_attr "type" "integer")
15603    (set_attr "length" "4")])
15604
15605 (define_insn "cdtbcd"
15606   [(set (match_operand:SI 0 "register_operand" "=r")
15607         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
15608                    UNSPEC_CDTBCD))]
15609   "TARGET_POPCNTD"
15610   "cdtbcd %0,%1"
15611   [(set_attr "type" "integer")
15612    (set_attr "length" "4")])
15613
15614 (define_insn "cbcdtd"
15615   [(set (match_operand:SI 0 "register_operand" "=r")
15616         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
15617                    UNSPEC_CBCDTD))]
15618   "TARGET_POPCNTD"
15619   "cbcdtd %0,%1"
15620   [(set_attr "type" "integer")
15621    (set_attr "length" "4")])
15622
15623 (define_int_iterator UNSPEC_DIV_EXTEND [UNSPEC_DIVE
15624                                         UNSPEC_DIVEO
15625                                         UNSPEC_DIVEU
15626                                         UNSPEC_DIVEUO])
15627
15628 (define_int_attr div_extend [(UNSPEC_DIVE       "e")
15629                              (UNSPEC_DIVEO      "eo")
15630                              (UNSPEC_DIVEU      "eu")
15631                              (UNSPEC_DIVEUO     "euo")])
15632
15633 (define_insn "div<div_extend>_<mode>"
15634   [(set (match_operand:GPR 0 "register_operand" "=r")
15635         (unspec:GPR [(match_operand:GPR 1 "register_operand" "r")
15636                      (match_operand:GPR 2 "register_operand" "r")]
15637                     UNSPEC_DIV_EXTEND))]
15638   "TARGET_POPCNTD"
15639   "div<wd><div_extend> %0,%1,%2"
15640   [(set_attr "type" "div")
15641    (set_attr "size" "<bits>")])
15642
15643 \f
15644 ;; Pack/unpack 128-bit floating point types that take 2 scalar registers
15645
15646 ; Type of the 64-bit part when packing/unpacking 128-bit floating point types
15647 (define_mode_attr FP128_64 [(TF "DF") (TD "DI")])
15648
15649 (define_expand "unpack<mode>"
15650   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "")
15651         (unspec:<FP128_64>
15652          [(match_operand:FMOVE128 1 "register_operand" "")
15653           (match_operand:QI 2 "const_0_to_1_operand" "")]
15654          UNSPEC_UNPACK_128BIT))]
15655   ""
15656   "")
15657
15658 ;; The Advance Toolchain 7.0-3 added private builtins: __builtin_longdouble_dw0
15659 ;; and __builtin_longdouble_dw1 to optimize glibc.  Add support for these
15660 ;; builtins here.
15661
15662 (define_expand "unpacktf_0"
15663   [(set (match_operand:DF 0 "nonimmediate_operand" "")
15664         (unspec:DF [(match_operand:TF 1 "register_operand" "")
15665                     (const_int 0)]
15666          UNSPEC_UNPACK_128BIT))]
15667   ""
15668   "")
15669
15670 (define_expand "unpacktf_1"
15671   [(set (match_operand:DF 0 "nonimmediate_operand" "")
15672         (unspec:DF [(match_operand:TF 1 "register_operand" "")
15673                     (const_int 1)]
15674          UNSPEC_UNPACK_128BIT))]
15675   ""
15676   "")
15677
15678 (define_insn_and_split "unpack<mode>_dm"
15679   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "=d,m,d,r,m")
15680         (unspec:<FP128_64>
15681          [(match_operand:FMOVE128 1 "register_operand" "d,d,r,d,r")
15682           (match_operand:QI 2 "const_0_to_1_operand" "i,i,i,i,i")]
15683          UNSPEC_UNPACK_128BIT))]
15684   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
15685   "#"
15686   "&& reload_completed"
15687   [(set (match_dup 0) (match_dup 3))]
15688 {
15689   unsigned fp_regno = REGNO (operands[1]) + UINTVAL (operands[2]);
15690
15691   if (REG_P (operands[0]) && REGNO (operands[0]) == fp_regno)
15692     {
15693       emit_note (NOTE_INSN_DELETED);
15694       DONE;
15695     }
15696
15697   operands[3] = gen_rtx_REG (<FP128_64>mode, fp_regno);
15698 }
15699   [(set_attr "type" "fp,fpstore,mffgpr,mftgpr,store")
15700    (set_attr "length" "4")])
15701
15702 (define_insn_and_split "unpack<mode>_nodm"
15703   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "=d,m")
15704         (unspec:<FP128_64>
15705          [(match_operand:FMOVE128 1 "register_operand" "d,d")
15706           (match_operand:QI 2 "const_0_to_1_operand" "i,i")]
15707          UNSPEC_UNPACK_128BIT))]
15708   "!TARGET_POWERPC64 || !TARGET_DIRECT_MOVE"
15709   "#"
15710   "&& reload_completed"
15711   [(set (match_dup 0) (match_dup 3))]
15712 {
15713   unsigned fp_regno = REGNO (operands[1]) + UINTVAL (operands[2]);
15714
15715   if (REG_P (operands[0]) && REGNO (operands[0]) == fp_regno)
15716     {
15717       emit_note (NOTE_INSN_DELETED);
15718       DONE;
15719     }
15720
15721   operands[3] = gen_rtx_REG (<FP128_64>mode, fp_regno);
15722 }
15723   [(set_attr "type" "fp,fpstore")
15724    (set_attr "length" "4")])
15725
15726 (define_insn_and_split "pack<mode>"
15727   [(set (match_operand:FMOVE128 0 "register_operand" "=d,&d")
15728         (unspec:FMOVE128
15729          [(match_operand:<FP128_64> 1 "register_operand" "0,d")
15730           (match_operand:<FP128_64> 2 "register_operand" "d,d")]
15731          UNSPEC_PACK_128BIT))]
15732   ""
15733   "@
15734    fmr %L0,%2
15735    #"
15736   "&& reload_completed && REGNO (operands[0]) != REGNO (operands[1])"
15737   [(set (match_dup 3) (match_dup 1))
15738    (set (match_dup 4) (match_dup 2))]
15739 {
15740   unsigned dest_hi = REGNO (operands[0]);
15741   unsigned dest_lo = dest_hi + 1;
15742
15743   gcc_assert (!IN_RANGE (REGNO (operands[1]), dest_hi, dest_lo));
15744   gcc_assert (!IN_RANGE (REGNO (operands[2]), dest_hi, dest_lo));
15745
15746   operands[3] = gen_rtx_REG (<FP128_64>mode, dest_hi);
15747   operands[4] = gen_rtx_REG (<FP128_64>mode, dest_lo);
15748 }
15749   [(set_attr "type" "fp,fp")
15750    (set_attr "length" "4,8")])
15751
15752 (define_insn "unpackv1ti"
15753   [(set (match_operand:DI 0 "register_operand" "=d,d")
15754         (unspec:DI [(match_operand:V1TI 1 "register_operand" "0,wa")
15755                     (match_operand:QI 2 "const_0_to_1_operand" "O,i")]
15756          UNSPEC_UNPACK_128BIT))]
15757   "TARGET_VSX"
15758 {
15759   if (REGNO (operands[0]) == REGNO (operands[1]) && INTVAL (operands[2]) == 0)
15760     return ASM_COMMENT_START " xxpermdi to same register";
15761
15762   operands[3] = GEN_INT (INTVAL (operands[2]) == 0 ? 0 : 3);
15763   return "xxpermdi %x0,%x1,%x1,%3";
15764 }
15765   [(set_attr "type" "vecperm")
15766    (set_attr "length" "4")])
15767
15768 (define_insn "packv1ti"
15769   [(set (match_operand:V1TI 0 "register_operand" "=wa")
15770         (unspec:V1TI
15771          [(match_operand:DI 1 "register_operand" "d")
15772           (match_operand:DI 2 "register_operand" "d")]
15773          UNSPEC_PACK_128BIT))]
15774   "TARGET_VSX"
15775   "xxpermdi %x0,%x1,%x2,0"
15776   [(set_attr "type" "vecperm")
15777    (set_attr "length" "4")])
15778
15779 \f
15780
15781 (include "sync.md")
15782 (include "vector.md")
15783 (include "vsx.md")
15784 (include "altivec.md")
15785 (include "spe.md")
15786 (include "dfp.md")
15787 (include "paired.md")
15788 (include "crypto.md")
15789 (include "htm.md")