rs6000: Merge ashrsi3 and ashrdi3
[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    add,logical,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,
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 add, logical, shift, 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 ;; Bitmask for shift instructions
442 (define_mode_attr hH [(SI "h") (DI "H")])
443
444 ;; Suffix for reload patterns
445 (define_mode_attr ptrsize [(SI "32bit")
446                            (DI "64bit")])
447
448 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
449                             (DI "TARGET_64BIT")])
450
451 (define_mode_attr mptrsize [(SI "si")
452                             (DI "di")])
453
454 (define_mode_attr ptrload [(SI "lwz")
455                            (DI "ld")])
456
457 (define_mode_attr ptrm [(SI "m")
458                         (DI "Y")])
459
460 (define_mode_attr rreg [(SF   "f")
461                         (DF   "ws")
462                         (TF   "f")
463                         (TD   "f")
464                         (V4SF "wf")
465                         (V2DF "wd")])
466
467 (define_mode_attr rreg2 [(SF   "f")
468                          (DF   "d")])
469
470 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
471                                  (DF "TARGET_FCFID")])
472
473 (define_mode_attr E500_CONVERT [(SF "!TARGET_FPRS")
474                                 (DF "TARGET_E500_DOUBLE")])
475
476 (define_mode_attr TARGET_FLOAT [(SF "TARGET_SINGLE_FLOAT")
477                                 (DF "TARGET_DOUBLE_FLOAT")])
478
479 ;; Mode iterator for logical operations on 128-bit types
480 (define_mode_iterator BOOL_128          [TI
481                                          PTI
482                                          (V16QI "TARGET_ALTIVEC")
483                                          (V8HI  "TARGET_ALTIVEC")
484                                          (V4SI  "TARGET_ALTIVEC")
485                                          (V4SF  "TARGET_ALTIVEC")
486                                          (V2DI  "TARGET_ALTIVEC")
487                                          (V2DF  "TARGET_ALTIVEC")
488                                          (V1TI  "TARGET_ALTIVEC")])
489
490 ;; For the GPRs we use 3 constraints for register outputs, two that are the
491 ;; same as the output register, and a third where the output register is an
492 ;; early clobber, so we don't have to deal with register overlaps.  For the
493 ;; vector types, we prefer to use the vector registers.  For TI mode, allow
494 ;; either.
495
496 ;; Mode attribute for boolean operation register constraints for output
497 (define_mode_attr BOOL_REGS_OUTPUT      [(TI    "&r,r,r,wa,v")
498                                          (PTI   "&r,r,r")
499                                          (V16QI "wa,v,&?r,?r,?r")
500                                          (V8HI  "wa,v,&?r,?r,?r")
501                                          (V4SI  "wa,v,&?r,?r,?r")
502                                          (V4SF  "wa,v,&?r,?r,?r")
503                                          (V2DI  "wa,v,&?r,?r,?r")
504                                          (V2DF  "wa,v,&?r,?r,?r")
505                                          (V1TI  "wa,v,&?r,?r,?r")])
506
507 ;; Mode attribute for boolean operation register constraints for operand1
508 (define_mode_attr BOOL_REGS_OP1         [(TI    "r,0,r,wa,v")
509                                          (PTI   "r,0,r")
510                                          (V16QI "wa,v,r,0,r")
511                                          (V8HI  "wa,v,r,0,r")
512                                          (V4SI  "wa,v,r,0,r")
513                                          (V4SF  "wa,v,r,0,r")
514                                          (V2DI  "wa,v,r,0,r")
515                                          (V2DF  "wa,v,r,0,r")
516                                          (V1TI  "wa,v,r,0,r")])
517
518 ;; Mode attribute for boolean operation register constraints for operand2
519 (define_mode_attr BOOL_REGS_OP2         [(TI    "r,r,0,wa,v")
520                                          (PTI   "r,r,0")
521                                          (V16QI "wa,v,r,r,0")
522                                          (V8HI  "wa,v,r,r,0")
523                                          (V4SI  "wa,v,r,r,0")
524                                          (V4SF  "wa,v,r,r,0")
525                                          (V2DI  "wa,v,r,r,0")
526                                          (V2DF  "wa,v,r,r,0")
527                                          (V1TI  "wa,v,r,r,0")])
528
529 ;; Mode attribute for boolean operation register constraints for operand1
530 ;; for one_cmpl.  To simplify things, we repeat the constraint where 0
531 ;; is used for operand1 or operand2
532 (define_mode_attr BOOL_REGS_UNARY       [(TI    "r,0,0,wa,v")
533                                          (PTI   "r,0,0")
534                                          (V16QI "wa,v,r,0,0")
535                                          (V8HI  "wa,v,r,0,0")
536                                          (V4SI  "wa,v,r,0,0")
537                                          (V4SF  "wa,v,r,0,0")
538                                          (V2DI  "wa,v,r,0,0")
539                                          (V2DF  "wa,v,r,0,0")
540                                          (V1TI  "wa,v,r,0,0")])
541
542 ;; Mode attribute for the clobber of CC0 for AND expansion.
543 ;; For the 128-bit types, we never do AND immediate, but we need to
544 ;; get the correct number of X's for the number of operands.
545 (define_mode_attr BOOL_REGS_AND_CR0     [(TI    "X,X,X,X,X")
546                                          (PTI   "X,X,X")
547                                          (V16QI "X,X,X,X,X")
548                                          (V8HI  "X,X,X,X,X")
549                                          (V4SI  "X,X,X,X,X")
550                                          (V4SF  "X,X,X,X,X")
551                                          (V2DI  "X,X,X,X,X")
552                                          (V2DF  "X,X,X,X,X")
553                                          (V1TI  "X,X,X,X,X")])
554 \f
555 ;; Start with fixed-point load and store insns.  Here we put only the more
556 ;; complex forms.  Basic data transfer is done later.
557
558 (define_expand "zero_extend<mode>di2"
559   [(set (match_operand:DI 0 "gpc_reg_operand" "")
560         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
561   "TARGET_POWERPC64"
562   "")
563
564 (define_insn "*zero_extend<mode>di2_internal1"
565   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
566         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
567   "TARGET_POWERPC64 && (<MODE>mode != SImode || !TARGET_LFIWZX)"
568   "@
569    l<wd>z%U1%X1 %0,%1
570    rldicl %0,%1,0,<dbits>"
571   [(set_attr "type" "load,shift")])
572
573 (define_insn "*zero_extend<mode>di2_internal2"
574   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
575         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
576                     (const_int 0)))
577    (clobber (match_scratch:DI 2 "=r,r"))]
578   "TARGET_64BIT"
579   "@
580    rldicl. %2,%1,0,<dbits>
581    #"
582   [(set_attr "type" "shift")
583    (set_attr "dot" "yes")
584    (set_attr "length" "4,8")])
585
586 (define_split
587   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
588         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
589                     (const_int 0)))
590    (clobber (match_scratch:DI 2 ""))]
591   "TARGET_POWERPC64 && reload_completed"
592   [(set (match_dup 2)
593         (zero_extend:DI (match_dup 1)))
594    (set (match_dup 0)
595         (compare:CC (match_dup 2)
596                     (const_int 0)))]
597   "")
598
599 (define_insn "*zero_extend<mode>di2_internal3"
600   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
601         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
602                     (const_int 0)))
603    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
604         (zero_extend:DI (match_dup 1)))]
605   "TARGET_64BIT"
606   "@
607    rldicl. %0,%1,0,<dbits>
608    #"
609   [(set_attr "type" "shift")
610    (set_attr "dot" "yes")
611    (set_attr "length" "4,8")])
612
613 (define_split
614   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
615         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
616                     (const_int 0)))
617    (set (match_operand:DI 0 "gpc_reg_operand" "")
618         (zero_extend:DI (match_dup 1)))]
619   "TARGET_POWERPC64 && reload_completed"
620   [(set (match_dup 0)
621         (zero_extend:DI (match_dup 1)))
622    (set (match_dup 2)
623         (compare:CC (match_dup 0)
624                     (const_int 0)))]
625   "")
626
627 (define_insn "*zero_extendsidi2_lfiwzx"
628   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,??wm,!wz,!wu")
629         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r,r,Z,Z")))]
630   "TARGET_POWERPC64 && TARGET_LFIWZX"
631   "@
632    lwz%U1%X1 %0,%1
633    rldicl %0,%1,0,32
634    mtvsrwz %x0,%1
635    lfiwzx %0,%y1
636    lxsiwzx %x0,%y1"
637   [(set_attr "type" "load,shift,mffgpr,fpload,fpload")])
638
639 (define_insn "extendqidi2"
640   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
641         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
642   "TARGET_POWERPC64"
643   "extsb %0,%1"
644   [(set_attr "type" "exts")])
645
646 (define_insn ""
647   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
648         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
649                     (const_int 0)))
650    (clobber (match_scratch:DI 2 "=r,r"))]
651   "TARGET_64BIT"
652   "@
653    extsb. %2,%1
654    #"
655   [(set_attr "type" "compare")
656    (set_attr "length" "4,8")])
657
658 (define_split
659   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
660         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
661                     (const_int 0)))
662    (clobber (match_scratch:DI 2 ""))]
663   "TARGET_POWERPC64 && reload_completed"
664   [(set (match_dup 2)
665         (sign_extend:DI (match_dup 1)))
666    (set (match_dup 0)
667         (compare:CC (match_dup 2)
668                     (const_int 0)))]
669   "")
670
671 (define_insn ""
672   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
673         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
674                     (const_int 0)))
675    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
676         (sign_extend:DI (match_dup 1)))]
677   "TARGET_64BIT"
678   "@
679    extsb. %0,%1
680    #"
681   [(set_attr "type" "compare")
682    (set_attr "length" "4,8")])
683
684 (define_split
685   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
686         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
687                     (const_int 0)))
688    (set (match_operand:DI 0 "gpc_reg_operand" "")
689         (sign_extend:DI (match_dup 1)))]
690   "TARGET_POWERPC64 && reload_completed"
691   [(set (match_dup 0)
692         (sign_extend:DI (match_dup 1)))
693    (set (match_dup 2)
694         (compare:CC (match_dup 0)
695                     (const_int 0)))]
696   "")
697
698 (define_expand "extendhidi2"
699   [(set (match_operand:DI 0 "gpc_reg_operand" "")
700         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
701   "TARGET_POWERPC64"
702   "")
703
704 (define_insn ""
705   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
706         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
707   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
708   "@
709    lha%U1%X1 %0,%1
710    extsh %0,%1"
711   [(set_attr "type" "load,exts")
712    (set_attr "sign_extend" "yes")])
713
714 (define_insn ""
715   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
716         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
717   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
718   "extsh %0,%1"
719   [(set_attr "type" "exts")])
720
721 (define_insn ""
722   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
723         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
724                     (const_int 0)))
725    (clobber (match_scratch:DI 2 "=r,r"))]
726   "TARGET_64BIT"
727   "@
728    extsh. %2,%1
729    #"
730   [(set_attr "type" "compare")
731    (set_attr "length" "4,8")])
732
733 (define_split
734   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
735         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
736                     (const_int 0)))
737    (clobber (match_scratch:DI 2 ""))]
738   "TARGET_POWERPC64 && reload_completed"
739   [(set (match_dup 2)
740         (sign_extend:DI (match_dup 1)))
741    (set (match_dup 0)
742         (compare:CC (match_dup 2)
743                     (const_int 0)))]
744   "")
745
746 (define_insn ""
747   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
748         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
749                     (const_int 0)))
750    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
751         (sign_extend:DI (match_dup 1)))]
752   "TARGET_64BIT"
753   "@
754    extsh. %0,%1
755    #"
756   [(set_attr "type" "compare")
757    (set_attr "length" "4,8")])
758
759 (define_split
760   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
761         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
762                     (const_int 0)))
763    (set (match_operand:DI 0 "gpc_reg_operand" "")
764         (sign_extend:DI (match_dup 1)))]
765   "TARGET_POWERPC64 && reload_completed"
766   [(set (match_dup 0)
767         (sign_extend:DI (match_dup 1)))
768    (set (match_dup 2)
769         (compare:CC (match_dup 0)
770                     (const_int 0)))]
771   "")
772
773 (define_expand "extendsidi2"
774   [(set (match_operand:DI 0 "gpc_reg_operand" "")
775         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
776   "TARGET_POWERPC64"
777   "")
778
779 (define_insn "*extendsidi2_lfiwax"
780   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,??wm,!wl,!wu")
781         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "Y,r,r,Z,Z")))]
782   "TARGET_POWERPC64 && TARGET_LFIWAX"
783   "@
784    lwa%U1%X1 %0,%1
785    extsw %0,%1
786    mtvsrwa %x0,%1
787    lfiwax %0,%y1
788    lxsiwax %x0,%y1"
789   [(set_attr "type" "load,exts,mffgpr,fpload,fpload")
790    (set_attr "sign_extend" "yes")])
791
792 (define_insn "*extendsidi2_nocell"
793   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
794         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "Y,r")))]
795   "TARGET_POWERPC64 && rs6000_gen_cell_microcode && !TARGET_LFIWAX"
796   "@
797    lwa%U1%X1 %0,%1
798    extsw %0,%1"
799   [(set_attr "type" "load,exts")
800    (set_attr "sign_extend" "yes")])
801
802 (define_insn "*extendsidi2_nocell"
803   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
804         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
805   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
806   "extsw %0,%1"
807   [(set_attr "type" "exts")])
808
809 (define_insn ""
810   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
811         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
812                     (const_int 0)))
813    (clobber (match_scratch:DI 2 "=r,r"))]
814   "TARGET_64BIT"
815   "@
816    extsw. %2,%1
817    #"
818   [(set_attr "type" "compare")
819    (set_attr "length" "4,8")])
820
821 (define_split
822   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
823         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
824                     (const_int 0)))
825    (clobber (match_scratch:DI 2 ""))]
826   "TARGET_POWERPC64 && reload_completed"
827   [(set (match_dup 2)
828         (sign_extend:DI (match_dup 1)))
829    (set (match_dup 0)
830         (compare:CC (match_dup 2)
831                     (const_int 0)))]
832   "")
833
834 (define_insn ""
835   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
836         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
837                     (const_int 0)))
838    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
839         (sign_extend:DI (match_dup 1)))]
840   "TARGET_64BIT"
841   "@
842    extsw. %0,%1
843    #"
844   [(set_attr "type" "compare")
845    (set_attr "length" "4,8")])
846
847 (define_split
848   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
849         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
850                     (const_int 0)))
851    (set (match_operand:DI 0 "gpc_reg_operand" "")
852         (sign_extend:DI (match_dup 1)))]
853   "TARGET_POWERPC64 && reload_completed"
854   [(set (match_dup 0)
855         (sign_extend:DI (match_dup 1)))
856    (set (match_dup 2)
857         (compare:CC (match_dup 0)
858                     (const_int 0)))]
859   "")
860
861 (define_expand "zero_extendqisi2"
862   [(set (match_operand:SI 0 "gpc_reg_operand" "")
863         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
864   ""
865   "")
866
867 (define_insn ""
868   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
869         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
870   ""
871   "@
872    lbz%U1%X1 %0,%1
873    rlwinm %0,%1,0,0xff"
874   [(set_attr "type" "load,shift")])
875
876 (define_insn ""
877   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
878         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
879                     (const_int 0)))
880    (clobber (match_scratch:SI 2 "=r,r"))]
881   ""
882   "@
883    andi. %2,%1,0xff
884    #"
885   [(set_attr "type" "logical,compare")
886    (set_attr "dot" "yes")
887    (set_attr "length" "4,8")])
888
889 (define_split
890   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
891         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
892                     (const_int 0)))
893    (clobber (match_scratch:SI 2 ""))]
894   "reload_completed"
895   [(set (match_dup 2)
896         (zero_extend:SI (match_dup 1)))
897    (set (match_dup 0)
898         (compare:CC (match_dup 2)
899                     (const_int 0)))]
900   "")
901
902 (define_insn ""
903   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
904         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
905                     (const_int 0)))
906    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
907         (zero_extend:SI (match_dup 1)))]
908   ""
909   "@
910    andi. %0,%1,0xff
911    #"
912   [(set_attr "type" "logical,compare")
913    (set_attr "dot" "yes")
914    (set_attr "length" "4,8")])
915
916 (define_split
917   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
918         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
919                     (const_int 0)))
920    (set (match_operand:SI 0 "gpc_reg_operand" "")
921         (zero_extend:SI (match_dup 1)))]
922   "reload_completed"
923   [(set (match_dup 0)
924         (zero_extend:SI (match_dup 1)))
925    (set (match_dup 2)
926         (compare:CC (match_dup 0)
927                     (const_int 0)))]
928   "")
929
930 (define_insn "extendqisi2"
931   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
932         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
933   ""
934   "extsb %0,%1"
935   [(set_attr "type" "exts")])
936
937 (define_insn ""
938   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
939         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
940                     (const_int 0)))
941    (clobber (match_scratch:SI 2 "=r,r"))]
942   ""
943   "@
944    extsb. %2,%1
945    #"
946   [(set_attr "type" "compare")
947    (set_attr "length" "4,8")])
948
949 (define_split
950   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
951         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
952                     (const_int 0)))
953    (clobber (match_scratch:SI 2 ""))]
954   "reload_completed"
955   [(set (match_dup 2)
956         (sign_extend:SI (match_dup 1)))
957    (set (match_dup 0)
958         (compare:CC (match_dup 2)
959                     (const_int 0)))]
960   "")
961
962 (define_insn ""
963   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
964         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
965                     (const_int 0)))
966    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
967         (sign_extend:SI (match_dup 1)))]
968   ""
969   "@
970    extsb. %0,%1
971    #"
972   [(set_attr "type" "compare")
973    (set_attr "length" "4,8")])
974
975 (define_split
976   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
977         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
978                     (const_int 0)))
979    (set (match_operand:SI 0 "gpc_reg_operand" "")
980         (sign_extend:SI (match_dup 1)))]
981   "reload_completed"
982   [(set (match_dup 0)
983         (sign_extend:SI (match_dup 1)))
984    (set (match_dup 2)
985         (compare:CC (match_dup 0)
986                     (const_int 0)))]
987   "")
988
989 (define_insn ""
990   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
991         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
992   ""
993   "@
994    lbz%U1%X1 %0,%1
995    rlwinm %0,%1,0,0xff"
996   [(set_attr "type" "load,shift")])
997
998 (define_insn ""
999   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1000         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1001                     (const_int 0)))
1002    (clobber (match_scratch:HI 2 "=r,r"))]
1003   ""
1004   "@
1005    andi. %2,%1,0xff
1006    #"
1007   [(set_attr "type" "logical,compare")
1008    (set_attr "dot" "yes")
1009    (set_attr "length" "4,8")])
1010
1011 (define_split
1012   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1013         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1014                     (const_int 0)))
1015    (clobber (match_scratch:HI 2 ""))]
1016   "reload_completed"
1017   [(set (match_dup 2)
1018         (zero_extend:HI (match_dup 1)))
1019    (set (match_dup 0)
1020         (compare:CC (match_dup 2)
1021                     (const_int 0)))]
1022   "")
1023
1024 (define_insn ""
1025   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1026         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1027                     (const_int 0)))
1028    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1029         (zero_extend:HI (match_dup 1)))]
1030   ""
1031   "@
1032    andi. %0,%1,0xff
1033    #"
1034   [(set_attr "type" "logical,compare")
1035    (set_attr "dot" "yes")
1036    (set_attr "length" "4,8")])
1037
1038 (define_split
1039   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1040         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1041                     (const_int 0)))
1042    (set (match_operand:HI 0 "gpc_reg_operand" "")
1043         (zero_extend:HI (match_dup 1)))]
1044   "reload_completed"
1045   [(set (match_dup 0)
1046         (zero_extend:HI (match_dup 1)))
1047    (set (match_dup 2)
1048         (compare:CC (match_dup 0)
1049                     (const_int 0)))]
1050   "")
1051
1052 (define_insn "extendqihi2"
1053   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
1054         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
1055   ""
1056   "extsb %0,%1"
1057   [(set_attr "type" "exts")])
1058
1059 (define_insn ""
1060   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1061         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1062                     (const_int 0)))
1063    (clobber (match_scratch:HI 2 "=r,r"))]
1064   ""
1065   "@
1066    extsb. %2,%1
1067    #"
1068   [(set_attr "type" "compare")
1069    (set_attr "length" "4,8")])
1070
1071 (define_split
1072   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1073         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1074                     (const_int 0)))
1075    (clobber (match_scratch:HI 2 ""))]
1076   "reload_completed"
1077   [(set (match_dup 2)
1078         (sign_extend:HI (match_dup 1)))
1079    (set (match_dup 0)
1080         (compare:CC (match_dup 2)
1081                     (const_int 0)))]
1082   "")
1083
1084 (define_insn ""
1085   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1086         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1087                     (const_int 0)))
1088    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1089         (sign_extend:HI (match_dup 1)))]
1090   ""
1091   "@
1092    extsb. %0,%1
1093    #"
1094   [(set_attr "type" "compare")
1095    (set_attr "length" "4,8")])
1096
1097 (define_split
1098   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1099         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1100                     (const_int 0)))
1101    (set (match_operand:HI 0 "gpc_reg_operand" "")
1102         (sign_extend:HI (match_dup 1)))]
1103   "reload_completed"
1104   [(set (match_dup 0)
1105         (sign_extend:HI (match_dup 1)))
1106    (set (match_dup 2)
1107         (compare:CC (match_dup 0)
1108                     (const_int 0)))]
1109   "")
1110
1111 (define_expand "zero_extendhisi2"
1112   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1113         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1114   ""
1115   "")
1116
1117 (define_insn ""
1118   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1119         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1120   ""
1121   "@
1122    lhz%U1%X1 %0,%1
1123    rlwinm %0,%1,0,0xffff"
1124   [(set_attr "type" "load,shift")])
1125
1126 (define_insn ""
1127   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1128         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1129                     (const_int 0)))
1130    (clobber (match_scratch:SI 2 "=r,r"))]
1131   ""
1132   "@
1133    andi. %2,%1,0xffff
1134    #"
1135   [(set_attr "type" "logical,compare")
1136    (set_attr "dot" "yes")
1137    (set_attr "length" "4,8")])
1138
1139 (define_split
1140   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1141         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1142                     (const_int 0)))
1143    (clobber (match_scratch:SI 2 ""))]
1144   "reload_completed"
1145   [(set (match_dup 2)
1146         (zero_extend:SI (match_dup 1)))
1147    (set (match_dup 0)
1148         (compare:CC (match_dup 2)
1149                     (const_int 0)))]
1150   "")
1151
1152 (define_insn ""
1153   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1154         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1155                     (const_int 0)))
1156    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1157         (zero_extend:SI (match_dup 1)))]
1158   ""
1159   "@
1160    andi. %0,%1,0xffff
1161    #"
1162   [(set_attr "type" "logical,compare")
1163    (set_attr "dot" "yes")
1164    (set_attr "length" "4,8")])
1165
1166 (define_split
1167   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1168         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1169                     (const_int 0)))
1170    (set (match_operand:SI 0 "gpc_reg_operand" "")
1171         (zero_extend:SI (match_dup 1)))]
1172   "reload_completed"
1173   [(set (match_dup 0)
1174         (zero_extend:SI (match_dup 1)))
1175    (set (match_dup 2)
1176         (compare:CC (match_dup 0)
1177                     (const_int 0)))]
1178   "")
1179
1180 (define_expand "extendhisi2"
1181   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1182         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1183   ""
1184   "")
1185
1186 (define_insn ""
1187   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1188         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1189   "rs6000_gen_cell_microcode"
1190   "@
1191    lha%U1%X1 %0,%1
1192    extsh %0,%1"
1193   [(set_attr "type" "load,exts")
1194    (set_attr "sign_extend" "yes")])
1195
1196 (define_insn ""
1197   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1198         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
1199   "!rs6000_gen_cell_microcode"
1200   "extsh %0,%1"
1201   [(set_attr "type" "exts")])
1202
1203 (define_insn ""
1204   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1205         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1206                     (const_int 0)))
1207    (clobber (match_scratch:SI 2 "=r,r"))]
1208   ""
1209   "@
1210    extsh. %2,%1
1211    #"
1212   [(set_attr "type" "compare")
1213    (set_attr "length" "4,8")])
1214
1215 (define_split
1216   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1217         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1218                     (const_int 0)))
1219    (clobber (match_scratch:SI 2 ""))]
1220   "reload_completed"
1221   [(set (match_dup 2)
1222         (sign_extend:SI (match_dup 1)))
1223    (set (match_dup 0)
1224         (compare:CC (match_dup 2)
1225                     (const_int 0)))]
1226   "")
1227
1228 (define_insn ""
1229   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1230         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1231                     (const_int 0)))
1232    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1233         (sign_extend:SI (match_dup 1)))]
1234   ""
1235   "@
1236    extsh. %0,%1
1237    #"
1238   [(set_attr "type" "compare")
1239    (set_attr "length" "4,8")])
1240
1241 (define_split
1242   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1243         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1244                     (const_int 0)))
1245    (set (match_operand:SI 0 "gpc_reg_operand" "")
1246         (sign_extend:SI (match_dup 1)))]
1247   "reload_completed"
1248   [(set (match_dup 0)
1249         (sign_extend:SI (match_dup 1)))
1250    (set (match_dup 2)
1251         (compare:CC (match_dup 0)
1252                     (const_int 0)))]
1253   "")
1254 \f
1255 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
1256
1257 (define_insn "*macchwc"
1258   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1259         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1260                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1261                                        (const_int 16))
1262                                       (sign_extend:SI
1263                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1264                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1265                     (const_int 0)))
1266    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1267         (plus:SI (mult:SI (ashiftrt:SI
1268                            (match_dup 2)
1269                            (const_int 16))
1270                           (sign_extend:SI
1271                            (match_dup 1)))
1272                  (match_dup 4)))]
1273   "TARGET_MULHW"
1274   "macchw. %0,%1,%2"
1275   [(set_attr "type" "halfmul")])
1276
1277 (define_insn "*macchw"
1278   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1279         (plus:SI (mult:SI (ashiftrt:SI
1280                            (match_operand:SI 2 "gpc_reg_operand" "r")
1281                            (const_int 16))
1282                           (sign_extend:SI
1283                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1284                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1285   "TARGET_MULHW"
1286   "macchw %0,%1,%2"
1287   [(set_attr "type" "halfmul")])
1288
1289 (define_insn "*macchwuc"
1290   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1291         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1292                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1293                                        (const_int 16))
1294                                       (zero_extend:SI
1295                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1296                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1297                     (const_int 0)))
1298    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1299         (plus:SI (mult:SI (lshiftrt:SI
1300                            (match_dup 2)
1301                            (const_int 16))
1302                           (zero_extend:SI
1303                            (match_dup 1)))
1304                  (match_dup 4)))]
1305   "TARGET_MULHW"
1306   "macchwu. %0,%1,%2"
1307   [(set_attr "type" "halfmul")])
1308
1309 (define_insn "*macchwu"
1310   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1311         (plus:SI (mult:SI (lshiftrt:SI
1312                            (match_operand:SI 2 "gpc_reg_operand" "r")
1313                            (const_int 16))
1314                           (zero_extend:SI
1315                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1316                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1317   "TARGET_MULHW"
1318   "macchwu %0,%1,%2"
1319   [(set_attr "type" "halfmul")])
1320
1321 (define_insn "*machhwc"
1322   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1323         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1324                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1325                                        (const_int 16))
1326                                       (ashiftrt:SI
1327                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1328                                        (const_int 16)))
1329                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1330                     (const_int 0)))
1331    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1332         (plus:SI (mult:SI (ashiftrt:SI
1333                            (match_dup 1)
1334                            (const_int 16))
1335                           (ashiftrt:SI
1336                            (match_dup 2)
1337                            (const_int 16)))
1338                  (match_dup 4)))]
1339   "TARGET_MULHW"
1340   "machhw. %0,%1,%2"
1341   [(set_attr "type" "halfmul")])
1342
1343 (define_insn "*machhw"
1344   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1345         (plus:SI (mult:SI (ashiftrt:SI
1346                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1347                            (const_int 16))
1348                           (ashiftrt:SI
1349                            (match_operand:SI 2 "gpc_reg_operand" "r")
1350                            (const_int 16)))
1351                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1352   "TARGET_MULHW"
1353   "machhw %0,%1,%2"
1354   [(set_attr "type" "halfmul")])
1355
1356 (define_insn "*machhwuc"
1357   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1358         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1359                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1360                                        (const_int 16))
1361                                       (lshiftrt:SI
1362                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1363                                        (const_int 16)))
1364                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1365                     (const_int 0)))
1366    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1367         (plus:SI (mult:SI (lshiftrt:SI
1368                            (match_dup 1)
1369                            (const_int 16))
1370                           (lshiftrt:SI
1371                            (match_dup 2)
1372                            (const_int 16)))
1373                  (match_dup 4)))]
1374   "TARGET_MULHW"
1375   "machhwu. %0,%1,%2"
1376   [(set_attr "type" "halfmul")])
1377
1378 (define_insn "*machhwu"
1379   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1380         (plus:SI (mult:SI (lshiftrt:SI
1381                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1382                            (const_int 16))
1383                           (lshiftrt:SI
1384                            (match_operand:SI 2 "gpc_reg_operand" "r")
1385                            (const_int 16)))
1386                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1387   "TARGET_MULHW"
1388   "machhwu %0,%1,%2"
1389   [(set_attr "type" "halfmul")])
1390
1391 (define_insn "*maclhwc"
1392   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1393         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1394                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1395                                       (sign_extend:SI
1396                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1397                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1398                     (const_int 0)))
1399    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1400         (plus:SI (mult:SI (sign_extend:SI
1401                            (match_dup 1))
1402                           (sign_extend:SI
1403                            (match_dup 2)))
1404                  (match_dup 4)))]
1405   "TARGET_MULHW"
1406   "maclhw. %0,%1,%2"
1407   [(set_attr "type" "halfmul")])
1408
1409 (define_insn "*maclhw"
1410   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1411         (plus:SI (mult:SI (sign_extend:SI
1412                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1413                           (sign_extend:SI
1414                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1415                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1416   "TARGET_MULHW"
1417   "maclhw %0,%1,%2"
1418   [(set_attr "type" "halfmul")])
1419
1420 (define_insn "*maclhwuc"
1421   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1422         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1423                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1424                                       (zero_extend:SI
1425                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1426                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1427                     (const_int 0)))
1428    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1429         (plus:SI (mult:SI (zero_extend:SI
1430                            (match_dup 1))
1431                           (zero_extend:SI
1432                            (match_dup 2)))
1433                  (match_dup 4)))]
1434   "TARGET_MULHW"
1435   "maclhwu. %0,%1,%2"
1436   [(set_attr "type" "halfmul")])
1437
1438 (define_insn "*maclhwu"
1439   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1440         (plus:SI (mult:SI (zero_extend:SI
1441                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1442                           (zero_extend:SI
1443                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1444                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1445   "TARGET_MULHW"
1446   "maclhwu %0,%1,%2"
1447   [(set_attr "type" "halfmul")])
1448
1449 (define_insn "*nmacchwc"
1450   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1451         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1452                               (mult:SI (ashiftrt:SI
1453                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1454                                         (const_int 16))
1455                                        (sign_extend:SI
1456                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1457                     (const_int 0)))
1458    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1459         (minus:SI (match_dup 4)
1460                   (mult:SI (ashiftrt:SI
1461                             (match_dup 2)
1462                             (const_int 16))
1463                            (sign_extend:SI
1464                             (match_dup 1)))))]
1465   "TARGET_MULHW"
1466   "nmacchw. %0,%1,%2"
1467   [(set_attr "type" "halfmul")])
1468
1469 (define_insn "*nmacchw"
1470   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1471         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1472                   (mult:SI (ashiftrt:SI
1473                             (match_operand:SI 2 "gpc_reg_operand" "r")
1474                             (const_int 16))
1475                            (sign_extend:SI
1476                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1477   "TARGET_MULHW"
1478   "nmacchw %0,%1,%2"
1479   [(set_attr "type" "halfmul")])
1480
1481 (define_insn "*nmachhwc"
1482   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1483         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1484                               (mult:SI (ashiftrt:SI
1485                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1486                                         (const_int 16))
1487                                        (ashiftrt:SI
1488                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1489                                         (const_int 16))))
1490                     (const_int 0)))
1491    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1492         (minus:SI (match_dup 4)
1493                   (mult:SI (ashiftrt:SI
1494                             (match_dup 1)
1495                             (const_int 16))
1496                            (ashiftrt:SI
1497                             (match_dup 2)
1498                             (const_int 16)))))]
1499   "TARGET_MULHW"
1500   "nmachhw. %0,%1,%2"
1501   [(set_attr "type" "halfmul")])
1502
1503 (define_insn "*nmachhw"
1504   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1505         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1506                   (mult:SI (ashiftrt:SI
1507                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1508                             (const_int 16))
1509                            (ashiftrt:SI
1510                             (match_operand:SI 2 "gpc_reg_operand" "r")
1511                             (const_int 16)))))]
1512   "TARGET_MULHW"
1513   "nmachhw %0,%1,%2"
1514   [(set_attr "type" "halfmul")])
1515
1516 (define_insn "*nmaclhwc"
1517   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1518         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1519                               (mult:SI (sign_extend:SI
1520                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1521                                        (sign_extend:SI
1522                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1523                     (const_int 0)))
1524    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1525         (minus:SI (match_dup 4)
1526                   (mult:SI (sign_extend:SI
1527                             (match_dup 1))
1528                            (sign_extend:SI
1529                             (match_dup 2)))))]
1530   "TARGET_MULHW"
1531   "nmaclhw. %0,%1,%2"
1532   [(set_attr "type" "halfmul")])
1533
1534 (define_insn "*nmaclhw"
1535   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1536         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1537                   (mult:SI (sign_extend:SI
1538                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1539                            (sign_extend:SI
1540                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1541   "TARGET_MULHW"
1542   "nmaclhw %0,%1,%2"
1543   [(set_attr "type" "halfmul")])
1544
1545 (define_insn "*mulchwc"
1546   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1547         (compare:CC (mult:SI (ashiftrt:SI
1548                               (match_operand:SI 2 "gpc_reg_operand" "r")
1549                               (const_int 16))
1550                              (sign_extend:SI
1551                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1552                     (const_int 0)))
1553    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1554         (mult:SI (ashiftrt:SI
1555                   (match_dup 2)
1556                   (const_int 16))
1557                  (sign_extend:SI
1558                   (match_dup 1))))]
1559   "TARGET_MULHW"
1560   "mulchw. %0,%1,%2"
1561   [(set_attr "type" "halfmul")])
1562
1563 (define_insn "*mulchw"
1564   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1565         (mult:SI (ashiftrt:SI
1566                   (match_operand:SI 2 "gpc_reg_operand" "r")
1567                   (const_int 16))
1568                  (sign_extend:SI
1569                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1570   "TARGET_MULHW"
1571   "mulchw %0,%1,%2"
1572   [(set_attr "type" "halfmul")])
1573
1574 (define_insn "*mulchwuc"
1575   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1576         (compare:CC (mult:SI (lshiftrt:SI
1577                               (match_operand:SI 2 "gpc_reg_operand" "r")
1578                               (const_int 16))
1579                              (zero_extend:SI
1580                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1581                     (const_int 0)))
1582    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1583         (mult:SI (lshiftrt:SI
1584                   (match_dup 2)
1585                   (const_int 16))
1586                  (zero_extend:SI
1587                   (match_dup 1))))]
1588   "TARGET_MULHW"
1589   "mulchwu. %0,%1,%2"
1590   [(set_attr "type" "halfmul")])
1591
1592 (define_insn "*mulchwu"
1593   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1594         (mult:SI (lshiftrt:SI
1595                   (match_operand:SI 2 "gpc_reg_operand" "r")
1596                   (const_int 16))
1597                  (zero_extend:SI
1598                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1599   "TARGET_MULHW"
1600   "mulchwu %0,%1,%2"
1601   [(set_attr "type" "halfmul")])
1602
1603 (define_insn "*mulhhwc"
1604   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1605         (compare:CC (mult:SI (ashiftrt:SI
1606                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1607                               (const_int 16))
1608                              (ashiftrt:SI
1609                               (match_operand:SI 2 "gpc_reg_operand" "r")
1610                               (const_int 16)))
1611                     (const_int 0)))
1612    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1613         (mult:SI (ashiftrt:SI
1614                   (match_dup 1)
1615                   (const_int 16))
1616                  (ashiftrt:SI
1617                   (match_dup 2)
1618                   (const_int 16))))]
1619   "TARGET_MULHW"
1620   "mulhhw. %0,%1,%2"
1621   [(set_attr "type" "halfmul")])
1622
1623 (define_insn "*mulhhw"
1624   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1625         (mult:SI (ashiftrt:SI
1626                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1627                   (const_int 16))
1628                  (ashiftrt:SI
1629                   (match_operand:SI 2 "gpc_reg_operand" "r")
1630                   (const_int 16))))]
1631   "TARGET_MULHW"
1632   "mulhhw %0,%1,%2"
1633   [(set_attr "type" "halfmul")])
1634
1635 (define_insn "*mulhhwuc"
1636   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1637         (compare:CC (mult:SI (lshiftrt:SI
1638                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1639                               (const_int 16))
1640                              (lshiftrt:SI
1641                               (match_operand:SI 2 "gpc_reg_operand" "r")
1642                               (const_int 16)))
1643                     (const_int 0)))
1644    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1645         (mult:SI (lshiftrt:SI
1646                   (match_dup 1)
1647                   (const_int 16))
1648                  (lshiftrt:SI
1649                   (match_dup 2)
1650                   (const_int 16))))]
1651   "TARGET_MULHW"
1652   "mulhhwu. %0,%1,%2"
1653   [(set_attr "type" "halfmul")])
1654
1655 (define_insn "*mulhhwu"
1656   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1657         (mult:SI (lshiftrt:SI
1658                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1659                   (const_int 16))
1660                  (lshiftrt:SI
1661                   (match_operand:SI 2 "gpc_reg_operand" "r")
1662                   (const_int 16))))]
1663   "TARGET_MULHW"
1664   "mulhhwu %0,%1,%2"
1665   [(set_attr "type" "halfmul")])
1666
1667 (define_insn "*mullhwc"
1668   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1669         (compare:CC (mult:SI (sign_extend:SI
1670                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1671                              (sign_extend:SI
1672                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1673                     (const_int 0)))
1674    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1675         (mult:SI (sign_extend:SI
1676                   (match_dup 1))
1677                  (sign_extend:SI
1678                   (match_dup 2))))]
1679   "TARGET_MULHW"
1680   "mullhw. %0,%1,%2"
1681   [(set_attr "type" "halfmul")])
1682
1683 (define_insn "*mullhw"
1684   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1685         (mult:SI (sign_extend:SI
1686                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1687                  (sign_extend:SI
1688                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1689   "TARGET_MULHW"
1690   "mullhw %0,%1,%2"
1691   [(set_attr "type" "halfmul")])
1692
1693 (define_insn "*mullhwuc"
1694   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1695         (compare:CC (mult:SI (zero_extend:SI
1696                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1697                              (zero_extend:SI
1698                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1699                     (const_int 0)))
1700    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1701         (mult:SI (zero_extend:SI
1702                   (match_dup 1))
1703                  (zero_extend:SI
1704                   (match_dup 2))))]
1705   "TARGET_MULHW"
1706   "mullhwu. %0,%1,%2"
1707   [(set_attr "type" "halfmul")])
1708
1709 (define_insn "*mullhwu"
1710   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1711         (mult:SI (zero_extend:SI
1712                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1713                  (zero_extend:SI
1714                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1715   "TARGET_MULHW"
1716   "mullhwu %0,%1,%2"
1717   [(set_attr "type" "halfmul")])
1718 \f
1719 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1720 (define_insn "dlmzb"
1721   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1722         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1723                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1724                    UNSPEC_DLMZB_CR))
1725    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1726         (unspec:SI [(match_dup 1)
1727                     (match_dup 2)]
1728                    UNSPEC_DLMZB))]
1729   "TARGET_DLMZB"
1730   "dlmzb. %0,%1,%2")
1731
1732 (define_expand "strlensi"
1733   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1734         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1735                     (match_operand:QI 2 "const_int_operand" "")
1736                     (match_operand 3 "const_int_operand" "")]
1737                    UNSPEC_DLMZB_STRLEN))
1738    (clobber (match_scratch:CC 4 "=x"))]
1739   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1740 {
1741   rtx result = operands[0];
1742   rtx src = operands[1];
1743   rtx search_char = operands[2];
1744   rtx align = operands[3];
1745   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1746   rtx loop_label, end_label, mem, cr0, cond;
1747   if (search_char != const0_rtx
1748       || GET_CODE (align) != CONST_INT
1749       || INTVAL (align) < 8)
1750         FAIL;
1751   word1 = gen_reg_rtx (SImode);
1752   word2 = gen_reg_rtx (SImode);
1753   scratch_dlmzb = gen_reg_rtx (SImode);
1754   scratch_string = gen_reg_rtx (Pmode);
1755   loop_label = gen_label_rtx ();
1756   end_label = gen_label_rtx ();
1757   addr = force_reg (Pmode, XEXP (src, 0));
1758   emit_move_insn (scratch_string, addr);
1759   emit_label (loop_label);
1760   mem = change_address (src, SImode, scratch_string);
1761   emit_move_insn (word1, mem);
1762   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1763   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1764   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1765   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1766   emit_jump_insn (gen_rtx_SET (VOIDmode,
1767                                pc_rtx,
1768                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1769                                                      cond,
1770                                                      gen_rtx_LABEL_REF
1771                                                        (VOIDmode,
1772                                                         end_label),
1773                                                      pc_rtx)));
1774   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1775   emit_jump_insn (gen_rtx_SET (VOIDmode,
1776                                pc_rtx,
1777                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1778   emit_barrier ();
1779   emit_label (end_label);
1780   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1781   emit_insn (gen_subsi3 (result, scratch_string, addr));
1782   emit_insn (gen_subsi3 (result, result, const1_rtx));
1783   DONE;
1784 })
1785 \f
1786 ;; Fixed-point arithmetic insns.
1787
1788 (define_expand "add<mode>3"
1789   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1790         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1791                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1792   ""
1793 {
1794   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1795     {
1796       if (non_short_cint_operand (operands[2], DImode))
1797         FAIL;
1798     }
1799   else if (GET_CODE (operands[2]) == CONST_INT
1800            && ! add_operand (operands[2], <MODE>mode))
1801     {
1802       rtx tmp = ((!can_create_pseudo_p ()
1803                   || rtx_equal_p (operands[0], operands[1]))
1804                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1805
1806       HOST_WIDE_INT val = INTVAL (operands[2]);
1807       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1808       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1809
1810       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1811         FAIL;
1812
1813       /* The ordering here is important for the prolog expander.
1814          When space is allocated from the stack, adding 'low' first may
1815          produce a temporary deallocation (which would be bad).  */
1816       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1817       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1818       DONE;
1819     }
1820 })
1821
1822 ;; Discourage ai/addic because of carry but provide it in an alternative
1823 ;; allowing register zero as source.
1824 (define_insn "*add<mode>3_internal1"
1825   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1826         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1827                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1828   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1829   "@
1830    add %0,%1,%2
1831    addi %0,%1,%2
1832    addic %0,%1,%2
1833    addis %0,%1,%v2"
1834   [(set_attr "type" "add")])
1835
1836 (define_insn "addsi3_high"
1837   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1838         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1839                  (high:SI (match_operand 2 "" ""))))]
1840   "TARGET_MACHO && !TARGET_64BIT"
1841   "addis %0,%1,ha16(%2)"
1842   [(set_attr "type" "add")])
1843
1844 (define_insn "*add<mode>3_internal2"
1845   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1846         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1847                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1848                     (const_int 0)))
1849    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1850   ""
1851   "@
1852    add. %3,%1,%2
1853    addic. %3,%1,%2
1854    #
1855    #"
1856   [(set_attr "type" "add,compare,compare,compare")
1857    (set_attr "dot" "yes")
1858    (set_attr "length" "4,4,8,8")])
1859
1860 (define_split
1861   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1862         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1863                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1864                     (const_int 0)))
1865    (clobber (match_scratch:GPR 3 ""))]
1866   "reload_completed"
1867   [(set (match_dup 3)
1868         (plus:GPR (match_dup 1)
1869                  (match_dup 2)))
1870    (set (match_dup 0)
1871         (compare:CC (match_dup 3)
1872                     (const_int 0)))]
1873   "")
1874
1875 (define_insn "*add<mode>3_internal3"
1876   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1877         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1878                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1879                     (const_int 0)))
1880    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1881         (plus:P (match_dup 1)
1882                 (match_dup 2)))]
1883   ""
1884   "@
1885    add. %0,%1,%2
1886    addic. %0,%1,%2
1887    #
1888    #"
1889   [(set_attr "type" "add,compare,compare,compare")
1890    (set_attr "dot" "yes")
1891    (set_attr "length" "4,4,8,8")])
1892
1893 (define_split
1894   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1895         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1896                             (match_operand:P 2 "reg_or_short_operand" ""))
1897                     (const_int 0)))
1898    (set (match_operand:P 0 "gpc_reg_operand" "")
1899         (plus:P (match_dup 1) (match_dup 2)))]
1900   "reload_completed"
1901   [(set (match_dup 0)
1902         (plus:P (match_dup 1)
1903                 (match_dup 2)))
1904    (set (match_dup 3)
1905         (compare:CC (match_dup 0)
1906                     (const_int 0)))]
1907   "")
1908
1909 ;; Split an add that we can't do in one insn into two insns, each of which
1910 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1911 ;; add should be last in case the result gets used in an address.
1912
1913 (define_split
1914   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1915         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1916                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1917   ""
1918   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1919    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1920 {
1921   HOST_WIDE_INT val = INTVAL (operands[2]);
1922   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1923   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1924
1925   operands[4] = GEN_INT (low);
1926   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1927     operands[3] = GEN_INT (rest);
1928   else if (can_create_pseudo_p ())
1929     {
1930       operands[3] = gen_reg_rtx (DImode);
1931       emit_move_insn (operands[3], operands[2]);
1932       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1933       DONE;
1934     }
1935   else
1936     FAIL;
1937 })
1938
1939 (define_expand "one_cmpl<mode>2"
1940   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1941         (not:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1942   ""
1943 {
1944   if (<MODE>mode == DImode && !TARGET_POWERPC64)
1945     {
1946       rs6000_split_logical (operands, NOT, false, false, false, NULL_RTX);
1947       DONE;
1948     }
1949 })
1950
1951 (define_insn "*one_cmpl<mode>2"
1952   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1953         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1954   ""
1955   "nor %0,%1,%1")
1956
1957 (define_insn ""
1958   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1959         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1960                     (const_int 0)))
1961    (clobber (match_scratch:P 2 "=r,r"))]
1962   ""
1963   "@
1964    nor. %2,%1,%1
1965    #"
1966   [(set_attr "type" "logical,compare")
1967    (set_attr "dot" "yes")
1968    (set_attr "length" "4,8")])
1969
1970 (define_split
1971   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1972         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1973                     (const_int 0)))
1974    (clobber (match_scratch:P 2 ""))]
1975   "reload_completed"
1976   [(set (match_dup 2)
1977         (not:P (match_dup 1)))
1978    (set (match_dup 0)
1979         (compare:CC (match_dup 2)
1980                     (const_int 0)))]
1981   "")
1982
1983 (define_insn ""
1984   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1985         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1986                     (const_int 0)))
1987    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1988         (not:P (match_dup 1)))]
1989   ""
1990   "@
1991    nor. %0,%1,%1
1992    #"
1993   [(set_attr "type" "logical,compare")
1994    (set_attr "dot" "yes")
1995    (set_attr "length" "4,8")])
1996
1997 (define_split
1998   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1999         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
2000                     (const_int 0)))
2001    (set (match_operand:P 0 "gpc_reg_operand" "")
2002         (not:P (match_dup 1)))]
2003   "reload_completed"
2004   [(set (match_dup 0)
2005         (not:P (match_dup 1)))
2006    (set (match_dup 2)
2007         (compare:CC (match_dup 0)
2008                     (const_int 0)))]
2009   "")
2010
2011 (define_insn ""
2012   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
2013         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
2014                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
2015   ""
2016   "@
2017    subf %0,%2,%1
2018    subfic %0,%2,%1"
2019   [(set_attr "type" "add")])
2020
2021 (define_insn ""
2022   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2023         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2024                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
2025                     (const_int 0)))
2026    (clobber (match_scratch:P 3 "=r,r"))]
2027   ""
2028   "@
2029    subf. %3,%2,%1
2030    #"
2031   [(set_attr "type" "add")
2032    (set_attr "dot" "yes")
2033    (set_attr "length" "4,8")])
2034
2035 (define_split
2036   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2037         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
2038                              (match_operand:P 2 "gpc_reg_operand" ""))
2039                     (const_int 0)))
2040    (clobber (match_scratch:P 3 ""))]
2041   "reload_completed"
2042   [(set (match_dup 3)
2043         (minus:P (match_dup 1)
2044                   (match_dup 2)))
2045    (set (match_dup 0)
2046         (compare:CC (match_dup 3)
2047                     (const_int 0)))]
2048   "")
2049
2050 (define_insn ""
2051   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2052         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2053                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
2054                     (const_int 0)))
2055    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2056         (minus:P (match_dup 1)
2057                   (match_dup 2)))]
2058   ""
2059   "@
2060    subf. %0,%2,%1
2061    #"
2062   [(set_attr "type" "add")
2063    (set_attr "dot" "yes")
2064    (set_attr "length" "4,8")])
2065
2066 (define_split
2067   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2068         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
2069                              (match_operand:P 2 "gpc_reg_operand" ""))
2070                     (const_int 0)))
2071    (set (match_operand:P 0 "gpc_reg_operand" "")
2072         (minus:P (match_dup 1)
2073                   (match_dup 2)))]
2074   "reload_completed"
2075   [(set (match_dup 0)
2076         (minus:P (match_dup 1)
2077                   (match_dup 2)))
2078    (set (match_dup 3)
2079         (compare:CC (match_dup 0)
2080                     (const_int 0)))]
2081   "")
2082
2083 (define_expand "sub<mode>3"
2084   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2085         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
2086                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
2087   ""
2088   "
2089 {
2090   if (GET_CODE (operands[2]) == CONST_INT)
2091     {
2092       emit_insn (gen_add<mode>3 (operands[0], operands[1],
2093                                  negate_rtx (<MODE>mode, operands[2])));
2094       DONE;
2095     }
2096 }")
2097
2098 (define_expand "neg<mode>2"
2099   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2100         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2101   ""
2102   "")
2103
2104 (define_insn "*neg<mode>2_internal"
2105   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2106         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2107   ""
2108   "neg %0,%1"
2109   [(set_attr "type" "add")])
2110
2111 (define_insn ""
2112   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2113         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2114                     (const_int 0)))
2115    (clobber (match_scratch:P 2 "=r,r"))]
2116   ""
2117   "@
2118    neg. %2,%1
2119    #"
2120   [(set_attr "type" "add")
2121    (set_attr "dot" "yes")
2122    (set_attr "length" "4,8")])
2123
2124 (define_split
2125   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2126         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2127                     (const_int 0)))
2128    (clobber (match_scratch:P 2 ""))]
2129   "reload_completed"
2130   [(set (match_dup 2)
2131         (neg:P (match_dup 1)))
2132    (set (match_dup 0)
2133         (compare:CC (match_dup 2)
2134                     (const_int 0)))]
2135   "")
2136
2137 (define_insn ""
2138   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2139         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2140                     (const_int 0)))
2141    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2142         (neg:P (match_dup 1)))]
2143   ""
2144   "@
2145    neg. %0,%1
2146    #"
2147   [(set_attr "type" "add")
2148    (set_attr "dot" "yes")
2149    (set_attr "length" "4,8")])
2150
2151 (define_split
2152   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2153         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2154                     (const_int 0)))
2155    (set (match_operand:P 0 "gpc_reg_operand" "")
2156         (neg:P (match_dup 1)))]
2157   "reload_completed"
2158   [(set (match_dup 0)
2159         (neg:P (match_dup 1)))
2160    (set (match_dup 2)
2161         (compare:CC (match_dup 0)
2162                     (const_int 0)))]
2163   "")
2164
2165 (define_insn "clz<mode>2"
2166   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2167         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2168   ""
2169   "cntlz<wd> %0,%1"
2170   [(set_attr "type" "cntlz")])
2171
2172 (define_expand "ctz<mode>2"
2173   [(set (match_dup 2)
2174         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2175    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2176                                           (match_dup 2)))
2177               (clobber (scratch:CC))])
2178    (set (match_dup 4) (clz:GPR (match_dup 3)))
2179    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2180         (minus:GPR (match_dup 5) (match_dup 4)))]
2181   ""
2182   {
2183      operands[2] = gen_reg_rtx (<MODE>mode);
2184      operands[3] = gen_reg_rtx (<MODE>mode);
2185      operands[4] = gen_reg_rtx (<MODE>mode);
2186      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2187   })
2188
2189 (define_expand "ffs<mode>2"
2190   [(set (match_dup 2)
2191         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2192    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2193                                           (match_dup 2)))
2194               (clobber (scratch:CC))])
2195    (set (match_dup 4) (clz:GPR (match_dup 3)))
2196    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2197         (minus:GPR (match_dup 5) (match_dup 4)))]
2198   ""
2199   {
2200      operands[2] = gen_reg_rtx (<MODE>mode);
2201      operands[3] = gen_reg_rtx (<MODE>mode);
2202      operands[4] = gen_reg_rtx (<MODE>mode);
2203      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2204   })
2205
2206 (define_insn "popcntb<mode>2"
2207   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2208         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2209                      UNSPEC_POPCNTB))]
2210   "TARGET_POPCNTB"
2211   "popcntb %0,%1"
2212   [(set_attr "length" "4")
2213    (set_attr "type" "popcnt")])
2214
2215 (define_insn "popcntd<mode>2"
2216   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2217         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2218   "TARGET_POPCNTD"
2219   "popcnt<wd> %0,%1"
2220   [(set_attr "length" "4")
2221    (set_attr "type" "popcnt")])
2222
2223 (define_expand "popcount<mode>2"
2224   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2225         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2226   "TARGET_POPCNTB || TARGET_POPCNTD"
2227   {
2228     rs6000_emit_popcount (operands[0], operands[1]);
2229     DONE;
2230   })
2231
2232 (define_insn "parity<mode>2_cmpb"
2233   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2234         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
2235   "TARGET_CMPB && TARGET_POPCNTB"
2236   "prty<wd> %0,%1"
2237   [(set_attr "length" "4")
2238    (set_attr "type" "popcnt")])
2239
2240 (define_expand "parity<mode>2"
2241   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2242         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2243   "TARGET_POPCNTB"
2244   {
2245     rs6000_emit_parity (operands[0], operands[1]);
2246     DONE;
2247   })
2248
2249 ;; Since the hardware zeros the upper part of the register, save generating the
2250 ;; AND immediate if we are converting to unsigned
2251 (define_insn "*bswaphi2_extenddi"
2252   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2253         (zero_extend:DI
2254          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2255   "TARGET_POWERPC64"
2256   "lhbrx %0,%y1"
2257   [(set_attr "length" "4")
2258    (set_attr "type" "load")])
2259
2260 (define_insn "*bswaphi2_extendsi"
2261   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2262         (zero_extend:SI
2263          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2264   ""
2265   "lhbrx %0,%y1"
2266   [(set_attr "length" "4")
2267    (set_attr "type" "load")])
2268
2269 (define_expand "bswaphi2"
2270   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
2271                    (bswap:HI
2272                     (match_operand:HI 1 "reg_or_mem_operand" "")))
2273               (clobber (match_scratch:SI 2 ""))])]
2274   ""
2275 {
2276   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2277     operands[1] = force_reg (HImode, operands[1]);
2278 })
2279
2280 (define_insn "bswaphi2_internal"
2281   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
2282         (bswap:HI
2283          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
2284    (clobber (match_scratch:SI 2 "=X,X,&r"))]
2285   ""
2286   "@
2287    lhbrx %0,%y1
2288    sthbrx %1,%y0
2289    #"
2290   [(set_attr "length" "4,4,12")
2291    (set_attr "type" "load,store,*")])
2292
2293 ;; We are always BITS_BIG_ENDIAN, so the (const_int 16) below is
2294 ;; correct for -mlittle as well as -mbig.
2295 (define_split
2296   [(set (match_operand:HI 0 "gpc_reg_operand" "")
2297         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
2298    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2299   "reload_completed"
2300   [(set (match_dup 3)
2301         (zero_extract:SI (match_dup 4)
2302                          (const_int 8)
2303                          (const_int 16)))
2304    (set (match_dup 2)
2305         (and:SI (ashift:SI (match_dup 4)
2306                            (const_int 8))
2307                 (const_int 65280)))             ;; 0xff00
2308    (set (match_dup 3)
2309         (ior:SI (match_dup 3)
2310                 (match_dup 2)))]
2311   "
2312 {
2313   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2314   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2315 }")
2316
2317 (define_insn "*bswapsi2_extenddi"
2318   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2319         (zero_extend:DI
2320          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2321   "TARGET_POWERPC64"
2322   "lwbrx %0,%y1"
2323   [(set_attr "length" "4")
2324    (set_attr "type" "load")])
2325
2326 (define_expand "bswapsi2"
2327   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2328         (bswap:SI
2329          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2330   ""
2331 {
2332   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2333     operands[1] = force_reg (SImode, operands[1]);
2334 })
2335
2336 (define_insn "*bswapsi2_internal"
2337   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2338         (bswap:SI
2339          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2340   ""
2341   "@
2342    lwbrx %0,%y1
2343    stwbrx %1,%y0
2344    #"
2345   [(set_attr "length" "4,4,12")
2346    (set_attr "type" "load,store,*")])
2347
2348 ;; We are always BITS_BIG_ENDIAN, so the bit positions below in
2349 ;; zero_extract insns do not change for -mlittle.
2350 (define_split
2351   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2352         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2353   "reload_completed"
2354   [(set (match_dup 0)
2355         (rotate:SI (match_dup 1) (const_int 8)))
2356    (set (zero_extract:SI (match_dup 0)
2357                          (const_int 8)
2358                          (const_int 0))
2359         (match_dup 1))
2360    (set (zero_extract:SI (match_dup 0)
2361                          (const_int 8)
2362                          (const_int 16))
2363         (rotate:SI (match_dup 1)
2364                    (const_int 16)))]
2365   "")
2366
2367 (define_expand "bswapdi2"
2368   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2369                    (bswap:DI
2370                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2371               (clobber (match_scratch:DI 2 ""))
2372               (clobber (match_scratch:DI 3 ""))
2373               (clobber (match_scratch:DI 4 ""))])]
2374   ""
2375 {
2376   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2377     operands[1] = force_reg (DImode, operands[1]);
2378
2379   if (!TARGET_POWERPC64)
2380     {
2381       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2382          that uses 64-bit registers needs the same scratch registers as 64-bit
2383          mode.  */
2384       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2385       DONE;
2386     }
2387 })
2388
2389 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2390 (define_insn "*bswapdi2_ldbrx"
2391   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2392         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2393    (clobber (match_scratch:DI 2 "=X,X,&r"))
2394    (clobber (match_scratch:DI 3 "=X,X,&r"))
2395    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2396   "TARGET_POWERPC64 && TARGET_LDBRX
2397    && (REG_P (operands[0]) || REG_P (operands[1]))"
2398   "@
2399    ldbrx %0,%y1
2400    stdbrx %1,%y0
2401    #"
2402   [(set_attr "length" "4,4,36")
2403    (set_attr "type" "load,store,*")])
2404
2405 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2406 (define_insn "*bswapdi2_64bit"
2407   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,&r")
2408         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2409    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2410    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2411    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2412   "TARGET_POWERPC64 && !TARGET_LDBRX
2413    && (REG_P (operands[0]) || REG_P (operands[1]))
2414    && !(MEM_P (operands[0]) && MEM_VOLATILE_P (operands[0]))
2415    && !(MEM_P (operands[1]) && MEM_VOLATILE_P (operands[1]))"
2416   "#"
2417   [(set_attr "length" "16,12,36")])
2418
2419 (define_split
2420   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2421         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2422    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2423    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2424    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2425   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2426   [(const_int 0)]
2427   "
2428 {
2429   rtx dest   = operands[0];
2430   rtx src    = operands[1];
2431   rtx op2    = operands[2];
2432   rtx op3    = operands[3];
2433   rtx op4    = operands[4];
2434   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode,
2435                                     BYTES_BIG_ENDIAN ? 4 : 0);
2436   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode,
2437                                     BYTES_BIG_ENDIAN ? 4 : 0);
2438   rtx addr1;
2439   rtx addr2;
2440   rtx word_high;
2441   rtx word_low;
2442
2443   addr1 = XEXP (src, 0);
2444   if (GET_CODE (addr1) == PLUS)
2445     {
2446       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2447       if (TARGET_AVOID_XFORM)
2448         {
2449           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2450           addr2 = op2;
2451         }
2452       else
2453         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2454     }
2455   else if (TARGET_AVOID_XFORM)
2456     {
2457       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2458       addr2 = op2;
2459     }
2460   else
2461     {
2462       emit_move_insn (op2, GEN_INT (4));
2463       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2464     }
2465
2466   if (BYTES_BIG_ENDIAN)
2467     {
2468       word_high = change_address (src, SImode, addr1);
2469       word_low  = change_address (src, SImode, addr2);
2470     }
2471   else
2472     {
2473       word_high = change_address (src, SImode, addr2);
2474       word_low  = change_address (src, SImode, addr1);
2475     }
2476
2477   emit_insn (gen_bswapsi2 (op3_32, word_low));
2478   emit_insn (gen_bswapsi2 (op4_32, word_high));
2479   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2480   emit_insn (gen_iordi3 (dest, dest, op4));
2481   DONE;
2482 }")
2483
2484 (define_split
2485   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2486         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2487    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2488    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2489    (clobber (match_operand:DI 4 "" ""))]
2490   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2491   [(const_int 0)]
2492   "
2493 {
2494   rtx dest   = operands[0];
2495   rtx src    = operands[1];
2496   rtx op2    = operands[2];
2497   rtx op3    = operands[3];
2498   rtx src_si = simplify_gen_subreg (SImode, src, DImode,
2499                                     BYTES_BIG_ENDIAN ? 4 : 0);
2500   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode,
2501                                     BYTES_BIG_ENDIAN ? 4 : 0);
2502   rtx addr1;
2503   rtx addr2;
2504   rtx word_high;
2505   rtx word_low;
2506
2507   addr1 = XEXP (dest, 0);
2508   if (GET_CODE (addr1) == PLUS)
2509     {
2510       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2511       if (TARGET_AVOID_XFORM)
2512         {
2513           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2514           addr2 = op2;
2515         }
2516       else
2517         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2518     }
2519   else if (TARGET_AVOID_XFORM)
2520     {
2521       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2522       addr2 = op2;
2523     }
2524   else
2525     {
2526       emit_move_insn (op2, GEN_INT (4));
2527       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2528     }
2529
2530   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2531   if (BYTES_BIG_ENDIAN)
2532     {
2533       word_high = change_address (dest, SImode, addr1);
2534       word_low  = change_address (dest, SImode, addr2);
2535     }
2536   else
2537     {
2538       word_high = change_address (dest, SImode, addr2);
2539       word_low  = change_address (dest, SImode, addr1);
2540     }
2541   emit_insn (gen_bswapsi2 (word_high, src_si));
2542   emit_insn (gen_bswapsi2 (word_low, op3_si));
2543   DONE;
2544 }")
2545
2546 (define_split
2547   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2548         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2549    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2550    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2551    (clobber (match_operand:DI 4 "" ""))]
2552   "TARGET_POWERPC64 && reload_completed"
2553   [(const_int 0)]
2554   "
2555 {
2556   rtx dest    = operands[0];
2557   rtx src     = operands[1];
2558   rtx op2     = operands[2];
2559   rtx op3     = operands[3];
2560   int lo_off  = BYTES_BIG_ENDIAN ? 4 : 0;
2561   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, lo_off);
2562   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, lo_off);
2563   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, lo_off);
2564   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, lo_off);
2565
2566   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2567   emit_insn (gen_bswapsi2 (dest_si, src_si));
2568   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2569   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2570   emit_insn (gen_iordi3 (dest, dest, op3));
2571   DONE;
2572 }")
2573
2574 (define_insn "bswapdi2_32bit"
2575   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,&r")
2576         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2577    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2578   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2579   "#"
2580   [(set_attr "length" "16,12,36")])
2581
2582 (define_split
2583   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2584         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2585    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2586   "!TARGET_POWERPC64 && reload_completed"
2587   [(const_int 0)]
2588   "
2589 {
2590   rtx dest  = operands[0];
2591   rtx src   = operands[1];
2592   rtx op2   = operands[2];
2593   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2594   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2595   rtx addr1;
2596   rtx addr2;
2597   rtx word1;
2598   rtx word2;
2599
2600   addr1 = XEXP (src, 0);
2601   if (GET_CODE (addr1) == PLUS)
2602     {
2603       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2604       if (TARGET_AVOID_XFORM)
2605         {
2606           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2607           addr2 = op2;
2608         }
2609       else
2610         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2611     }
2612   else if (TARGET_AVOID_XFORM)
2613     {
2614       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2615       addr2 = op2;
2616     }
2617   else
2618     {
2619       emit_move_insn (op2, GEN_INT (4));
2620       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2621     }
2622
2623   word1 = change_address (src, SImode, addr1);
2624   word2 = change_address (src, SImode, addr2);
2625
2626   emit_insn (gen_bswapsi2 (dest2, word1));
2627   emit_insn (gen_bswapsi2 (dest1, word2));
2628   DONE;
2629 }")
2630
2631 (define_split
2632   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2633         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2634    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2635   "!TARGET_POWERPC64 && reload_completed"
2636   [(const_int 0)]
2637   "
2638 {
2639   rtx dest = operands[0];
2640   rtx src  = operands[1];
2641   rtx op2  = operands[2];
2642   rtx src1 = simplify_gen_subreg (SImode, src, DImode, 0);
2643   rtx src2 = simplify_gen_subreg (SImode, src, DImode, 4);
2644   rtx addr1;
2645   rtx addr2;
2646   rtx word1;
2647   rtx word2;
2648
2649   addr1 = XEXP (dest, 0);
2650   if (GET_CODE (addr1) == PLUS)
2651     {
2652       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2653       if (TARGET_AVOID_XFORM)
2654         {
2655           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2656           addr2 = op2;
2657         }
2658       else
2659         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2660     }
2661   else if (TARGET_AVOID_XFORM)
2662     {
2663       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2664       addr2 = op2;
2665     }
2666   else
2667     {
2668       emit_move_insn (op2, GEN_INT (4));
2669       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2670     }
2671
2672   word1 = change_address (dest, SImode, addr1);
2673   word2 = change_address (dest, SImode, addr2);
2674
2675   emit_insn (gen_bswapsi2 (word2, src1));
2676   emit_insn (gen_bswapsi2 (word1, src2));
2677   DONE;
2678 }")
2679
2680 (define_split
2681   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2682         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2683    (clobber (match_operand:SI 2 "" ""))]
2684   "!TARGET_POWERPC64 && reload_completed"
2685   [(const_int 0)]
2686   "
2687 {
2688   rtx dest  = operands[0];
2689   rtx src   = operands[1];
2690   rtx src1  = simplify_gen_subreg (SImode, src, DImode, 0);
2691   rtx src2  = simplify_gen_subreg (SImode, src, DImode, 4);
2692   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2693   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2694
2695   emit_insn (gen_bswapsi2 (dest1, src2));
2696   emit_insn (gen_bswapsi2 (dest2, src1));
2697   DONE;
2698 }")
2699
2700 (define_insn "mulsi3"
2701   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2702         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2703                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2704   ""
2705   "@
2706    mullw %0,%1,%2
2707    mulli %0,%1,%2"
2708    [(set_attr "type" "mul")
2709     (set (attr "size")
2710       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2711                 (const_string "8")
2712              (match_operand:SI 2 "short_cint_operand" "")
2713                 (const_string "16")]
2714         (const_string "32")))])
2715
2716 (define_insn "*mulsi3_internal1"
2717   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2718         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2719                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2720                     (const_int 0)))
2721    (clobber (match_scratch:SI 3 "=r,r"))]
2722   "TARGET_32BIT"
2723   "@
2724    mullw. %3,%1,%2
2725    #"
2726   [(set_attr "type" "mul")
2727    (set_attr "dot" "yes")
2728    (set_attr "length" "4,8")])
2729
2730 (define_split
2731   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2732         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2733                              (match_operand:SI 2 "gpc_reg_operand" ""))
2734                     (const_int 0)))
2735    (clobber (match_scratch:SI 3 ""))]
2736   "TARGET_32BIT && reload_completed"
2737   [(set (match_dup 3)
2738         (mult:SI (match_dup 1) (match_dup 2)))
2739    (set (match_dup 0)
2740         (compare:CC (match_dup 3)
2741                     (const_int 0)))]
2742   "")
2743
2744 (define_insn "*mulsi3_internal2"
2745   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2746         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2747                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2748                     (const_int 0)))
2749    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2750         (mult:SI (match_dup 1) (match_dup 2)))]
2751   "TARGET_32BIT"
2752   "@
2753    mullw. %0,%1,%2
2754    #"
2755   [(set_attr "type" "mul")
2756    (set_attr "dot" "yes")
2757    (set_attr "length" "4,8")])
2758
2759 (define_split
2760   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2761         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2762                              (match_operand:SI 2 "gpc_reg_operand" ""))
2763                     (const_int 0)))
2764    (set (match_operand:SI 0 "gpc_reg_operand" "")
2765         (mult:SI (match_dup 1) (match_dup 2)))]
2766   "TARGET_32BIT && reload_completed"
2767   [(set (match_dup 0)
2768         (mult:SI (match_dup 1) (match_dup 2)))
2769    (set (match_dup 3)
2770         (compare:CC (match_dup 0)
2771                     (const_int 0)))]
2772   "")
2773
2774
2775 (define_insn "udiv<mode>3"
2776   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2777         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2778                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2779   ""
2780   "div<wd>u %0,%1,%2"
2781   [(set_attr "type" "div")
2782    (set_attr "size" "<bits>")])
2783
2784
2785 ;; For powers of two we can do srai/aze for divide and then adjust for
2786 ;; modulus.  If it isn't a power of two, force operands into register and do
2787 ;; a normal divide.
2788 (define_expand "div<mode>3"
2789   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2790         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2791                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2792   ""
2793 {
2794   if (GET_CODE (operands[2]) != CONST_INT
2795       || INTVAL (operands[2]) <= 0
2796       || exact_log2 (INTVAL (operands[2])) < 0)
2797     operands[2] = force_reg (<MODE>mode, operands[2]);
2798 })
2799
2800 (define_insn "*div<mode>3"
2801   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2802         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2803                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2804   ""
2805   "div<wd> %0,%1,%2"
2806   [(set_attr "type" "div")
2807    (set_attr "size" "<bits>")])
2808
2809 (define_expand "mod<mode>3"
2810   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2811    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2812    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2813   ""
2814   "
2815 {
2816   int i;
2817   rtx temp1;
2818   rtx temp2;
2819
2820   if (GET_CODE (operands[2]) != CONST_INT
2821       || INTVAL (operands[2]) <= 0
2822       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2823     FAIL;
2824
2825   temp1 = gen_reg_rtx (<MODE>mode);
2826   temp2 = gen_reg_rtx (<MODE>mode);
2827
2828   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2829   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2830   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2831   DONE;
2832 }")
2833
2834 (define_insn ""
2835   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2836         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2837                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2838   ""
2839   "sra<wd>i %0,%1,%p2\;addze %0,%0"
2840   [(set_attr "type" "two")
2841    (set_attr "length" "8")])
2842
2843 (define_insn ""
2844   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2845         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2846                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2847                     (const_int 0)))
2848    (clobber (match_scratch:P 3 "=r,r"))]
2849   ""
2850   "@
2851    sra<wd>i %3,%1,%p2\;addze. %3,%3
2852    #"
2853   [(set_attr "type" "compare")
2854    (set_attr "length" "8,12")
2855    (set_attr "cell_micro" "not")])
2856
2857 (define_split
2858   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2859         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2860                              (match_operand:GPR 2 "exact_log2_cint_operand"
2861                               ""))
2862                     (const_int 0)))
2863    (clobber (match_scratch:GPR 3 ""))]
2864   "reload_completed"
2865   [(set (match_dup 3)
2866         (div:<MODE> (match_dup 1) (match_dup 2)))
2867    (set (match_dup 0)
2868         (compare:CC (match_dup 3)
2869                     (const_int 0)))]
2870   "")
2871
2872 (define_insn ""
2873   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2874         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2875                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2876                     (const_int 0)))
2877    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2878         (div:P (match_dup 1) (match_dup 2)))]
2879   ""
2880   "@
2881    sra<wd>i %0,%1,%p2\;addze. %0,%0
2882    #"
2883   [(set_attr "type" "compare")
2884    (set_attr "length" "8,12")
2885    (set_attr "cell_micro" "not")])
2886
2887 (define_split
2888   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2889         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2890                              (match_operand:GPR 2 "exact_log2_cint_operand"
2891                               ""))
2892                     (const_int 0)))
2893    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2894         (div:GPR (match_dup 1) (match_dup 2)))]
2895   "reload_completed"
2896   [(set (match_dup 0)
2897         (div:<MODE> (match_dup 1) (match_dup 2)))
2898    (set (match_dup 3)
2899         (compare:CC (match_dup 0)
2900                     (const_int 0)))]
2901   "")
2902 \f
2903 ;; Logical instructions
2904 ;; The logical instructions are mostly combined by using match_operator,
2905 ;; but the plain AND insns are somewhat different because there is no
2906 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2907 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2908
2909 (define_expand "andsi3"
2910   [(parallel
2911     [(set (match_operand:SI 0 "gpc_reg_operand" "")
2912           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2913                   (match_operand:SI 2 "and_operand" "")))
2914      (clobber (match_scratch:CC 3 ""))])]
2915   ""
2916   "")
2917
2918 (define_insn "andsi3_mc"
2919   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2920         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2921                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2922    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2923   "rs6000_gen_cell_microcode"
2924   "@
2925    and %0,%1,%2
2926    rlwinm %0,%1,0,%m2,%M2
2927    andi. %0,%1,%b2
2928    andis. %0,%1,%u2"
2929   [(set_attr "type" "*,shift,logical,logical")
2930    (set_attr "dot" "no,no,yes,yes")])
2931
2932 (define_insn "andsi3_nomc"
2933   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2934         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2935                 (match_operand:SI 2 "and_operand" "?r,T")))
2936    (clobber (match_scratch:CC 3 "=X,X"))]
2937   "!rs6000_gen_cell_microcode"
2938   "@
2939    and %0,%1,%2
2940    rlwinm %0,%1,0,%m2,%M2"
2941   [(set_attr "type" "logical,shift")])
2942
2943 (define_insn "andsi3_internal0_nomc"
2944   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2945         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2946                 (match_operand:SI 2 "and_operand" "?r,T")))]
2947   "!rs6000_gen_cell_microcode"
2948   "@
2949    and %0,%1,%2
2950    rlwinm %0,%1,0,%m2,%M2"
2951   [(set_attr "type" "logical,shift")])
2952
2953
2954 ;; Note to set cr's other than cr0 we do the and immediate and then
2955 ;; the test again -- this avoids a mfcr which on the higher end
2956 ;; machines causes an execution serialization
2957
2958 (define_insn "*andsi3_internal2_mc"
2959   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2960         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2961                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2962                     (const_int 0)))
2963    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2964    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2965   "TARGET_32BIT && rs6000_gen_cell_microcode"
2966   "@
2967    and. %3,%1,%2
2968    andi. %3,%1,%b2
2969    andis. %3,%1,%u2
2970    rlwinm. %3,%1,0,%m2,%M2
2971    #
2972    #
2973    #
2974    #"
2975   [(set_attr "type" "logical,logical,logical,shift,\
2976                      compare,compare,compare,compare")
2977    (set_attr "dot" "yes")
2978    (set_attr "length" "4,4,4,4,8,8,8,8")])
2979
2980 (define_insn "*andsi3_internal3_mc"
2981   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2982         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2983                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2984                     (const_int 0)))
2985    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2986    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2987   "TARGET_64BIT && rs6000_gen_cell_microcode"
2988   "@
2989    #
2990    andi. %3,%1,%b2
2991    andis. %3,%1,%u2
2992    rlwinm. %3,%1,0,%m2,%M2
2993    #
2994    #
2995    #
2996    #"
2997   [(set_attr "type" "compare,logical,logical,shift,compare,\
2998                      compare,compare,compare")
2999    (set_attr "dot" "yes")
3000    (set_attr "length" "8,4,4,4,8,8,8,8")])
3001
3002 (define_split
3003   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3004         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
3005                              (match_operand:GPR 2 "and_operand" ""))
3006                     (const_int 0)))
3007    (clobber (match_scratch:GPR 3 ""))
3008    (clobber (match_scratch:CC 4 ""))]
3009   "reload_completed"
3010   [(parallel [(set (match_dup 3)
3011                    (and:<MODE> (match_dup 1)
3012                                (match_dup 2)))
3013               (clobber (match_dup 4))])
3014    (set (match_dup 0)
3015         (compare:CC (match_dup 3)
3016                     (const_int 0)))]
3017   "")
3018
3019 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
3020 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
3021
3022 (define_split
3023   [(set (match_operand:CC 0 "cc_reg_operand" "")
3024         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3025                             (match_operand:SI 2 "gpc_reg_operand" ""))
3026                     (const_int 0)))
3027    (clobber (match_scratch:SI 3 ""))
3028    (clobber (match_scratch:CC 4 ""))]
3029   "TARGET_POWERPC64 && reload_completed"
3030   [(parallel [(set (match_dup 3)
3031                    (and:SI (match_dup 1)
3032                            (match_dup 2)))
3033               (clobber (match_dup 4))])
3034    (set (match_dup 0)
3035         (compare:CC (match_dup 3)
3036                     (const_int 0)))]
3037   "")
3038
3039 (define_insn "*andsi3_internal4"
3040   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3041         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3042                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3043                     (const_int 0)))
3044    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3045         (and:SI (match_dup 1)
3046                 (match_dup 2)))
3047    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3048   "TARGET_32BIT && rs6000_gen_cell_microcode"
3049   "@
3050    and. %0,%1,%2
3051    andi. %0,%1,%b2
3052    andis. %0,%1,%u2
3053    rlwinm. %0,%1,0,%m2,%M2
3054    #
3055    #
3056    #
3057    #"
3058   [(set_attr "type" "logical,logical,logical,shift,\
3059                      compare,compare,compare,compare")
3060    (set_attr "dot" "yes")
3061    (set_attr "length" "4,4,4,4,8,8,8,8")])
3062
3063 (define_insn "*andsi3_internal5_mc"
3064   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3065         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3066                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3067                     (const_int 0)))
3068    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3069         (and:SI (match_dup 1)
3070                 (match_dup 2)))
3071    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3072   "TARGET_64BIT && rs6000_gen_cell_microcode"
3073   "@
3074    #
3075    andi. %0,%1,%b2
3076    andis. %0,%1,%u2
3077    rlwinm. %0,%1,0,%m2,%M2
3078    #
3079    #
3080    #
3081    #"
3082   [(set_attr "type" "compare,logical,logical,shift,compare,\
3083                      compare,compare,compare")
3084    (set_attr "dot" "yes")
3085    (set_attr "length" "8,4,4,4,8,8,8,8")])
3086
3087 (define_split
3088   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3089         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3090                             (match_operand:SI 2 "and_operand" ""))
3091                     (const_int 0)))
3092    (set (match_operand:SI 0 "gpc_reg_operand" "")
3093         (and:SI (match_dup 1)
3094                 (match_dup 2)))
3095    (clobber (match_scratch:CC 4 ""))]
3096   "reload_completed"
3097   [(parallel [(set (match_dup 0)
3098                    (and:SI (match_dup 1)
3099                            (match_dup 2)))
3100               (clobber (match_dup 4))])
3101    (set (match_dup 3)
3102         (compare:CC (match_dup 0)
3103                     (const_int 0)))]
3104   "")
3105
3106 (define_split
3107   [(set (match_operand:CC 3 "cc_reg_operand" "")
3108         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3109                             (match_operand:SI 2 "gpc_reg_operand" ""))
3110                     (const_int 0)))
3111    (set (match_operand:SI 0 "gpc_reg_operand" "")
3112         (and:SI (match_dup 1)
3113                 (match_dup 2)))
3114    (clobber (match_scratch:CC 4 ""))]
3115   "TARGET_POWERPC64 && reload_completed"
3116   [(parallel [(set (match_dup 0)
3117                    (and:SI (match_dup 1)
3118                            (match_dup 2)))
3119               (clobber (match_dup 4))])
3120    (set (match_dup 3)
3121         (compare:CC (match_dup 0)
3122                     (const_int 0)))]
3123   "")
3124
3125 ;; Handle the PowerPC64 rlwinm corner case
3126
3127 (define_insn_and_split "*andsi3_internal6"
3128   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3129         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3130                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3131   "TARGET_POWERPC64"
3132   "#"
3133   "TARGET_POWERPC64"
3134   [(set (match_dup 0)
3135         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3136                 (match_dup 4)))
3137    (set (match_dup 0)
3138         (rotate:SI (match_dup 0) (match_dup 5)))]
3139   "
3140 {
3141   int mb = extract_MB (operands[2]);
3142   int me = extract_ME (operands[2]);
3143   operands[3] = GEN_INT (me + 1);
3144   operands[5] = GEN_INT (32 - (me + 1));
3145   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3146 }"
3147   [(set_attr "length" "8")])
3148
3149 (define_expand "iorsi3"
3150   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3151         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3152                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3153   ""
3154   "
3155 {
3156   if (GET_CODE (operands[2]) == CONST_INT
3157       && ! logical_operand (operands[2], SImode))
3158     {
3159       HOST_WIDE_INT value = INTVAL (operands[2]);
3160       rtx tmp = ((!can_create_pseudo_p ()
3161                   || rtx_equal_p (operands[0], operands[1]))
3162                  ? operands[0] : gen_reg_rtx (SImode));
3163
3164       emit_insn (gen_iorsi3 (tmp, operands[1],
3165                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3166       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3167       DONE;
3168     }
3169 }")
3170
3171 (define_expand "xorsi3"
3172   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3173         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3174                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3175   ""
3176   "
3177 {
3178   if (GET_CODE (operands[2]) == CONST_INT
3179       && ! logical_operand (operands[2], SImode))
3180     {
3181       HOST_WIDE_INT value = INTVAL (operands[2]);
3182       rtx tmp = ((!can_create_pseudo_p ()
3183                   || rtx_equal_p (operands[0], operands[1]))
3184                  ? operands[0] : gen_reg_rtx (SImode));
3185
3186       emit_insn (gen_xorsi3 (tmp, operands[1],
3187                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3188       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3189       DONE;
3190     }
3191 }")
3192
3193 (define_insn "*boolsi3_internal1"
3194   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3195         (match_operator:SI 3 "boolean_or_operator"
3196          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3197           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3198   ""
3199   "@
3200    %q3 %0,%1,%2
3201    %q3i %0,%1,%b2
3202    %q3is %0,%1,%u2")
3203
3204 (define_insn "*boolsi3_internal2"
3205   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3206         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3207          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3208           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3209          (const_int 0)))
3210    (clobber (match_scratch:SI 3 "=r,r"))]
3211   "TARGET_32BIT"
3212   "@
3213    %q4. %3,%1,%2
3214    #"
3215   [(set_attr "type" "logical,compare")
3216    (set_attr "dot" "yes")
3217    (set_attr "length" "4,8")])
3218
3219 (define_split
3220   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3221         (compare:CC (match_operator:SI 4 "boolean_operator"
3222          [(match_operand:SI 1 "gpc_reg_operand" "")
3223           (match_operand:SI 2 "gpc_reg_operand" "")])
3224          (const_int 0)))
3225    (clobber (match_scratch:SI 3 ""))]
3226   "TARGET_32BIT && reload_completed"
3227   [(set (match_dup 3) (match_dup 4))
3228    (set (match_dup 0)
3229         (compare:CC (match_dup 3)
3230                     (const_int 0)))]
3231   "")
3232
3233 (define_insn "*boolsi3_internal3"
3234   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3235         (compare:CC (match_operator:SI 4 "boolean_operator"
3236          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3237           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3238          (const_int 0)))
3239    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3240         (match_dup 4))]
3241   "TARGET_32BIT"
3242   "@
3243    %q4. %0,%1,%2
3244    #"
3245   [(set_attr "type" "logical,compare")
3246    (set_attr "dot" "yes")
3247    (set_attr "length" "4,8")])
3248
3249 (define_split
3250   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3251         (compare:CC (match_operator:SI 4 "boolean_operator"
3252          [(match_operand:SI 1 "gpc_reg_operand" "")
3253           (match_operand:SI 2 "gpc_reg_operand" "")])
3254          (const_int 0)))
3255    (set (match_operand:SI 0 "gpc_reg_operand" "")
3256         (match_dup 4))]
3257   "TARGET_32BIT && reload_completed"
3258   [(set (match_dup 0) (match_dup 4))
3259    (set (match_dup 3)
3260         (compare:CC (match_dup 0)
3261                     (const_int 0)))]
3262   "")
3263
3264 ;; Split a logical operation that we can't do in one insn into two insns,
3265 ;; each of which does one 16-bit part.  This is used by combine.
3266
3267 (define_split
3268   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3269         (match_operator:SI 3 "boolean_or_operator"
3270          [(match_operand:SI 1 "gpc_reg_operand" "")
3271           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3272   ""
3273   [(set (match_dup 0) (match_dup 4))
3274    (set (match_dup 0) (match_dup 5))]
3275 "
3276 {
3277   rtx i;
3278   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3279   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3280                                 operands[1], i);
3281   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3282   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3283                                 operands[0], i);
3284 }")
3285
3286 (define_insn "*boolcsi3_internal1"
3287   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3288         (match_operator:SI 3 "boolean_operator"
3289          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3290           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3291   ""
3292   "%q3 %0,%2,%1")
3293
3294 (define_insn "*boolcsi3_internal2"
3295   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3296         (compare:CC (match_operator:SI 4 "boolean_operator"
3297          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3298           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3299          (const_int 0)))
3300    (clobber (match_scratch:SI 3 "=r,r"))]
3301   "TARGET_32BIT"
3302   "@
3303    %q4. %3,%2,%1
3304    #"
3305   [(set_attr "type" "compare")
3306    (set_attr "length" "4,8")])
3307
3308 (define_split
3309   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3310         (compare:CC (match_operator:SI 4 "boolean_operator"
3311          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3312           (match_operand:SI 2 "gpc_reg_operand" "")])
3313          (const_int 0)))
3314    (clobber (match_scratch:SI 3 ""))]
3315   "TARGET_32BIT && reload_completed"
3316   [(set (match_dup 3) (match_dup 4))
3317    (set (match_dup 0)
3318         (compare:CC (match_dup 3)
3319                     (const_int 0)))]
3320   "")
3321
3322 (define_insn "*boolcsi3_internal3"
3323   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3324         (compare:CC (match_operator:SI 4 "boolean_operator"
3325          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3326           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3327          (const_int 0)))
3328    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3329         (match_dup 4))]
3330   "TARGET_32BIT"
3331   "@
3332    %q4. %0,%2,%1
3333    #"
3334   [(set_attr "type" "compare")
3335    (set_attr "length" "4,8")])
3336
3337 (define_split
3338   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3339         (compare:CC (match_operator:SI 4 "boolean_operator"
3340          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3341           (match_operand:SI 2 "gpc_reg_operand" "")])
3342          (const_int 0)))
3343    (set (match_operand:SI 0 "gpc_reg_operand" "")
3344         (match_dup 4))]
3345   "TARGET_32BIT && reload_completed"
3346   [(set (match_dup 0) (match_dup 4))
3347    (set (match_dup 3)
3348         (compare:CC (match_dup 0)
3349                     (const_int 0)))]
3350   "")
3351
3352 (define_insn "*boolccsi3_internal1"
3353   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3354         (match_operator:SI 3 "boolean_operator"
3355          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3356           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3357   ""
3358   "%q3 %0,%1,%2")
3359
3360 (define_insn "*boolccsi3_internal2"
3361   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3362         (compare:CC (match_operator:SI 4 "boolean_operator"
3363          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3364           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3365          (const_int 0)))
3366    (clobber (match_scratch:SI 3 "=r,r"))]
3367   "TARGET_32BIT"
3368   "@
3369    %q4. %3,%1,%2
3370    #"
3371   [(set_attr "type" "logical,compare")
3372    (set_attr "dot" "yes")
3373    (set_attr "length" "4,8")])
3374
3375 (define_split
3376   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3377         (compare:CC (match_operator:SI 4 "boolean_operator"
3378          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3379           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3380          (const_int 0)))
3381    (clobber (match_scratch:SI 3 ""))]
3382   "TARGET_32BIT && reload_completed"
3383   [(set (match_dup 3) (match_dup 4))
3384    (set (match_dup 0)
3385         (compare:CC (match_dup 3)
3386                     (const_int 0)))]
3387   "")
3388
3389 (define_insn "*boolccsi3_internal3"
3390   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3391         (compare:CC (match_operator:SI 4 "boolean_operator"
3392          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3393           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3394          (const_int 0)))
3395    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3396         (match_dup 4))]
3397   "TARGET_32BIT"
3398   "@
3399    %q4. %0,%1,%2
3400    #"
3401   [(set_attr "type" "logical,compare")
3402    (set_attr "dot" "yes")
3403    (set_attr "length" "4,8")])
3404
3405 (define_split
3406   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3407         (compare:CC (match_operator:SI 4 "boolean_operator"
3408          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3409           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3410          (const_int 0)))
3411    (set (match_operand:SI 0 "gpc_reg_operand" "")
3412         (match_dup 4))]
3413   "TARGET_32BIT && reload_completed"
3414   [(set (match_dup 0) (match_dup 4))
3415    (set (match_dup 3)
3416         (compare:CC (match_dup 0)
3417                     (const_int 0)))]
3418   "")
3419 \f
3420 ;; Rotate and shift insns, in all their variants.  These support shifts,
3421 ;; field inserts and extracts, and various combinations thereof.
3422 (define_expand "insv"
3423   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3424                        (match_operand:SI 1 "const_int_operand" "")
3425                        (match_operand:SI 2 "const_int_operand" ""))
3426         (match_operand 3 "gpc_reg_operand" ""))]
3427   ""
3428   "
3429 {
3430   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3431      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3432      compiler if the address of the structure is taken later.  Likewise, do
3433      not handle invalid E500 subregs.  */
3434   if (GET_CODE (operands[0]) == SUBREG
3435       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3436           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3437               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3438     FAIL;
3439
3440   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3441     emit_insn (gen_insvdi_internal (operands[0], operands[1], operands[2],
3442                                     operands[3]));
3443   else
3444     emit_insn (gen_insvsi_internal (operands[0], operands[1], operands[2],
3445                                     operands[3]));
3446   DONE;
3447 }")
3448
3449 (define_insn "insvsi_internal"
3450   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3451                          (match_operand:SI 1 "const_int_operand" "i")
3452                          (match_operand:SI 2 "const_int_operand" "i"))
3453         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3454   ""
3455   "*
3456 {
3457   int start = INTVAL (operands[2]) & 31;
3458   int size = INTVAL (operands[1]) & 31;
3459
3460   operands[4] = GEN_INT (32 - start - size);
3461   operands[1] = GEN_INT (start + size - 1);
3462   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3463 }"
3464   [(set_attr "type" "insert")])
3465
3466 (define_insn "*insvsi_internal1"
3467   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3468                          (match_operand:SI 1 "const_int_operand" "i")
3469                          (match_operand:SI 2 "const_int_operand" "i"))
3470         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3471                    (match_operand:SI 4 "const_int_operand" "i")))]
3472   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3473   "*
3474 {
3475   int shift = INTVAL (operands[4]) & 31;
3476   int start = INTVAL (operands[2]) & 31;
3477   int size = INTVAL (operands[1]) & 31;
3478
3479   operands[4] = GEN_INT (shift - start - size);
3480   operands[1] = GEN_INT (start + size - 1);
3481   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3482 }"
3483   [(set_attr "type" "insert")])
3484
3485 (define_insn "*insvsi_internal2"
3486   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3487                          (match_operand:SI 1 "const_int_operand" "i")
3488                          (match_operand:SI 2 "const_int_operand" "i"))
3489         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3490                      (match_operand:SI 4 "const_int_operand" "i")))]
3491   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3492   "*
3493 {
3494   int shift = INTVAL (operands[4]) & 31;
3495   int start = INTVAL (operands[2]) & 31;
3496   int size = INTVAL (operands[1]) & 31;
3497
3498   operands[4] = GEN_INT (32 - shift - start - size);
3499   operands[1] = GEN_INT (start + size - 1);
3500   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3501 }"
3502   [(set_attr "type" "insert")])
3503
3504 (define_insn "*insvsi_internal3"
3505   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3506                          (match_operand:SI 1 "const_int_operand" "i")
3507                          (match_operand:SI 2 "const_int_operand" "i"))
3508         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3509                      (match_operand:SI 4 "const_int_operand" "i")))]
3510   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3511   "*
3512 {
3513   int shift = INTVAL (operands[4]) & 31;
3514   int start = INTVAL (operands[2]) & 31;
3515   int size = INTVAL (operands[1]) & 31;
3516
3517   operands[4] = GEN_INT (32 - shift - start - size);
3518   operands[1] = GEN_INT (start + size - 1);
3519   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3520 }"
3521   [(set_attr "type" "insert")])
3522
3523 (define_insn "*insvsi_internal4"
3524   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3525                          (match_operand:SI 1 "const_int_operand" "i")
3526                          (match_operand:SI 2 "const_int_operand" "i"))
3527         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3528                          (match_operand:SI 4 "const_int_operand" "i")
3529                          (match_operand:SI 5 "const_int_operand" "i")))]
3530   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3531   "*
3532 {
3533   int extract_start = INTVAL (operands[5]) & 31;
3534   int extract_size = INTVAL (operands[4]) & 31;
3535   int insert_start = INTVAL (operands[2]) & 31;
3536   int insert_size = INTVAL (operands[1]) & 31;
3537
3538 /* Align extract field with insert field */
3539   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3540   operands[1] = GEN_INT (insert_start + insert_size - 1);
3541   return \"rlwimi %0,%3,%h5,%h2,%h1\";
3542 }"
3543   [(set_attr "type" "insert")])
3544
3545 ;; combine patterns for rlwimi
3546 (define_insn "*insvsi_internal5"
3547   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3548         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3549                         (match_operand:SI 1 "mask_operand" "i"))
3550                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3551                                      (match_operand:SI 2 "const_int_operand" "i"))
3552                         (match_operand:SI 5 "mask_operand" "i"))))]
3553   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3554   "*
3555 {
3556  int me = extract_ME(operands[5]);
3557  int mb = extract_MB(operands[5]);
3558  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3559  operands[2] = GEN_INT(mb);
3560  operands[1] = GEN_INT(me);
3561  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3562 }"
3563   [(set_attr "type" "insert")])
3564
3565 (define_insn "*insvsi_internal6"
3566   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3567         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3568                                      (match_operand:SI 2 "const_int_operand" "i"))
3569                         (match_operand:SI 5 "mask_operand" "i"))
3570                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3571                         (match_operand:SI 1 "mask_operand" "i"))))]
3572   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3573   "*
3574 {
3575  int me = extract_ME(operands[5]);
3576  int mb = extract_MB(operands[5]);
3577  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3578  operands[2] = GEN_INT(mb);
3579  operands[1] = GEN_INT(me);
3580  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3581 }"
3582   [(set_attr "type" "insert")])
3583
3584 (define_insn "insvdi_internal"
3585   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3586                          (match_operand:SI 1 "const_int_operand" "i")
3587                          (match_operand:SI 2 "const_int_operand" "i"))
3588         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3589   "TARGET_POWERPC64"
3590   "*
3591 {
3592   int start = INTVAL (operands[2]) & 63;
3593   int size = INTVAL (operands[1]) & 63;
3594
3595   operands[1] = GEN_INT (64 - start - size);
3596   return \"rldimi %0,%3,%H1,%H2\";
3597 }"
3598   [(set_attr "type" "insert")
3599    (set_attr "size" "64")])
3600
3601 (define_insn "*insvdi_internal2"
3602   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3603                          (match_operand:SI 1 "const_int_operand" "i")
3604                          (match_operand:SI 2 "const_int_operand" "i"))
3605         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3606                      (match_operand:SI 4 "const_int_operand" "i")))]
3607   "TARGET_POWERPC64
3608    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3609   "*
3610 {
3611   int shift = INTVAL (operands[4]) & 63;
3612   int start = (INTVAL (operands[2]) & 63) - 32;
3613   int size = INTVAL (operands[1]) & 63;
3614
3615   operands[4] = GEN_INT (64 - shift - start - size);
3616   operands[2] = GEN_INT (start);
3617   operands[1] = GEN_INT (start + size - 1);
3618   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3619 }")
3620
3621 (define_insn "*insvdi_internal3"
3622   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3623                          (match_operand:SI 1 "const_int_operand" "i")
3624                          (match_operand:SI 2 "const_int_operand" "i"))
3625         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3626                      (match_operand:SI 4 "const_int_operand" "i")))]
3627   "TARGET_POWERPC64
3628    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3629   "*
3630 {
3631   int shift = INTVAL (operands[4]) & 63;
3632   int start = (INTVAL (operands[2]) & 63) - 32;
3633   int size = INTVAL (operands[1]) & 63;
3634
3635   operands[4] = GEN_INT (64 - shift - start - size);
3636   operands[2] = GEN_INT (start);
3637   operands[1] = GEN_INT (start + size - 1);
3638   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3639 }")
3640
3641 (define_expand "extzv"
3642   [(set (match_operand 0 "gpc_reg_operand" "")
3643         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3644                        (match_operand:SI 2 "const_int_operand" "")
3645                        (match_operand:SI 3 "const_int_operand" "")))]
3646   ""
3647   "
3648 {
3649   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3650      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3651      compiler if the address of the structure is taken later.  */
3652   if (GET_CODE (operands[0]) == SUBREG
3653       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3654     FAIL;
3655
3656   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3657     emit_insn (gen_extzvdi_internal (operands[0], operands[1], operands[2],
3658                                      operands[3]));
3659   else
3660     emit_insn (gen_extzvsi_internal (operands[0], operands[1], operands[2],
3661                                      operands[3]));
3662   DONE;
3663 }")
3664
3665 (define_insn "extzvsi_internal"
3666   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3667         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3668                          (match_operand:SI 2 "const_int_operand" "i")
3669                          (match_operand:SI 3 "const_int_operand" "i")))]
3670   ""
3671   "*
3672 {
3673   int start = INTVAL (operands[3]) & 31;
3674   int size = INTVAL (operands[2]) & 31;
3675
3676   if (start + size >= 32)
3677     operands[3] = const0_rtx;
3678   else
3679     operands[3] = GEN_INT (start + size);
3680   return \"rlwinm %0,%1,%3,%s2,31\";
3681 }"
3682   [(set_attr "type" "shift")])
3683
3684 (define_insn "*extzvsi_internal1"
3685   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3686         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3687                          (match_operand:SI 2 "const_int_operand" "i,i")
3688                          (match_operand:SI 3 "const_int_operand" "i,i"))
3689                     (const_int 0)))
3690    (clobber (match_scratch:SI 4 "=r,r"))]
3691   ""
3692   "*
3693 {
3694   int start = INTVAL (operands[3]) & 31;
3695   int size = INTVAL (operands[2]) & 31;
3696
3697   /* Force split for non-cc0 compare.  */
3698   if (which_alternative == 1)
3699      return \"#\";
3700
3701   /* If the bit-field being tested fits in the upper or lower half of a
3702      word, it is possible to use andiu. or andil. to test it.  This is
3703      useful because the condition register set-use delay is smaller for
3704      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3705      position is 0 because the LT and GT bits may be set wrong.  */
3706
3707   if ((start > 0 && start + size <= 16) || start >= 16)
3708     {
3709       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3710                               - (1 << (16 - (start & 15) - size))));
3711       if (start < 16)
3712         return \"andis. %4,%1,%3\";
3713       else
3714         return \"andi. %4,%1,%3\";
3715     }
3716
3717   if (start + size >= 32)
3718     operands[3] = const0_rtx;
3719   else
3720     operands[3] = GEN_INT (start + size);
3721   return \"rlwinm. %4,%1,%3,%s2,31\";
3722 }"
3723   [(set_attr "type" "shift")
3724    (set_attr "dot" "yes")
3725    (set_attr "length" "4,8")])
3726
3727 (define_split
3728   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3729         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3730                          (match_operand:SI 2 "const_int_operand" "")
3731                          (match_operand:SI 3 "const_int_operand" ""))
3732                     (const_int 0)))
3733    (clobber (match_scratch:SI 4 ""))]
3734   "reload_completed"
3735   [(set (match_dup 4)
3736         (zero_extract:SI (match_dup 1) (match_dup 2)
3737                          (match_dup 3)))
3738    (set (match_dup 0)
3739         (compare:CC (match_dup 4)
3740                     (const_int 0)))]
3741   "")
3742
3743 (define_insn "*extzvsi_internal2"
3744   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3745         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3746                          (match_operand:SI 2 "const_int_operand" "i,i")
3747                          (match_operand:SI 3 "const_int_operand" "i,i"))
3748                     (const_int 0)))
3749    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3750         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3751   ""
3752   "*
3753 {
3754   int start = INTVAL (operands[3]) & 31;
3755   int size = INTVAL (operands[2]) & 31;
3756
3757   /* Force split for non-cc0 compare.  */
3758   if (which_alternative == 1)
3759      return \"#\";
3760
3761   /* Since we are using the output value, we can't ignore any need for
3762      a shift.  The bit-field must end at the LSB.  */
3763   if (start >= 16 && start + size == 32)
3764     {
3765       operands[3] = GEN_INT ((1 << size) - 1);
3766       return \"andi. %0,%1,%3\";
3767     }
3768
3769   if (start + size >= 32)
3770     operands[3] = const0_rtx;
3771   else
3772     operands[3] = GEN_INT (start + size);
3773   return \"rlwinm. %0,%1,%3,%s2,31\";
3774 }"
3775   [(set_attr "type" "shift")
3776    (set_attr "dot" "yes")
3777    (set_attr "length" "4,8")])
3778
3779 (define_split
3780   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3781         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3782                          (match_operand:SI 2 "const_int_operand" "")
3783                          (match_operand:SI 3 "const_int_operand" ""))
3784                     (const_int 0)))
3785    (set (match_operand:SI 0 "gpc_reg_operand" "")
3786         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3787   "reload_completed"
3788   [(set (match_dup 0)
3789         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3790    (set (match_dup 4)
3791         (compare:CC (match_dup 0)
3792                     (const_int 0)))]
3793   "")
3794
3795 (define_insn "extzvdi_internal"
3796   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3797         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3798                          (match_operand:SI 2 "const_int_operand" "i")
3799                          (match_operand:SI 3 "const_int_operand" "i")))]
3800   "TARGET_POWERPC64"
3801   "*
3802 {
3803   int start = INTVAL (operands[3]) & 63;
3804   int size = INTVAL (operands[2]) & 63;
3805
3806   if (start + size >= 64)
3807     operands[3] = const0_rtx;
3808   else
3809     operands[3] = GEN_INT (start + size);
3810   operands[2] = GEN_INT (64 - size);
3811   return \"rldicl %0,%1,%3,%2\";
3812 }"
3813   [(set_attr "type" "shift")])
3814
3815 (define_insn "*extzvdi_internal1"
3816   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3817         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3818                          (match_operand:SI 2 "const_int_operand" "i")
3819                          (match_operand:SI 3 "const_int_operand" "i"))
3820                     (const_int 0)))
3821    (clobber (match_scratch:DI 4 "=r"))]
3822   "TARGET_64BIT && rs6000_gen_cell_microcode"
3823   "*
3824 {
3825   int start = INTVAL (operands[3]) & 63;
3826   int size = INTVAL (operands[2]) & 63;
3827
3828   if (start + size >= 64)
3829     operands[3] = const0_rtx;
3830   else
3831     operands[3] = GEN_INT (start + size);
3832   operands[2] = GEN_INT (64 - size);
3833   return \"rldicl. %4,%1,%3,%2\";
3834 }"
3835   [(set_attr "type" "shift")
3836    (set_attr "dot" "yes")])
3837
3838 (define_insn "*extzvdi_internal2"
3839   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3840         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3841                          (match_operand:SI 2 "const_int_operand" "i")
3842                          (match_operand:SI 3 "const_int_operand" "i"))
3843                     (const_int 0)))
3844    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3845         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3846   "TARGET_64BIT && rs6000_gen_cell_microcode"
3847   "*
3848 {
3849   int start = INTVAL (operands[3]) & 63;
3850   int size = INTVAL (operands[2]) & 63;
3851
3852   if (start + size >= 64)
3853     operands[3] = const0_rtx;
3854   else
3855     operands[3] = GEN_INT (start + size);
3856   operands[2] = GEN_INT (64 - size);
3857   return \"rldicl. %0,%1,%3,%2\";
3858 }"
3859   [(set_attr "type" "shift")
3860    (set_attr "dot" "yes")])
3861
3862
3863 (define_insn "rotl<mode>3"
3864   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
3865         (rotate:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
3866                     (match_operand:GPR 2 "reg_or_cint_operand" "r,n")))]
3867   ""
3868   "@
3869    rotl<wd> %0,%1,%2
3870    rotl<wd>i %0,%1,%<hH>2"
3871   [(set_attr "type" "shift")
3872    (set_attr "var_shift" "yes,no")])
3873
3874 (define_insn "*rotlsi3_64"
3875   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3876         (zero_extend:DI
3877             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3878                        (match_operand:SI 2 "reg_or_cint_operand" "r,n"))))]
3879   "TARGET_POWERPC64"
3880   "@
3881    rotlw %0,%1,%2
3882    rotlwi %0,%1,%h2"
3883   [(set_attr "type" "shift")
3884    (set_attr "var_shift" "yes,no")])
3885
3886 (define_insn_and_split "*rotl<mode>3_dot"
3887   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3888         (compare:CC (rotate:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")
3889                                 (match_operand:GPR 2 "reg_or_cint_operand" "r,n,r,n"))
3890                     (const_int 0)))
3891    (clobber (match_scratch:GPR 0 "=r,r,r,r"))]
3892   "<MODE>mode == Pmode && rs6000_gen_cell_microcode"
3893   "@
3894    rotl<wd>. %0,%1,%2
3895    rotl<wd>i. %0,%1,%<hH>2
3896    #
3897    #"
3898   "&& reload_completed"
3899   [(set (match_dup 0)
3900         (rotate:GPR (match_dup 1)
3901                     (match_dup 2)))
3902    (set (match_dup 3)
3903         (compare:CC (match_dup 0)
3904                     (const_int 0)))]
3905   ""
3906   [(set_attr "type" "shift")
3907    (set_attr "var_shift" "yes,no,yes,no")
3908    (set_attr "dot" "yes")
3909    (set_attr "length" "4,4,8,8")])
3910
3911 (define_insn_and_split "*rotl<mode>3_dot2"
3912   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3913         (compare:CC (rotate:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")
3914                                 (match_operand:GPR 2 "reg_or_cint_operand" "r,n,r,n"))
3915                     (const_int 0)))
3916    (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,r,r")
3917         (rotate:GPR (match_dup 1)
3918                     (match_dup 2)))]
3919   "<MODE>mode == Pmode && rs6000_gen_cell_microcode"
3920   "@
3921    rotl<wd>. %0,%1,%2
3922    rotl<wd>i. %0,%1,%<hH>2
3923    #
3924    #"
3925   "&& reload_completed"
3926   [(set (match_dup 0)
3927         (rotate:GPR (match_dup 1)
3928                     (match_dup 2)))
3929    (set (match_dup 3)
3930         (compare:CC (match_dup 0)
3931                     (const_int 0)))]
3932   ""
3933   [(set_attr "type" "shift")
3934    (set_attr "var_shift" "yes,no,yes,no")
3935    (set_attr "dot" "yes")
3936    (set_attr "length" "4,4,8,8")])
3937
3938
3939 (define_insn "*rotlsi3_internal4"
3940   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3941         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3942                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
3943                 (match_operand:SI 3 "mask_operand" "n,n")))]
3944   ""
3945   "@
3946    rlwnm %0,%1,%2,%m3,%M3
3947    rlwinm %0,%1,%h2,%m3,%M3"
3948   [(set_attr "type" "shift")
3949    (set_attr "var_shift" "yes,no")])
3950
3951 (define_insn "*rotlsi3_internal5"
3952   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3953         (compare:CC (and:SI
3954                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3955                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3956                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3957                     (const_int 0)))
3958    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
3959   ""
3960   "@
3961    rlwnm. %4,%1,%2,%m3,%M3
3962    rlwinm. %4,%1,%h2,%m3,%M3
3963    #
3964    #"
3965   [(set_attr "type" "shift")
3966    (set_attr "var_shift" "yes,no,yes,no")
3967    (set_attr "dot" "yes")
3968    (set_attr "length" "4,4,8,8")])
3969
3970 (define_split
3971   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3972         (compare:CC (and:SI
3973                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3974                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3975                      (match_operand:SI 3 "mask_operand" ""))
3976                     (const_int 0)))
3977    (clobber (match_scratch:SI 4 ""))]
3978   "reload_completed"
3979   [(set (match_dup 4)
3980         (and:SI (rotate:SI (match_dup 1)
3981                                 (match_dup 2))
3982                      (match_dup 3)))
3983    (set (match_dup 0)
3984         (compare:CC (match_dup 4)
3985                     (const_int 0)))]
3986   "")
3987
3988 (define_insn "*rotlsi3_internal6"
3989   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
3990         (compare:CC (and:SI
3991                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3992                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3993                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3994                     (const_int 0)))
3995    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3996         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3997   ""
3998   "@
3999    rlwnm. %0,%1,%2,%m3,%M3
4000    rlwinm. %0,%1,%h2,%m3,%M3
4001    #
4002    #"
4003   [(set_attr "type" "shift")
4004    (set_attr "var_shift" "yes,no,yes,no")
4005    (set_attr "dot" "yes")
4006    (set_attr "length" "4,4,8,8")])
4007
4008 (define_split
4009   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4010         (compare:CC (and:SI
4011                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4012                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4013                      (match_operand:SI 3 "mask_operand" ""))
4014                     (const_int 0)))
4015    (set (match_operand:SI 0 "gpc_reg_operand" "")
4016         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4017   "reload_completed"
4018   [(set (match_dup 0)
4019         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4020    (set (match_dup 4)
4021         (compare:CC (match_dup 0)
4022                     (const_int 0)))]
4023   "")
4024
4025 (define_insn "*rotlsi3_internal7le"
4026   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4027         (zero_extend:SI
4028          (subreg:QI
4029           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4030                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4031   "!BYTES_BIG_ENDIAN"
4032   "rlw%I2nm %0,%1,%h2,0xff"
4033   [(set (attr "cell_micro")
4034      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4035         (const_string "not")
4036         (const_string "always")))
4037    (set_attr "type" "shift")])
4038
4039 (define_insn "*rotlsi3_internal7be"
4040   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4041         (zero_extend:SI
4042          (subreg:QI
4043           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4044                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 3)))]
4045   "BYTES_BIG_ENDIAN"
4046   "rlw%I2nm %0,%1,%h2,0xff"
4047   [(set (attr "cell_micro")
4048      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4049         (const_string "not")
4050         (const_string "always")))
4051    (set_attr "type" "shift")])
4052
4053 (define_insn "*rotlsi3_internal8le"
4054   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4055         (compare:CC (zero_extend:SI
4056                      (subreg:QI
4057                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4058                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4059                     (const_int 0)))
4060    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4061   "!BYTES_BIG_ENDIAN"
4062   "@
4063    rlwnm. %3,%1,%2,0xff
4064    rlwinm. %3,%1,%h2,0xff
4065    #
4066    #"
4067   [(set_attr "type" "shift")
4068    (set_attr "var_shift" "yes,no,yes,no")
4069    (set_attr "dot" "yes")
4070    (set_attr "length" "4,4,8,8")])
4071
4072 (define_insn "*rotlsi3_internal8be"
4073   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4074         (compare:CC (zero_extend:SI
4075                      (subreg:QI
4076                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4077                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 3))
4078                     (const_int 0)))
4079    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4080   "BYTES_BIG_ENDIAN"
4081   "@
4082    rlwnm. %3,%1,%2,0xff
4083    rlwinm. %3,%1,%h2,0xff
4084    #
4085    #"
4086   [(set_attr "type" "shift")
4087    (set_attr "var_shift" "yes,no,yes,no")
4088    (set_attr "dot" "yes")
4089    (set_attr "length" "4,4,8,8")])
4090
4091 (define_split
4092   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4093         (compare:CC (zero_extend:SI
4094                      (subreg:QI
4095                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4096                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4097                     (const_int 0)))
4098    (clobber (match_scratch:SI 3 ""))]
4099   "!BYTES_BIG_ENDIAN && reload_completed"
4100   [(set (match_dup 3)
4101         (zero_extend:SI (subreg:QI
4102                       (rotate:SI (match_dup 1)
4103                                  (match_dup 2)) 0)))
4104    (set (match_dup 0)
4105         (compare:CC (match_dup 3)
4106                     (const_int 0)))]
4107   "")
4108
4109 (define_split
4110   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4111         (compare:CC (zero_extend:SI
4112                      (subreg:QI
4113                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4114                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 3))
4115                     (const_int 0)))
4116    (clobber (match_scratch:SI 3 ""))]
4117   "BYTES_BIG_ENDIAN && reload_completed"
4118   [(set (match_dup 3)
4119         (zero_extend:SI (subreg:QI
4120                       (rotate:SI (match_dup 1)
4121                                  (match_dup 2)) 3)))
4122    (set (match_dup 0)
4123         (compare:CC (match_dup 3)
4124                     (const_int 0)))]
4125   "")
4126
4127 (define_insn "*rotlsi3_internal9le"
4128   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4129         (compare:CC (zero_extend:SI
4130                      (subreg:QI
4131                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4132                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4133                     (const_int 0)))
4134    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4135         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4136   "!BYTES_BIG_ENDIAN"
4137   "@
4138    rlwnm. %0,%1,%2,0xff
4139    rlwinm. %0,%1,%h2,0xff
4140    #
4141    #"
4142   [(set_attr "type" "shift")
4143    (set_attr "var_shift" "yes,no,yes,no")
4144    (set_attr "dot" "yes")
4145    (set_attr "length" "4,4,8,8")])
4146
4147 (define_insn "*rotlsi3_internal9be"
4148   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4149         (compare:CC (zero_extend:SI
4150                      (subreg:QI
4151                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4152                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 3))
4153                     (const_int 0)))
4154    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4155         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))]
4156   "BYTES_BIG_ENDIAN"
4157   "@
4158    rlwnm. %0,%1,%2,0xff
4159    rlwinm. %0,%1,%h2,0xff
4160    #
4161    #"
4162   [(set_attr "type" "shift")
4163    (set_attr "var_shift" "yes,no,yes,no")
4164    (set_attr "dot" "yes")
4165    (set_attr "length" "4,4,8,8")])
4166
4167 (define_split
4168   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4169         (compare:CC (zero_extend:SI
4170                      (subreg:QI
4171                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4172                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4173                     (const_int 0)))
4174    (set (match_operand:SI 0 "gpc_reg_operand" "")
4175         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4176   "!BYTES_BIG_ENDIAN && reload_completed"
4177   [(set (match_dup 0)
4178         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4179    (set (match_dup 3)
4180         (compare:CC (match_dup 0)
4181                     (const_int 0)))]
4182   "")
4183
4184 (define_split
4185   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4186         (compare:CC (zero_extend:SI
4187                      (subreg:QI
4188                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4189                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 3))
4190                     (const_int 0)))
4191    (set (match_operand:SI 0 "gpc_reg_operand" "")
4192         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))]
4193   "BYTES_BIG_ENDIAN && reload_completed"
4194   [(set (match_dup 0)
4195         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))
4196    (set (match_dup 3)
4197         (compare:CC (match_dup 0)
4198                     (const_int 0)))]
4199   "")
4200
4201 (define_insn "*rotlsi3_internal10le"
4202   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4203         (zero_extend:SI
4204          (subreg:HI
4205           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4206                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4207   "!BYTES_BIG_ENDIAN"
4208   "@
4209    rlwnm %0,%1,%2,0xffff
4210    rlwinm %0,%1,%h2,0xffff"
4211   [(set_attr "type" "shift")
4212    (set_attr "var_shift" "yes,no")])
4213
4214 (define_insn "*rotlsi3_internal10be"
4215   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4216         (zero_extend:SI
4217          (subreg:HI
4218           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4219                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 2)))]
4220   "BYTES_BIG_ENDIAN"
4221   "@
4222    rlwnm %0,%1,%2,0xffff
4223    rlwinm %0,%1,%h2,0xffff"
4224   [(set_attr "type" "shift")
4225    (set_attr "var_shift" "yes,no")])
4226
4227 (define_insn "*rotlsi3_internal11le"
4228   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4229         (compare:CC (zero_extend:SI
4230                      (subreg:HI
4231                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4232                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4233                     (const_int 0)))
4234    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4235   "!BYTES_BIG_ENDIAN"
4236   "@
4237    rlwnm. %3,%1,%2,0xffff
4238    rlwinm. %3,%1,%h2,0xffff
4239    #
4240    #"
4241   [(set_attr "type" "shift")
4242    (set_attr "var_shift" "yes,no,yes,no")
4243    (set_attr "dot" "yes")
4244    (set_attr "length" "4,4,8,8")])
4245
4246 (define_insn "*rotlsi3_internal11be"
4247   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4248         (compare:CC (zero_extend:SI
4249                      (subreg:HI
4250                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4251                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 2))
4252                     (const_int 0)))
4253    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4254   "BYTES_BIG_ENDIAN"
4255   "@
4256    rlwnm. %3,%1,%2,0xffff
4257    rlwinm. %3,%1,%h2,0xffff
4258    #
4259    #"
4260   [(set_attr "type" "shift")
4261    (set_attr "var_shift" "yes,no,yes,no")
4262    (set_attr "dot" "yes")
4263    (set_attr "length" "4,4,8,8")])
4264
4265 (define_split
4266   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4267         (compare:CC (zero_extend:SI
4268                      (subreg:HI
4269                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4270                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4271                     (const_int 0)))
4272    (clobber (match_scratch:SI 3 ""))]
4273   "!BYTES_BIG_ENDIAN && reload_completed"
4274   [(set (match_dup 3)
4275         (zero_extend:SI (subreg:HI
4276                       (rotate:SI (match_dup 1)
4277                                  (match_dup 2)) 0)))
4278    (set (match_dup 0)
4279         (compare:CC (match_dup 3)
4280                     (const_int 0)))]
4281   "")
4282
4283 (define_split
4284   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4285         (compare:CC (zero_extend:SI
4286                      (subreg:HI
4287                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4288                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 2))
4289                     (const_int 0)))
4290    (clobber (match_scratch:SI 3 ""))]
4291   "BYTES_BIG_ENDIAN && reload_completed"
4292   [(set (match_dup 3)
4293         (zero_extend:SI (subreg:HI
4294                       (rotate:SI (match_dup 1)
4295                                  (match_dup 2)) 2)))
4296    (set (match_dup 0)
4297         (compare:CC (match_dup 3)
4298                     (const_int 0)))]
4299   "")
4300
4301 (define_insn "*rotlsi3_internal12le"
4302   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4303         (compare:CC (zero_extend:SI
4304                      (subreg:HI
4305                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4306                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4307                     (const_int 0)))
4308    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4309         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4310   "!BYTES_BIG_ENDIAN"
4311   "@
4312    rlwnm. %0,%1,%2,0xffff
4313    rlwinm. %0,%1,%h2,0xffff
4314    #
4315    #"
4316   [(set_attr "type" "shift")
4317    (set_attr "var_shift" "yes,no,yes,no")
4318    (set_attr "dot" "yes")
4319    (set_attr "length" "4,4,8,8")])
4320
4321 (define_insn "*rotlsi3_internal12be"
4322   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4323         (compare:CC (zero_extend:SI
4324                      (subreg:HI
4325                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4326                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 2))
4327                     (const_int 0)))
4328    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4329         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))]
4330   "BYTES_BIG_ENDIAN"
4331   "@
4332    rlwnm. %0,%1,%2,0xffff
4333    rlwinm. %0,%1,%h2,0xffff
4334    #
4335    #"
4336   [(set_attr "type" "shift")
4337    (set_attr "var_shift" "yes,no,yes,no")
4338    (set_attr "dot" "yes")
4339    (set_attr "length" "4,4,8,8")])
4340
4341 (define_split
4342   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4343         (compare:CC (zero_extend:SI
4344                      (subreg:HI
4345                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4346                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4347                     (const_int 0)))
4348    (set (match_operand:SI 0 "gpc_reg_operand" "")
4349         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4350   "!BYTES_BIG_ENDIAN && reload_completed"
4351   [(set (match_dup 0)
4352         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4353    (set (match_dup 3)
4354         (compare:CC (match_dup 0)
4355                     (const_int 0)))]
4356   "")
4357
4358 (define_split
4359   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4360         (compare:CC (zero_extend:SI
4361                      (subreg:HI
4362                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4363                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 2))
4364                     (const_int 0)))
4365    (set (match_operand:SI 0 "gpc_reg_operand" "")
4366         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))]
4367   "BYTES_BIG_ENDIAN && reload_completed"
4368   [(set (match_dup 0)
4369         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))
4370    (set (match_dup 3)
4371         (compare:CC (match_dup 0)
4372                     (const_int 0)))]
4373   "")
4374
4375
4376 (define_insn "ashl<mode>3"
4377   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4378         (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4379                     (match_operand:GPR 2 "reg_or_cint_operand" "r,n")))]
4380   ""
4381   "@
4382    sl<wd> %0,%1,%2
4383    sl<wd>i %0,%1,%<hH>2"
4384   [(set_attr "type" "shift")
4385    (set_attr "var_shift" "yes,no")])
4386
4387 (define_insn "*ashlsi3_64"
4388   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4389         (zero_extend:DI
4390             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4391                        (match_operand:SI 2 "reg_or_cint_operand" "r,n"))))]
4392   "TARGET_POWERPC64"
4393   "@
4394    slw %0,%1,%2
4395    slwi %0,%1,%h2"
4396   [(set_attr "type" "shift")
4397    (set_attr "var_shift" "yes,no")])
4398
4399 (define_insn_and_split "*ashl<mode>3_dot"
4400   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4401         (compare:CC (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")
4402                                 (match_operand:GPR 2 "reg_or_cint_operand" "r,n,r,n"))
4403                     (const_int 0)))
4404    (clobber (match_scratch:GPR 0 "=r,r,r,r"))]
4405   "<MODE>mode == Pmode && rs6000_gen_cell_microcode"
4406   "@
4407    sl<wd>. %0,%1,%2
4408    sl<wd>i. %0,%1,%<hH>2
4409    #
4410    #"
4411   "&& reload_completed"
4412   [(set (match_dup 0)
4413         (ashift:GPR (match_dup 1)
4414                     (match_dup 2)))
4415    (set (match_dup 3)
4416         (compare:CC (match_dup 0)
4417                     (const_int 0)))]
4418   ""
4419   [(set_attr "type" "shift")
4420    (set_attr "var_shift" "yes,no,yes,no")
4421    (set_attr "dot" "yes")
4422    (set_attr "length" "4,4,8,8")])
4423
4424 (define_insn_and_split "*ashl<mode>3_dot2"
4425   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4426         (compare:CC (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")
4427                                 (match_operand:GPR 2 "reg_or_cint_operand" "r,n,r,n"))
4428                     (const_int 0)))
4429    (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,r,r")
4430         (ashift:GPR (match_dup 1)
4431                     (match_dup 2)))]
4432   "<MODE>mode == Pmode && rs6000_gen_cell_microcode"
4433   "@
4434    sl<wd>. %0,%1,%2
4435    sl<wd>i. %0,%1,%<hH>2
4436    #
4437    #"
4438   "&& reload_completed"
4439   [(set (match_dup 0)
4440         (ashift:GPR (match_dup 1)
4441                     (match_dup 2)))
4442    (set (match_dup 3)
4443         (compare:CC (match_dup 0)
4444                     (const_int 0)))]
4445   ""
4446   [(set_attr "type" "shift")
4447    (set_attr "var_shift" "yes,no,yes,no")
4448    (set_attr "dot" "yes")
4449    (set_attr "length" "4,4,8,8")])
4450
4451
4452 (define_insn "rlwinm"
4453   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4454         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4455                            (match_operand:SI 2 "const_int_operand" "i"))
4456                 (match_operand:SI 3 "mask_operand" "n")))]
4457   "includes_lshift_p (operands[2], operands[3])"
4458   "rlwinm %0,%1,%h2,%m3,%M3"
4459   [(set_attr "type" "shift")])
4460
4461 (define_insn ""
4462   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4463         (compare:CC
4464          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4465                             (match_operand:SI 2 "const_int_operand" "i,i"))
4466                  (match_operand:SI 3 "mask_operand" "n,n"))
4467          (const_int 0)))
4468    (clobber (match_scratch:SI 4 "=r,r"))]
4469   "includes_lshift_p (operands[2], operands[3])"
4470   "@
4471    rlwinm. %4,%1,%h2,%m3,%M3
4472    #"
4473   [(set_attr "type" "shift")
4474    (set_attr "dot" "yes")
4475    (set_attr "length" "4,8")])
4476
4477 (define_split
4478   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4479         (compare:CC
4480          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4481                             (match_operand:SI 2 "const_int_operand" ""))
4482                  (match_operand:SI 3 "mask_operand" ""))
4483          (const_int 0)))
4484    (clobber (match_scratch:SI 4 ""))]
4485   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4486   [(set (match_dup 4)
4487         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4488                  (match_dup 3)))
4489    (set (match_dup 0)
4490         (compare:CC (match_dup 4)
4491                     (const_int 0)))]
4492   "")
4493
4494 (define_insn ""
4495   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4496         (compare:CC
4497          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4498                             (match_operand:SI 2 "const_int_operand" "i,i"))
4499                  (match_operand:SI 3 "mask_operand" "n,n"))
4500          (const_int 0)))
4501    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4502         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4503   "includes_lshift_p (operands[2], operands[3])"
4504   "@
4505    rlwinm. %0,%1,%h2,%m3,%M3
4506    #"
4507   [(set_attr "type" "shift")
4508    (set_attr "dot" "yes")
4509    (set_attr "length" "4,8")])
4510
4511 (define_split
4512   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4513         (compare:CC
4514          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4515                             (match_operand:SI 2 "const_int_operand" ""))
4516                  (match_operand:SI 3 "mask_operand" ""))
4517          (const_int 0)))
4518    (set (match_operand:SI 0 "gpc_reg_operand" "")
4519         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4520   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4521   [(set (match_dup 0)
4522         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4523    (set (match_dup 4)
4524         (compare:CC (match_dup 0)
4525                     (const_int 0)))]
4526   "")
4527
4528
4529 (define_insn "lshr<mode>3"
4530   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4531         (lshiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4532                       (match_operand:GPR 2 "reg_or_cint_operand" "r,n")))]
4533   ""
4534   "@
4535    sr<wd> %0,%1,%2
4536    sr<wd>i %0,%1,%<hH>2"
4537   [(set_attr "type" "shift")
4538    (set_attr "var_shift" "yes,no")])
4539
4540 (define_insn "*lshrsi3_64"
4541   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4542         (zero_extend:DI
4543             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4544                          (match_operand:SI 2 "reg_or_cint_operand" "r,n"))))]
4545   "TARGET_POWERPC64"
4546   "@
4547    srw %0,%1,%2
4548    srwi %0,%1,%h2"
4549   [(set_attr "type" "shift")
4550    (set_attr "var_shift" "yes,no")])
4551
4552 (define_insn_and_split "*lshr<mode>3_dot"
4553   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4554         (compare:CC (lshiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")
4555                                   (match_operand:GPR 2 "reg_or_cint_operand" "r,n,r,n"))
4556                     (const_int 0)))
4557    (clobber (match_scratch:GPR 0 "=r,r,r,r"))]
4558   "<MODE>mode == Pmode && rs6000_gen_cell_microcode"
4559   "@
4560    sr<wd>. %0,%1,%2
4561    sr<wd>i. %0,%1,%<hH>2
4562    #
4563    #"
4564   "&& reload_completed"
4565   [(set (match_dup 0)
4566         (lshiftrt:GPR (match_dup 1)
4567                       (match_dup 2)))
4568    (set (match_dup 3)
4569         (compare:CC (match_dup 0)
4570                     (const_int 0)))]
4571   ""
4572   [(set_attr "type" "shift")
4573    (set_attr "var_shift" "yes,no,yes,no")
4574    (set_attr "dot" "yes")
4575    (set_attr "length" "4,4,8,8")])
4576
4577 (define_insn_and_split "*lshr<mode>3_dot2"
4578   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4579         (compare:CC (lshiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")
4580                                   (match_operand:GPR 2 "reg_or_cint_operand" "r,n,r,n"))
4581                     (const_int 0)))
4582    (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,r,r")
4583         (lshiftrt:GPR (match_dup 1)
4584                       (match_dup 2)))]
4585   "<MODE>mode == Pmode && rs6000_gen_cell_microcode"
4586   "@
4587    sr<wd>. %0,%1,%2
4588    sr<wd>i. %0,%1,%<hH>2
4589    #
4590    #"
4591   "&& reload_completed"
4592   [(set (match_dup 0)
4593         (lshiftrt:GPR (match_dup 1)
4594                       (match_dup 2)))
4595    (set (match_dup 3)
4596         (compare:CC (match_dup 0)
4597                     (const_int 0)))]
4598   ""
4599   [(set_attr "type" "shift")
4600    (set_attr "var_shift" "yes,no,yes,no")
4601    (set_attr "dot" "yes")
4602    (set_attr "length" "4,4,8,8")])
4603
4604
4605 (define_insn ""
4606   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4607         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4608                              (match_operand:SI 2 "const_int_operand" "i"))
4609                 (match_operand:SI 3 "mask_operand" "n")))]
4610   "includes_rshift_p (operands[2], operands[3])"
4611   "rlwinm %0,%1,%s2,%m3,%M3"
4612   [(set_attr "type" "shift")])
4613
4614 (define_insn ""
4615   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4616         (compare:CC
4617          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4618                               (match_operand:SI 2 "const_int_operand" "i,i"))
4619                  (match_operand:SI 3 "mask_operand" "n,n"))
4620          (const_int 0)))
4621    (clobber (match_scratch:SI 4 "=r,r"))]
4622   "includes_rshift_p (operands[2], operands[3])"
4623   "@
4624    rlwinm. %4,%1,%s2,%m3,%M3
4625    #"
4626   [(set_attr "type" "shift")
4627    (set_attr "dot" "yes")
4628    (set_attr "length" "4,8")])
4629
4630 (define_split
4631   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4632         (compare:CC
4633          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4634                               (match_operand:SI 2 "const_int_operand" ""))
4635                  (match_operand:SI 3 "mask_operand" ""))
4636          (const_int 0)))
4637    (clobber (match_scratch:SI 4 ""))]
4638   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4639   [(set (match_dup 4)
4640         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4641                  (match_dup 3)))
4642    (set (match_dup 0)
4643         (compare:CC (match_dup 4)
4644                     (const_int 0)))]
4645   "")
4646
4647 (define_insn ""
4648   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4649         (compare:CC
4650          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4651                               (match_operand:SI 2 "const_int_operand" "i,i"))
4652                  (match_operand:SI 3 "mask_operand" "n,n"))
4653          (const_int 0)))
4654    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4655         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4656   "includes_rshift_p (operands[2], operands[3])"
4657   "@
4658    rlwinm. %0,%1,%s2,%m3,%M3
4659    #"
4660   [(set_attr "type" "shift")
4661    (set_attr "dot" "yes")
4662    (set_attr "length" "4,8")])
4663
4664 (define_split
4665   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4666         (compare:CC
4667          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4668                               (match_operand:SI 2 "const_int_operand" ""))
4669                  (match_operand:SI 3 "mask_operand" ""))
4670          (const_int 0)))
4671    (set (match_operand:SI 0 "gpc_reg_operand" "")
4672         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4673   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4674   [(set (match_dup 0)
4675         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4676    (set (match_dup 4)
4677         (compare:CC (match_dup 0)
4678                     (const_int 0)))]
4679   "")
4680
4681 (define_insn "*lshiftrt_internal1le"
4682   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4683         (zero_extend:SI
4684          (subreg:QI
4685           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4686                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4687   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4688   "rlwinm %0,%1,%s2,0xff"
4689   [(set_attr "type" "shift")])
4690
4691 (define_insn "*lshiftrt_internal1be"
4692   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4693         (zero_extend:SI
4694          (subreg:QI
4695           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4696                        (match_operand:SI 2 "const_int_operand" "i")) 3)))]
4697   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4698   "rlwinm %0,%1,%s2,0xff"
4699   [(set_attr "type" "shift")])
4700
4701 (define_insn "*lshiftrt_internal2le"
4702   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4703         (compare:CC
4704          (zero_extend:SI
4705           (subreg:QI
4706            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4707                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4708          (const_int 0)))
4709    (clobber (match_scratch:SI 3 "=r,r"))]
4710   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4711   "@
4712    rlwinm. %3,%1,%s2,0xff
4713    #"
4714   [(set_attr "type" "shift")
4715    (set_attr "dot" "yes")
4716    (set_attr "length" "4,8")])
4717
4718 (define_insn "*lshiftrt_internal2be"
4719   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4720         (compare:CC
4721          (zero_extend:SI
4722           (subreg:QI
4723            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4724                         (match_operand:SI 2 "const_int_operand" "i,i")) 3))
4725          (const_int 0)))
4726    (clobber (match_scratch:SI 3 "=r,r"))]
4727   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4728   "@
4729    rlwinm. %3,%1,%s2,0xff
4730    #"
4731   [(set_attr "type" "shift")
4732    (set_attr "dot" "yes")
4733    (set_attr "length" "4,8")])
4734
4735 (define_split
4736   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4737         (compare:CC
4738          (zero_extend:SI
4739           (subreg:QI
4740            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4741                         (match_operand:SI 2 "const_int_operand" "")) 0))
4742          (const_int 0)))
4743    (clobber (match_scratch:SI 3 ""))]
4744   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4745   [(set (match_dup 3)
4746         (zero_extend:SI (subreg:QI
4747            (lshiftrt:SI (match_dup 1)
4748                         (match_dup 2)) 0)))
4749    (set (match_dup 0)
4750         (compare:CC (match_dup 3)
4751                     (const_int 0)))]
4752   "")
4753
4754 (define_split
4755   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4756         (compare:CC
4757          (zero_extend:SI
4758           (subreg:QI
4759            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4760                         (match_operand:SI 2 "const_int_operand" "")) 3))
4761          (const_int 0)))
4762    (clobber (match_scratch:SI 3 ""))]
4763   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4764   [(set (match_dup 3)
4765         (zero_extend:SI (subreg:QI
4766            (lshiftrt:SI (match_dup 1)
4767                         (match_dup 2)) 3)))
4768    (set (match_dup 0)
4769         (compare:CC (match_dup 3)
4770                     (const_int 0)))]
4771   "")
4772
4773 (define_insn "*lshiftrt_internal3le"
4774   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4775         (compare:CC
4776          (zero_extend:SI
4777           (subreg:QI
4778            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4779                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4780          (const_int 0)))
4781    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4782         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4783   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4784   "@
4785    rlwinm. %0,%1,%s2,0xff
4786    #"
4787   [(set_attr "type" "shift")
4788    (set_attr "dot" "yes")
4789    (set_attr "length" "4,8")])
4790
4791 (define_insn "*lshiftrt_internal3be"
4792   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4793         (compare:CC
4794          (zero_extend:SI
4795           (subreg:QI
4796            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4797                         (match_operand:SI 2 "const_int_operand" "i,i")) 3))
4798          (const_int 0)))
4799    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4800         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))]
4801   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4802   "@
4803    rlwinm. %0,%1,%s2,0xff
4804    #"
4805   [(set_attr "type" "shift")
4806    (set_attr "dot" "yes")
4807    (set_attr "length" "4,8")])
4808
4809 (define_split
4810   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4811         (compare:CC
4812          (zero_extend:SI
4813           (subreg:QI
4814            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4815                         (match_operand:SI 2 "const_int_operand" "")) 0))
4816          (const_int 0)))
4817    (set (match_operand:SI 0 "gpc_reg_operand" "")
4818         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4819   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4820   [(set (match_dup 0)
4821         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4822    (set (match_dup 3)
4823         (compare:CC (match_dup 0)
4824                     (const_int 0)))]
4825   "")
4826
4827 (define_split
4828   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4829         (compare:CC
4830          (zero_extend:SI
4831           (subreg:QI
4832            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4833                         (match_operand:SI 2 "const_int_operand" "")) 3))
4834          (const_int 0)))
4835    (set (match_operand:SI 0 "gpc_reg_operand" "")
4836         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))]
4837   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4838   [(set (match_dup 0)
4839         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))
4840    (set (match_dup 3)
4841         (compare:CC (match_dup 0)
4842                     (const_int 0)))]
4843   "")
4844
4845 (define_insn "*lshiftrt_internal4le"
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")) 0)))]
4851   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4852   "rlwinm %0,%1,%s2,0xffff"
4853   [(set_attr "type" "shift")])
4854
4855 (define_insn "*lshiftrt_internal4be"
4856   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4857         (zero_extend:SI
4858          (subreg:HI
4859           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4860                        (match_operand:SI 2 "const_int_operand" "i")) 2)))]
4861   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4862   "rlwinm %0,%1,%s2,0xffff"
4863   [(set_attr "type" "shift")])
4864
4865 (define_insn "*lshiftrt_internal5le"
4866   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4867         (compare:CC
4868          (zero_extend:SI
4869           (subreg:HI
4870            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4871                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4872          (const_int 0)))
4873    (clobber (match_scratch:SI 3 "=r,r"))]
4874   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4875   "@
4876    rlwinm. %3,%1,%s2,0xffff
4877    #"
4878   [(set_attr "type" "shift")
4879    (set_attr "dot" "yes")
4880    (set_attr "length" "4,8")])
4881
4882 (define_insn "*lshiftrt_internal5be"
4883   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4884         (compare:CC
4885          (zero_extend:SI
4886           (subreg:HI
4887            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4888                         (match_operand:SI 2 "const_int_operand" "i,i")) 2))
4889          (const_int 0)))
4890    (clobber (match_scratch:SI 3 "=r,r"))]
4891   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4892   "@
4893    rlwinm. %3,%1,%s2,0xffff
4894    #"
4895   [(set_attr "type" "shift")
4896    (set_attr "dot" "yes")
4897    (set_attr "length" "4,8")])
4898
4899 (define_split
4900   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4901         (compare:CC
4902          (zero_extend:SI
4903           (subreg:HI
4904            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4905                         (match_operand:SI 2 "const_int_operand" "")) 0))
4906          (const_int 0)))
4907    (clobber (match_scratch:SI 3 ""))]
4908   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4909   [(set (match_dup 3)
4910         (zero_extend:SI (subreg:HI
4911            (lshiftrt:SI (match_dup 1)
4912                         (match_dup 2)) 0)))
4913    (set (match_dup 0)
4914         (compare:CC (match_dup 3)
4915                     (const_int 0)))]
4916   "")
4917
4918 (define_split
4919   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4920         (compare:CC
4921          (zero_extend:SI
4922           (subreg:HI
4923            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4924                         (match_operand:SI 2 "const_int_operand" "")) 2))
4925          (const_int 0)))
4926    (clobber (match_scratch:SI 3 ""))]
4927   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4928   [(set (match_dup 3)
4929         (zero_extend:SI (subreg:HI
4930            (lshiftrt:SI (match_dup 1)
4931                         (match_dup 2)) 2)))
4932    (set (match_dup 0)
4933         (compare:CC (match_dup 3)
4934                     (const_int 0)))]
4935   "")
4936
4937 (define_insn "*lshiftrt_internal5le"
4938   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4939         (compare:CC
4940          (zero_extend:SI
4941           (subreg:HI
4942            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4943                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4944          (const_int 0)))
4945    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4946         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4947   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4948   "@
4949    rlwinm. %0,%1,%s2,0xffff
4950    #"
4951   [(set_attr "type" "shift")
4952    (set_attr "dot" "yes")
4953    (set_attr "length" "4,8")])
4954
4955 (define_insn "*lshiftrt_internal5be"
4956   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4957         (compare:CC
4958          (zero_extend:SI
4959           (subreg:HI
4960            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4961                         (match_operand:SI 2 "const_int_operand" "i,i")) 2))
4962          (const_int 0)))
4963    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4964         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))]
4965   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4966   "@
4967    rlwinm. %0,%1,%s2,0xffff
4968    #"
4969   [(set_attr "type" "shift")
4970    (set_attr "dot" "yes")
4971    (set_attr "length" "4,8")])
4972
4973 (define_split
4974   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4975         (compare:CC
4976          (zero_extend:SI
4977           (subreg:HI
4978            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4979                         (match_operand:SI 2 "const_int_operand" "")) 0))
4980          (const_int 0)))
4981    (set (match_operand:SI 0 "gpc_reg_operand" "")
4982         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4983   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4984   [(set (match_dup 0)
4985         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4986    (set (match_dup 3)
4987         (compare:CC (match_dup 0)
4988                     (const_int 0)))]
4989   "")
4990
4991 (define_split
4992   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4993         (compare:CC
4994          (zero_extend:SI
4995           (subreg:HI
4996            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4997                         (match_operand:SI 2 "const_int_operand" "")) 2))
4998          (const_int 0)))
4999    (set (match_operand:SI 0 "gpc_reg_operand" "")
5000         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))]
5001   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5002   [(set (match_dup 0)
5003         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))
5004    (set (match_dup 3)
5005         (compare:CC (match_dup 0)
5006                     (const_int 0)))]
5007   "")
5008
5009
5010 (define_expand "ashr<mode>3"
5011   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
5012         (ashiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
5013                       (match_operand:GPR 2 "reg_or_cint_operand" "")))]
5014   ""
5015 {
5016   /* The generic code does not generate optimal code for the low word
5017      (it should be a rlwimi and a rot).  Until we have target code to
5018      solve this generically, keep this expander.  */
5019
5020   if (<MODE>mode == DImode && !TARGET_POWERPC64)
5021     {
5022       if (CONST_INT_P (operands[2]))
5023         {
5024           emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
5025           DONE;
5026         }
5027       else
5028         FAIL;
5029     }
5030 })
5031
5032 (define_insn "*ashr<mode>3"
5033   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5034         (ashiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
5035                       (match_operand:GPR 2 "reg_or_cint_operand" "r,n")))]
5036   ""
5037   "@
5038    sra<wd> %0,%1,%2
5039    sra<wd>i %0,%1,%<hH>2"
5040   [(set_attr "type" "shift")
5041    (set_attr "var_shift" "yes,no")])
5042
5043 (define_insn "*ashrsi3_64"
5044   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5045         (sign_extend:DI
5046             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5047                          (match_operand:SI 2 "reg_or_cint_operand" "r,n"))))]
5048   "TARGET_POWERPC64"
5049   "@
5050    sraw %0,%1,%2
5051    srawi %0,%1,%h2"
5052   [(set_attr "type" "shift")
5053    (set_attr "var_shift" "yes,no")])
5054
5055 (define_insn_and_split "*ashr<mode>3_dot"
5056   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5057         (compare:CC (ashiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")
5058                                   (match_operand:GPR 2 "reg_or_cint_operand" "r,n,r,n"))
5059                     (const_int 0)))
5060    (clobber (match_scratch:GPR 0 "=r,r,r,r"))]
5061   "<MODE>mode == Pmode && rs6000_gen_cell_microcode"
5062   "@
5063    sra<wd>. %0,%1,%2
5064    sra<wd>i. %0,%1,%<hH>2
5065    #
5066    #"
5067   "&& reload_completed"
5068   [(set (match_dup 0)
5069         (ashiftrt:GPR (match_dup 1)
5070                       (match_dup 2)))
5071    (set (match_dup 3)
5072         (compare:CC (match_dup 0)
5073                     (const_int 0)))]
5074   ""
5075   [(set_attr "type" "shift")
5076    (set_attr "var_shift" "yes,no,yes,no")
5077    (set_attr "dot" "yes")
5078    (set_attr "length" "4,4,8,8")])
5079
5080 (define_insn_and_split "*ashr<mode>3_dot2"
5081   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5082         (compare:CC (ashiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")
5083                                   (match_operand:GPR 2 "reg_or_cint_operand" "r,n,r,n"))
5084                     (const_int 0)))
5085    (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,r,r")
5086         (ashiftrt:GPR (match_dup 1)
5087                       (match_dup 2)))]
5088   "<MODE>mode == Pmode && rs6000_gen_cell_microcode"
5089   "@
5090    sra<wd>. %0,%1,%2
5091    sra<wd>i. %0,%1,%<hH>2
5092    #
5093    #"
5094   "&& reload_completed"
5095   [(set (match_dup 0)
5096         (ashiftrt:GPR (match_dup 1)
5097                       (match_dup 2)))
5098    (set (match_dup 3)
5099         (compare:CC (match_dup 0)
5100                     (const_int 0)))]
5101   ""
5102   [(set_attr "type" "shift")
5103    (set_attr "var_shift" "yes,no,yes,no")
5104    (set_attr "dot" "yes")
5105    (set_attr "length" "4,4,8,8")])
5106 \f
5107 ;; Builtins to replace a division to generate FRE reciprocal estimate
5108 ;; instructions and the necessary fixup instructions
5109 (define_expand "recip<mode>3"
5110   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5111    (match_operand:RECIPF 1 "gpc_reg_operand" "")
5112    (match_operand:RECIPF 2 "gpc_reg_operand" "")]
5113   "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
5114 {
5115    rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
5116    DONE;
5117 })
5118
5119 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
5120 ;; hardware division.  This is only done before register allocation and with
5121 ;; -ffast-math.  This must appear before the divsf3/divdf3 insns.
5122 (define_split
5123   [(set (match_operand:RECIPF 0 "gpc_reg_operand" "")
5124         (div:RECIPF (match_operand 1 "gpc_reg_operand" "")
5125                     (match_operand 2 "gpc_reg_operand" "")))]
5126   "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
5127    && can_create_pseudo_p () && optimize_insn_for_speed_p ()
5128    && flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math"
5129   [(const_int 0)]
5130 {
5131   rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
5132   DONE;
5133 })
5134
5135 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
5136 ;; appropriate fixup.
5137 (define_expand "rsqrt<mode>2"
5138   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
5139    (match_operand:RECIPF 1 "gpc_reg_operand" "")]
5140   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
5141 {
5142   rs6000_emit_swrsqrt (operands[0], operands[1]);
5143   DONE;
5144 })
5145 \f
5146 ;; Floating-point insns, excluding normal data motion.  We combine the SF/DF
5147 ;; modes here, and also add in conditional vsx/power8-vector support to access
5148 ;; values in the traditional Altivec registers if the appropriate
5149 ;; -mupper-regs-{df,sf} option is enabled.
5150
5151 (define_expand "abs<mode>2"
5152   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5153         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5154   "TARGET_<MODE>_INSN"
5155   "")
5156
5157 (define_insn "*abs<mode>2_fpr"
5158   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5159         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5160   "TARGET_<MODE>_FPR"
5161   "@
5162    fabs %0,%1
5163    xsabsdp %x0,%x1"
5164   [(set_attr "type" "fp")
5165    (set_attr "fp_type" "fp_addsub_<Fs>")])
5166
5167 (define_insn "*nabs<mode>2_fpr"
5168   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5169         (neg:SFDF
5170          (abs:SFDF
5171           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>"))))]
5172   "TARGET_<MODE>_FPR"
5173   "@
5174    fnabs %0,%1
5175    xsnabsdp %x0,%x1"
5176   [(set_attr "type" "fp")
5177    (set_attr "fp_type" "fp_addsub_<Fs>")])
5178
5179 (define_expand "neg<mode>2"
5180   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5181         (neg:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5182   "TARGET_<MODE>_INSN"
5183   "")
5184
5185 (define_insn "*neg<mode>2_fpr"
5186   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5187         (neg:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5188   "TARGET_<MODE>_FPR"
5189   "@
5190    fneg %0,%1
5191    xsnegdp %x0,%x1"
5192   [(set_attr "type" "fp")
5193    (set_attr "fp_type" "fp_addsub_<Fs>")])
5194
5195 (define_expand "add<mode>3"
5196   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5197         (plus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5198                    (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5199   "TARGET_<MODE>_INSN"
5200   "")
5201
5202 (define_insn "*add<mode>3_fpr"
5203   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5204         (plus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5205                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5206   "TARGET_<MODE>_FPR"
5207   "@
5208    fadd<Ftrad> %0,%1,%2
5209    xsadd<Fvsx> %x0,%x1,%x2"
5210   [(set_attr "type" "fp")
5211    (set_attr "fp_type" "fp_addsub_<Fs>")])
5212
5213 (define_expand "sub<mode>3"
5214   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5215         (minus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5216                     (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5217   "TARGET_<MODE>_INSN"
5218   "")
5219
5220 (define_insn "*sub<mode>3_fpr"
5221   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5222         (minus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5223                     (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5224   "TARGET_<MODE>_FPR"
5225   "@
5226    fsub<Ftrad> %0,%1,%2
5227    xssub<Fvsx> %x0,%x1,%x2"
5228   [(set_attr "type" "fp")
5229    (set_attr "fp_type" "fp_addsub_<Fs>")])
5230
5231 (define_expand "mul<mode>3"
5232   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5233         (mult:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5234                    (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5235   "TARGET_<MODE>_INSN"
5236   "")
5237
5238 (define_insn "*mul<mode>3_fpr"
5239   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5240         (mult:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5241                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5242   "TARGET_<MODE>_FPR"
5243   "@
5244    fmul<Ftrad> %0,%1,%2
5245    xsmul<Fvsx> %x0,%x1,%x2"
5246   [(set_attr "type" "dmul")
5247    (set_attr "fp_type" "fp_mul_<Fs>")])
5248
5249 (define_expand "div<mode>3"
5250   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5251         (div:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5252                   (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5253   "TARGET_<MODE>_INSN && !TARGET_SIMPLE_FPU"
5254   "")
5255
5256 (define_insn "*div<mode>3_fpr"
5257   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5258         (div:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5259                   (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5260   "TARGET_<MODE>_FPR && !TARGET_SIMPLE_FPU"
5261   "@
5262    fdiv<Ftrad> %0,%1,%2
5263    xsdiv<Fvsx> %x0,%x1,%x2"
5264   [(set_attr "type" "<Fs>div")
5265    (set_attr "fp_type" "fp_div_<Fs>")])
5266
5267 (define_insn "sqrt<mode>2"
5268   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5269         (sqrt:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5270   "TARGET_<MODE>_FPR && !TARGET_SIMPLE_FPU
5271    && (TARGET_PPC_GPOPT || (<MODE>mode == SFmode && TARGET_XILINX_FPU))"
5272   "@
5273    fsqrt<Ftrad> %0,%1
5274    xssqrt<Fvsx> %x0,%x1"
5275   [(set_attr "type" "<Fs>sqrt")
5276    (set_attr "fp_type" "fp_sqrt_<Fs>")])
5277
5278 ;; Floating point reciprocal approximation
5279 (define_insn "fre<Fs>"
5280   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5281         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
5282                      UNSPEC_FRES))]
5283   "TARGET_<FFRE>"
5284   "@
5285    fre<Ftrad> %0,%1
5286    xsre<Fvsx> %x0,%x1"
5287   [(set_attr "type" "fp")])
5288
5289 (define_insn "*rsqrt<mode>2"
5290   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5291         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
5292                      UNSPEC_RSQRT))]
5293   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
5294   "@
5295    frsqrte<Ftrad> %0,%1
5296    xsrsqrte<Fvsx> %x0,%x1"
5297   [(set_attr "type" "fp")])
5298
5299 ;; Floating point comparisons
5300 (define_insn "*cmp<mode>_fpr"
5301   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y,y")
5302         (compare:CCFP (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5303                       (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5304   "TARGET_<MODE>_FPR"
5305   "@
5306    fcmpu %0,%1,%2
5307    xscmpudp %0,%x1,%x2"
5308   [(set_attr "type" "fpcompare")])
5309
5310 ;; Floating point conversions
5311 (define_expand "extendsfdf2"
5312   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5313         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5314   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5315   "")
5316
5317 (define_insn_and_split "*extendsfdf2_fpr"
5318   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d,ws,?ws,wv")
5319         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m,0,wy,Z")))]
5320   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5321   "@
5322    #
5323    fmr %0,%1
5324    lfs%U1%X1 %0,%1
5325    #
5326    xxlor %x0,%x1,%x1
5327    lxsspx %x0,%y1"
5328   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5329   [(const_int 0)]
5330 {
5331   emit_note (NOTE_INSN_DELETED);
5332   DONE;
5333 }
5334   [(set_attr "type" "fp,fp,fpload,fp,vecsimple,fpload")])
5335
5336 (define_expand "truncdfsf2"
5337   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5338         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5339   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5340   "")
5341
5342 (define_insn "*truncdfsf2_fpr"
5343   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5344         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5345   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5346   "frsp %0,%1"
5347   [(set_attr "type" "fp")])
5348
5349 ;; This expander is here to avoid FLOAT_WORDS_BIGENDIAN tests in
5350 ;; builtins.c and optabs.c that are not correct for IBM long double
5351 ;; when little-endian.
5352 (define_expand "signbittf2"
5353   [(set (match_dup 2)
5354         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))
5355    (set (match_dup 3)
5356         (subreg:DI (match_dup 2) 0))
5357    (set (match_dup 4)
5358         (match_dup 5))
5359    (set (match_operand:SI 0 "gpc_reg_operand" "")
5360         (match_dup 6))]
5361   "!TARGET_IEEEQUAD
5362    && TARGET_HARD_FLOAT
5363    && (TARGET_FPRS || TARGET_E500_DOUBLE)
5364    && TARGET_LONG_DOUBLE_128"
5365 {
5366   operands[2] = gen_reg_rtx (DFmode);
5367   operands[3] = gen_reg_rtx (DImode);
5368   if (TARGET_POWERPC64)
5369     {
5370       operands[4] = gen_reg_rtx (DImode);
5371       operands[5] = gen_rtx_LSHIFTRT (DImode, operands[3], GEN_INT (63));
5372       operands[6] = gen_rtx_SUBREG (SImode, operands[4],
5373                                     WORDS_BIG_ENDIAN ? 4 : 0);
5374     }
5375   else
5376     {
5377       operands[4] = gen_reg_rtx (SImode);
5378       operands[5] = gen_rtx_SUBREG (SImode, operands[3],
5379                                     WORDS_BIG_ENDIAN ? 0 : 4);
5380       operands[6] = gen_rtx_LSHIFTRT (SImode, operands[4], GEN_INT (31));
5381     }
5382 })
5383
5384 (define_expand "copysign<mode>3"
5385   [(set (match_dup 3)
5386         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))
5387    (set (match_dup 4)
5388         (neg:SFDF (abs:SFDF (match_dup 1))))
5389    (set (match_operand:SFDF 0 "gpc_reg_operand" "")
5390         (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand" "")
5391                                (match_dup 5))
5392                          (match_dup 3)
5393                          (match_dup 4)))]
5394   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5395    && ((TARGET_PPC_GFXOPT
5396         && !HONOR_NANS (<MODE>mode)
5397         && !HONOR_SIGNED_ZEROS (<MODE>mode))
5398        || TARGET_CMPB
5399        || VECTOR_UNIT_VSX_P (<MODE>mode))"
5400 {
5401   if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
5402     {
5403       emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
5404                                              operands[2]));
5405       DONE;
5406     }
5407
5408    operands[3] = gen_reg_rtx (<MODE>mode);
5409    operands[4] = gen_reg_rtx (<MODE>mode);
5410    operands[5] = CONST0_RTX (<MODE>mode);
5411   })
5412
5413 ;; Use an unspec rather providing an if-then-else in RTL, to prevent the
5414 ;; compiler from optimizing -0.0
5415 (define_insn "copysign<mode>3_fcpsgn"
5416   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5417         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5418                       (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")]
5419                      UNSPEC_COPYSIGN))]
5420   "TARGET_<MODE>_FPR && TARGET_CMPB"
5421   "@
5422    fcpsgn %0,%2,%1
5423    xscpsgn<Fvsx> %x0,%x2,%x1"
5424   [(set_attr "type" "fp")])
5425
5426 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5427 ;; fsel instruction and some auxiliary computations.  Then we just have a
5428 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5429 ;; combine.
5430 ;; For MIN, MAX on non-VSX machines, and conditional move all of the time, we
5431 ;; use DEFINE_EXPAND's that involve a fsel instruction and some auxiliary
5432 ;; computations.  Then we just have a single DEFINE_INSN for fsel and the
5433 ;; define_splits to make them if made by combine.  On VSX machines we have the
5434 ;; min/max instructions.
5435 ;;
5436 ;; On VSX, we only check for TARGET_VSX instead of checking for a vsx/p8 vector
5437 ;; to allow either DF/SF to use only traditional registers.
5438
5439 (define_expand "smax<mode>3"
5440   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5441         (if_then_else:SFDF (ge (match_operand:SFDF 1 "gpc_reg_operand" "")
5442                                (match_operand:SFDF 2 "gpc_reg_operand" ""))
5443                            (match_dup 1)
5444                            (match_dup 2)))]
5445   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math"
5446 {
5447   rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
5448   DONE;
5449 })
5450
5451 (define_insn "*smax<mode>3_vsx"
5452   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5453         (smax:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5454                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5455   "TARGET_<MODE>_FPR && TARGET_VSX"
5456   "xsmaxdp %x0,%x1,%x2"
5457   [(set_attr "type" "fp")])
5458
5459 (define_expand "smin<mode>3"
5460   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5461         (if_then_else:SFDF (ge (match_operand:SFDF 1 "gpc_reg_operand" "")
5462                                (match_operand:SFDF 2 "gpc_reg_operand" ""))
5463                            (match_dup 2)
5464                            (match_dup 1)))]
5465   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math"
5466 {
5467   rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
5468   DONE;
5469 })
5470
5471 (define_insn "*smin<mode>3_vsx"
5472   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5473         (smin:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5474                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5475   "TARGET_<MODE>_FPR && TARGET_VSX"
5476   "xsmindp %x0,%x1,%x2"
5477   [(set_attr "type" "fp")])
5478
5479 (define_split
5480   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5481         (match_operator:SFDF 3 "min_max_operator"
5482          [(match_operand:SFDF 1 "gpc_reg_operand" "")
5483           (match_operand:SFDF 2 "gpc_reg_operand" "")]))]
5484   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math
5485    && !TARGET_VSX"
5486   [(const_int 0)]
5487 {
5488   rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), operands[1],
5489                       operands[2]);
5490   DONE;
5491 })
5492
5493 (define_split
5494   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5495         (match_operator:SF 3 "min_max_operator"
5496          [(match_operand:SF 1 "gpc_reg_operand" "")
5497           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5498   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
5499    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
5500   [(const_int 0)]
5501   "
5502 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5503                       operands[1], operands[2]);
5504   DONE;
5505 }")
5506
5507 (define_expand "mov<mode>cc"
5508    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
5509          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
5510                            (match_operand:GPR 2 "gpc_reg_operand" "")
5511                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
5512   "TARGET_ISEL<sel>"
5513   "
5514 {
5515   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5516     DONE;
5517   else
5518     FAIL;
5519 }")
5520
5521 ;; We use the BASE_REGS for the isel input operands because, if rA is
5522 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5523 ;; because we may switch the operands and rB may end up being rA.
5524 ;;
5525 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5526 ;; leave out the mode in operand 4 and use one pattern, but reload can
5527 ;; change the mode underneath our feet and then gets confused trying
5528 ;; to reload the value.
5529 (define_insn "isel_signed_<mode>"
5530   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5531         (if_then_else:GPR
5532          (match_operator 1 "scc_comparison_operator"
5533                          [(match_operand:CC 4 "cc_reg_operand" "y,y")
5534                           (const_int 0)])
5535          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
5536          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5537   "TARGET_ISEL<sel>"
5538   "*
5539 { return output_isel (operands); }"
5540   [(set_attr "type" "isel")
5541    (set_attr "length" "4")])
5542
5543 (define_insn "isel_unsigned_<mode>"
5544   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5545         (if_then_else:GPR
5546          (match_operator 1 "scc_comparison_operator"
5547                          [(match_operand:CCUNS 4 "cc_reg_operand" "y,y")
5548                           (const_int 0)])
5549          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
5550          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5551   "TARGET_ISEL<sel>"
5552   "*
5553 { return output_isel (operands); }"
5554   [(set_attr "type" "isel")
5555    (set_attr "length" "4")])
5556
5557 ;; These patterns can be useful for combine; they let combine know that
5558 ;; isel can handle reversed comparisons so long as the operands are
5559 ;; registers.
5560
5561 (define_insn "*isel_reversed_signed_<mode>"
5562   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5563         (if_then_else:GPR
5564          (match_operator 1 "scc_rev_comparison_operator"
5565                          [(match_operand:CC 4 "cc_reg_operand" "y")
5566                           (const_int 0)])
5567          (match_operand:GPR 2 "gpc_reg_operand" "b")
5568          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
5569   "TARGET_ISEL<sel>"
5570   "*
5571 { return output_isel (operands); }"
5572   [(set_attr "type" "isel")
5573    (set_attr "length" "4")])
5574
5575 (define_insn "*isel_reversed_unsigned_<mode>"
5576   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5577         (if_then_else:GPR
5578          (match_operator 1 "scc_rev_comparison_operator"
5579                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5580                           (const_int 0)])
5581          (match_operand:GPR 2 "gpc_reg_operand" "b")
5582          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
5583   "TARGET_ISEL<sel>"
5584   "*
5585 { return output_isel (operands); }"
5586   [(set_attr "type" "isel")
5587    (set_attr "length" "4")])
5588
5589 (define_expand "movsfcc"
5590    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5591          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5592                           (match_operand:SF 2 "gpc_reg_operand" "")
5593                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5594   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5595   "
5596 {
5597   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5598     DONE;
5599   else
5600     FAIL;
5601 }")
5602
5603 (define_insn "*fselsfsf4"
5604   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5605         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5606                              (match_operand:SF 4 "zero_fp_constant" "F"))
5607                          (match_operand:SF 2 "gpc_reg_operand" "f")
5608                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5609   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5610   "fsel %0,%1,%2,%3"
5611   [(set_attr "type" "fp")])
5612
5613 (define_insn "*fseldfsf4"
5614   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5615         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5616                              (match_operand:DF 4 "zero_fp_constant" "F"))
5617                          (match_operand:SF 2 "gpc_reg_operand" "f")
5618                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5619   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5620   "fsel %0,%1,%2,%3"
5621   [(set_attr "type" "fp")])
5622
5623 ;; The conditional move instructions allow us to perform max and min
5624 ;; operations even when
5625
5626 (define_split
5627   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5628         (match_operator:DF 3 "min_max_operator"
5629          [(match_operand:DF 1 "gpc_reg_operand" "")
5630           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5631   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5632    && !flag_trapping_math"
5633   [(const_int 0)]
5634   "
5635 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5636                       operands[1], operands[2]);
5637   DONE;
5638 }")
5639
5640 (define_expand "movdfcc"
5641    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5642          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5643                           (match_operand:DF 2 "gpc_reg_operand" "")
5644                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5645   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5646   "
5647 {
5648   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5649     DONE;
5650   else
5651     FAIL;
5652 }")
5653
5654 (define_insn "*fseldfdf4"
5655   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5656         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5657                              (match_operand:DF 4 "zero_fp_constant" "F"))
5658                          (match_operand:DF 2 "gpc_reg_operand" "d")
5659                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5660   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5661   "fsel %0,%1,%2,%3"
5662   [(set_attr "type" "fp")])
5663
5664 (define_insn "*fselsfdf4"
5665   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5666         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5667                              (match_operand:SF 4 "zero_fp_constant" "F"))
5668                          (match_operand:DF 2 "gpc_reg_operand" "d")
5669                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5670   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5671   "fsel %0,%1,%2,%3"
5672   [(set_attr "type" "fp")])
5673 \f
5674 ;; Conversions to and from floating-point.
5675
5676 ; We don't define lfiwax/lfiwzx with the normal definition, because we
5677 ; don't want to support putting SImode in FPR registers.
5678 (define_insn "lfiwax"
5679   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wm,!wm")
5680         (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r")]
5681                    UNSPEC_LFIWAX))]
5682   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX"
5683   "@
5684    lfiwax %0,%y1
5685    lxsiwax %x0,%y1
5686    mtvsrwa %x0,%1"
5687   [(set_attr "type" "fpload,fpload,mffgpr")])
5688
5689 ; This split must be run before register allocation because it allocates the
5690 ; memory slot that is needed to move values to/from the FPR.  We don't allocate
5691 ; it earlier to allow for the combiner to merge insns together where it might
5692 ; not be needed and also in case the insns are deleted as dead code.
5693
5694 (define_insn_and_split "floatsi<mode>2_lfiwax"
5695   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5696         (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5697    (clobber (match_scratch:DI 2 "=d"))]
5698   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5699    && <SI_CONVERT_FP> && can_create_pseudo_p ()"
5700   "#"
5701   ""
5702   [(pc)]
5703   "
5704 {
5705   rtx dest = operands[0];
5706   rtx src = operands[1];
5707   rtx tmp;
5708
5709   if (!MEM_P (src) && TARGET_POWERPC64
5710       && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
5711     tmp = convert_to_mode (DImode, src, false);
5712   else
5713     {
5714       tmp = operands[2];
5715       if (GET_CODE (tmp) == SCRATCH)
5716         tmp = gen_reg_rtx (DImode);
5717       if (MEM_P (src))
5718         {
5719           src = rs6000_address_for_fpconvert (src);
5720           emit_insn (gen_lfiwax (tmp, src));
5721         }
5722       else
5723         {
5724           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5725           emit_move_insn (stack, src);
5726           emit_insn (gen_lfiwax (tmp, stack));
5727         }
5728     }
5729   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5730   DONE;
5731 }"
5732   [(set_attr "length" "12")
5733    (set_attr "type" "fpload")])
5734
5735 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
5736   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5737         (float:SFDF
5738          (sign_extend:DI
5739           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5740    (clobber (match_scratch:DI 2 "=0,d"))]
5741   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5742    && <SI_CONVERT_FP>"
5743   "#"
5744   ""
5745   [(pc)]
5746   "
5747 {
5748   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5749   if (GET_CODE (operands[2]) == SCRATCH)
5750     operands[2] = gen_reg_rtx (DImode);
5751   emit_insn (gen_lfiwax (operands[2], operands[1]));
5752   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5753   DONE;
5754 }"
5755   [(set_attr "length" "8")
5756    (set_attr "type" "fpload")])
5757
5758 (define_insn "lfiwzx"
5759   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wm,!wm")
5760         (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r")]
5761                    UNSPEC_LFIWZX))]
5762   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX"
5763   "@
5764    lfiwzx %0,%y1
5765    lxsiwzx %x0,%y1
5766    mtvsrwz %x0,%1"
5767   [(set_attr "type" "fpload,fpload,mftgpr")])
5768
5769 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
5770   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5771         (unsigned_float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5772    (clobber (match_scratch:DI 2 "=d"))]
5773   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5774    && <SI_CONVERT_FP>"
5775   "#"
5776   ""
5777   [(pc)]
5778   "
5779 {
5780   rtx dest = operands[0];
5781   rtx src = operands[1];
5782   rtx tmp;
5783
5784   if (!MEM_P (src) && TARGET_POWERPC64
5785       && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
5786     tmp = convert_to_mode (DImode, src, true);
5787   else
5788     {
5789       tmp = operands[2];
5790       if (GET_CODE (tmp) == SCRATCH)
5791         tmp = gen_reg_rtx (DImode);
5792       if (MEM_P (src))
5793         {
5794           src = rs6000_address_for_fpconvert (src);
5795           emit_insn (gen_lfiwzx (tmp, src));
5796         }
5797       else
5798         {
5799           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5800           emit_move_insn (stack, src);
5801           emit_insn (gen_lfiwzx (tmp, stack));
5802         }
5803     }
5804   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5805   DONE;
5806 }"
5807   [(set_attr "length" "12")
5808    (set_attr "type" "fpload")])
5809
5810 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
5811   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5812         (unsigned_float:SFDF
5813          (zero_extend:DI
5814           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5815    (clobber (match_scratch:DI 2 "=0,d"))]
5816   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5817    && <SI_CONVERT_FP>"
5818   "#"
5819   ""
5820   [(pc)]
5821   "
5822 {
5823   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5824   if (GET_CODE (operands[2]) == SCRATCH)
5825     operands[2] = gen_reg_rtx (DImode);
5826   emit_insn (gen_lfiwzx (operands[2], operands[1]));
5827   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5828   DONE;
5829 }"
5830   [(set_attr "length" "8")
5831    (set_attr "type" "fpload")])
5832
5833 ; For each of these conversions, there is a define_expand, a define_insn
5834 ; with a '#' template, and a define_split (with C code).  The idea is
5835 ; to allow constant folding with the template of the define_insn,
5836 ; then to have the insns split later (between sched1 and final).
5837
5838 (define_expand "floatsidf2"
5839   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5840                    (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5841               (use (match_dup 2))
5842               (use (match_dup 3))
5843               (clobber (match_dup 4))
5844               (clobber (match_dup 5))
5845               (clobber (match_dup 6))])]
5846   "TARGET_HARD_FLOAT 
5847    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5848   "
5849 {
5850   if (TARGET_E500_DOUBLE)
5851     {
5852       if (!REG_P (operands[1]))
5853         operands[1] = force_reg (SImode, operands[1]);
5854       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5855       DONE;
5856     }
5857   else if (TARGET_LFIWAX && TARGET_FCFID)
5858     {
5859       emit_insn (gen_floatsidf2_lfiwax (operands[0], operands[1]));
5860       DONE;
5861     }
5862   else if (TARGET_FCFID)
5863     {
5864       rtx dreg = operands[1];
5865       if (!REG_P (dreg))
5866         dreg = force_reg (SImode, dreg);
5867       dreg = convert_to_mode (DImode, dreg, false);
5868       emit_insn (gen_floatdidf2 (operands[0], dreg));
5869       DONE;
5870     }
5871
5872   if (!REG_P (operands[1]))
5873     operands[1] = force_reg (SImode, operands[1]);
5874   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5875   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5876   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5877   operands[5] = gen_reg_rtx (DFmode);
5878   operands[6] = gen_reg_rtx (SImode);
5879 }")
5880
5881 (define_insn_and_split "*floatsidf2_internal"
5882   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5883         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5884    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5885    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5886    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5887    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
5888    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5889   "! TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5890   "#"
5891   ""
5892   [(pc)]
5893   "
5894 {
5895   rtx lowword, highword;
5896   gcc_assert (MEM_P (operands[4]));
5897   highword = adjust_address (operands[4], SImode, 0);
5898   lowword = adjust_address (operands[4], SImode, 4);
5899   if (! WORDS_BIG_ENDIAN)
5900     {
5901       rtx tmp;
5902       tmp = highword; highword = lowword; lowword = tmp;
5903     }
5904
5905   emit_insn (gen_xorsi3 (operands[6], operands[1],
5906                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5907   emit_move_insn (lowword, operands[6]);
5908   emit_move_insn (highword, operands[2]);
5909   emit_move_insn (operands[5], operands[4]);
5910   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5911   DONE;
5912 }"
5913   [(set_attr "length" "24")
5914    (set_attr "type" "fp")])
5915
5916 ;; If we don't have a direct conversion to single precision, don't enable this
5917 ;; conversion for 32-bit without fast math, because we don't have the insn to
5918 ;; generate the fixup swizzle to avoid double rounding problems.
5919 (define_expand "floatunssisf2"
5920   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5921         (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5922   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
5923    && (!TARGET_FPRS
5924        || (TARGET_FPRS
5925            && ((TARGET_FCFIDUS && TARGET_LFIWZX)
5926                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
5927                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
5928   "
5929 {
5930   if (!TARGET_FPRS)
5931     {
5932       if (!REG_P (operands[1]))
5933         operands[1] = force_reg (SImode, operands[1]);
5934     }
5935   else if (TARGET_LFIWZX && TARGET_FCFIDUS)
5936     {
5937       emit_insn (gen_floatunssisf2_lfiwzx (operands[0], operands[1]));
5938       DONE;
5939     }
5940   else
5941     {
5942       rtx dreg = operands[1];
5943       if (!REG_P (dreg))
5944         dreg = force_reg (SImode, dreg);
5945       dreg = convert_to_mode (DImode, dreg, true);
5946       emit_insn (gen_floatdisf2 (operands[0], dreg));
5947       DONE;
5948     }
5949 }")
5950
5951 (define_expand "floatunssidf2"
5952   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5953                    (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5954               (use (match_dup 2))
5955               (use (match_dup 3))
5956               (clobber (match_dup 4))
5957               (clobber (match_dup 5))])]
5958   "TARGET_HARD_FLOAT
5959    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5960   "
5961 {
5962   if (TARGET_E500_DOUBLE)
5963     {
5964       if (!REG_P (operands[1]))
5965         operands[1] = force_reg (SImode, operands[1]);
5966       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5967       DONE;
5968     }
5969   else if (TARGET_LFIWZX && TARGET_FCFID)
5970     {
5971       emit_insn (gen_floatunssidf2_lfiwzx (operands[0], operands[1]));
5972       DONE;
5973     }
5974   else if (TARGET_FCFID)
5975     {
5976       rtx dreg = operands[1];
5977       if (!REG_P (dreg))
5978         dreg = force_reg (SImode, dreg);
5979       dreg = convert_to_mode (DImode, dreg, true);
5980       emit_insn (gen_floatdidf2 (operands[0], dreg));
5981       DONE;
5982     }
5983
5984   if (!REG_P (operands[1]))
5985     operands[1] = force_reg (SImode, operands[1]);
5986   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5987   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5988   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5989   operands[5] = gen_reg_rtx (DFmode);
5990 }")
5991
5992 (define_insn_and_split "*floatunssidf2_internal"
5993   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5994         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5995    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5996    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5997    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5998    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
5999   "! TARGET_FCFIDU && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6000    && !(TARGET_FCFID && TARGET_POWERPC64)"
6001   "#"
6002   ""
6003   [(pc)]
6004   "
6005 {
6006   rtx lowword, highword;
6007   gcc_assert (MEM_P (operands[4]));
6008   highword = adjust_address (operands[4], SImode, 0);
6009   lowword = adjust_address (operands[4], SImode, 4);
6010   if (! WORDS_BIG_ENDIAN)
6011     {
6012       rtx tmp;
6013       tmp = highword; highword = lowword; lowword = tmp;
6014     }
6015
6016   emit_move_insn (lowword, operands[1]);
6017   emit_move_insn (highword, operands[2]);
6018   emit_move_insn (operands[5], operands[4]);
6019   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6020   DONE;
6021 }"
6022   [(set_attr "length" "20")
6023    (set_attr "type" "fp")])
6024
6025 (define_expand "fix_trunc<mode>si2"
6026   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6027         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6028   "TARGET_HARD_FLOAT && ((TARGET_FPRS && <TARGET_FLOAT>) || <E500_CONVERT>)"
6029   "
6030 {
6031   if (!<E500_CONVERT>)
6032     {
6033       rtx tmp, stack;
6034
6035       if (TARGET_STFIWX)
6036         emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6037       else
6038         {
6039           tmp = gen_reg_rtx (DImode);
6040           stack = rs6000_allocate_stack_temp (DImode, true, false);
6041           emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], operands[1],
6042                                                       tmp, stack));
6043         }
6044       DONE;
6045     }
6046 }")
6047
6048 ; Like the convert to float patterns, this insn must be split before
6049 ; register allocation so that it can allocate the memory slot if it
6050 ; needed
6051 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
6052   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6053         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6054    (clobber (match_scratch:DI 2 "=d"))]
6055   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6056    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
6057    && TARGET_STFIWX && can_create_pseudo_p ()"
6058   "#"
6059   ""
6060   [(pc)]
6061 {
6062   rtx dest = operands[0];
6063   rtx src = operands[1];
6064   rtx tmp = operands[2];
6065
6066   if (GET_CODE (tmp) == SCRATCH)
6067     tmp = gen_reg_rtx (DImode);
6068
6069   emit_insn (gen_fctiwz_<mode> (tmp, src));
6070   if (MEM_P (dest))
6071     {
6072       dest = rs6000_address_for_fpconvert (dest);
6073       emit_insn (gen_stfiwx (dest, tmp));
6074       DONE;
6075     }
6076   else if (TARGET_POWERPC64 && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
6077     {
6078       dest = gen_lowpart (DImode, dest);
6079       emit_move_insn (dest, tmp);
6080       DONE;
6081     }
6082   else
6083     {
6084       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6085       emit_insn (gen_stfiwx (stack, tmp));
6086       emit_move_insn (dest, stack);
6087       DONE;
6088     }
6089 }
6090   [(set_attr "length" "12")
6091    (set_attr "type" "fp")])
6092
6093 (define_insn_and_split "fix_trunc<mode>si2_internal"
6094   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,?r")
6095         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,<rreg>")))
6096    (clobber (match_operand:DI 2 "gpc_reg_operand" "=1,d"))
6097    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o,o"))]
6098   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6099   "#"
6100   ""
6101   [(pc)]
6102   "
6103 {
6104   rtx lowword;
6105   gcc_assert (MEM_P (operands[3]));
6106   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6107
6108   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
6109   emit_move_insn (operands[3], operands[2]);
6110   emit_move_insn (operands[0], lowword);
6111   DONE;
6112 }"
6113   [(set_attr "length" "16")
6114    (set_attr "type" "fp")])
6115
6116 (define_expand "fix_trunc<mode>di2"
6117   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6118         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6119   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6120    && TARGET_FCFID"
6121   "")
6122
6123 (define_insn "*fix_trunc<mode>di2_fctidz"
6124   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6125         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6126   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6127     && TARGET_FCFID && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6128   "fctidz %0,%1"
6129   [(set_attr "type" "fp")])
6130
6131 (define_expand "fixuns_trunc<mode>si2"
6132   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6133         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6134   "TARGET_HARD_FLOAT
6135    && ((TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ && TARGET_STFIWX)
6136        || <E500_CONVERT>)"
6137   "
6138 {
6139   if (!<E500_CONVERT>)
6140     {
6141       emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6142       DONE;
6143     }
6144 }")
6145
6146 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
6147   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6148         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6149    (clobber (match_scratch:DI 2 "=d"))]
6150   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
6151    && TARGET_STFIWX && can_create_pseudo_p ()"
6152   "#"
6153   ""
6154   [(pc)]
6155 {
6156   rtx dest = operands[0];
6157   rtx src = operands[1];
6158   rtx tmp = operands[2];
6159
6160   if (GET_CODE (tmp) == SCRATCH)
6161     tmp = gen_reg_rtx (DImode);
6162
6163   emit_insn (gen_fctiwuz_<mode> (tmp, src));
6164   if (MEM_P (dest))
6165     {
6166       dest = rs6000_address_for_fpconvert (dest);
6167       emit_insn (gen_stfiwx (dest, tmp));
6168       DONE;
6169     }
6170   else if (TARGET_POWERPC64 && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
6171     {
6172       dest = gen_lowpart (DImode, dest);
6173       emit_move_insn (dest, tmp);
6174       DONE;
6175     }
6176   else
6177     {
6178       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6179       emit_insn (gen_stfiwx (stack, tmp));
6180       emit_move_insn (dest, stack);
6181       DONE;
6182     }
6183 }
6184   [(set_attr "length" "12")
6185    (set_attr "type" "fp")])
6186
6187 (define_expand "fixuns_trunc<mode>di2"
6188   [(set (match_operand:DI 0 "register_operand" "")
6189         (unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
6190   "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
6191   "")
6192
6193 (define_insn "*fixuns_trunc<mode>di2_fctiduz"
6194   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6195         (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6196   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6197     && TARGET_FCTIDUZ && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6198   "fctiduz %0,%1"
6199   [(set_attr "type" "fp")])
6200
6201 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6202 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
6203 ; because the first makes it clear that operand 0 is not live
6204 ; before the instruction.
6205 (define_insn "fctiwz_<mode>"
6206   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6207         (unspec:DI [(fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))]
6208                    UNSPEC_FCTIWZ))]
6209   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6210   "fctiwz %0,%1"
6211   [(set_attr "type" "fp")])
6212
6213 (define_insn "fctiwuz_<mode>"
6214   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6215         (unspec:DI [(unsigned_fix:SI
6216                      (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>"))]
6217                    UNSPEC_FCTIWUZ))]
6218   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ"
6219   "fctiwuz %0,%1"
6220   [(set_attr "type" "fp")])
6221
6222 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
6223 ;; since the friz instruction does not truncate the value if the floating
6224 ;; point value is < LONG_MIN or > LONG_MAX.
6225 (define_insn "*friz"
6226   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6227         (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d"))))]
6228   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_FPRND
6229    && !VECTOR_UNIT_VSX_P (DFmode) && flag_unsafe_math_optimizations
6230    && !flag_trapping_math && TARGET_FRIZ"
6231   "friz %0,%1"
6232   [(set_attr "type" "fp")])
6233
6234 ;; Since FCTIWZ doesn't sign extend the upper bits, we have to do a store and a
6235 ;; load to properly sign extend the value, but at least doing a store, load
6236 ;; into a GPR to sign extend, a store from the GPR and a load back into the FPR
6237 ;; if we have 32-bit memory ops
6238 (define_insn_and_split "*round32<mode>2_fprs"
6239   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6240         (float:SFDF
6241          (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6242    (clobber (match_scratch:DI 2 "=d"))
6243    (clobber (match_scratch:DI 3 "=d"))]
6244   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6245    && <SI_CONVERT_FP> && TARGET_LFIWAX && TARGET_STFIWX && TARGET_FCFID
6246    && can_create_pseudo_p ()"
6247   "#"
6248   ""
6249   [(pc)]
6250 {
6251   rtx dest = operands[0];
6252   rtx src = operands[1];
6253   rtx tmp1 = operands[2];
6254   rtx tmp2 = operands[3];
6255   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6256
6257   if (GET_CODE (tmp1) == SCRATCH)
6258     tmp1 = gen_reg_rtx (DImode);
6259   if (GET_CODE (tmp2) == SCRATCH)
6260     tmp2 = gen_reg_rtx (DImode);
6261
6262   emit_insn (gen_fctiwz_<mode> (tmp1, src));
6263   emit_insn (gen_stfiwx (stack, tmp1));
6264   emit_insn (gen_lfiwax (tmp2, stack));
6265   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6266   DONE;
6267 }
6268   [(set_attr "type" "fpload")
6269    (set_attr "length" "16")])
6270
6271 (define_insn_and_split "*roundu32<mode>2_fprs"
6272   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6273         (unsigned_float:SFDF
6274          (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6275    (clobber (match_scratch:DI 2 "=d"))
6276    (clobber (match_scratch:DI 3 "=d"))]
6277   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6278    && TARGET_LFIWZX && TARGET_STFIWX && TARGET_FCFIDU
6279    && can_create_pseudo_p ()"
6280   "#"
6281   ""
6282   [(pc)]
6283 {
6284   rtx dest = operands[0];
6285   rtx src = operands[1];
6286   rtx tmp1 = operands[2];
6287   rtx tmp2 = operands[3];
6288   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6289
6290   if (GET_CODE (tmp1) == SCRATCH)
6291     tmp1 = gen_reg_rtx (DImode);
6292   if (GET_CODE (tmp2) == SCRATCH)
6293     tmp2 = gen_reg_rtx (DImode);
6294
6295   emit_insn (gen_fctiwuz_<mode> (tmp1, src));
6296   emit_insn (gen_stfiwx (stack, tmp1));
6297   emit_insn (gen_lfiwzx (tmp2, stack));
6298   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6299   DONE;
6300 }
6301   [(set_attr "type" "fpload")
6302    (set_attr "length" "16")])
6303
6304 ;; No VSX equivalent to fctid
6305 (define_insn "lrint<mode>di2"
6306   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6307         (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6308                    UNSPEC_FCTID))]
6309   "TARGET_<MODE>_FPR && TARGET_FPRND"
6310   "fctid %0,%1"
6311   [(set_attr "type" "fp")])
6312
6313 (define_insn "btrunc<mode>2"
6314   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6315         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6316                      UNSPEC_FRIZ))]
6317   "TARGET_<MODE>_FPR && TARGET_FPRND"
6318   "@
6319    friz %0,%1
6320    xsrdpiz %x0,%x1"
6321   [(set_attr "type" "fp")
6322    (set_attr "fp_type" "fp_addsub_<Fs>")])
6323
6324 (define_insn "ceil<mode>2"
6325   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6326         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6327                      UNSPEC_FRIP))]
6328   "TARGET_<MODE>_FPR && TARGET_FPRND"
6329   "@
6330    frip %0,%1
6331    xsrdpip %x0,%x1"
6332   [(set_attr "type" "fp")
6333    (set_attr "fp_type" "fp_addsub_<Fs>")])
6334
6335 (define_insn "floor<mode>2"
6336   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6337         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6338                      UNSPEC_FRIM))]
6339   "TARGET_<MODE>_FPR && TARGET_FPRND"
6340   "@
6341    frim %0,%1
6342    xsrdpim %x0,%x1"
6343   [(set_attr "type" "fp")
6344    (set_attr "fp_type" "fp_addsub_<Fs>")])
6345
6346 ;; No VSX equivalent to frin
6347 (define_insn "round<mode>2"
6348   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6349         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6350                      UNSPEC_FRIN))]
6351   "TARGET_<MODE>_FPR && TARGET_FPRND"
6352   "frin %0,%1"
6353   [(set_attr "type" "fp")
6354    (set_attr "fp_type" "fp_addsub_<Fs>")])
6355
6356 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6357 (define_insn "stfiwx"
6358   [(set (match_operand:SI 0 "memory_operand" "=Z")
6359         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
6360                    UNSPEC_STFIWX))]
6361   "TARGET_PPC_GFXOPT"
6362   "stfiwx %1,%y0"
6363   [(set_attr "type" "fpstore")])
6364
6365 ;; If we don't have a direct conversion to single precision, don't enable this
6366 ;; conversion for 32-bit without fast math, because we don't have the insn to
6367 ;; generate the fixup swizzle to avoid double rounding problems.
6368 (define_expand "floatsisf2"
6369   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6370         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
6371   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
6372    && (!TARGET_FPRS
6373        || (TARGET_FPRS
6374            && ((TARGET_FCFIDS && TARGET_LFIWAX)
6375                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
6376                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
6377   "
6378 {
6379   if (!TARGET_FPRS)
6380     {
6381       if (!REG_P (operands[1]))
6382         operands[1] = force_reg (SImode, operands[1]);
6383     }
6384   else if (TARGET_FCFIDS && TARGET_LFIWAX)
6385     {
6386       emit_insn (gen_floatsisf2_lfiwax (operands[0], operands[1]));
6387       DONE;
6388     }
6389   else if (TARGET_FCFID && TARGET_LFIWAX)
6390     {
6391       rtx dfreg = gen_reg_rtx (DFmode);
6392       emit_insn (gen_floatsidf2_lfiwax (dfreg, operands[1]));
6393       emit_insn (gen_truncdfsf2 (operands[0], dfreg));
6394       DONE;
6395     }
6396   else
6397     {
6398       rtx dreg = operands[1];
6399       if (!REG_P (dreg))
6400         dreg = force_reg (SImode, dreg);
6401       dreg = convert_to_mode (DImode, dreg, false);
6402       emit_insn (gen_floatdisf2 (operands[0], dreg));
6403       DONE;
6404     }
6405 }")
6406
6407 (define_expand "floatdidf2"
6408   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6409         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
6410   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
6411   "")
6412
6413 (define_insn "*floatdidf2_fpr"
6414   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6415         (float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6416   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6417    && !VECTOR_UNIT_VSX_P (DFmode)"
6418   "fcfid %0,%1"
6419   [(set_attr "type" "fp")])
6420
6421 ; Allow the combiner to merge source memory operands to the conversion so that
6422 ; the optimizer/register allocator doesn't try to load the value too early in a
6423 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
6424 ; hit.  We will split after reload to avoid the trip through the GPRs
6425
6426 (define_insn_and_split "*floatdidf2_mem"
6427   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6428         (float:DF (match_operand:DI 1 "memory_operand" "m")))
6429    (clobber (match_scratch:DI 2 "=d"))]
6430   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCFID"
6431   "#"
6432   "&& reload_completed"
6433   [(set (match_dup 2) (match_dup 1))
6434    (set (match_dup 0) (float:DF (match_dup 2)))]
6435   ""
6436   [(set_attr "length" "8")
6437    (set_attr "type" "fpload")])
6438
6439 (define_expand "floatunsdidf2"
6440   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6441         (unsigned_float:DF
6442          (match_operand:DI 1 "gpc_reg_operand" "")))]
6443   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
6444   "")
6445
6446 (define_insn "*floatunsdidf2_fcfidu"
6447   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6448         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6449   "TARGET_HARD_FLOAT && TARGET_FCFIDU && !VECTOR_UNIT_VSX_P (DFmode)"
6450   "fcfidu %0,%1"
6451   [(set_attr "type" "fp")
6452    (set_attr "length" "4")])
6453
6454 (define_insn_and_split "*floatunsdidf2_mem"
6455   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6456         (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m")))
6457    (clobber (match_scratch:DI 2 "=d"))]
6458   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
6459   "#"
6460   "&& reload_completed"
6461   [(set (match_dup 2) (match_dup 1))
6462    (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
6463   ""
6464   [(set_attr "length" "8")
6465    (set_attr "type" "fpload")])
6466
6467 (define_expand "floatdisf2"
6468   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6469         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6470   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6471    && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
6472   "
6473 {
6474   if (!TARGET_FCFIDS)
6475     {
6476       rtx val = operands[1];
6477       if (!flag_unsafe_math_optimizations)
6478         {
6479           rtx label = gen_label_rtx ();
6480           val = gen_reg_rtx (DImode);
6481           emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
6482           emit_label (label);
6483         }
6484       emit_insn (gen_floatdisf2_internal1 (operands[0], val));
6485       DONE;
6486     }
6487 }")
6488
6489 (define_insn "floatdisf2_fcfids"
6490   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6491         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6492   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6493    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
6494   "fcfids %0,%1"
6495   [(set_attr "type" "fp")])
6496
6497 (define_insn_and_split "*floatdisf2_mem"
6498   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6499         (float:SF (match_operand:DI 1 "memory_operand" "m")))
6500    (clobber (match_scratch:DI 2 "=f"))]
6501   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6502    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
6503   "#"
6504   "&& reload_completed"
6505   [(pc)]
6506   "
6507 {
6508   emit_move_insn (operands[2], operands[1]);
6509   emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
6510   DONE;
6511 }"
6512   [(set_attr "length" "8")])
6513
6514 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6515 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6516 ;; from double rounding.
6517 ;; Instead of creating a new cpu type for two FP operations, just use fp
6518 (define_insn_and_split "floatdisf2_internal1"
6519   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6520         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
6521    (clobber (match_scratch:DF 2 "=d"))]
6522   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6523   "#"
6524   "&& reload_completed"
6525   [(set (match_dup 2)
6526         (float:DF (match_dup 1)))
6527    (set (match_dup 0)
6528         (float_truncate:SF (match_dup 2)))]
6529   ""
6530   [(set_attr "length" "8")
6531    (set_attr "type" "fp")])
6532
6533 ;; Twiddles bits to avoid double rounding.
6534 ;; Bits that might be truncated when converting to DFmode are replaced
6535 ;; by a bit that won't be lost at that stage, but is below the SFmode
6536 ;; rounding position.
6537 (define_expand "floatdisf2_internal2"
6538   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6539                                    (const_int 53)))
6540    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6541                                                       (const_int 2047)))
6542               (clobber (scratch:CC))])
6543    (set (match_dup 3) (plus:DI (match_dup 3)
6544                                (const_int 1)))
6545    (set (match_dup 0) (plus:DI (match_dup 0)
6546                                (const_int 2047)))
6547    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6548                                      (const_int 2)))
6549    (set (match_dup 0) (ior:DI (match_dup 0)
6550                               (match_dup 1)))
6551    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6552                                          (const_int -2048)))
6553               (clobber (scratch:CC))])
6554    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6555                            (label_ref (match_operand:DI 2 "" ""))
6556                            (pc)))
6557    (set (match_dup 0) (match_dup 1))]
6558   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6559   "
6560 {
6561   operands[3] = gen_reg_rtx (DImode);
6562   operands[4] = gen_reg_rtx (CCUNSmode);
6563 }")
6564
6565 (define_expand "floatunsdisf2"
6566   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6567         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6568   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6569    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6570   "")
6571
6572 (define_insn "floatunsdisf2_fcfidus"
6573   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6574         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6575   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6576    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6577   "fcfidus %0,%1"
6578   [(set_attr "type" "fp")])
6579
6580 (define_insn_and_split "*floatunsdisf2_mem"
6581   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6582         (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m")))
6583    (clobber (match_scratch:DI 2 "=f"))]
6584   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6585    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6586   "#"
6587   "&& reload_completed"
6588   [(pc)]
6589   "
6590 {
6591   emit_move_insn (operands[2], operands[1]);
6592   emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
6593   DONE;
6594 }"
6595   [(set_attr "length" "8")
6596    (set_attr "type" "fpload")])
6597 \f
6598 ;; Define the TImode operations that can be done in a small number
6599 ;; of instructions.  The & constraints are to prevent the register
6600 ;; allocator from allocating registers that overlap with the inputs
6601 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6602 ;; also allow for the output being the same as one of the inputs.
6603
6604 (define_insn "addti3"
6605   [(set (match_operand:TI 0 "gpc_reg_operand" "=&r,&r,r,r")
6606         (plus:TI (match_operand:TI 1 "gpc_reg_operand" "%r,r,0,0")
6607                  (match_operand:TI 2 "reg_or_short_operand" "r,I,r,I")))]
6608   "TARGET_64BIT"
6609 {
6610   if (WORDS_BIG_ENDIAN)
6611     return (GET_CODE (operands[2])) != CONST_INT
6612             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6613             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6614   else
6615     return (GET_CODE (operands[2])) != CONST_INT
6616             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6617             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6618 }
6619   [(set_attr "type" "two")
6620    (set_attr "length" "8")])
6621
6622 (define_insn "subti3"
6623   [(set (match_operand:TI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6624         (minus:TI (match_operand:TI 1 "reg_or_short_operand" "r,I,0,r,I")
6625                   (match_operand:TI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6626   "TARGET_64BIT"
6627 {
6628   if (WORDS_BIG_ENDIAN)
6629     return (GET_CODE (operands[1]) != CONST_INT)
6630             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6631             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6632   else
6633     return (GET_CODE (operands[1]) != CONST_INT)
6634             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6635             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6636 }
6637   [(set_attr "type" "two")
6638    (set_attr "length" "8")])
6639
6640
6641 ;; Define the DImode operations that can be done in a small number
6642 ;; of instructions.  The & constraints are to prevent the register
6643 ;; allocator from allocating registers that overlap with the inputs
6644 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6645 ;; also allow for the output being the same as one of the inputs.
6646
6647 (define_insn "*adddi3_noppc64"
6648   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6649         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6650                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6651   "! TARGET_POWERPC64"
6652   "*
6653 {
6654   if (WORDS_BIG_ENDIAN)
6655     return (GET_CODE (operands[2])) != CONST_INT
6656             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6657             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6658   else
6659     return (GET_CODE (operands[2])) != CONST_INT
6660             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6661             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6662 }"
6663   [(set_attr "type" "two")
6664    (set_attr "length" "8")])
6665
6666 (define_insn "*subdi3_noppc64"
6667   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6668         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6669                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6670   "! TARGET_POWERPC64"
6671   "*
6672 {
6673   if (WORDS_BIG_ENDIAN)
6674     return (GET_CODE (operands[1]) != CONST_INT)
6675             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6676             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6677   else
6678     return (GET_CODE (operands[1]) != CONST_INT)
6679             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6680             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6681 }"
6682   [(set_attr "type" "two")
6683    (set_attr "length" "8")])
6684
6685 (define_insn "*negdi2_noppc64"
6686   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6687         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6688   "! TARGET_POWERPC64"
6689   "*
6690 {
6691   return (WORDS_BIG_ENDIAN)
6692     ? \"subfic %L0,%L1,0\;subfze %0,%1\"
6693     : \"subfic %0,%1,0\;subfze %L0,%L1\";
6694 }"
6695   [(set_attr "type" "two")
6696    (set_attr "length" "8")])
6697
6698 (define_insn "mulsidi3"
6699   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6700         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6701                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6702   "! TARGET_POWERPC64"
6703 {
6704   return (WORDS_BIG_ENDIAN)
6705     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6706     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6707 }
6708   [(set_attr "type" "mul")
6709    (set_attr "length" "8")])
6710
6711 (define_split
6712   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6713         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6714                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6715   "! TARGET_POWERPC64 && reload_completed"
6716   [(set (match_dup 3)
6717         (truncate:SI
6718          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6719                                (sign_extend:DI (match_dup 2)))
6720                       (const_int 32))))
6721    (set (match_dup 4)
6722         (mult:SI (match_dup 1)
6723                  (match_dup 2)))]
6724   "
6725 {
6726   int endian = (WORDS_BIG_ENDIAN == 0);
6727   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6728   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6729 }")
6730
6731 (define_insn "umulsidi3"
6732   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6733         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6734                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6735   "! TARGET_POWERPC64"
6736   "*
6737 {
6738   return (WORDS_BIG_ENDIAN)
6739     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6740     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6741 }"
6742   [(set_attr "type" "mul")
6743    (set_attr "length" "8")])
6744
6745 (define_split
6746   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6747         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6748                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6749   "! TARGET_POWERPC64 && reload_completed"
6750   [(set (match_dup 3)
6751         (truncate:SI
6752          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6753                                (zero_extend:DI (match_dup 2)))
6754                       (const_int 32))))
6755    (set (match_dup 4)
6756         (mult:SI (match_dup 1)
6757                  (match_dup 2)))]
6758   "
6759 {
6760   int endian = (WORDS_BIG_ENDIAN == 0);
6761   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6762   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6763 }")
6764
6765 (define_insn "smulsi3_highpart"
6766   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6767         (truncate:SI
6768          (lshiftrt:DI (mult:DI (sign_extend:DI
6769                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6770                                (sign_extend:DI
6771                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6772                       (const_int 32))))]
6773   ""
6774   "mulhw %0,%1,%2"
6775   [(set_attr "type" "mul")])
6776
6777 (define_insn "umulsi3_highpart"
6778   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6779         (truncate:SI
6780          (lshiftrt:DI (mult:DI (zero_extend:DI
6781                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6782                                (zero_extend:DI
6783                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6784                       (const_int 32))))]
6785   ""
6786   "mulhwu %0,%1,%2"
6787   [(set_attr "type" "mul")])
6788
6789 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6790 ;; just handle shifts by constants.
6791 (define_insn "ashrdi3_no_power"
6792   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6793         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6794                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6795   "!TARGET_POWERPC64"
6796   "*
6797 {
6798   switch (which_alternative)
6799     {
6800     default:
6801       gcc_unreachable ();
6802     case 0:
6803       if (WORDS_BIG_ENDIAN)
6804         return \"srawi %0,%1,31\;srawi %L0,%1,%h2\";
6805       else
6806         return \"srawi %L0,%L1,31\;srawi %0,%L1,%h2\";
6807     case 1:
6808       if (WORDS_BIG_ENDIAN)
6809         return \"srwi %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;srawi %0,%1,%h2\";
6810       else
6811         return \"srwi %0,%1,%h2\;insrwi %0,%L1,%h2,0\;srawi %L0,%L1,%h2\";
6812     }
6813 }"
6814   [(set_attr "type" "two,three")
6815    (set_attr "length" "8,12")])
6816
6817 (define_insn "*ashrdisi3_noppc64be"
6818   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6819         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6820                                 (const_int 32)) 4))]
6821   "TARGET_32BIT && !TARGET_POWERPC64 && WORDS_BIG_ENDIAN"
6822   "*
6823 {
6824   if (REGNO (operands[0]) == REGNO (operands[1]))
6825     return \"\";
6826   else
6827     return \"mr %0,%1\";
6828 }"
6829    [(set_attr "length" "4")])
6830
6831 \f
6832 ;; PowerPC64 DImode operations.
6833
6834 (define_insn "muldi3"
6835   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6836         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6837                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6838   "TARGET_POWERPC64"
6839   "@
6840    mulld %0,%1,%2
6841    mulli %0,%1,%2"
6842    [(set_attr "type" "mul")
6843     (set (attr "size")
6844       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6845                 (const_string "8")
6846              (match_operand:SI 2 "short_cint_operand" "")
6847                 (const_string "16")]
6848         (const_string "64")))])
6849
6850 (define_insn "*muldi3_internal1"
6851   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6852         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6853                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6854                     (const_int 0)))
6855    (clobber (match_scratch:DI 3 "=r,r"))]
6856   "TARGET_POWERPC64"
6857   "@
6858    mulld. %3,%1,%2
6859    #"
6860   [(set_attr "type" "mul")
6861    (set_attr "size" "64")
6862    (set_attr "dot" "yes")
6863    (set_attr "length" "4,8")])
6864
6865 (define_split
6866   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6867         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6868                              (match_operand:DI 2 "gpc_reg_operand" ""))
6869                     (const_int 0)))
6870    (clobber (match_scratch:DI 3 ""))]
6871   "TARGET_POWERPC64 && reload_completed"
6872   [(set (match_dup 3)
6873         (mult:DI (match_dup 1) (match_dup 2)))
6874    (set (match_dup 0)
6875         (compare:CC (match_dup 3)
6876                     (const_int 0)))]
6877   "")
6878
6879 (define_insn "*muldi3_internal2"
6880   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6881         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6882                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6883                     (const_int 0)))
6884    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6885         (mult:DI (match_dup 1) (match_dup 2)))]
6886   "TARGET_POWERPC64"
6887   "@
6888    mulld. %0,%1,%2
6889    #"
6890   [(set_attr "type" "mul")
6891    (set_attr "size" "64")
6892    (set_attr "dot" "yes")
6893    (set_attr "length" "4,8")])
6894
6895 (define_split
6896   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6897         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6898                              (match_operand:DI 2 "gpc_reg_operand" ""))
6899                     (const_int 0)))
6900    (set (match_operand:DI 0 "gpc_reg_operand" "")
6901         (mult:DI (match_dup 1) (match_dup 2)))]
6902   "TARGET_POWERPC64 && reload_completed"
6903   [(set (match_dup 0)
6904         (mult:DI (match_dup 1) (match_dup 2)))
6905    (set (match_dup 3)
6906         (compare:CC (match_dup 0)
6907                     (const_int 0)))]
6908   "")
6909
6910 (define_insn "smuldi3_highpart"
6911   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6912         (truncate:DI
6913          (lshiftrt:TI (mult:TI (sign_extend:TI
6914                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6915                                (sign_extend:TI
6916                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6917                       (const_int 64))))]
6918   "TARGET_POWERPC64"
6919   "mulhd %0,%1,%2"
6920   [(set_attr "type" "mul")
6921    (set_attr "size" "64")])
6922
6923 (define_insn "umuldi3_highpart"
6924   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6925         (truncate:DI
6926          (lshiftrt:TI (mult:TI (zero_extend:TI
6927                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6928                                (zero_extend:TI
6929                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6930                       (const_int 64))))]
6931   "TARGET_POWERPC64"
6932   "mulhdu %0,%1,%2"
6933   [(set_attr "type" "mul")
6934    (set_attr "size" "64")])
6935
6936 (define_expand "mulditi3"
6937   [(set (match_operand:TI 0 "gpc_reg_operand")
6938         (mult:TI (sign_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6939                  (sign_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6940   "TARGET_POWERPC64"
6941 {
6942   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6943   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6944   emit_insn (gen_smuldi3_highpart (h, operands[1], operands[2]));
6945   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6946   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6947   DONE;
6948 })
6949
6950 (define_expand "umulditi3"
6951   [(set (match_operand:TI 0 "gpc_reg_operand")
6952         (mult:TI (zero_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6953                  (zero_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6954   "TARGET_POWERPC64"
6955 {
6956   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6957   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6958   emit_insn (gen_umuldi3_highpart (h, operands[1], operands[2]));
6959   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6960   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6961   DONE;
6962 })
6963
6964 (define_insn "*rotldi3_internal4"
6965   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6966         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6967                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
6968                 (match_operand:DI 3 "mask64_operand" "n,n")))]
6969   "TARGET_POWERPC64"
6970   "@
6971    rldc%B3 %0,%1,%2,%S3
6972    rldic%B3 %0,%1,%H2,%S3"
6973   [(set_attr "type" "shift")
6974    (set_attr "var_shift" "yes,no")])
6975
6976 (define_insn "*rotldi3_internal5"
6977   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6978         (compare:CC (and:DI
6979                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6980                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6981                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6982                     (const_int 0)))
6983    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
6984   "TARGET_64BIT"
6985   "@
6986    rldc%B3. %4,%1,%2,%S3
6987    rldic%B3. %4,%1,%H2,%S3
6988    #
6989    #"
6990   [(set_attr "type" "shift")
6991    (set_attr "var_shift" "yes,no,yes,no")
6992    (set_attr "dot" "yes")
6993    (set_attr "length" "4,4,8,8")])
6994
6995 (define_split
6996   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6997         (compare:CC (and:DI
6998                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6999                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7000                      (match_operand:DI 3 "mask64_operand" ""))
7001                     (const_int 0)))
7002    (clobber (match_scratch:DI 4 ""))]
7003   "TARGET_POWERPC64 && reload_completed"
7004   [(set (match_dup 4)
7005         (and:DI (rotate:DI (match_dup 1)
7006                                 (match_dup 2))
7007                      (match_dup 3)))
7008    (set (match_dup 0)
7009         (compare:CC (match_dup 4)
7010                     (const_int 0)))]
7011   "")
7012
7013 (define_insn "*rotldi3_internal6"
7014   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
7015         (compare:CC (and:DI
7016                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7017                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7018                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7019                     (const_int 0)))
7020    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7021         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7022   "TARGET_64BIT"
7023   "@
7024    rldc%B3. %0,%1,%2,%S3
7025    rldic%B3. %0,%1,%H2,%S3
7026    #
7027    #"
7028   [(set_attr "type" "shift")
7029    (set_attr "var_shift" "yes,no,yes,no")
7030    (set_attr "dot" "yes")
7031    (set_attr "length" "4,4,8,8")])
7032
7033 (define_split
7034   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7035         (compare:CC (and:DI
7036                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7037                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7038                      (match_operand:DI 3 "mask64_operand" ""))
7039                     (const_int 0)))
7040    (set (match_operand:DI 0 "gpc_reg_operand" "")
7041         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7042   "TARGET_POWERPC64 && reload_completed"
7043   [(set (match_dup 0)
7044         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
7045    (set (match_dup 4)
7046         (compare:CC (match_dup 0)
7047                     (const_int 0)))]
7048   "")
7049
7050 (define_insn "*rotldi3_internal7le"
7051   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7052         (zero_extend:DI
7053          (subreg:QI
7054           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7055                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7056   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7057   "@
7058    rldcl %0,%1,%2,56
7059    rldicl %0,%1,%H2,56"
7060   [(set_attr "type" "shift")
7061    (set_attr "var_shift" "yes,no")])
7062
7063 (define_insn "*rotldi3_internal7be"
7064   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7065         (zero_extend:DI
7066          (subreg:QI
7067           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7068                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 7)))]
7069   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7070   "@
7071    rldcl %0,%1,%2,56
7072    rldicl %0,%1,%H2,56"
7073   [(set_attr "type" "shift")
7074    (set_attr "var_shift" "yes,no")])
7075
7076 (define_insn "*rotldi3_internal8le"
7077   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7078         (compare:CC (zero_extend:DI
7079                      (subreg:QI
7080                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7081                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7082                     (const_int 0)))
7083    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7084   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7085   "@
7086    rldcl. %3,%1,%2,56
7087    rldicl. %3,%1,%H2,56
7088    #
7089    #"
7090   [(set_attr "type" "shift")
7091    (set_attr "var_shift" "yes,no,yes,no")
7092    (set_attr "dot" "yes")
7093    (set_attr "length" "4,4,8,8")])
7094
7095 (define_insn "*rotldi3_internal8be"
7096   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7097         (compare:CC (zero_extend:DI
7098                      (subreg:QI
7099                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7100                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 7))
7101                     (const_int 0)))
7102    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7103   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7104   "@
7105    rldcl. %3,%1,%2,56
7106    rldicl. %3,%1,%H2,56
7107    #
7108    #"
7109   [(set_attr "type" "shift")
7110    (set_attr "var_shift" "yes,no,yes,no")
7111    (set_attr "dot" "yes")
7112    (set_attr "length" "4,4,8,8")])
7113
7114 (define_split
7115   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7116         (compare:CC (zero_extend:DI
7117                      (subreg:QI
7118                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7119                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7120                     (const_int 0)))
7121    (clobber (match_scratch:DI 3 ""))]
7122   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7123   [(set (match_dup 3)
7124         (zero_extend:DI (subreg:QI
7125                       (rotate:DI (match_dup 1)
7126                                  (match_dup 2)) 0)))
7127    (set (match_dup 0)
7128         (compare:CC (match_dup 3)
7129                     (const_int 0)))]
7130   "")
7131
7132 (define_split
7133   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7134         (compare:CC (zero_extend:DI
7135                      (subreg:QI
7136                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7137                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 7))
7138                     (const_int 0)))
7139    (clobber (match_scratch:DI 3 ""))]
7140   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7141   [(set (match_dup 3)
7142         (zero_extend:DI (subreg:QI
7143                       (rotate:DI (match_dup 1)
7144                                  (match_dup 2)) 7)))
7145    (set (match_dup 0)
7146         (compare:CC (match_dup 3)
7147                     (const_int 0)))]
7148   "")
7149
7150 (define_insn "*rotldi3_internal9le"
7151   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7152         (compare:CC (zero_extend:DI
7153                      (subreg:QI
7154                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7155                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7156                     (const_int 0)))
7157    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7158         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7159   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7160   "@
7161    rldcl. %0,%1,%2,56
7162    rldicl. %0,%1,%H2,56
7163    #
7164    #"
7165   [(set_attr "type" "shift")
7166    (set_attr "var_shift" "yes,no,yes,no")
7167    (set_attr "dot" "yes")
7168    (set_attr "length" "4,4,8,8")])
7169
7170 (define_insn "*rotldi3_internal9be"
7171   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7172         (compare:CC (zero_extend:DI
7173                      (subreg:QI
7174                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7175                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 7))
7176                     (const_int 0)))
7177    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7178         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))]
7179   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7180   "@
7181    rldcl. %0,%1,%2,56
7182    rldicl. %0,%1,%H2,56
7183    #
7184    #"
7185   [(set_attr "type" "shift")
7186    (set_attr "var_shift" "yes,no,yes,no")
7187    (set_attr "dot" "yes")
7188    (set_attr "length" "4,4,8,8")])
7189
7190 (define_split
7191   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7192         (compare:CC (zero_extend:DI
7193                      (subreg:QI
7194                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7195                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7196                     (const_int 0)))
7197    (set (match_operand:DI 0 "gpc_reg_operand" "")
7198         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7199   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7200   [(set (match_dup 0)
7201         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7202    (set (match_dup 3)
7203         (compare:CC (match_dup 0)
7204                     (const_int 0)))]
7205   "")
7206
7207 (define_split
7208   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7209         (compare:CC (zero_extend:DI
7210                      (subreg:QI
7211                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7212                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 7))
7213                     (const_int 0)))
7214    (set (match_operand:DI 0 "gpc_reg_operand" "")
7215         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))]
7216   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7217   [(set (match_dup 0)
7218         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))
7219    (set (match_dup 3)
7220         (compare:CC (match_dup 0)
7221                     (const_int 0)))]
7222   "")
7223
7224 (define_insn "*rotldi3_internal10le"
7225   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7226         (zero_extend:DI
7227          (subreg:HI
7228           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7229                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7230   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7231   "@
7232    rldcl %0,%1,%2,48
7233    rldicl %0,%1,%H2,48"
7234   [(set_attr "type" "shift")
7235    (set_attr "var_shift" "yes,no")])
7236
7237 (define_insn "*rotldi3_internal10be"
7238   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7239         (zero_extend:DI
7240          (subreg:HI
7241           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7242                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 6)))]
7243   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7244   "@
7245    rldcl %0,%1,%2,48
7246    rldicl %0,%1,%H2,48"
7247   [(set_attr "type" "shift")
7248    (set_attr "var_shift" "yes,no")])
7249
7250 (define_insn "*rotldi3_internal11le"
7251   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7252         (compare:CC (zero_extend:DI
7253                      (subreg:HI
7254                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7255                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7256                     (const_int 0)))
7257    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7258   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7259   "@
7260    rldcl. %3,%1,%2,48
7261    rldicl. %3,%1,%H2,48
7262    #
7263    #"
7264   [(set_attr "type" "shift")
7265    (set_attr "var_shift" "yes,no,yes,no")
7266    (set_attr "dot" "yes")
7267    (set_attr "length" "4,4,8,8")])
7268
7269 (define_insn "*rotldi3_internal11be"
7270   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7271         (compare:CC (zero_extend:DI
7272                      (subreg:HI
7273                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7274                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 6))
7275                     (const_int 0)))
7276    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7277   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7278   "@
7279    rldcl. %3,%1,%2,48
7280    rldicl. %3,%1,%H2,48
7281    #
7282    #"
7283   [(set_attr "type" "shift")
7284    (set_attr "var_shift" "yes,no,yes,no")
7285    (set_attr "dot" "yes")
7286    (set_attr "length" "4,4,8,8")])
7287
7288 (define_split
7289   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7290         (compare:CC (zero_extend:DI
7291                      (subreg:HI
7292                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7293                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7294                     (const_int 0)))
7295    (clobber (match_scratch:DI 3 ""))]
7296   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7297   [(set (match_dup 3)
7298         (zero_extend:DI (subreg:HI
7299                       (rotate:DI (match_dup 1)
7300                                  (match_dup 2)) 0)))
7301    (set (match_dup 0)
7302         (compare:CC (match_dup 3)
7303                     (const_int 0)))]
7304   "")
7305
7306 (define_split
7307   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7308         (compare:CC (zero_extend:DI
7309                      (subreg:HI
7310                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7311                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 6))
7312                     (const_int 0)))
7313    (clobber (match_scratch:DI 3 ""))]
7314   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7315   [(set (match_dup 3)
7316         (zero_extend:DI (subreg:HI
7317                       (rotate:DI (match_dup 1)
7318                                  (match_dup 2)) 6)))
7319    (set (match_dup 0)
7320         (compare:CC (match_dup 3)
7321                     (const_int 0)))]
7322   "")
7323
7324 (define_insn "*rotldi3_internal12le"
7325   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7326         (compare:CC (zero_extend:DI
7327                      (subreg:HI
7328                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7329                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7330                     (const_int 0)))
7331    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7332         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7333   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7334   "@
7335    rldcl. %0,%1,%2,48
7336    rldicl. %0,%1,%H2,48
7337    #
7338    #"
7339   [(set_attr "type" "shift")
7340    (set_attr "var_shift" "yes,no,yes,no")
7341    (set_attr "dot" "yes")
7342    (set_attr "length" "4,4,8,8")])
7343
7344 (define_insn "*rotldi3_internal12be"
7345   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7346         (compare:CC (zero_extend:DI
7347                      (subreg:HI
7348                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7349                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 6))
7350                     (const_int 0)))
7351    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7352         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))]
7353   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7354   "@
7355    rldcl. %0,%1,%2,48
7356    rldicl. %0,%1,%H2,48
7357    #
7358    #"
7359   [(set_attr "type" "shift")
7360    (set_attr "var_shift" "yes,no,yes,no")
7361    (set_attr "dot" "yes")
7362    (set_attr "length" "4,4,8,8")])
7363
7364 (define_split
7365   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7366         (compare:CC (zero_extend:DI
7367                      (subreg:HI
7368                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7369                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7370                     (const_int 0)))
7371    (set (match_operand:DI 0 "gpc_reg_operand" "")
7372         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7373   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7374   [(set (match_dup 0)
7375         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7376    (set (match_dup 3)
7377         (compare:CC (match_dup 0)
7378                     (const_int 0)))]
7379   "")
7380
7381 (define_split
7382   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7383         (compare:CC (zero_extend:DI
7384                      (subreg:HI
7385                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7386                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 6))
7387                     (const_int 0)))
7388    (set (match_operand:DI 0 "gpc_reg_operand" "")
7389         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))]
7390   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7391   [(set (match_dup 0)
7392         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))
7393    (set (match_dup 3)
7394         (compare:CC (match_dup 0)
7395                     (const_int 0)))]
7396   "")
7397
7398 (define_insn "*rotldi3_internal13le"
7399   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7400         (zero_extend:DI
7401          (subreg:SI
7402           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7403                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7404   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7405   "@
7406    rldcl %0,%1,%2,32
7407    rldicl %0,%1,%H2,32"
7408   [(set_attr "type" "shift")
7409    (set_attr "var_shift" "yes,no")])
7410
7411 (define_insn "*rotldi3_internal13be"
7412   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7413         (zero_extend:DI
7414          (subreg:SI
7415           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7416                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 4)))]
7417   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7418   "@
7419    rldcl %0,%1,%2,32
7420    rldicl %0,%1,%H2,32"
7421   [(set_attr "type" "shift")
7422    (set_attr "var_shift" "yes,no")])
7423
7424 (define_insn "*rotldi3_internal14le"
7425   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7426         (compare:CC (zero_extend:DI
7427                      (subreg:SI
7428                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7429                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7430                     (const_int 0)))
7431    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7432   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7433   "@
7434    rldcl. %3,%1,%2,32
7435    rldicl. %3,%1,%H2,32
7436    #
7437    #"
7438   [(set_attr "type" "shift")
7439    (set_attr "var_shift" "yes,no,yes,no")
7440    (set_attr "dot" "yes")
7441    (set_attr "length" "4,4,8,8")])
7442
7443 (define_insn "*rotldi3_internal14be"
7444   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7445         (compare:CC (zero_extend:DI
7446                      (subreg:SI
7447                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7448                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 4))
7449                     (const_int 0)))
7450    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7451   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7452   "@
7453    rldcl. %3,%1,%2,32
7454    rldicl. %3,%1,%H2,32
7455    #
7456    #"
7457   [(set_attr "type" "shift")
7458    (set_attr "var_shift" "yes,no,yes,no")
7459    (set_attr "dot" "yes")
7460    (set_attr "length" "4,4,8,8")])
7461
7462 (define_split
7463   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7464         (compare:CC (zero_extend:DI
7465                      (subreg:SI
7466                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7467                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7468                     (const_int 0)))
7469    (clobber (match_scratch:DI 3 ""))]
7470   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7471   [(set (match_dup 3)
7472         (zero_extend:DI (subreg:SI
7473                       (rotate:DI (match_dup 1)
7474                                  (match_dup 2)) 0)))
7475    (set (match_dup 0)
7476         (compare:CC (match_dup 3)
7477                     (const_int 0)))]
7478   "")
7479
7480 (define_split
7481   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7482         (compare:CC (zero_extend:DI
7483                      (subreg:SI
7484                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7485                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 4))
7486                     (const_int 0)))
7487    (clobber (match_scratch:DI 3 ""))]
7488   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7489   [(set (match_dup 3)
7490         (zero_extend:DI (subreg:SI
7491                       (rotate:DI (match_dup 1)
7492                                  (match_dup 2)) 4)))
7493    (set (match_dup 0)
7494         (compare:CC (match_dup 3)
7495                     (const_int 0)))]
7496   "")
7497
7498 (define_insn "*rotldi3_internal15le"
7499   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7500         (compare:CC (zero_extend:DI
7501                      (subreg:SI
7502                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7503                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7504                     (const_int 0)))
7505    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7506         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7507   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7508   "@
7509    rldcl. %0,%1,%2,32
7510    rldicl. %0,%1,%H2,32
7511    #
7512    #"
7513   [(set_attr "type" "shift")
7514    (set_attr "var_shift" "yes,no,yes,no")
7515    (set_attr "dot" "yes")
7516    (set_attr "length" "4,4,8,8")])
7517
7518 (define_insn "*rotldi3_internal15be"
7519   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7520         (compare:CC (zero_extend:DI
7521                      (subreg:SI
7522                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7523                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 4))
7524                     (const_int 0)))
7525    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7526         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))]
7527   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7528   "@
7529    rldcl. %0,%1,%2,32
7530    rldicl. %0,%1,%H2,32
7531    #
7532    #"
7533   [(set_attr "type" "shift")
7534    (set_attr "var_shift" "yes,no,yes,no")
7535    (set_attr "dot" "yes")
7536    (set_attr "length" "4,4,8,8")])
7537
7538 (define_split
7539   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7540         (compare:CC (zero_extend:DI
7541                      (subreg:SI
7542                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7543                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7544                     (const_int 0)))
7545    (set (match_operand:DI 0 "gpc_reg_operand" "")
7546         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7547   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7548   [(set (match_dup 0)
7549         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7550    (set (match_dup 3)
7551         (compare:CC (match_dup 0)
7552                     (const_int 0)))]
7553   "")
7554
7555 (define_split
7556   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7557         (compare:CC (zero_extend:DI
7558                      (subreg:SI
7559                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7560                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 4))
7561                     (const_int 0)))
7562    (set (match_operand:DI 0 "gpc_reg_operand" "")
7563         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))]
7564   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7565   [(set (match_dup 0)
7566         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))
7567    (set (match_dup 3)
7568         (compare:CC (match_dup 0)
7569                     (const_int 0)))]
7570   "")
7571
7572 (define_insn "*ashldi3_internal4"
7573   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7574         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7575                            (match_operand:SI 2 "const_int_operand" "i"))
7576                 (match_operand:DI 3 "const_int_operand" "n")))]
7577   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7578   "rldic %0,%1,%H2,%W3"
7579   [(set_attr "type" "shift")])
7580
7581 (define_insn "ashldi3_internal5"
7582   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7583         (compare:CC
7584          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7585                             (match_operand:SI 2 "const_int_operand" "i,i"))
7586                  (match_operand:DI 3 "const_int_operand" "n,n"))
7587          (const_int 0)))
7588    (clobber (match_scratch:DI 4 "=r,r"))]
7589   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7590   "@
7591    rldic. %4,%1,%H2,%W3
7592    #"
7593   [(set_attr "type" "shift")
7594    (set_attr "dot" "yes")
7595    (set_attr "length" "4,8")])
7596
7597 (define_split
7598   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7599         (compare:CC
7600          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7601                             (match_operand:SI 2 "const_int_operand" ""))
7602                  (match_operand:DI 3 "const_int_operand" ""))
7603          (const_int 0)))
7604    (clobber (match_scratch:DI 4 ""))]
7605   "TARGET_POWERPC64 && reload_completed
7606    && includes_rldic_lshift_p (operands[2], operands[3])"
7607   [(set (match_dup 4)
7608         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7609                 (match_dup 3)))
7610    (set (match_dup 0)
7611         (compare:CC (match_dup 4)
7612                     (const_int 0)))]
7613   "")
7614
7615 (define_insn "*ashldi3_internal6"
7616   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7617         (compare:CC
7618          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7619                             (match_operand:SI 2 "const_int_operand" "i,i"))
7620                     (match_operand:DI 3 "const_int_operand" "n,n"))
7621          (const_int 0)))
7622    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7623         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7624   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7625   "@
7626    rldic. %0,%1,%H2,%W3
7627    #"
7628   [(set_attr "type" "shift")
7629    (set_attr "dot" "yes")
7630    (set_attr "length" "4,8")])
7631
7632 (define_split
7633   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7634         (compare:CC
7635          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7636                             (match_operand:SI 2 "const_int_operand" ""))
7637                  (match_operand:DI 3 "const_int_operand" ""))
7638          (const_int 0)))
7639    (set (match_operand:DI 0 "gpc_reg_operand" "")
7640         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7641   "TARGET_POWERPC64 && reload_completed
7642    && includes_rldic_lshift_p (operands[2], operands[3])"
7643   [(set (match_dup 0)
7644         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7645                 (match_dup 3)))
7646    (set (match_dup 4)
7647         (compare:CC (match_dup 0)
7648                     (const_int 0)))]
7649   "")
7650
7651 (define_insn "*ashldi3_internal7"
7652   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7653         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7654                            (match_operand:SI 2 "const_int_operand" "i"))
7655                 (match_operand:DI 3 "mask64_operand" "n")))]
7656   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7657   "rldicr %0,%1,%H2,%S3"
7658   [(set_attr "type" "shift")])
7659
7660 (define_insn "ashldi3_internal8"
7661   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7662         (compare:CC
7663          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7664                             (match_operand:SI 2 "const_int_operand" "i,i"))
7665                  (match_operand:DI 3 "mask64_operand" "n,n"))
7666          (const_int 0)))
7667    (clobber (match_scratch:DI 4 "=r,r"))]
7668   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7669   "@
7670    rldicr. %4,%1,%H2,%S3
7671    #"
7672   [(set_attr "type" "shift")
7673    (set_attr "dot" "yes")
7674    (set_attr "length" "4,8")])
7675
7676 (define_split
7677   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7678         (compare:CC
7679          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7680                             (match_operand:SI 2 "const_int_operand" ""))
7681                  (match_operand:DI 3 "mask64_operand" ""))
7682          (const_int 0)))
7683    (clobber (match_scratch:DI 4 ""))]
7684   "TARGET_POWERPC64 && reload_completed
7685    && includes_rldicr_lshift_p (operands[2], operands[3])"
7686   [(set (match_dup 4)
7687         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7688                 (match_dup 3)))
7689    (set (match_dup 0)
7690         (compare:CC (match_dup 4)
7691                     (const_int 0)))]
7692   "")
7693
7694 (define_insn "*ashldi3_internal9"
7695   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7696         (compare:CC
7697          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7698                             (match_operand:SI 2 "const_int_operand" "i,i"))
7699                     (match_operand:DI 3 "mask64_operand" "n,n"))
7700          (const_int 0)))
7701    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7702         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7703   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7704   "@
7705    rldicr. %0,%1,%H2,%S3
7706    #"
7707   [(set_attr "type" "shift")
7708    (set_attr "dot" "yes")
7709    (set_attr "length" "4,8")])
7710
7711 (define_split
7712   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7713         (compare:CC
7714          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7715                             (match_operand:SI 2 "const_int_operand" ""))
7716                  (match_operand:DI 3 "mask64_operand" ""))
7717          (const_int 0)))
7718    (set (match_operand:DI 0 "gpc_reg_operand" "")
7719         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7720   "TARGET_POWERPC64 && reload_completed
7721    && includes_rldicr_lshift_p (operands[2], operands[3])"
7722   [(set (match_dup 0)
7723         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7724                 (match_dup 3)))
7725    (set (match_dup 4)
7726         (compare:CC (match_dup 0)
7727                     (const_int 0)))]
7728   "")
7729
7730 (define_expand "anddi3"
7731   [(parallel
7732     [(set (match_operand:DI 0 "gpc_reg_operand" "")
7733           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7734                   (match_operand:DI 2 "reg_or_cint_operand" "")))
7735      (clobber (match_scratch:CC 3 ""))])]
7736   ""
7737 {
7738   if (!TARGET_POWERPC64)
7739     {
7740       rtx cc = gen_rtx_SCRATCH (CCmode);
7741       rs6000_split_logical (operands, AND, false, false, false, cc);
7742       DONE;
7743     }
7744   else if (!and64_2_operand (operands[2], DImode))
7745     operands[2] = force_reg (DImode, operands[2]);
7746 })
7747
7748 (define_insn "anddi3_mc"
7749   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7750         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7751                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7752    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7753   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
7754   "@
7755    and %0,%1,%2
7756    rldic%B2 %0,%1,0,%S2
7757    rlwinm %0,%1,0,%m2,%M2
7758    andi. %0,%1,%b2
7759    andis. %0,%1,%u2
7760    #"
7761   [(set_attr "type" "*,shift,shift,logical,logical,*")
7762    (set_attr "dot" "no,no,no,yes,yes,no")
7763    (set_attr "length" "4,4,4,4,4,8")])
7764
7765 (define_insn "anddi3_nomc"
7766   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7767         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
7768                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
7769    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
7770   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
7771   "@
7772    and %0,%1,%2
7773    rldic%B2 %0,%1,0,%S2
7774    rlwinm %0,%1,0,%m2,%M2
7775    #"
7776   [(set_attr "type" "*,shift,shift,*")
7777    (set_attr "length" "4,4,4,8")])
7778
7779 (define_split
7780   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7781         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7782                 (match_operand:DI 2 "mask64_2_operand" "")))
7783    (clobber (match_scratch:CC 3 ""))]
7784   "TARGET_POWERPC64
7785     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7786     && !mask_operand (operands[2], DImode)
7787     && !mask64_operand (operands[2], DImode)"
7788   [(set (match_dup 0)
7789         (and:DI (rotate:DI (match_dup 1)
7790                            (match_dup 4))
7791                 (match_dup 5)))
7792    (set (match_dup 0)
7793         (and:DI (rotate:DI (match_dup 0)
7794                            (match_dup 6))
7795                 (match_dup 7)))]
7796 {
7797   build_mask64_2_operands (operands[2], &operands[4]);
7798 })
7799
7800 (define_insn "*anddi3_internal2_mc"
7801   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7802         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7803                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7804                     (const_int 0)))
7805    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
7806    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7807   "TARGET_64BIT && rs6000_gen_cell_microcode"
7808   "@
7809    and. %3,%1,%2
7810    rldic%B2. %3,%1,0,%S2
7811    rlwinm. %3,%1,0,%m2,%M2
7812    andi. %3,%1,%b2
7813    andis. %3,%1,%u2
7814    #
7815    #
7816    #
7817    #
7818    #
7819    #
7820    #"
7821   [(set_attr "type" "logical,shift,shift,logical,\
7822                      logical,compare,compare,compare,compare,compare,\
7823                      compare,compare")
7824    (set_attr "dot" "yes")
7825    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7826
7827 (define_split
7828   [(set (match_operand:CC 0 "cc_reg_operand" "")
7829         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7830                             (match_operand:DI 2 "mask64_2_operand" ""))
7831                     (const_int 0)))
7832    (clobber (match_scratch:DI 3 ""))
7833    (clobber (match_scratch:CC 4 ""))]
7834   "TARGET_64BIT && reload_completed
7835     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7836     && !mask_operand (operands[2], DImode)
7837     && !mask64_operand (operands[2], DImode)"
7838   [(set (match_dup 3)
7839         (and:DI (rotate:DI (match_dup 1)
7840                            (match_dup 5))
7841                 (match_dup 6)))
7842    (parallel [(set (match_dup 0)
7843                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7844                                                   (match_dup 7))
7845                                        (match_dup 8))
7846                                (const_int 0)))
7847               (clobber (match_dup 3))])]
7848   "
7849 {
7850   build_mask64_2_operands (operands[2], &operands[5]);
7851 }")
7852
7853 (define_insn "*anddi3_internal3_mc"
7854   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7855         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7856                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7857                     (const_int 0)))
7858    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
7859         (and:DI (match_dup 1) (match_dup 2)))
7860    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7861   "TARGET_64BIT && rs6000_gen_cell_microcode"
7862   "@
7863    and. %0,%1,%2
7864    rldic%B2. %0,%1,0,%S2
7865    rlwinm. %0,%1,0,%m2,%M2
7866    andi. %0,%1,%b2
7867    andis. %0,%1,%u2
7868    #
7869    #
7870    #
7871    #
7872    #
7873    #
7874    #"
7875   [(set_attr "type" "logical,shift,shift,logical,\
7876                      logical,compare,compare,compare,compare,compare,\
7877                      compare,compare")
7878    (set_attr "dot" "yes")
7879    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7880
7881 (define_split
7882   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7883         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7884                             (match_operand:DI 2 "and64_2_operand" ""))
7885                     (const_int 0)))
7886    (set (match_operand:DI 0 "gpc_reg_operand" "")
7887         (and:DI (match_dup 1) (match_dup 2)))
7888    (clobber (match_scratch:CC 4 ""))]
7889   "TARGET_64BIT && reload_completed"
7890   [(parallel [(set (match_dup 0)
7891                     (and:DI (match_dup 1) (match_dup 2)))
7892                (clobber (match_dup 4))])
7893    (set (match_dup 3)
7894         (compare:CC (match_dup 0)
7895                     (const_int 0)))]
7896   "")
7897
7898 (define_split
7899   [(set (match_operand:CC 3 "cc_reg_operand" "")
7900         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7901                             (match_operand:DI 2 "mask64_2_operand" ""))
7902                     (const_int 0)))
7903    (set (match_operand:DI 0 "gpc_reg_operand" "")
7904         (and:DI (match_dup 1) (match_dup 2)))
7905    (clobber (match_scratch:CC 4 ""))]
7906   "TARGET_64BIT && reload_completed
7907     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7908     && !mask_operand (operands[2], DImode)
7909     && !mask64_operand (operands[2], DImode)"
7910   [(set (match_dup 0)
7911         (and:DI (rotate:DI (match_dup 1)
7912                            (match_dup 5))
7913                 (match_dup 6)))
7914    (parallel [(set (match_dup 3)
7915                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7916                                                   (match_dup 7))
7917                                        (match_dup 8))
7918                                (const_int 0)))
7919               (set (match_dup 0)
7920                    (and:DI (rotate:DI (match_dup 0)
7921                                       (match_dup 7))
7922                            (match_dup 8)))])]
7923   "
7924 {
7925   build_mask64_2_operands (operands[2], &operands[5]);
7926 }")
7927
7928 (define_expand "iordi3"
7929   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7930         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7931                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
7932   ""
7933 {
7934   if (!TARGET_POWERPC64)
7935     {
7936       rs6000_split_logical (operands, IOR, false, false, false, NULL_RTX);
7937       DONE;
7938     }
7939   else if (!reg_or_logical_cint_operand (operands[2], DImode))
7940     operands[2] = force_reg (DImode, operands[2]);
7941   else if (non_logical_cint_operand (operands[2], DImode))
7942     {
7943       HOST_WIDE_INT value;
7944       rtx tmp = ((!can_create_pseudo_p ()
7945                   || rtx_equal_p (operands[0], operands[1]))
7946                  ? operands[0] : gen_reg_rtx (DImode));
7947
7948       value = INTVAL (operands[2]);
7949       emit_insn (gen_iordi3 (tmp, operands[1],
7950                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7951
7952       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7953       DONE;
7954     }
7955 })
7956
7957 (define_expand "xordi3"
7958   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7959         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7960                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
7961   ""
7962 {
7963   if (!TARGET_POWERPC64)
7964     {
7965       rs6000_split_logical (operands, XOR, false, false, false, NULL_RTX);
7966       DONE;
7967     }
7968   else if (!reg_or_logical_cint_operand (operands[2], DImode))
7969     operands[2] = force_reg (DImode, operands[2]);
7970   if (non_logical_cint_operand (operands[2], DImode))
7971     {
7972       HOST_WIDE_INT value;
7973       rtx tmp = ((!can_create_pseudo_p ()
7974                   || rtx_equal_p (operands[0], operands[1]))
7975                  ? operands[0] : gen_reg_rtx (DImode));
7976
7977       value = INTVAL (operands[2]);
7978       emit_insn (gen_xordi3 (tmp, operands[1],
7979                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7980
7981       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7982       DONE;
7983     }
7984 })
7985
7986 (define_insn "*booldi3_internal1"
7987   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7988         (match_operator:DI 3 "boolean_or_operator"
7989          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7990           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7991   "TARGET_POWERPC64"
7992   "@
7993    %q3 %0,%1,%2
7994    %q3i %0,%1,%b2
7995    %q3is %0,%1,%u2")
7996
7997 (define_insn "*booldi3_internal2"
7998   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7999         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8000          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8001           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8002          (const_int 0)))
8003    (clobber (match_scratch:DI 3 "=r,r"))]
8004   "TARGET_64BIT"
8005   "@
8006    %q4. %3,%1,%2
8007    #"
8008   [(set_attr "type" "logical,compare")
8009    (set_attr "dot" "yes")
8010    (set_attr "length" "4,8")])
8011
8012 (define_split
8013   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8014         (compare:CC (match_operator:DI 4 "boolean_operator"
8015          [(match_operand:DI 1 "gpc_reg_operand" "")
8016           (match_operand:DI 2 "gpc_reg_operand" "")])
8017          (const_int 0)))
8018    (clobber (match_scratch:DI 3 ""))]
8019   "TARGET_POWERPC64 && reload_completed"
8020   [(set (match_dup 3) (match_dup 4))
8021    (set (match_dup 0)
8022         (compare:CC (match_dup 3)
8023                     (const_int 0)))]
8024   "")
8025
8026 (define_insn "*booldi3_internal3"
8027   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8028         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8029          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8030           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8031          (const_int 0)))
8032    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8033         (match_dup 4))]
8034   "TARGET_64BIT"
8035   "@
8036    %q4. %0,%1,%2
8037    #"
8038   [(set_attr "type" "logical,compare")
8039    (set_attr "dot" "yes")
8040    (set_attr "length" "4,8")])
8041
8042 (define_split
8043   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8044         (compare:CC (match_operator:DI 4 "boolean_operator"
8045          [(match_operand:DI 1 "gpc_reg_operand" "")
8046           (match_operand:DI 2 "gpc_reg_operand" "")])
8047          (const_int 0)))
8048    (set (match_operand:DI 0 "gpc_reg_operand" "")
8049         (match_dup 4))]
8050   "TARGET_POWERPC64 && reload_completed"
8051   [(set (match_dup 0) (match_dup 4))
8052    (set (match_dup 3)
8053         (compare:CC (match_dup 0)
8054                     (const_int 0)))]
8055   "")
8056
8057 ;; Split a logical operation that we can't do in one insn into two insns,
8058 ;; each of which does one 16-bit part.  This is used by combine.
8059
8060 (define_split
8061   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8062         (match_operator:DI 3 "boolean_or_operator"
8063          [(match_operand:DI 1 "gpc_reg_operand" "")
8064           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
8065   "TARGET_POWERPC64"
8066   [(set (match_dup 0) (match_dup 4))
8067    (set (match_dup 0) (match_dup 5))]
8068 "
8069 {
8070   rtx i3,i4;
8071
8072   i3 = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
8073   i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
8074   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8075                                 operands[1], i3);
8076   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8077                                 operands[0], i4);
8078 }")
8079
8080 (define_insn "*boolcdi3_internal1"
8081   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8082         (match_operator:DI 3 "boolean_operator"
8083          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8084           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
8085   "TARGET_POWERPC64"
8086   "%q3 %0,%2,%1")
8087
8088 (define_insn "*boolcdi3_internal2"
8089   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8090         (compare:CC (match_operator:DI 4 "boolean_operator"
8091          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8092           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8093          (const_int 0)))
8094    (clobber (match_scratch:DI 3 "=r,r"))]
8095   "TARGET_64BIT"
8096   "@
8097    %q4. %3,%2,%1
8098    #"
8099   [(set_attr "type" "logical,compare")
8100    (set_attr "dot" "yes")
8101    (set_attr "length" "4,8")])
8102
8103 (define_split
8104   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8105         (compare:CC (match_operator:DI 4 "boolean_operator"
8106          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8107           (match_operand:DI 2 "gpc_reg_operand" "")])
8108          (const_int 0)))
8109    (clobber (match_scratch:DI 3 ""))]
8110   "TARGET_POWERPC64 && reload_completed"
8111   [(set (match_dup 3) (match_dup 4))
8112    (set (match_dup 0)
8113         (compare:CC (match_dup 3)
8114                     (const_int 0)))]
8115   "")
8116
8117 (define_insn "*boolcdi3_internal3"
8118   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8119         (compare:CC (match_operator:DI 4 "boolean_operator"
8120          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8121           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8122          (const_int 0)))
8123    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8124         (match_dup 4))]
8125   "TARGET_64BIT"
8126   "@
8127    %q4. %0,%2,%1
8128    #"
8129   [(set_attr "type" "logical,compare")
8130    (set_attr "dot" "yes")
8131    (set_attr "length" "4,8")])
8132
8133 (define_split
8134   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8135         (compare:CC (match_operator:DI 4 "boolean_operator"
8136          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8137           (match_operand:DI 2 "gpc_reg_operand" "")])
8138          (const_int 0)))
8139    (set (match_operand:DI 0 "gpc_reg_operand" "")
8140         (match_dup 4))]
8141   "TARGET_POWERPC64 && reload_completed"
8142   [(set (match_dup 0) (match_dup 4))
8143    (set (match_dup 3)
8144         (compare:CC (match_dup 0)
8145                     (const_int 0)))]
8146   "")
8147
8148 (define_insn "*boolccdi3_internal1"
8149   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8150         (match_operator:DI 3 "boolean_operator"
8151          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8152           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
8153   "TARGET_POWERPC64"
8154   "%q3 %0,%1,%2")
8155
8156 (define_insn "*boolccdi3_internal2"
8157   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8158         (compare:CC (match_operator:DI 4 "boolean_operator"
8159          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8160           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8161          (const_int 0)))
8162    (clobber (match_scratch:DI 3 "=r,r"))]
8163   "TARGET_64BIT"
8164   "@
8165    %q4. %3,%1,%2
8166    #"
8167   [(set_attr "type" "logical,compare")
8168    (set_attr "dot" "yes")
8169    (set_attr "length" "4,8")])
8170
8171 (define_split
8172   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8173         (compare:CC (match_operator:DI 4 "boolean_operator"
8174          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8175           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8176          (const_int 0)))
8177    (clobber (match_scratch:DI 3 ""))]
8178   "TARGET_POWERPC64 && reload_completed"
8179   [(set (match_dup 3) (match_dup 4))
8180    (set (match_dup 0)
8181         (compare:CC (match_dup 3)
8182                     (const_int 0)))]
8183   "")
8184
8185 (define_insn "*boolccdi3_internal3"
8186   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8187         (compare:CC (match_operator:DI 4 "boolean_operator"
8188          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8189           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8190          (const_int 0)))
8191    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8192         (match_dup 4))]
8193   "TARGET_64BIT"
8194   "@
8195    %q4. %0,%1,%2
8196    #"
8197   [(set_attr "type" "logical,compare")
8198    (set_attr "dot" "yes")
8199    (set_attr "length" "4,8")])
8200
8201 (define_split
8202   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8203         (compare:CC (match_operator:DI 4 "boolean_operator"
8204          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8205           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8206          (const_int 0)))
8207    (set (match_operand:DI 0 "gpc_reg_operand" "")
8208         (match_dup 4))]
8209   "TARGET_POWERPC64 && reload_completed"
8210   [(set (match_dup 0) (match_dup 4))
8211    (set (match_dup 3)
8212         (compare:CC (match_dup 0)
8213                     (const_int 0)))]
8214   "")
8215
8216 ;; Eqv operation.
8217 (define_insn "*eqv<mode>3"
8218   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
8219         (not:GPR
8220          (xor:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
8221                   (match_operand:GPR 2 "gpc_reg_operand" "r"))))]
8222   ""
8223   "eqv %0,%1,%2"
8224   [(set_attr "type" "integer")
8225    (set_attr "length" "4")])
8226
8227 \f
8228 ;; 128-bit logical operations expanders
8229
8230 (define_expand "and<mode>3"
8231   [(parallel [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8232                    (and:BOOL_128
8233                     (match_operand:BOOL_128 1 "vlogical_operand" "")
8234                     (match_operand:BOOL_128 2 "vlogical_operand" "")))
8235               (clobber (match_scratch:CC 3 ""))])]
8236   ""
8237   "")
8238
8239 (define_expand "ior<mode>3"
8240   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8241         (ior:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8242                       (match_operand:BOOL_128 2 "vlogical_operand" "")))]
8243   ""
8244   "")
8245
8246 (define_expand "xor<mode>3"
8247   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8248         (xor:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8249                       (match_operand:BOOL_128 2 "vlogical_operand" "")))]
8250   ""
8251   "")
8252
8253 (define_expand "one_cmpl<mode>2"
8254   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8255         (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8256   ""
8257   "")
8258
8259 (define_expand "nor<mode>3"
8260   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8261         (and:BOOL_128
8262          (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" ""))
8263          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8264   ""
8265   "")
8266
8267 (define_expand "andc<mode>3"
8268   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8269         (and:BOOL_128
8270          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))
8271          (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8272   ""
8273   "")
8274
8275 ;; Power8 vector logical instructions.
8276 (define_expand "eqv<mode>3"
8277   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8278         (not:BOOL_128
8279          (xor:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8280                        (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8281   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8282   "")
8283
8284 ;; Rewrite nand into canonical form
8285 (define_expand "nand<mode>3"
8286   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8287         (ior:BOOL_128
8288          (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" ""))
8289          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8290   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8291   "")
8292
8293 ;; The canonical form is to have the negated element first, so we need to
8294 ;; reverse arguments.
8295 (define_expand "orc<mode>3"
8296   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8297         (ior:BOOL_128
8298          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))
8299          (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8300   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8301   "")
8302
8303 ;; 128-bit logical operations insns and split operations
8304 (define_insn_and_split "*and<mode>3_internal"
8305   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8306         (and:BOOL_128
8307          (match_operand:BOOL_128 1 "vlogical_operand" "%<BOOL_REGS_OP1>")
8308          (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>")))
8309    (clobber (match_scratch:CC 3 "<BOOL_REGS_AND_CR0>"))]
8310   ""
8311 {
8312   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8313     return "xxland %x0,%x1,%x2";
8314
8315   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8316     return "vand %0,%1,%2";
8317
8318   return "#";
8319 }
8320   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8321   [(const_int 0)]
8322 {
8323   rs6000_split_logical (operands, AND, false, false, false, operands[3]);
8324   DONE;
8325 }
8326   [(set (attr "type")
8327       (if_then_else
8328         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8329         (const_string "vecsimple")
8330         (const_string "integer")))
8331    (set (attr "length")
8332       (if_then_else
8333         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8334         (const_string "4")
8335         (if_then_else
8336          (match_test "TARGET_POWERPC64")
8337          (const_string "8")
8338          (const_string "16"))))])
8339
8340 ;; 128-bit IOR/XOR
8341 (define_insn_and_split "*bool<mode>3_internal"
8342   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8343         (match_operator:BOOL_128 3 "boolean_or_operator"
8344          [(match_operand:BOOL_128 1 "vlogical_operand" "%<BOOL_REGS_OP1>")
8345           (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>")]))]
8346   ""
8347 {
8348   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8349     return "xxl%q3 %x0,%x1,%x2";
8350
8351   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8352     return "v%q3 %0,%1,%2";
8353
8354   return "#";
8355 }
8356   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8357   [(const_int 0)]
8358 {
8359   rs6000_split_logical (operands, GET_CODE (operands[3]), false, false, false,
8360                         NULL_RTX);
8361   DONE;
8362 }
8363   [(set (attr "type")
8364       (if_then_else
8365         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8366         (const_string "vecsimple")
8367         (const_string "integer")))
8368    (set (attr "length")
8369       (if_then_else
8370         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8371         (const_string "4")
8372         (if_then_else
8373          (match_test "TARGET_POWERPC64")
8374          (const_string "8")
8375          (const_string "16"))))])
8376
8377 ;; 128-bit ANDC/ORC
8378 (define_insn_and_split "*boolc<mode>3_internal1"
8379   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8380         (match_operator:BOOL_128 3 "boolean_operator"
8381          [(not:BOOL_128
8382            (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP1>"))
8383           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP2>")]))]
8384   "TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND)"
8385 {
8386   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8387     return "xxl%q3 %x0,%x1,%x2";
8388
8389   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8390     return "v%q3 %0,%1,%2";
8391
8392   return "#";
8393 }
8394   "(TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND))
8395    && reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8396   [(const_int 0)]
8397 {
8398   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, false,
8399                         NULL_RTX);
8400   DONE;
8401 }
8402   [(set (attr "type")
8403       (if_then_else
8404         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8405         (const_string "vecsimple")
8406         (const_string "integer")))
8407    (set (attr "length")
8408       (if_then_else
8409         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8410         (const_string "4")
8411         (if_then_else
8412          (match_test "TARGET_POWERPC64")
8413          (const_string "8")
8414          (const_string "16"))))])
8415
8416 (define_insn_and_split "*boolc<mode>3_internal2"
8417   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8418         (match_operator:TI2 3 "boolean_operator"
8419          [(not:TI2
8420            (match_operand:TI2 1 "int_reg_operand" "r,0,r"))
8421           (match_operand:TI2 2 "int_reg_operand" "r,r,0")]))]
8422   "!TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8423   "#"
8424   "reload_completed && !TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8425   [(const_int 0)]
8426 {
8427   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, false,
8428                         NULL_RTX);
8429   DONE;
8430 }
8431   [(set_attr "type" "integer")
8432    (set (attr "length")
8433         (if_then_else
8434          (match_test "TARGET_POWERPC64")
8435          (const_string "8")
8436          (const_string "16")))])
8437
8438 ;; 128-bit NAND/NOR
8439 (define_insn_and_split "*boolcc<mode>3_internal1"
8440   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8441         (match_operator:BOOL_128 3 "boolean_operator"
8442          [(not:BOOL_128
8443            (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>"))
8444           (not:BOOL_128
8445            (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))]))]
8446   "TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND)"
8447 {
8448   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8449     return "xxl%q3 %x0,%x1,%x2";
8450
8451   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8452     return "v%q3 %0,%1,%2";
8453
8454   return "#";
8455 }
8456   "(TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND))
8457    && reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8458   [(const_int 0)]
8459 {
8460   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, true,
8461                         NULL_RTX);
8462   DONE;
8463 }
8464   [(set (attr "type")
8465       (if_then_else
8466         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8467         (const_string "vecsimple")
8468         (const_string "integer")))
8469    (set (attr "length")
8470       (if_then_else
8471         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8472         (const_string "4")
8473         (if_then_else
8474          (match_test "TARGET_POWERPC64")
8475          (const_string "8")
8476          (const_string "16"))))])
8477
8478 (define_insn_and_split "*boolcc<mode>3_internal2"
8479   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8480         (match_operator:TI2 3 "boolean_operator"
8481          [(not:TI2
8482            (match_operand:TI2 1 "int_reg_operand" "r,0,r"))
8483           (not:TI2
8484            (match_operand:TI2 2 "int_reg_operand" "r,r,0"))]))]
8485   "!TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8486   "#"
8487   "reload_completed && !TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8488   [(const_int 0)]
8489 {
8490   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, true,
8491                         NULL_RTX);
8492   DONE;
8493 }
8494   [(set_attr "type" "integer")
8495    (set (attr "length")
8496         (if_then_else
8497          (match_test "TARGET_POWERPC64")
8498          (const_string "8")
8499          (const_string "16")))])
8500
8501
8502 ;; 128-bit EQV
8503 (define_insn_and_split "*eqv<mode>3_internal1"
8504   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8505         (not:BOOL_128
8506          (xor:BOOL_128
8507           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>")
8508           (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))))]
8509   "TARGET_P8_VECTOR"
8510 {
8511   if (vsx_register_operand (operands[0], <MODE>mode))
8512     return "xxleqv %x0,%x1,%x2";
8513
8514   return "#";
8515 }
8516   "TARGET_P8_VECTOR && reload_completed
8517    && int_reg_operand (operands[0], <MODE>mode)"
8518   [(const_int 0)]
8519 {
8520   rs6000_split_logical (operands, XOR, true, false, false, NULL_RTX);
8521   DONE;
8522 }
8523   [(set (attr "type")
8524       (if_then_else
8525         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8526         (const_string "vecsimple")
8527         (const_string "integer")))
8528    (set (attr "length")
8529       (if_then_else
8530         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8531         (const_string "4")
8532         (if_then_else
8533          (match_test "TARGET_POWERPC64")
8534          (const_string "8")
8535          (const_string "16"))))])
8536
8537 (define_insn_and_split "*eqv<mode>3_internal2"
8538   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8539         (not:TI2
8540          (xor:TI2
8541           (match_operand:TI2 1 "int_reg_operand" "r,0,r")
8542           (match_operand:TI2 2 "int_reg_operand" "r,r,0"))))]
8543   "!TARGET_P8_VECTOR"
8544   "#"
8545   "reload_completed && !TARGET_P8_VECTOR"
8546   [(const_int 0)]
8547 {
8548   rs6000_split_logical (operands, XOR, true, false, false, NULL_RTX);
8549   DONE;
8550 }
8551   [(set_attr "type" "integer")
8552    (set (attr "length")
8553         (if_then_else
8554          (match_test "TARGET_POWERPC64")
8555          (const_string "8")
8556          (const_string "16")))])
8557
8558 ;; 128-bit one's complement
8559 (define_insn_and_split "*one_cmpl<mode>3_internal"
8560   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8561         (not:BOOL_128
8562           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_UNARY>")))]
8563   ""
8564 {
8565   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8566     return "xxlnor %x0,%x1,%x1";
8567
8568   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8569     return "vnor %0,%1,%1";
8570
8571   return "#";
8572 }
8573   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8574   [(const_int 0)]
8575 {
8576   rs6000_split_logical (operands, NOT, false, false, false, NULL_RTX);
8577   DONE;
8578 }
8579   [(set (attr "type")
8580       (if_then_else
8581         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8582         (const_string "vecsimple")
8583         (const_string "integer")))
8584    (set (attr "length")
8585       (if_then_else
8586         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8587         (const_string "4")
8588         (if_then_else
8589          (match_test "TARGET_POWERPC64")
8590          (const_string "8")
8591          (const_string "16"))))])
8592
8593 \f
8594 ;; Now define ways of moving data around.
8595
8596 ;; Set up a register with a value from the GOT table
8597
8598 (define_expand "movsi_got"
8599   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8600         (unspec:SI [(match_operand:SI 1 "got_operand" "")
8601                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
8602   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8603   "
8604 {
8605   if (GET_CODE (operands[1]) == CONST)
8606     {
8607       rtx offset = const0_rtx;
8608       HOST_WIDE_INT value;
8609
8610       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
8611       value = INTVAL (offset);
8612       if (value != 0)
8613         {
8614           rtx tmp = (!can_create_pseudo_p ()
8615                      ? operands[0]
8616                      : gen_reg_rtx (Pmode));
8617           emit_insn (gen_movsi_got (tmp, operands[1]));
8618           emit_insn (gen_addsi3 (operands[0], tmp, offset));
8619           DONE;
8620         }
8621     }
8622
8623   operands[2] = rs6000_got_register (operands[1]);
8624 }")
8625
8626 (define_insn "*movsi_got_internal"
8627   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8628         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8629                     (match_operand:SI 2 "gpc_reg_operand" "b")]
8630                    UNSPEC_MOVSI_GOT))]
8631   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8632   "lwz %0,%a1@got(%2)"
8633   [(set_attr "type" "load")])
8634
8635 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
8636 ;; didn't get allocated to a hard register.
8637 (define_split
8638   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8639         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8640                     (match_operand:SI 2 "memory_operand" "")]
8641                    UNSPEC_MOVSI_GOT))]
8642   "DEFAULT_ABI == ABI_V4
8643     && flag_pic == 1
8644     && (reload_in_progress || reload_completed)"
8645   [(set (match_dup 0) (match_dup 2))
8646    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
8647                                  UNSPEC_MOVSI_GOT))]
8648   "")
8649
8650 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8651 ;; do the load 16-bits at a time.  We could do this by loading from memory,
8652 ;; and this is even supposed to be faster, but it is simpler not to get
8653 ;; integers in the TOC.
8654 (define_insn "movsi_low"
8655   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8656         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8657                            (match_operand 2 "" ""))))]
8658   "TARGET_MACHO && ! TARGET_64BIT"
8659   "lwz %0,lo16(%2)(%1)"
8660   [(set_attr "type" "load")
8661    (set_attr "length" "4")])
8662
8663 (define_insn "*movsi_internal1"
8664   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h")
8665         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0"))]
8666   "!TARGET_SINGLE_FPU &&
8667    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8668   "@
8669    mr %0,%1
8670    la %0,%a1
8671    lwz%U1%X1 %0,%1
8672    stw%U0%X0 %1,%0
8673    li %0,%1
8674    lis %0,%v1
8675    #
8676    mf%1 %0
8677    mt%0 %1
8678    mt%0 %1
8679    nop"
8680   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*")
8681    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4")])
8682
8683 (define_insn "*movsi_internal1_single"
8684   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h,m,*f")
8685         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0,f,m"))]
8686   "TARGET_SINGLE_FPU &&
8687    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
8688   "@
8689    mr %0,%1
8690    la %0,%a1
8691    lwz%U1%X1 %0,%1
8692    stw%U0%X0 %1,%0
8693    li %0,%1
8694    lis %0,%v1
8695    #
8696    mf%1 %0
8697    mt%0 %1
8698    mt%0 %1
8699    nop
8700    stfs%U0%X0 %1,%0
8701    lfs%U1%X1 %0,%1"
8702   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*,fpstore,fpload")
8703    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
8704
8705 ;; Split a load of a large constant into the appropriate two-insn
8706 ;; sequence.
8707
8708 (define_split
8709   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8710         (match_operand:SI 1 "const_int_operand" ""))]
8711   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
8712    && (INTVAL (operands[1]) & 0xffff) != 0"
8713   [(set (match_dup 0)
8714         (match_dup 2))
8715    (set (match_dup 0)
8716         (ior:SI (match_dup 0)
8717                 (match_dup 3)))]
8718   "
8719 {
8720   if (rs6000_emit_set_const (operands[0], operands[1]))
8721     DONE;
8722   else
8723     FAIL;
8724 }")
8725
8726 (define_insn "*mov<mode>_internal2"
8727   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8728         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
8729                     (const_int 0)))
8730    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8731   ""
8732   "@
8733    cmp<wd>i %2,%0,0
8734    mr. %0,%1
8735    #"
8736   [(set_attr "type" "cmp,logical,cmp")
8737    (set_attr "dot" "yes")
8738    (set_attr "length" "4,4,8")])
8739
8740 (define_split
8741   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
8742         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
8743                     (const_int 0)))
8744    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
8745   "reload_completed"
8746   [(set (match_dup 0) (match_dup 1))
8747    (set (match_dup 2)
8748         (compare:CC (match_dup 0)
8749                     (const_int 0)))]
8750   "")
8751 \f
8752 (define_insn "*movhi_internal"
8753   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
8754         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,0"))]
8755   "gpc_reg_operand (operands[0], HImode)
8756    || gpc_reg_operand (operands[1], HImode)"
8757   "@
8758    mr %0,%1
8759    lhz%U1%X1 %0,%1
8760    sth%U0%X0 %1,%0
8761    li %0,%w1
8762    mf%1 %0
8763    mt%0 %1
8764    nop"
8765   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
8766
8767 (define_expand "mov<mode>"
8768   [(set (match_operand:INT 0 "general_operand" "")
8769         (match_operand:INT 1 "any_operand" ""))]
8770   ""
8771   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8772
8773 (define_insn "*movqi_internal"
8774   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
8775         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,0"))]
8776   "gpc_reg_operand (operands[0], QImode)
8777    || gpc_reg_operand (operands[1], QImode)"
8778   "@
8779    mr %0,%1
8780    lbz%U1%X1 %0,%1
8781    stb%U0%X0 %1,%0
8782    li %0,%1
8783    mf%1 %0
8784    mt%0 %1
8785    nop"
8786   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
8787 \f
8788 ;; Here is how to move condition codes around.  When we store CC data in
8789 ;; an integer register or memory, we store just the high-order 4 bits.
8790 ;; This lets us not shift in the most common case of CR0.
8791 (define_expand "movcc"
8792   [(set (match_operand:CC 0 "nonimmediate_operand" "")
8793         (match_operand:CC 1 "nonimmediate_operand" ""))]
8794   ""
8795   "")
8796
8797 (define_insn "*movcc_internal1"
8798   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,cl,r,m")
8799         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,m,r"))]
8800   "register_operand (operands[0], CCmode)
8801    || register_operand (operands[1], CCmode)"
8802   "@
8803    mcrf %0,%1
8804    mtcrf 128,%1
8805    rlwinm %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;rlwinm %1,%1,%f0,0xffffffff
8806    crxor %0,%0,%0
8807    mfcr %0%Q1
8808    mfcr %0%Q1\;rlwinm %0,%0,%f1,0xf0000000
8809    mr %0,%1
8810    li %0,%1
8811    mf%1 %0
8812    mt%0 %1
8813    lwz%U1%X1 %0,%1
8814    stw%U0%X0 %1,%0"
8815   [(set (attr "type")
8816      (cond [(eq_attr "alternative" "0,3")
8817                 (const_string "cr_logical")
8818             (eq_attr "alternative" "1,2")
8819                 (const_string "mtcr")
8820             (eq_attr "alternative" "6,7")
8821                 (const_string "integer")
8822             (eq_attr "alternative" "8")
8823                 (const_string "mfjmpr")
8824             (eq_attr "alternative" "9")
8825                 (const_string "mtjmpr")
8826             (eq_attr "alternative" "10")
8827                 (const_string "load")
8828             (eq_attr "alternative" "11")
8829                 (const_string "store")
8830             (match_test "TARGET_MFCRF")
8831                 (const_string "mfcrf")
8832            ]
8833         (const_string "mfcr")))
8834    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4")])
8835 \f
8836 ;; For floating-point, we normally deal with the floating-point registers
8837 ;; unless -msoft-float is used.  The sole exception is that parameter passing
8838 ;; can produce floating-point values in fixed-point registers.  Unless the
8839 ;; value is a simple constant or already in memory, we deal with this by
8840 ;; allocating memory and copying the value explicitly via that memory location.
8841
8842 ;; Move 32-bit binary/decimal floating point
8843 (define_expand "mov<mode>"
8844   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "")
8845         (match_operand:FMOVE32 1 "any_operand" ""))]
8846   "<fmove_ok>"
8847   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8848
8849 (define_split
8850   [(set (match_operand:FMOVE32 0 "gpc_reg_operand" "")
8851         (match_operand:FMOVE32 1 "const_double_operand" ""))]
8852   "reload_completed
8853    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8854        || (GET_CODE (operands[0]) == SUBREG
8855            && GET_CODE (SUBREG_REG (operands[0])) == REG
8856            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8857   [(set (match_dup 2) (match_dup 3))]
8858   "
8859 {
8860   long l;
8861   REAL_VALUE_TYPE rv;
8862
8863   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8864   <real_value_to_target> (rv, l);
8865
8866   if (! TARGET_POWERPC64)
8867     operands[2] = operand_subword (operands[0], 0, 0, <MODE>mode);
8868   else
8869     operands[2] = gen_lowpart (SImode, operands[0]);
8870
8871   operands[3] = gen_int_mode (l, SImode);
8872 }")
8873
8874 (define_insn "mov<mode>_hardfloat"
8875   [(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")
8876         (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"))]
8877   "(gpc_reg_operand (operands[0], <MODE>mode)
8878    || gpc_reg_operand (operands[1], <MODE>mode))
8879    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
8880   "@
8881    mr %0,%1
8882    lwz%U1%X1 %0,%1
8883    stw%U0%X0 %1,%0
8884    fmr %0,%1
8885    xxlor %x0,%x1,%x1
8886    xxlxor %x0,%x0,%x0
8887    <f32_li>
8888    <f32_si>
8889    <f32_lv>
8890    <f32_sv>
8891    mtvsrwz %x0,%1
8892    mfvsrwz %0,%x1
8893    mt%0 %1
8894    mf%1 %0
8895    nop
8896    #
8897    #"
8898   [(set_attr "type" "*,load,store,fp,vecsimple,vecsimple,fpload,fpstore,fpload,fpstore,mftgpr,mffgpr,mtjmpr,mfjmpr,*,*,*")
8899    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8")])
8900
8901 (define_insn "*mov<mode>_softfloat"
8902   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "=r,cl,r,r,m,r,r,r,r,*h")
8903         (match_operand:FMOVE32 1 "input_operand" "r,r,h,m,r,I,L,G,Fn,0"))]
8904   "(gpc_reg_operand (operands[0], <MODE>mode)
8905    || gpc_reg_operand (operands[1], <MODE>mode))
8906    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
8907   "@
8908    mr %0,%1
8909    mt%0 %1
8910    mf%1 %0
8911    lwz%U1%X1 %0,%1
8912    stw%U0%X0 %1,%0
8913    li %0,%1
8914    lis %0,%v1
8915    #
8916    #
8917    nop"
8918   [(set_attr "type" "*,mtjmpr,mfjmpr,load,store,*,*,*,*,*")
8919    (set_attr "length" "4,4,4,4,4,4,4,4,8,4")])
8920
8921 \f
8922 ;; Move 64-bit binary/decimal floating point
8923 (define_expand "mov<mode>"
8924   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "")
8925         (match_operand:FMOVE64 1 "any_operand" ""))]
8926   ""
8927   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8928
8929 (define_split
8930   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
8931         (match_operand:FMOVE64 1 "const_int_operand" ""))]
8932   "! TARGET_POWERPC64 && reload_completed
8933    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8934        || (GET_CODE (operands[0]) == SUBREG
8935            && GET_CODE (SUBREG_REG (operands[0])) == REG
8936            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8937   [(set (match_dup 2) (match_dup 4))
8938    (set (match_dup 3) (match_dup 1))]
8939   "
8940 {
8941   int endian = (WORDS_BIG_ENDIAN == 0);
8942   HOST_WIDE_INT value = INTVAL (operands[1]);
8943
8944   operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
8945   operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
8946   operands[4] = GEN_INT (value >> 32);
8947   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8948 }")
8949
8950 (define_split
8951   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
8952         (match_operand:FMOVE64 1 "const_double_operand" ""))]
8953   "! TARGET_POWERPC64 && reload_completed
8954    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8955        || (GET_CODE (operands[0]) == SUBREG
8956            && GET_CODE (SUBREG_REG (operands[0])) == REG
8957            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8958   [(set (match_dup 2) (match_dup 4))
8959    (set (match_dup 3) (match_dup 5))]
8960   "
8961 {
8962   int endian = (WORDS_BIG_ENDIAN == 0);
8963   long l[2];
8964   REAL_VALUE_TYPE rv;
8965
8966   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8967   <real_value_to_target> (rv, l);
8968
8969   operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
8970   operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
8971   operands[4] = gen_int_mode (l[endian], SImode);
8972   operands[5] = gen_int_mode (l[1 - endian], SImode);
8973 }")
8974
8975 (define_split
8976   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
8977         (match_operand:FMOVE64 1 "const_double_operand" ""))]
8978   "TARGET_POWERPC64 && reload_completed
8979    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8980        || (GET_CODE (operands[0]) == SUBREG
8981            && GET_CODE (SUBREG_REG (operands[0])) == REG
8982            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8983   [(set (match_dup 2) (match_dup 3))]
8984   "
8985 {
8986   int endian = (WORDS_BIG_ENDIAN == 0);
8987   long l[2];
8988   REAL_VALUE_TYPE rv;
8989   HOST_WIDE_INT val;
8990
8991   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8992   <real_value_to_target> (rv, l);
8993
8994   operands[2] = gen_lowpart (DImode, operands[0]);
8995   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8996   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8997          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8998
8999   operands[3] = gen_int_mode (val, DImode);
9000 }")
9001
9002 ;; Don't have reload use general registers to load a constant.  It is
9003 ;; less efficient than loading the constant into an FP register, since
9004 ;; it will probably be used there.
9005
9006 ;; The move constraints are ordered to prefer floating point registers before
9007 ;; general purpose registers to avoid doing a store and a load to get the value
9008 ;; into a floating point register when it is needed for a floating point
9009 ;; operation.  Prefer traditional floating point registers over VSX registers,
9010 ;; since the D-form version of the memory instructions does not need a GPR for
9011 ;; reloading.
9012
9013 (define_insn "*mov<mode>_hardfloat32"
9014   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=m,d,d,wv,Z,wa,wa,Y,r,!r,!r,!r,!r")
9015         (match_operand:FMOVE64 1 "input_operand" "d,m,d,Z,wv,wa,j,r,Y,r,G,H,F"))]
9016   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9017    && (gpc_reg_operand (operands[0], <MODE>mode)
9018        || gpc_reg_operand (operands[1], <MODE>mode))"
9019   "@
9020    stfd%U0%X0 %1,%0
9021    lfd%U1%X1 %0,%1
9022    fmr %0,%1
9023    lxsd%U1x %x0,%y1
9024    stxsd%U0x %x1,%y0
9025    xxlor %x0,%x1,%x1
9026    xxlxor %x0,%x0,%x0
9027    #
9028    #
9029    #
9030    #
9031    #
9032    #"
9033   [(set_attr "type" "fpstore,fpload,fp,fpload,fpstore,vecsimple,vecsimple,store,load,two,fp,fp,*")
9034    (set_attr "length" "4,4,4,4,4,4,4,8,8,8,8,12,16")])
9035
9036 (define_insn "*mov<mode>_softfloat32"
9037   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=Y,r,r,r,r,r")
9038         (match_operand:FMOVE64 1 "input_operand" "r,Y,r,G,H,F"))]
9039   "! TARGET_POWERPC64 
9040    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
9041        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE
9042        || (<MODE>mode == DDmode && TARGET_E500_DOUBLE))
9043    && (gpc_reg_operand (operands[0], <MODE>mode)
9044        || gpc_reg_operand (operands[1], <MODE>mode))"
9045   "#"
9046   [(set_attr "type" "store,load,two,*,*,*")
9047    (set_attr "length" "8,8,8,8,12,16")])
9048
9049 ; ld/std require word-aligned displacements -> 'Y' constraint.
9050 ; List Y->r and r->Y before r->r for reload.
9051 (define_insn "*mov<mode>_hardfloat64"
9052   [(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")
9053         (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"))]
9054   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
9055    && (gpc_reg_operand (operands[0], <MODE>mode)
9056        || gpc_reg_operand (operands[1], <MODE>mode))"
9057   "@
9058    stfd%U0%X0 %1,%0
9059    lfd%U1%X1 %0,%1
9060    fmr %0,%1
9061    lxsd%U1x %x0,%y1
9062    stxsd%U0x %x1,%y0
9063    xxlor %x0,%x1,%x1
9064    xxlxor %x0,%x0,%x0
9065    std%U0%X0 %1,%0
9066    ld%U1%X1 %0,%1
9067    mr %0,%1
9068    mt%0 %1
9069    mf%1 %0
9070    nop
9071    #
9072    #
9073    #
9074    mftgpr %0,%1
9075    mffgpr %0,%1
9076    mfvsrd %0,%x1
9077    mtvsrd %x0,%1"
9078   [(set_attr "type" "fpstore,fpload,fp,fpload,fpstore,vecsimple,vecsimple,store,load,*,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr,mftgpr,mffgpr")
9079    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4,4,4")])
9080
9081 (define_insn "*mov<mode>_softfloat64"
9082   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=Y,r,r,cl,r,r,r,r,*h")
9083         (match_operand:FMOVE64 1 "input_operand" "r,Y,r,r,h,G,H,F,0"))]
9084   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
9085    && (gpc_reg_operand (operands[0], <MODE>mode)
9086        || gpc_reg_operand (operands[1], <MODE>mode))"
9087   "@
9088    std%U0%X0 %1,%0
9089    ld%U1%X1 %0,%1
9090    mr %0,%1
9091    mt%0 %1
9092    mf%1 %0
9093    #
9094    #
9095    #
9096    nop"
9097   [(set_attr "type" "store,load,*,mtjmpr,mfjmpr,*,*,*,*")
9098    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
9099 \f
9100 (define_expand "mov<mode>"
9101   [(set (match_operand:FMOVE128 0 "general_operand" "")
9102         (match_operand:FMOVE128 1 "any_operand" ""))]
9103   ""
9104   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9105
9106 ;; It's important to list Y->r and r->Y before r->r because otherwise
9107 ;; reload, given m->r, will try to pick r->r and reload it, which
9108 ;; doesn't make progress.
9109
9110 ;; We can't split little endian direct moves of TDmode, because the words are
9111 ;; not swapped like they are for TImode or TFmode.  Subregs therefore are
9112 ;; problematical.  Don't allow direct move for this case.
9113
9114 (define_insn_and_split "*mov<mode>_64bit_dm"
9115   [(set (match_operand:FMOVE128 0 "nonimmediate_operand" "=m,d,d,Y,r,r,r,wm")
9116         (match_operand:FMOVE128 1 "input_operand" "d,m,d,r,YGHF,r,wm,r"))]
9117   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_POWERPC64
9118    && (<MODE>mode != TDmode || WORDS_BIG_ENDIAN)
9119    && (gpc_reg_operand (operands[0], <MODE>mode)
9120        || gpc_reg_operand (operands[1], <MODE>mode))"
9121   "#"
9122   "&& reload_completed"
9123   [(pc)]
9124 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9125   [(set_attr "length" "8,8,8,12,12,8,8,8")])
9126
9127 (define_insn_and_split "*movtd_64bit_nodm"
9128   [(set (match_operand:TD 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
9129         (match_operand:TD 1 "input_operand" "d,m,d,r,YGHF,r"))]
9130   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_POWERPC64 && !WORDS_BIG_ENDIAN
9131    && (gpc_reg_operand (operands[0], TDmode)
9132        || gpc_reg_operand (operands[1], TDmode))"
9133   "#"
9134   "&& reload_completed"
9135   [(pc)]
9136 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9137   [(set_attr "length" "8,8,8,12,12,8")])
9138
9139 (define_insn_and_split "*mov<mode>_32bit"
9140   [(set (match_operand:FMOVE128 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
9141         (match_operand:FMOVE128 1 "input_operand" "d,m,d,r,YGHF,r"))]
9142   "TARGET_HARD_FLOAT && TARGET_FPRS && !TARGET_POWERPC64
9143    && (gpc_reg_operand (operands[0], <MODE>mode)
9144        || gpc_reg_operand (operands[1], <MODE>mode))"
9145   "#"
9146   "&& reload_completed"
9147   [(pc)]
9148 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9149   [(set_attr "length" "8,8,8,20,20,16")])
9150
9151 (define_insn_and_split "*mov<mode>_softfloat"
9152   [(set (match_operand:FMOVE128 0 "rs6000_nonimmediate_operand" "=Y,r,r")
9153         (match_operand:FMOVE128 1 "input_operand" "r,YGHF,r"))]
9154   "(TARGET_SOFT_FLOAT || !TARGET_FPRS)
9155    && (gpc_reg_operand (operands[0], <MODE>mode)
9156        || gpc_reg_operand (operands[1], <MODE>mode))"
9157   "#"
9158   "&& reload_completed"
9159   [(pc)]
9160 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9161   [(set_attr "length" "20,20,16")])
9162
9163 (define_expand "extenddftf2"
9164   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9165         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
9166   "!TARGET_IEEEQUAD
9167    && TARGET_HARD_FLOAT
9168    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9169    && TARGET_LONG_DOUBLE_128"
9170 {
9171   if (TARGET_E500_DOUBLE)
9172     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
9173   else
9174     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
9175   DONE;
9176 })
9177
9178 (define_expand "extenddftf2_fprs"
9179   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9180                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
9181               (use (match_dup 2))])]
9182   "!TARGET_IEEEQUAD
9183    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9184    && TARGET_LONG_DOUBLE_128"
9185 {
9186   operands[2] = CONST0_RTX (DFmode);
9187   /* Generate GOT reference early for SVR4 PIC.  */
9188   if (DEFAULT_ABI == ABI_V4 && flag_pic)
9189     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
9190 })
9191
9192 (define_insn_and_split "*extenddftf2_internal"
9193   [(set (match_operand:TF 0 "nonimmediate_operand" "=m,Y,d,&d,r")
9194        (float_extend:TF (match_operand:DF 1 "input_operand" "d,r,md,md,rmGHF")))
9195    (use (match_operand:DF 2 "zero_reg_mem_operand" "d,r,m,d,n"))]
9196   "!TARGET_IEEEQUAD
9197    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9198    && TARGET_LONG_DOUBLE_128"
9199   "#"
9200   "&& reload_completed"
9201   [(pc)]
9202 {
9203   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9204   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9205   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
9206                   operands[1]);
9207   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
9208                   operands[2]);
9209   DONE;
9210 })
9211
9212 (define_expand "extendsftf2"
9213   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9214         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
9215   "!TARGET_IEEEQUAD
9216    && TARGET_HARD_FLOAT
9217    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9218    && TARGET_LONG_DOUBLE_128"
9219 {
9220   rtx tmp = gen_reg_rtx (DFmode);
9221   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
9222   emit_insn (gen_extenddftf2 (operands[0], tmp));
9223   DONE;
9224 })
9225
9226 (define_expand "trunctfdf2"
9227   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9228         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
9229   "!TARGET_IEEEQUAD
9230    && TARGET_HARD_FLOAT
9231    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9232    && TARGET_LONG_DOUBLE_128"
9233   "")
9234
9235 (define_insn_and_split "trunctfdf2_internal1"
9236   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
9237         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
9238   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
9239    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9240   "@
9241    #
9242    fmr %0,%1"
9243   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
9244   [(const_int 0)]
9245 {
9246   emit_note (NOTE_INSN_DELETED);
9247   DONE;
9248 }
9249   [(set_attr "type" "fp")])
9250
9251 (define_insn "trunctfdf2_internal2"
9252   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9253         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9254   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
9255    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9256    && TARGET_LONG_DOUBLE_128"
9257   "fadd %0,%1,%L1"
9258   [(set_attr "type" "fp")
9259    (set_attr "fp_type" "fp_addsub_d")])
9260
9261 (define_expand "trunctfsf2"
9262   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9263         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
9264   "!TARGET_IEEEQUAD
9265    && TARGET_HARD_FLOAT
9266    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9267    && TARGET_LONG_DOUBLE_128"
9268 {
9269   if (TARGET_E500_DOUBLE)
9270     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
9271   else
9272     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
9273   DONE;
9274 })
9275
9276 (define_insn_and_split "trunctfsf2_fprs"
9277   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
9278         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
9279    (clobber (match_scratch:DF 2 "=d"))]
9280   "!TARGET_IEEEQUAD
9281    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
9282    && TARGET_LONG_DOUBLE_128"
9283   "#"
9284   "&& reload_completed"
9285   [(set (match_dup 2)
9286         (float_truncate:DF (match_dup 1)))
9287    (set (match_dup 0)
9288         (float_truncate:SF (match_dup 2)))]
9289   "")
9290
9291 (define_expand "floatsitf2"
9292   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9293         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
9294   "!TARGET_IEEEQUAD
9295    && TARGET_HARD_FLOAT
9296    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9297    && TARGET_LONG_DOUBLE_128"
9298 {
9299   rtx tmp = gen_reg_rtx (DFmode);
9300   expand_float (tmp, operands[1], false);
9301   emit_insn (gen_extenddftf2 (operands[0], tmp));
9302   DONE;
9303 })
9304
9305 ; fadd, but rounding towards zero.
9306 ; This is probably not the optimal code sequence.
9307 (define_insn "fix_trunc_helper"
9308   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9309         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
9310                    UNSPEC_FIX_TRUNC_TF))
9311    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
9312   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
9313   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
9314   [(set_attr "type" "fp")
9315    (set_attr "length" "20")])
9316
9317 (define_expand "fix_trunctfsi2"
9318   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9319         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
9320   "!TARGET_IEEEQUAD && TARGET_HARD_FLOAT
9321    && (TARGET_FPRS || TARGET_E500_DOUBLE) && TARGET_LONG_DOUBLE_128"
9322 {
9323   if (TARGET_E500_DOUBLE)
9324     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
9325   else
9326     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
9327   DONE;
9328 })
9329
9330 (define_expand "fix_trunctfsi2_fprs"
9331   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
9332                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
9333               (clobber (match_dup 2))
9334               (clobber (match_dup 3))
9335               (clobber (match_dup 4))
9336               (clobber (match_dup 5))])]
9337   "!TARGET_IEEEQUAD
9338    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9339 {
9340   operands[2] = gen_reg_rtx (DFmode);
9341   operands[3] = gen_reg_rtx (DFmode);
9342   operands[4] = gen_reg_rtx (DImode);
9343   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode));
9344 })
9345
9346 (define_insn_and_split "*fix_trunctfsi2_internal"
9347   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9348         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
9349    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
9350    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
9351    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
9352    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
9353   "!TARGET_IEEEQUAD
9354    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9355   "#"
9356   ""
9357   [(pc)]
9358 {
9359   rtx lowword;
9360   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
9361
9362   gcc_assert (MEM_P (operands[5]));
9363   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
9364
9365   emit_insn (gen_fctiwz_df (operands[4], operands[2]));
9366   emit_move_insn (operands[5], operands[4]);
9367   emit_move_insn (operands[0], lowword);
9368   DONE;
9369 })
9370
9371 (define_expand "negtf2"
9372   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9373         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9374   "!TARGET_IEEEQUAD
9375    && TARGET_HARD_FLOAT
9376    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9377    && TARGET_LONG_DOUBLE_128"
9378   "")
9379
9380 (define_insn "negtf2_internal"
9381   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
9382         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9383   "!TARGET_IEEEQUAD
9384    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9385   "*
9386 {
9387   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9388     return \"fneg %L0,%L1\;fneg %0,%1\";
9389   else
9390     return \"fneg %0,%1\;fneg %L0,%L1\";
9391 }"
9392   [(set_attr "type" "fp")
9393    (set_attr "length" "8")])
9394
9395 (define_expand "abstf2"
9396   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9397         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9398   "!TARGET_IEEEQUAD
9399    && TARGET_HARD_FLOAT
9400    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9401    && TARGET_LONG_DOUBLE_128"
9402   "
9403 {
9404   rtx label = gen_label_rtx ();
9405   if (TARGET_E500_DOUBLE)
9406     {
9407       if (flag_finite_math_only && !flag_trapping_math)
9408         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
9409       else
9410         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
9411     }
9412   else
9413     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
9414   emit_label (label);
9415   DONE;
9416 }")
9417
9418 (define_expand "abstf2_internal"
9419   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9420         (match_operand:TF 1 "gpc_reg_operand" ""))
9421    (set (match_dup 3) (match_dup 5))
9422    (set (match_dup 5) (abs:DF (match_dup 5)))
9423    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
9424    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
9425                            (label_ref (match_operand 2 "" ""))
9426                            (pc)))
9427    (set (match_dup 6) (neg:DF (match_dup 6)))]
9428   "!TARGET_IEEEQUAD
9429    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9430    && TARGET_LONG_DOUBLE_128"
9431   "
9432 {
9433   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9434   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9435   operands[3] = gen_reg_rtx (DFmode);
9436   operands[4] = gen_reg_rtx (CCFPmode);
9437   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
9438   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
9439 }")
9440 \f
9441 ;; Reload helper functions used by rs6000_secondary_reload.  The patterns all
9442 ;; must have 3 arguments, and scratch register constraint must be a single
9443 ;; constraint.
9444
9445 ;; Reload patterns to support gpr load/store with misaligned mem.
9446 ;; and multiple gpr load/store at offset >= 0xfffc
9447 (define_expand "reload_<mode>_store"
9448   [(parallel [(match_operand 0 "memory_operand" "=m")
9449               (match_operand 1 "gpc_reg_operand" "r")
9450               (match_operand:GPR 2 "register_operand" "=&b")])]
9451   ""
9452 {
9453   rs6000_secondary_reload_gpr (operands[1], operands[0], operands[2], true);
9454   DONE;
9455 })
9456
9457 (define_expand "reload_<mode>_load"
9458   [(parallel [(match_operand 0 "gpc_reg_operand" "=r")
9459               (match_operand 1 "memory_operand" "m")
9460               (match_operand:GPR 2 "register_operand" "=b")])]
9461   ""
9462 {
9463   rs6000_secondary_reload_gpr (operands[0], operands[1], operands[2], false);
9464   DONE;
9465 })
9466
9467 \f
9468 ;; Power8 merge instructions to allow direct move to/from floating point
9469 ;; registers in 32-bit mode.  We use TF mode to get two registers to move the
9470 ;; individual 32-bit parts across.  Subreg doesn't work too well on the TF
9471 ;; value, since it is allocated in reload and not all of the flow information
9472 ;; is setup for it.  We have two patterns to do the two moves between gprs and
9473 ;; fprs.  There isn't a dependancy between the two, but we could potentially
9474 ;; schedule other instructions between the two instructions.  TFmode is
9475 ;; currently limited to traditional FPR registers.  If/when this is changed, we
9476 ;; will need to revist %L to make sure it works with VSX registers, or add an
9477 ;; %x version of %L.
9478
9479 (define_insn "p8_fmrgow_<mode>"
9480   [(set (match_operand:FMOVE64X 0 "register_operand" "=d")
9481         (unspec:FMOVE64X [(match_operand:TF 1 "register_operand" "d")]
9482                          UNSPEC_P8V_FMRGOW))]
9483   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9484   "fmrgow %0,%1,%L1"
9485   [(set_attr "type" "vecperm")])
9486
9487 (define_insn "p8_mtvsrwz_1"
9488   [(set (match_operand:TF 0 "register_operand" "=d")
9489         (unspec:TF [(match_operand:SI 1 "register_operand" "r")]
9490                    UNSPEC_P8V_MTVSRWZ))]
9491   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9492   "mtvsrwz %x0,%1"
9493   [(set_attr "type" "mftgpr")])
9494
9495 (define_insn "p8_mtvsrwz_2"
9496   [(set (match_operand:TF 0 "register_operand" "+d")
9497         (unspec:TF [(match_dup 0)
9498                     (match_operand:SI 1 "register_operand" "r")]
9499                    UNSPEC_P8V_MTVSRWZ))]
9500   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9501   "mtvsrwz %L0,%1"
9502   [(set_attr "type" "mftgpr")])
9503
9504 (define_insn_and_split "reload_fpr_from_gpr<mode>"
9505   [(set (match_operand:FMOVE64X 0 "register_operand" "=ws")
9506         (unspec:FMOVE64X [(match_operand:FMOVE64X 1 "register_operand" "r")]
9507                          UNSPEC_P8V_RELOAD_FROM_GPR))
9508    (clobber (match_operand:TF 2 "register_operand" "=d"))]
9509   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9510   "#"
9511   "&& reload_completed"
9512   [(const_int 0)]
9513 {
9514   rtx dest = operands[0];
9515   rtx src = operands[1];
9516   rtx tmp = operands[2];
9517   rtx gpr_hi_reg = gen_highpart (SImode, src);
9518   rtx gpr_lo_reg = gen_lowpart (SImode, src);
9519
9520   emit_insn (gen_p8_mtvsrwz_1 (tmp, gpr_hi_reg));
9521   emit_insn (gen_p8_mtvsrwz_2 (tmp, gpr_lo_reg));
9522   emit_insn (gen_p8_fmrgow_<mode> (dest, tmp));
9523   DONE;
9524 }
9525   [(set_attr "length" "12")
9526    (set_attr "type" "three")])
9527
9528 ;; Move 128 bit values from GPRs to VSX registers in 64-bit mode
9529 (define_insn "p8_mtvsrd_1"
9530   [(set (match_operand:TF 0 "register_operand" "=ws")
9531         (unspec:TF [(match_operand:DI 1 "register_operand" "r")]
9532                    UNSPEC_P8V_MTVSRD))]
9533   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9534   "mtvsrd %0,%1"
9535   [(set_attr "type" "mftgpr")])
9536
9537 (define_insn "p8_mtvsrd_2"
9538   [(set (match_operand:TF 0 "register_operand" "+ws")
9539         (unspec:TF [(match_dup 0)
9540                     (match_operand:DI 1 "register_operand" "r")]
9541                    UNSPEC_P8V_MTVSRD))]
9542   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9543   "mtvsrd %L0,%1"
9544   [(set_attr "type" "mftgpr")])
9545
9546 (define_insn "p8_xxpermdi_<mode>"
9547   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9548         (unspec:FMOVE128_GPR [(match_operand:TF 1 "register_operand" "ws")]
9549                              UNSPEC_P8V_XXPERMDI))]
9550   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9551   "xxpermdi %x0,%1,%L1,0"
9552   [(set_attr "type" "vecperm")])
9553
9554 (define_insn_and_split "reload_vsx_from_gpr<mode>"
9555   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9556         (unspec:FMOVE128_GPR
9557          [(match_operand:FMOVE128_GPR 1 "register_operand" "r")]
9558          UNSPEC_P8V_RELOAD_FROM_GPR))
9559    (clobber (match_operand:TF 2 "register_operand" "=ws"))]
9560   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9561   "#"
9562   "&& reload_completed"
9563   [(const_int 0)]
9564 {
9565   rtx dest = operands[0];
9566   rtx src = operands[1];
9567   rtx tmp = operands[2];
9568   rtx gpr_hi_reg = gen_highpart (DImode, src);
9569   rtx gpr_lo_reg = gen_lowpart (DImode, src);
9570
9571   emit_insn (gen_p8_mtvsrd_1 (tmp, gpr_hi_reg));
9572   emit_insn (gen_p8_mtvsrd_2 (tmp, gpr_lo_reg));
9573   emit_insn (gen_p8_xxpermdi_<mode> (dest, tmp));
9574 }
9575   [(set_attr "length" "12")
9576    (set_attr "type" "three")])
9577
9578 (define_split
9579   [(set (match_operand:FMOVE128_GPR 0 "nonimmediate_operand" "")
9580         (match_operand:FMOVE128_GPR 1 "input_operand" ""))]
9581   "reload_completed
9582    && (int_reg_operand (operands[0], <MODE>mode)
9583        || int_reg_operand (operands[1], <MODE>mode))"
9584   [(pc)]
9585 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9586
9587 ;; Move SFmode to a VSX from a GPR register.  Because scalar floating point
9588 ;; type is stored internally as double precision in the VSX registers, we have
9589 ;; to convert it from the vector format.
9590
9591 (define_insn_and_split "reload_vsx_from_gprsf"
9592   [(set (match_operand:SF 0 "register_operand" "=wa")
9593         (unspec:SF [(match_operand:SF 1 "register_operand" "r")]
9594                    UNSPEC_P8V_RELOAD_FROM_GPR))
9595    (clobber (match_operand:DI 2 "register_operand" "=r"))]
9596   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9597   "#"
9598   "&& reload_completed"
9599   [(const_int 0)]
9600 {
9601   rtx op0 = operands[0];
9602   rtx op1 = operands[1];
9603   rtx op2 = operands[2];
9604   /* Also use the destination register to hold the unconverted DImode value.
9605      This is conceptually a separate value from OP0, so we use gen_rtx_REG
9606      rather than simplify_gen_subreg.  */
9607   rtx op0_di = gen_rtx_REG (DImode, REGNO (op0));
9608   rtx op1_di = simplify_gen_subreg (DImode, op1, SFmode, 0);
9609
9610   /* Move SF value to upper 32-bits for xscvspdpn.  */
9611   emit_insn (gen_ashldi3 (op2, op1_di, GEN_INT (32)));
9612   emit_move_insn (op0_di, op2);
9613   emit_insn (gen_vsx_xscvspdpn_directmove (op0, op0_di));
9614   DONE;
9615 }
9616   [(set_attr "length" "8")
9617    (set_attr "type" "two")])
9618
9619 ;; Move 128 bit values from VSX registers to GPRs in 64-bit mode by doing a
9620 ;; normal 64-bit move, followed by an xxpermdi to get the bottom 64-bit value,
9621 ;; and then doing a move of that.
9622 (define_insn "p8_mfvsrd_3_<mode>"
9623   [(set (match_operand:DF 0 "register_operand" "=r")
9624         (unspec:DF [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9625                    UNSPEC_P8V_RELOAD_FROM_VSX))]
9626   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9627   "mfvsrd %0,%x1"
9628   [(set_attr "type" "mftgpr")])
9629
9630 (define_insn_and_split "reload_gpr_from_vsx<mode>"
9631   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=r")
9632         (unspec:FMOVE128_GPR
9633          [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9634          UNSPEC_P8V_RELOAD_FROM_VSX))
9635    (clobber (match_operand:FMOVE128_GPR 2 "register_operand" "=wa"))]
9636   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9637   "#"
9638   "&& reload_completed"
9639   [(const_int 0)]
9640 {
9641   rtx dest = operands[0];
9642   rtx src = operands[1];
9643   rtx tmp = operands[2];
9644   rtx gpr_hi_reg = gen_highpart (DFmode, dest);
9645   rtx gpr_lo_reg = gen_lowpart (DFmode, dest);
9646
9647   emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_hi_reg, src));
9648   emit_insn (gen_vsx_xxpermdi_<mode> (tmp, src, src, GEN_INT (3)));
9649   emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_lo_reg, tmp));
9650 }
9651   [(set_attr "length" "12")
9652    (set_attr "type" "three")])
9653
9654 ;; Move SFmode to a GPR from a VSX register.  Because scalar floating point
9655 ;; type is stored internally as double precision, we have to convert it to the
9656 ;; vector format.
9657
9658 (define_insn_and_split "reload_gpr_from_vsxsf"
9659   [(set (match_operand:SF 0 "register_operand" "=r")
9660         (unspec:SF [(match_operand:SF 1 "register_operand" "wa")]
9661                    UNSPEC_P8V_RELOAD_FROM_VSX))
9662    (clobber (match_operand:V4SF 2 "register_operand" "=wa"))]
9663   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9664   "#"
9665   "&& reload_completed"
9666   [(const_int 0)]
9667 {
9668   rtx op0 = operands[0];
9669   rtx op1 = operands[1];
9670   rtx op2 = operands[2];
9671   rtx diop0 = simplify_gen_subreg (DImode, op0, SFmode, 0);
9672
9673   emit_insn (gen_vsx_xscvdpspn_scalar (op2, op1));
9674   emit_insn (gen_p8_mfvsrd_4_disf (diop0, op2));
9675   emit_insn (gen_lshrdi3 (diop0, diop0, GEN_INT (32)));
9676   DONE;
9677 }
9678   [(set_attr "length" "12")
9679    (set_attr "type" "three")])
9680
9681 (define_insn "p8_mfvsrd_4_disf"
9682   [(set (match_operand:DI 0 "register_operand" "=r")
9683         (unspec:DI [(match_operand:V4SF 1 "register_operand" "wa")]
9684                    UNSPEC_P8V_RELOAD_FROM_VSX))]
9685   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9686   "mfvsrd %0,%x1"
9687   [(set_attr "type" "mftgpr")])
9688
9689 \f
9690 ;; Next come the multi-word integer load and store and the load and store
9691 ;; multiple insns.
9692
9693 ;; List r->r after r->Y, otherwise reload will try to reload a
9694 ;; non-offsettable address by using r->r which won't make progress.
9695 ;; Use of fprs is disparaged slightly otherwise reload prefers to reload
9696 ;; a gpr into a fpr instead of reloading an invalid 'Y' address
9697 (define_insn "*movdi_internal32"
9698   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=Y,r,r,?m,?*d,?*d,r")
9699         (match_operand:DI 1 "input_operand" "r,Y,r,d,m,d,IJKnGHF"))]
9700   "! TARGET_POWERPC64
9701    && (gpc_reg_operand (operands[0], DImode)
9702        || gpc_reg_operand (operands[1], DImode))"
9703   "@
9704    #
9705    #
9706    #
9707    stfd%U0%X0 %1,%0
9708    lfd%U1%X1 %0,%1
9709    fmr %0,%1
9710    #"
9711   [(set_attr "type" "store,load,*,fpstore,fpload,fp,*")])
9712
9713 (define_split
9714   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9715         (match_operand:DI 1 "const_int_operand" ""))]
9716   "! TARGET_POWERPC64 && reload_completed
9717    && gpr_or_gpr_p (operands[0], operands[1])
9718    && !direct_move_p (operands[0], operands[1])"
9719   [(set (match_dup 2) (match_dup 4))
9720    (set (match_dup 3) (match_dup 1))]
9721   "
9722 {
9723   HOST_WIDE_INT value = INTVAL (operands[1]);
9724   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9725                                        DImode);
9726   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9727                                        DImode);
9728   operands[4] = GEN_INT (value >> 32);
9729   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9730 }")
9731
9732 (define_split
9733   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
9734         (match_operand:DIFD 1 "input_operand" ""))]
9735   "reload_completed && !TARGET_POWERPC64
9736    && gpr_or_gpr_p (operands[0], operands[1])
9737    && !direct_move_p (operands[0], operands[1])"
9738   [(pc)]
9739 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9740
9741 (define_insn "*movdi_internal64"
9742   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,r,r,r,r,?m,?*d,?*d,r,*h,*h,r,?*wg,r,?*wm")
9743         (match_operand:DI 1 "input_operand" "r,Y,r,I,L,nF,d,m,d,*h,r,0,*wg,r,*wm,r"))]
9744   "TARGET_POWERPC64
9745    && (gpc_reg_operand (operands[0], DImode)
9746        || gpc_reg_operand (operands[1], DImode))"
9747   "@
9748    std%U0%X0 %1,%0
9749    ld%U1%X1 %0,%1
9750    mr %0,%1
9751    li %0,%1
9752    lis %0,%v1
9753    #
9754    stfd%U0%X0 %1,%0
9755    lfd%U1%X1 %0,%1
9756    fmr %0,%1
9757    mf%1 %0
9758    mt%0 %1
9759    nop
9760    mftgpr %0,%1
9761    mffgpr %0,%1
9762    mfvsrd %0,%x1
9763    mtvsrd %x0,%1"
9764   [(set_attr "type" "store,load,*,*,*,*,fpstore,fpload,fp,mfjmpr,mtjmpr,*,mftgpr,mffgpr,mftgpr,mffgpr")
9765    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4,4")])
9766
9767 ;; Generate all one-bits and clear left or right.
9768 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
9769 (define_split
9770   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9771         (match_operand:DI 1 "mask64_operand" ""))]
9772   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9773   [(set (match_dup 0) (const_int -1))
9774    (set (match_dup 0)
9775         (and:DI (rotate:DI (match_dup 0)
9776                            (const_int 0))
9777                 (match_dup 1)))]
9778   "")
9779
9780 ;; Split a load of a large constant into the appropriate five-instruction
9781 ;; sequence.  Handle anything in a constant number of insns.
9782 ;; When non-easy constants can go in the TOC, this should use
9783 ;; easy_fp_constant predicate.
9784 (define_split
9785   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9786         (match_operand:DI 1 "const_int_operand" ""))]
9787   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9788   [(set (match_dup 0) (match_dup 2))
9789    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9790   "
9791 {
9792   if (rs6000_emit_set_const (operands[0], operands[1]))
9793     DONE;
9794   else
9795     FAIL;
9796 }")
9797
9798 (define_split
9799   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9800         (match_operand:DI 1 "const_scalar_int_operand" ""))]
9801   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9802   [(set (match_dup 0) (match_dup 2))
9803    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9804   "
9805 {
9806   if (rs6000_emit_set_const (operands[0], operands[1]))
9807     DONE;
9808   else
9809     FAIL;
9810 }")
9811 \f
9812 ;; TImode/PTImode is similar, except that we usually want to compute the
9813 ;; address into a register and use lsi/stsi (the exception is during reload).
9814
9815 (define_insn "*mov<mode>_string"
9816   [(set (match_operand:TI2 0 "reg_or_mem_operand" "=Q,Y,????r,????r,????r,r")
9817         (match_operand:TI2 1 "input_operand" "r,r,Q,Y,r,n"))]
9818   "! TARGET_POWERPC64
9819    && (<MODE>mode != TImode || VECTOR_MEM_NONE_P (TImode))
9820    && (gpc_reg_operand (operands[0], <MODE>mode)
9821        || gpc_reg_operand (operands[1], <MODE>mode))"
9822   "*
9823 {
9824   switch (which_alternative)
9825     {
9826     default:
9827       gcc_unreachable ();
9828     case 0:
9829       if (TARGET_STRING)
9830         return \"stswi %1,%P0,16\";
9831     case 1:
9832       return \"#\";
9833     case 2:
9834       /* If the address is not used in the output, we can use lsi.  Otherwise,
9835          fall through to generating four loads.  */
9836       if (TARGET_STRING
9837           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9838         return \"lswi %0,%P1,16\";
9839       /* ... fall through ...  */
9840     case 3:
9841     case 4:
9842     case 5:
9843       return \"#\";
9844     }
9845 }"
9846   [(set_attr "type" "store,store,load,load,*,*")
9847    (set_attr "update" "yes")
9848    (set_attr "indexed" "yes")
9849    (set (attr "cell_micro") (if_then_else (match_test "TARGET_STRING")
9850                                           (const_string "always")
9851                                           (const_string "conditional")))])
9852
9853 (define_insn "*mov<mode>_ppc64"
9854   [(set (match_operand:TI2 0 "nonimmediate_operand" "=wQ,Y,r,r,r,r")
9855         (match_operand:TI2 1 "input_operand" "r,r,wQ,Y,r,n"))]
9856   "(TARGET_POWERPC64 && VECTOR_MEM_NONE_P (<MODE>mode)
9857    && (gpc_reg_operand (operands[0], <MODE>mode)
9858        || gpc_reg_operand (operands[1], <MODE>mode)))"
9859 {
9860   return rs6000_output_move_128bit (operands);
9861 }
9862   [(set_attr "type" "store,store,load,load,*,*")
9863    (set_attr "length" "8")])
9864
9865 (define_split
9866   [(set (match_operand:TI2 0 "int_reg_operand" "")
9867         (match_operand:TI2 1 "const_scalar_int_operand" ""))]
9868   "TARGET_POWERPC64
9869    && (VECTOR_MEM_NONE_P (<MODE>mode)
9870        || (reload_completed && INT_REGNO_P (REGNO (operands[0]))))"
9871   [(set (match_dup 2) (match_dup 4))
9872    (set (match_dup 3) (match_dup 5))]
9873   "
9874 {
9875   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9876                                        <MODE>mode);
9877   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9878                                        <MODE>mode);
9879   if (CONST_WIDE_INT_P (operands[1]))
9880     {
9881       operands[4] = GEN_INT (CONST_WIDE_INT_ELT (operands[1], 1));
9882       operands[5] = GEN_INT (CONST_WIDE_INT_ELT (operands[1], 0));
9883     }
9884   else if (CONST_INT_P (operands[1]))
9885     {
9886       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
9887       operands[5] = operands[1];
9888     }
9889   else
9890     FAIL;
9891 }")
9892
9893 (define_split
9894   [(set (match_operand:TI2 0 "nonimmediate_operand" "")
9895         (match_operand:TI2 1 "input_operand" ""))]
9896   "reload_completed
9897    && gpr_or_gpr_p (operands[0], operands[1])
9898    && !direct_move_p (operands[0], operands[1])
9899    && !quad_load_store_p (operands[0], operands[1])"
9900   [(pc)]
9901 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9902 \f
9903 (define_expand "load_multiple"
9904   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9905                           (match_operand:SI 1 "" ""))
9906                      (use (match_operand:SI 2 "" ""))])]
9907   "TARGET_STRING && !TARGET_POWERPC64"
9908   "
9909 {
9910   int regno;
9911   int count;
9912   rtx op1;
9913   int i;
9914
9915   /* Support only loading a constant number of fixed-point registers from
9916      memory and only bother with this if more than two; the machine
9917      doesn't support more than eight.  */
9918   if (GET_CODE (operands[2]) != CONST_INT
9919       || INTVAL (operands[2]) <= 2
9920       || INTVAL (operands[2]) > 8
9921       || GET_CODE (operands[1]) != MEM
9922       || GET_CODE (operands[0]) != REG
9923       || REGNO (operands[0]) >= 32)
9924     FAIL;
9925
9926   count = INTVAL (operands[2]);
9927   regno = REGNO (operands[0]);
9928
9929   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
9930   op1 = replace_equiv_address (operands[1],
9931                                force_reg (SImode, XEXP (operands[1], 0)));
9932
9933   for (i = 0; i < count; i++)
9934     XVECEXP (operands[3], 0, i)
9935       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
9936                      adjust_address_nv (op1, SImode, i * 4));
9937 }")
9938
9939 (define_insn "*ldmsi8"
9940   [(match_parallel 0 "load_multiple_operation"
9941     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9942           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9943      (set (match_operand:SI 3 "gpc_reg_operand" "")
9944           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9945      (set (match_operand:SI 4 "gpc_reg_operand" "")
9946           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9947      (set (match_operand:SI 5 "gpc_reg_operand" "")
9948           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9949      (set (match_operand:SI 6 "gpc_reg_operand" "")
9950           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9951      (set (match_operand:SI 7 "gpc_reg_operand" "")
9952           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
9953      (set (match_operand:SI 8 "gpc_reg_operand" "")
9954           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
9955      (set (match_operand:SI 9 "gpc_reg_operand" "")
9956           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
9957   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
9958   "*
9959 { return rs6000_output_load_multiple (operands); }"
9960   [(set_attr "type" "load")
9961    (set_attr "update" "yes")
9962    (set_attr "indexed" "yes")
9963    (set_attr "length" "32")])
9964
9965 (define_insn "*ldmsi7"
9966   [(match_parallel 0 "load_multiple_operation"
9967     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9968           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9969      (set (match_operand:SI 3 "gpc_reg_operand" "")
9970           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9971      (set (match_operand:SI 4 "gpc_reg_operand" "")
9972           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9973      (set (match_operand:SI 5 "gpc_reg_operand" "")
9974           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9975      (set (match_operand:SI 6 "gpc_reg_operand" "")
9976           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9977      (set (match_operand:SI 7 "gpc_reg_operand" "")
9978           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
9979      (set (match_operand:SI 8 "gpc_reg_operand" "")
9980           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
9981   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
9982   "*
9983 { return rs6000_output_load_multiple (operands); }"
9984   [(set_attr "type" "load")
9985    (set_attr "update" "yes")
9986    (set_attr "indexed" "yes")
9987    (set_attr "length" "32")])
9988
9989 (define_insn "*ldmsi6"
9990   [(match_parallel 0 "load_multiple_operation"
9991     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9992           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9993      (set (match_operand:SI 3 "gpc_reg_operand" "")
9994           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9995      (set (match_operand:SI 4 "gpc_reg_operand" "")
9996           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9997      (set (match_operand:SI 5 "gpc_reg_operand" "")
9998           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9999      (set (match_operand:SI 6 "gpc_reg_operand" "")
10000           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10001      (set (match_operand:SI 7 "gpc_reg_operand" "")
10002           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
10003   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10004   "*
10005 { return rs6000_output_load_multiple (operands); }"
10006   [(set_attr "type" "load")
10007    (set_attr "update" "yes")
10008    (set_attr "indexed" "yes")
10009    (set_attr "length" "32")])
10010
10011 (define_insn "*ldmsi5"
10012   [(match_parallel 0 "load_multiple_operation"
10013     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10014           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10015      (set (match_operand:SI 3 "gpc_reg_operand" "")
10016           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10017      (set (match_operand:SI 4 "gpc_reg_operand" "")
10018           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10019      (set (match_operand:SI 5 "gpc_reg_operand" "")
10020           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10021      (set (match_operand:SI 6 "gpc_reg_operand" "")
10022           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
10023   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10024   "*
10025 { return rs6000_output_load_multiple (operands); }"
10026   [(set_attr "type" "load")
10027    (set_attr "update" "yes")
10028    (set_attr "indexed" "yes")
10029    (set_attr "length" "32")])
10030
10031 (define_insn "*ldmsi4"
10032   [(match_parallel 0 "load_multiple_operation"
10033     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10034           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10035      (set (match_operand:SI 3 "gpc_reg_operand" "")
10036           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10037      (set (match_operand:SI 4 "gpc_reg_operand" "")
10038           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10039      (set (match_operand:SI 5 "gpc_reg_operand" "")
10040           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
10041   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10042   "*
10043 { return rs6000_output_load_multiple (operands); }"
10044   [(set_attr "type" "load")
10045    (set_attr "update" "yes")
10046    (set_attr "indexed" "yes")
10047    (set_attr "length" "32")])
10048
10049 (define_insn "*ldmsi3"
10050   [(match_parallel 0 "load_multiple_operation"
10051     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10052           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10053      (set (match_operand:SI 3 "gpc_reg_operand" "")
10054           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10055      (set (match_operand:SI 4 "gpc_reg_operand" "")
10056           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
10057   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
10058   "*
10059 { return rs6000_output_load_multiple (operands); }"
10060   [(set_attr "type" "load")
10061    (set_attr "update" "yes")
10062    (set_attr "indexed" "yes")
10063    (set_attr "length" "32")])
10064
10065 (define_expand "store_multiple"
10066   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10067                           (match_operand:SI 1 "" ""))
10068                      (clobber (scratch:SI))
10069                      (use (match_operand:SI 2 "" ""))])]
10070   "TARGET_STRING && !TARGET_POWERPC64"
10071   "
10072 {
10073   int regno;
10074   int count;
10075   rtx to;
10076   rtx op0;
10077   int i;
10078
10079   /* Support only storing a constant number of fixed-point registers to
10080      memory and only bother with this if more than two; the machine
10081      doesn't support more than eight.  */
10082   if (GET_CODE (operands[2]) != CONST_INT
10083       || INTVAL (operands[2]) <= 2
10084       || INTVAL (operands[2]) > 8
10085       || GET_CODE (operands[0]) != MEM
10086       || GET_CODE (operands[1]) != REG
10087       || REGNO (operands[1]) >= 32)
10088     FAIL;
10089
10090   count = INTVAL (operands[2]);
10091   regno = REGNO (operands[1]);
10092
10093   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
10094   to = force_reg (SImode, XEXP (operands[0], 0));
10095   op0 = replace_equiv_address (operands[0], to);
10096
10097   XVECEXP (operands[3], 0, 0)
10098     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
10099   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
10100                                                  gen_rtx_SCRATCH (SImode));
10101
10102   for (i = 1; i < count; i++)
10103     XVECEXP (operands[3], 0, i + 1)
10104       = gen_rtx_SET (VOIDmode,
10105                      adjust_address_nv (op0, SImode, i * 4),
10106                      gen_rtx_REG (SImode, regno + i));
10107 }")
10108
10109 (define_insn "*stmsi8"
10110   [(match_parallel 0 "store_multiple_operation"
10111     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10112           (match_operand:SI 2 "gpc_reg_operand" "r"))
10113      (clobber (match_scratch:SI 3 "=X"))
10114      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10115           (match_operand:SI 4 "gpc_reg_operand" "r"))
10116      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10117           (match_operand:SI 5 "gpc_reg_operand" "r"))
10118      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10119           (match_operand:SI 6 "gpc_reg_operand" "r"))
10120      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10121           (match_operand:SI 7 "gpc_reg_operand" "r"))
10122      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10123           (match_operand:SI 8 "gpc_reg_operand" "r"))
10124      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10125           (match_operand:SI 9 "gpc_reg_operand" "r"))
10126      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10127           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10128   "TARGET_STRING && XVECLEN (operands[0], 0) == 9"
10129   "stswi %2,%1,%O0"
10130   [(set_attr "type" "store")
10131    (set_attr "update" "yes")
10132    (set_attr "indexed" "yes")
10133    (set_attr "cell_micro" "always")])
10134
10135 (define_insn "*stmsi7"
10136   [(match_parallel 0 "store_multiple_operation"
10137     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10138           (match_operand:SI 2 "gpc_reg_operand" "r"))
10139      (clobber (match_scratch:SI 3 "=X"))
10140      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10141           (match_operand:SI 4 "gpc_reg_operand" "r"))
10142      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10143           (match_operand:SI 5 "gpc_reg_operand" "r"))
10144      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10145           (match_operand:SI 6 "gpc_reg_operand" "r"))
10146      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10147           (match_operand:SI 7 "gpc_reg_operand" "r"))
10148      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10149           (match_operand:SI 8 "gpc_reg_operand" "r"))
10150      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10151           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10152   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10153   "stswi %2,%1,%O0"
10154   [(set_attr "type" "store")
10155    (set_attr "update" "yes")
10156    (set_attr "indexed" "yes")
10157    (set_attr "cell_micro" "always")])
10158
10159 (define_insn "*stmsi6"
10160   [(match_parallel 0 "store_multiple_operation"
10161     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10162           (match_operand:SI 2 "gpc_reg_operand" "r"))
10163      (clobber (match_scratch:SI 3 "=X"))
10164      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10165           (match_operand:SI 4 "gpc_reg_operand" "r"))
10166      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10167           (match_operand:SI 5 "gpc_reg_operand" "r"))
10168      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10169           (match_operand:SI 6 "gpc_reg_operand" "r"))
10170      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10171           (match_operand:SI 7 "gpc_reg_operand" "r"))
10172      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10173           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10174   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10175   "stswi %2,%1,%O0"
10176   [(set_attr "type" "store")
10177    (set_attr "update" "yes")
10178    (set_attr "indexed" "yes")
10179    (set_attr "cell_micro" "always")])
10180
10181 (define_insn "*stmsi5"
10182   [(match_parallel 0 "store_multiple_operation"
10183     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10184           (match_operand:SI 2 "gpc_reg_operand" "r"))
10185      (clobber (match_scratch:SI 3 "=X"))
10186      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10187           (match_operand:SI 4 "gpc_reg_operand" "r"))
10188      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10189           (match_operand:SI 5 "gpc_reg_operand" "r"))
10190      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10191           (match_operand:SI 6 "gpc_reg_operand" "r"))
10192      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10193           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10194   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10195   "stswi %2,%1,%O0"
10196   [(set_attr "type" "store")
10197    (set_attr "update" "yes")
10198    (set_attr "indexed" "yes")
10199    (set_attr "cell_micro" "always")])
10200
10201 (define_insn "*stmsi4"
10202   [(match_parallel 0 "store_multiple_operation"
10203     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10204           (match_operand:SI 2 "gpc_reg_operand" "r"))
10205      (clobber (match_scratch:SI 3 "=X"))
10206      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10207           (match_operand:SI 4 "gpc_reg_operand" "r"))
10208      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10209           (match_operand:SI 5 "gpc_reg_operand" "r"))
10210      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10211           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10212   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10213   "stswi %2,%1,%O0"
10214   [(set_attr "type" "store")
10215    (set_attr "update" "yes")
10216    (set_attr "indexed" "yes")
10217    (set_attr "cell_micro" "always")])
10218
10219 (define_insn "*stmsi3"
10220   [(match_parallel 0 "store_multiple_operation"
10221     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10222           (match_operand:SI 2 "gpc_reg_operand" "r"))
10223      (clobber (match_scratch:SI 3 "=X"))
10224      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10225           (match_operand:SI 4 "gpc_reg_operand" "r"))
10226      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10227           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10228   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10229   "stswi %2,%1,%O0"
10230   [(set_attr "type" "store")
10231    (set_attr "update" "yes")
10232    (set_attr "indexed" "yes")
10233    (set_attr "cell_micro" "always")])
10234 \f
10235 (define_expand "setmemsi"
10236   [(parallel [(set (match_operand:BLK 0 "" "")
10237                    (match_operand 2 "const_int_operand" ""))
10238               (use (match_operand:SI 1 "" ""))
10239               (use (match_operand:SI 3 "" ""))])]
10240   ""
10241   "
10242 {
10243   /* If value to set is not zero, use the library routine.  */
10244   if (operands[2] != const0_rtx)
10245     FAIL;
10246
10247   if (expand_block_clear (operands))
10248     DONE;
10249   else
10250     FAIL;
10251 }")
10252
10253 ;; String/block move insn.
10254 ;; Argument 0 is the destination
10255 ;; Argument 1 is the source
10256 ;; Argument 2 is the length
10257 ;; Argument 3 is the alignment
10258
10259 (define_expand "movmemsi"
10260   [(parallel [(set (match_operand:BLK 0 "" "")
10261                    (match_operand:BLK 1 "" ""))
10262               (use (match_operand:SI 2 "" ""))
10263               (use (match_operand:SI 3 "" ""))])]
10264   ""
10265   "
10266 {
10267   if (expand_block_move (operands))
10268     DONE;
10269   else
10270     FAIL;
10271 }")
10272
10273 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
10274 ;; register allocator doesn't have a clue about allocating 8 word registers.
10275 ;; rD/rS = r5 is preferred, efficient form.
10276 (define_expand "movmemsi_8reg"
10277   [(parallel [(set (match_operand 0 "" "")
10278                    (match_operand 1 "" ""))
10279               (use (match_operand 2 "" ""))
10280               (use (match_operand 3 "" ""))
10281               (clobber (reg:SI  5))
10282               (clobber (reg:SI  6))
10283               (clobber (reg:SI  7))
10284               (clobber (reg:SI  8))
10285               (clobber (reg:SI  9))
10286               (clobber (reg:SI 10))
10287               (clobber (reg:SI 11))
10288               (clobber (reg:SI 12))
10289               (clobber (match_scratch:SI 4 ""))])]
10290   "TARGET_STRING"
10291   "")
10292
10293 (define_insn ""
10294   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10295         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10296    (use (match_operand:SI 2 "immediate_operand" "i"))
10297    (use (match_operand:SI 3 "immediate_operand" "i"))
10298    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10299    (clobber (reg:SI  6))
10300    (clobber (reg:SI  7))
10301    (clobber (reg:SI  8))
10302    (clobber (reg:SI  9))
10303    (clobber (reg:SI 10))
10304    (clobber (reg:SI 11))
10305    (clobber (reg:SI 12))
10306    (clobber (match_scratch:SI 5 "=X"))]
10307   "TARGET_STRING
10308    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10309        || INTVAL (operands[2]) == 0)
10310    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10311    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10312    && REGNO (operands[4]) == 5"
10313   "lswi %4,%1,%2\;stswi %4,%0,%2"
10314   [(set_attr "type" "store")
10315    (set_attr "update" "yes")
10316    (set_attr "indexed" "yes")
10317    (set_attr "cell_micro" "always")
10318    (set_attr "length" "8")])
10319
10320 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
10321 ;; register allocator doesn't have a clue about allocating 6 word registers.
10322 ;; rD/rS = r5 is preferred, efficient form.
10323 (define_expand "movmemsi_6reg"
10324   [(parallel [(set (match_operand 0 "" "")
10325                    (match_operand 1 "" ""))
10326               (use (match_operand 2 "" ""))
10327               (use (match_operand 3 "" ""))
10328               (clobber (reg:SI  5))
10329               (clobber (reg:SI  6))
10330               (clobber (reg:SI  7))
10331               (clobber (reg:SI  8))
10332               (clobber (reg:SI  9))
10333               (clobber (reg:SI 10))
10334               (clobber (match_scratch:SI 4 ""))])]
10335   "TARGET_STRING"
10336   "")
10337
10338 (define_insn ""
10339   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10340         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10341    (use (match_operand:SI 2 "immediate_operand" "i"))
10342    (use (match_operand:SI 3 "immediate_operand" "i"))
10343    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10344    (clobber (reg:SI  6))
10345    (clobber (reg:SI  7))
10346    (clobber (reg:SI  8))
10347    (clobber (reg:SI  9))
10348    (clobber (reg:SI 10))
10349    (clobber (match_scratch:SI 5 "=X"))]
10350   "TARGET_STRING
10351    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
10352    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10353    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10354    && REGNO (operands[4]) == 5"
10355   "lswi %4,%1,%2\;stswi %4,%0,%2"
10356   [(set_attr "type" "store")
10357    (set_attr "update" "yes")
10358    (set_attr "indexed" "yes")
10359    (set_attr "cell_micro" "always")
10360    (set_attr "length" "8")])
10361
10362 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
10363 ;; problems with TImode.
10364 ;; rD/rS = r5 is preferred, efficient form.
10365 (define_expand "movmemsi_4reg"
10366   [(parallel [(set (match_operand 0 "" "")
10367                    (match_operand 1 "" ""))
10368               (use (match_operand 2 "" ""))
10369               (use (match_operand 3 "" ""))
10370               (clobber (reg:SI 5))
10371               (clobber (reg:SI 6))
10372               (clobber (reg:SI 7))
10373               (clobber (reg:SI 8))
10374               (clobber (match_scratch:SI 4 ""))])]
10375   "TARGET_STRING"
10376   "")
10377
10378 (define_insn ""
10379   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10380         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10381    (use (match_operand:SI 2 "immediate_operand" "i"))
10382    (use (match_operand:SI 3 "immediate_operand" "i"))
10383    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10384    (clobber (reg:SI 6))
10385    (clobber (reg:SI 7))
10386    (clobber (reg:SI 8))
10387    (clobber (match_scratch:SI 5 "=X"))]
10388   "TARGET_STRING
10389    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
10390    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
10391    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
10392    && REGNO (operands[4]) == 5"
10393   "lswi %4,%1,%2\;stswi %4,%0,%2"
10394   [(set_attr "type" "store")
10395    (set_attr "update" "yes")
10396    (set_attr "indexed" "yes")
10397    (set_attr "cell_micro" "always")
10398    (set_attr "length" "8")])
10399
10400 ;; Move up to 8 bytes at a time.
10401 (define_expand "movmemsi_2reg"
10402   [(parallel [(set (match_operand 0 "" "")
10403                    (match_operand 1 "" ""))
10404               (use (match_operand 2 "" ""))
10405               (use (match_operand 3 "" ""))
10406               (clobber (match_scratch:DI 4 ""))
10407               (clobber (match_scratch:SI 5 ""))])]
10408   "TARGET_STRING && ! TARGET_POWERPC64"
10409   "")
10410
10411 (define_insn ""
10412   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10413         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10414    (use (match_operand:SI 2 "immediate_operand" "i"))
10415    (use (match_operand:SI 3 "immediate_operand" "i"))
10416    (clobber (match_scratch:DI 4 "=&r"))
10417    (clobber (match_scratch:SI 5 "=X"))]
10418   "TARGET_STRING && ! TARGET_POWERPC64
10419    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
10420   "lswi %4,%1,%2\;stswi %4,%0,%2"
10421   [(set_attr "type" "store")
10422    (set_attr "update" "yes")
10423    (set_attr "indexed" "yes")
10424    (set_attr "cell_micro" "always")
10425    (set_attr "length" "8")])
10426
10427 ;; Move up to 4 bytes at a time.
10428 (define_expand "movmemsi_1reg"
10429   [(parallel [(set (match_operand 0 "" "")
10430                    (match_operand 1 "" ""))
10431               (use (match_operand 2 "" ""))
10432               (use (match_operand 3 "" ""))
10433               (clobber (match_scratch:SI 4 ""))
10434               (clobber (match_scratch:SI 5 ""))])]
10435   "TARGET_STRING"
10436   "")
10437
10438 (define_insn ""
10439   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10440         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10441    (use (match_operand:SI 2 "immediate_operand" "i"))
10442    (use (match_operand:SI 3 "immediate_operand" "i"))
10443    (clobber (match_scratch:SI 4 "=&r"))
10444    (clobber (match_scratch:SI 5 "=X"))]
10445   "TARGET_STRING && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
10446   "lswi %4,%1,%2\;stswi %4,%0,%2"
10447   [(set_attr "type" "store")
10448    (set_attr "update" "yes")
10449    (set_attr "indexed" "yes")
10450    (set_attr "cell_micro" "always")
10451    (set_attr "length" "8")])
10452 \f
10453 ;; Define insns that do load or store with update.  Some of these we can
10454 ;; get by using pre-decrement or pre-increment, but the hardware can also
10455 ;; do cases where the increment is not the size of the object.
10456 ;;
10457 ;; In all these cases, we use operands 0 and 1 for the register being
10458 ;; incremented because those are the operands that local-alloc will
10459 ;; tie and these are the pair most likely to be tieable (and the ones
10460 ;; that will benefit the most).
10461
10462 (define_insn "*movdi_update1"
10463   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
10464         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
10465                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
10466    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
10467         (plus:DI (match_dup 1) (match_dup 2)))]
10468   "TARGET_POWERPC64 && TARGET_UPDATE
10469    && (!avoiding_indexed_address_p (DImode)
10470        || !gpc_reg_operand (operands[2], DImode))"
10471   "@
10472    ldux %3,%0,%2
10473    ldu %3,%2(%0)"
10474   [(set_attr "type" "load")
10475    (set_attr "update" "yes")
10476    (set_attr "indexed" "yes,no")])
10477
10478 (define_insn "movdi_<mode>_update"
10479   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10480                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10481         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10482    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10483         (plus:P (match_dup 1) (match_dup 2)))]
10484   "TARGET_POWERPC64 && TARGET_UPDATE
10485    && (!avoiding_indexed_address_p (Pmode)
10486        || !gpc_reg_operand (operands[2], Pmode)
10487        || (REG_P (operands[0])
10488            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10489   "@
10490    stdux %3,%0,%2
10491    stdu %3,%2(%0)"
10492   [(set_attr "type" "store")
10493    (set_attr "update" "yes")
10494    (set_attr "indexed" "yes,no")])
10495
10496 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
10497 ;; needed for stack allocation, even if the user passes -mno-update.
10498 (define_insn "movdi_<mode>_update_stack"
10499   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10500                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10501         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10502    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10503         (plus:P (match_dup 1) (match_dup 2)))]
10504   "TARGET_POWERPC64"
10505   "@
10506    stdux %3,%0,%2
10507    stdu %3,%2(%0)"
10508   [(set_attr "type" "store")
10509    (set_attr "update" "yes")
10510    (set_attr "indexed" "yes,no")])
10511
10512 (define_insn "*movsi_update1"
10513   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10514         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10515                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10516    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10517         (plus:SI (match_dup 1) (match_dup 2)))]
10518   "TARGET_UPDATE
10519    && (!avoiding_indexed_address_p (SImode)
10520        || !gpc_reg_operand (operands[2], SImode))"
10521   "@
10522    lwzux %3,%0,%2
10523    lwzu %3,%2(%0)"
10524   [(set_attr "type" "load")
10525    (set_attr "update" "yes")
10526    (set_attr "indexed" "yes,no")])
10527
10528 (define_insn "*movsi_update2"
10529   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
10530         (sign_extend:DI
10531          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
10532                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
10533    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
10534         (plus:DI (match_dup 1) (match_dup 2)))]
10535   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
10536    && !avoiding_indexed_address_p (DImode)"
10537   "lwaux %3,%0,%2"
10538   [(set_attr "type" "load")
10539    (set_attr "sign_extend" "yes")
10540    (set_attr "update" "yes")
10541    (set_attr "indexed" "yes")])
10542
10543 (define_insn "movsi_update"
10544   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10545                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10546         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10547    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10548         (plus:SI (match_dup 1) (match_dup 2)))]
10549   "TARGET_UPDATE
10550    && (!avoiding_indexed_address_p (SImode)
10551        || !gpc_reg_operand (operands[2], SImode)
10552        || (REG_P (operands[0])
10553            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10554   "@
10555    stwux %3,%0,%2
10556    stwu %3,%2(%0)"
10557   [(set_attr "type" "store")
10558    (set_attr "update" "yes")
10559    (set_attr "indexed" "yes,no")])
10560
10561 ;; This is an unconditional pattern; needed for stack allocation, even
10562 ;; if the user passes -mno-update.
10563 (define_insn "movsi_update_stack"
10564   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10565                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10566         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10567    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10568         (plus:SI (match_dup 1) (match_dup 2)))]
10569   ""
10570   "@
10571    stwux %3,%0,%2
10572    stwu %3,%2(%0)"
10573   [(set_attr "type" "store")
10574    (set_attr "update" "yes")
10575    (set_attr "indexed" "yes,no")])
10576
10577 (define_insn "*movhi_update1"
10578   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
10579         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10580                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10581    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10582         (plus:SI (match_dup 1) (match_dup 2)))]
10583   "TARGET_UPDATE
10584    && (!avoiding_indexed_address_p (SImode)
10585        || !gpc_reg_operand (operands[2], SImode))"
10586   "@
10587    lhzux %3,%0,%2
10588    lhzu %3,%2(%0)"
10589   [(set_attr "type" "load")
10590    (set_attr "update" "yes")
10591    (set_attr "indexed" "yes,no")])
10592
10593 (define_insn "*movhi_update2"
10594   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10595         (zero_extend:SI
10596          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10597                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10598    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10599         (plus:SI (match_dup 1) (match_dup 2)))]
10600   "TARGET_UPDATE
10601    && (!avoiding_indexed_address_p (SImode)
10602        || !gpc_reg_operand (operands[2], SImode))"
10603   "@
10604    lhzux %3,%0,%2
10605    lhzu %3,%2(%0)"
10606   [(set_attr "type" "load")
10607    (set_attr "update" "yes")
10608    (set_attr "indexed" "yes,no")])
10609
10610 (define_insn "*movhi_update3"
10611   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10612         (sign_extend:SI
10613          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10614                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10615    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10616         (plus:SI (match_dup 1) (match_dup 2)))]
10617   "TARGET_UPDATE && rs6000_gen_cell_microcode
10618    && (!avoiding_indexed_address_p (SImode)
10619        || !gpc_reg_operand (operands[2], SImode))"
10620   "@
10621    lhaux %3,%0,%2
10622    lhau %3,%2(%0)"
10623   [(set_attr "type" "load")
10624    (set_attr "sign_extend" "yes")
10625    (set_attr "update" "yes")
10626    (set_attr "indexed" "yes,no")])
10627
10628 (define_insn "*movhi_update4"
10629   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10630                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10631         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
10632    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10633         (plus:SI (match_dup 1) (match_dup 2)))]
10634   "TARGET_UPDATE
10635    && (!avoiding_indexed_address_p (SImode)
10636        || !gpc_reg_operand (operands[2], SImode))"
10637   "@
10638    sthux %3,%0,%2
10639    sthu %3,%2(%0)"
10640   [(set_attr "type" "store")
10641    (set_attr "update" "yes")
10642    (set_attr "indexed" "yes,no")])
10643
10644 (define_insn "*movqi_update1"
10645   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
10646         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10647                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10648    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10649         (plus:SI (match_dup 1) (match_dup 2)))]
10650   "TARGET_UPDATE
10651    && (!avoiding_indexed_address_p (SImode)
10652        || !gpc_reg_operand (operands[2], SImode))"
10653   "@
10654    lbzux %3,%0,%2
10655    lbzu %3,%2(%0)"
10656   [(set_attr "type" "load")
10657    (set_attr "update" "yes")
10658    (set_attr "indexed" "yes,no")])
10659
10660 (define_insn "*movqi_update2"
10661   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10662         (zero_extend:SI
10663          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10664                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10665    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10666         (plus:SI (match_dup 1) (match_dup 2)))]
10667   "TARGET_UPDATE
10668    && (!avoiding_indexed_address_p (SImode)
10669        || !gpc_reg_operand (operands[2], SImode))"
10670   "@
10671    lbzux %3,%0,%2
10672    lbzu %3,%2(%0)"
10673   [(set_attr "type" "load")
10674    (set_attr "update" "yes")
10675    (set_attr "indexed" "yes,no")])
10676
10677 (define_insn "*movqi_update3"
10678   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10679                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10680         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
10681    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10682         (plus:SI (match_dup 1) (match_dup 2)))]
10683   "TARGET_UPDATE
10684    && (!avoiding_indexed_address_p (SImode)
10685        || !gpc_reg_operand (operands[2], SImode))"
10686   "@
10687    stbux %3,%0,%2
10688    stbu %3,%2(%0)"
10689   [(set_attr "type" "store")
10690    (set_attr "update" "yes")
10691    (set_attr "indexed" "yes,no")])
10692
10693 (define_insn "*movsf_update1"
10694   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
10695         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10696                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10697    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10698         (plus:SI (match_dup 1) (match_dup 2)))]
10699   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10700    && (!avoiding_indexed_address_p (SImode)
10701        || !gpc_reg_operand (operands[2], SImode))"
10702   "@
10703    lfsux %3,%0,%2
10704    lfsu %3,%2(%0)"
10705   [(set_attr "type" "fpload")
10706    (set_attr "update" "yes")
10707    (set_attr "indexed" "yes,no")])
10708
10709 (define_insn "*movsf_update2"
10710   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10711                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10712         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
10713    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10714         (plus:SI (match_dup 1) (match_dup 2)))]
10715   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
10716    && (!avoiding_indexed_address_p (SImode)
10717        || !gpc_reg_operand (operands[2], SImode))"
10718   "@
10719    stfsux %3,%0,%2
10720    stfsu %3,%2(%0)"
10721   [(set_attr "type" "fpstore")
10722    (set_attr "update" "yes")
10723    (set_attr "indexed" "yes,no")])
10724
10725 (define_insn "*movsf_update3"
10726   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
10727         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10728                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10729    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10730         (plus:SI (match_dup 1) (match_dup 2)))]
10731   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
10732    && (!avoiding_indexed_address_p (SImode)
10733        || !gpc_reg_operand (operands[2], SImode))"
10734   "@
10735    lwzux %3,%0,%2
10736    lwzu %3,%2(%0)"
10737   [(set_attr "type" "load")
10738    (set_attr "update" "yes")
10739    (set_attr "indexed" "yes,no")])
10740
10741 (define_insn "*movsf_update4"
10742   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10743                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10744         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
10745    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10746         (plus:SI (match_dup 1) (match_dup 2)))]
10747   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
10748    && (!avoiding_indexed_address_p (SImode)
10749        || !gpc_reg_operand (operands[2], SImode))"
10750   "@
10751    stwux %3,%0,%2
10752    stwu %3,%2(%0)"
10753   [(set_attr "type" "store")
10754    (set_attr "update" "yes")
10755    (set_attr "indexed" "yes,no")])
10756
10757 (define_insn "*movdf_update1"
10758   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
10759         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10760                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10761    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10762         (plus:SI (match_dup 1) (match_dup 2)))]
10763   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
10764    && (!avoiding_indexed_address_p (SImode)
10765        || !gpc_reg_operand (operands[2], SImode))"
10766   "@
10767    lfdux %3,%0,%2
10768    lfdu %3,%2(%0)"
10769   [(set_attr "type" "fpload")
10770    (set_attr "update" "yes")
10771    (set_attr "indexed" "yes,no")])
10772
10773 (define_insn "*movdf_update2"
10774   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10775                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10776         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
10777    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10778         (plus:SI (match_dup 1) (match_dup 2)))]
10779   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
10780    && (!avoiding_indexed_address_p (SImode)
10781        || !gpc_reg_operand (operands[2], SImode))"
10782   "@
10783    stfdux %3,%0,%2
10784    stfdu %3,%2(%0)"
10785   [(set_attr "type" "fpstore")
10786    (set_attr "update" "yes")
10787    (set_attr "indexed" "yes,no")])
10788
10789
10790 ;; After inserting conditional returns we can sometimes have
10791 ;; unnecessary register moves.  Unfortunately we cannot have a
10792 ;; modeless peephole here, because some single SImode sets have early
10793 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
10794 ;; sequences, using get_attr_length here will smash the operands
10795 ;; array.  Neither is there an early_cobbler_p predicate.
10796 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
10797 (define_peephole2
10798   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10799         (match_operand:DF 1 "any_operand" ""))
10800    (set (match_operand:DF 2 "gpc_reg_operand" "")
10801         (match_dup 0))]
10802   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
10803    && peep2_reg_dead_p (2, operands[0])"
10804   [(set (match_dup 2) (match_dup 1))])
10805
10806 (define_peephole2
10807   [(set (match_operand:SF 0 "gpc_reg_operand" "")
10808         (match_operand:SF 1 "any_operand" ""))
10809    (set (match_operand:SF 2 "gpc_reg_operand" "")
10810         (match_dup 0))]
10811   "peep2_reg_dead_p (2, operands[0])"
10812   [(set (match_dup 2) (match_dup 1))])
10813
10814 \f
10815 ;; TLS support.
10816
10817 ;; Mode attributes for different ABIs.
10818 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
10819 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
10820 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
10821 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
10822
10823 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
10824   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10825         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
10826               (match_operand 4 "" "g")))
10827    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10828                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10829                    UNSPEC_TLSGD)
10830    (clobber (reg:SI LR_REGNO))]
10831   "HAVE_AS_TLS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
10832 {
10833   if (TARGET_CMODEL != CMODEL_SMALL)
10834     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;"
10835            "bl %z3\;nop";
10836   else
10837     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;nop";
10838 }
10839   "&& TARGET_TLS_MARKERS"
10840   [(set (match_dup 0)
10841         (unspec:TLSmode [(match_dup 1)
10842                          (match_dup 2)]
10843                         UNSPEC_TLSGD))
10844    (parallel [(set (match_dup 0)
10845                    (call (mem:TLSmode (match_dup 3))
10846                          (match_dup 4)))
10847               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
10848               (clobber (reg:SI LR_REGNO))])]
10849   ""
10850   [(set_attr "type" "two")
10851    (set (attr "length")
10852      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10853                    (const_int 16)
10854                    (const_int 12)))])
10855
10856 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
10857   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10858         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
10859               (match_operand 4 "" "g")))
10860    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10861                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10862                    UNSPEC_TLSGD)
10863    (clobber (reg:SI LR_REGNO))]
10864   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
10865 {
10866   if (flag_pic)
10867     {
10868       if (TARGET_SECURE_PLT && flag_pic == 2)
10869         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
10870       else
10871         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
10872     }
10873   else
10874     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
10875 }
10876   "&& TARGET_TLS_MARKERS"
10877   [(set (match_dup 0)
10878         (unspec:TLSmode [(match_dup 1)
10879                          (match_dup 2)]
10880                         UNSPEC_TLSGD))
10881    (parallel [(set (match_dup 0)
10882                    (call (mem:TLSmode (match_dup 3))
10883                          (match_dup 4)))
10884               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
10885               (clobber (reg:SI LR_REGNO))])]
10886   ""
10887   [(set_attr "type" "two")
10888    (set_attr "length" "8")])
10889
10890 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
10891   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10892         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10893                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10894                         UNSPEC_TLSGD))]
10895   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
10896   "addi %0,%1,%2@got@tlsgd"
10897   "&& TARGET_CMODEL != CMODEL_SMALL"
10898   [(set (match_dup 3)
10899         (high:TLSmode
10900             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))
10901    (set (match_dup 0)
10902         (lo_sum:TLSmode (match_dup 3)
10903             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))]
10904   "
10905 {
10906   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
10907 }"
10908   [(set (attr "length")
10909      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10910                    (const_int 8)
10911                    (const_int 4)))])
10912
10913 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
10914   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10915      (high:TLSmode
10916        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10917                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10918                        UNSPEC_TLSGD)))]
10919   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
10920   "addis %0,%1,%2@got@tlsgd@ha"
10921   [(set_attr "length" "4")])
10922
10923 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
10924   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10925      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
10926        (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
10927                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10928                        UNSPEC_TLSGD)))]
10929   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
10930   "addi %0,%1,%2@got@tlsgd@l"
10931   [(set_attr "length" "4")])
10932
10933 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
10934   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10935         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
10936               (match_operand 2 "" "g")))
10937    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
10938                    UNSPEC_TLSGD)
10939    (clobber (reg:SI LR_REGNO))]
10940   "HAVE_AS_TLS && TARGET_TLS_MARKERS
10941    && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
10942   "bl %z1(%3@tlsgd)\;nop"
10943   [(set_attr "type" "branch")
10944    (set_attr "length" "8")])
10945
10946 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
10947   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10948         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
10949               (match_operand 2 "" "g")))
10950    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
10951                    UNSPEC_TLSGD)
10952    (clobber (reg:SI LR_REGNO))]
10953   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
10954 {
10955   if (flag_pic)
10956     {
10957       if (TARGET_SECURE_PLT && flag_pic == 2)
10958         return "bl %z1+32768(%3@tlsgd)@plt";
10959       return "bl %z1(%3@tlsgd)@plt";
10960     }
10961   return "bl %z1(%3@tlsgd)";
10962 }
10963   [(set_attr "type" "branch")
10964    (set_attr "length" "4")])
10965
10966 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
10967   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10968         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
10969               (match_operand 3 "" "g")))
10970    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
10971                    UNSPEC_TLSLD)
10972    (clobber (reg:SI LR_REGNO))]
10973   "HAVE_AS_TLS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
10974 {
10975   if (TARGET_CMODEL != CMODEL_SMALL)
10976     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;"
10977            "bl %z2\;nop";
10978   else
10979     return "addi %0,%1,%&@got@tlsld\;bl %z2\;nop";
10980 }
10981   "&& TARGET_TLS_MARKERS"
10982   [(set (match_dup 0)
10983         (unspec:TLSmode [(match_dup 1)]
10984                         UNSPEC_TLSLD))
10985    (parallel [(set (match_dup 0)
10986                    (call (mem:TLSmode (match_dup 2))
10987                          (match_dup 3)))
10988               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
10989               (clobber (reg:SI LR_REGNO))])]
10990   ""
10991   [(set_attr "type" "two")
10992    (set (attr "length")
10993      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10994                    (const_int 16)
10995                    (const_int 12)))])
10996
10997 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
10998   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
10999         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11000               (match_operand 3 "" "g")))
11001    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11002                    UNSPEC_TLSLD)
11003    (clobber (reg:SI LR_REGNO))]
11004   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11005 {
11006   if (flag_pic)
11007     {
11008       if (TARGET_SECURE_PLT && flag_pic == 2)
11009         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11010       else
11011         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11012     }
11013   else
11014     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11015 }
11016   "&& TARGET_TLS_MARKERS"
11017   [(set (match_dup 0)
11018         (unspec:TLSmode [(match_dup 1)]
11019                         UNSPEC_TLSLD))
11020    (parallel [(set (match_dup 0)
11021                    (call (mem:TLSmode (match_dup 2))
11022                          (match_dup 3)))
11023               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11024               (clobber (reg:SI LR_REGNO))])]
11025   ""
11026   [(set_attr "length" "8")])
11027
11028 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
11029   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11030         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11031                         UNSPEC_TLSLD))]
11032   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11033   "addi %0,%1,%&@got@tlsld"
11034   "&& TARGET_CMODEL != CMODEL_SMALL"
11035   [(set (match_dup 2)
11036         (high:TLSmode
11037             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))
11038    (set (match_dup 0)
11039         (lo_sum:TLSmode (match_dup 2)
11040             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))]
11041   "
11042 {
11043   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11044 }"
11045   [(set (attr "length")
11046      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11047                    (const_int 8)
11048                    (const_int 4)))])
11049
11050 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
11051   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11052      (high:TLSmode
11053        (unspec:TLSmode [(const_int 0)
11054                         (match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11055                        UNSPEC_TLSLD)))]
11056   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11057   "addis %0,%1,%&@got@tlsld@ha"
11058   [(set_attr "length" "4")])
11059
11060 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
11061   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11062      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11063        (unspec:TLSmode [(const_int 0)
11064                         (match_operand:TLSmode 2 "gpc_reg_operand" "b")]
11065                        UNSPEC_TLSLD)))]
11066   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11067   "addi %0,%1,%&@got@tlsld@l"
11068   [(set_attr "length" "4")])
11069
11070 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11071   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11072         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11073               (match_operand 2 "" "g")))
11074    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11075    (clobber (reg:SI LR_REGNO))]
11076   "HAVE_AS_TLS && TARGET_TLS_MARKERS
11077    && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11078   "bl %z1(%&@tlsld)\;nop"
11079   [(set_attr "type" "branch")
11080    (set_attr "length" "8")])
11081
11082 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11083   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11084         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11085               (match_operand 2 "" "g")))
11086    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11087    (clobber (reg:SI LR_REGNO))]
11088   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11089 {
11090   if (flag_pic)
11091     {
11092       if (TARGET_SECURE_PLT && flag_pic == 2)
11093         return "bl %z1+32768(%&@tlsld)@plt";
11094       return "bl %z1(%&@tlsld)@plt";
11095     }
11096   return "bl %z1(%&@tlsld)";
11097 }
11098   [(set_attr "type" "branch")
11099    (set_attr "length" "4")])
11100
11101 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11102   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11103         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11104                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11105                         UNSPEC_TLSDTPREL))]
11106   "HAVE_AS_TLS"
11107   "addi %0,%1,%2@dtprel")
11108
11109 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11110   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11111         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11112                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11113                         UNSPEC_TLSDTPRELHA))]
11114   "HAVE_AS_TLS"
11115   "addis %0,%1,%2@dtprel@ha")
11116
11117 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11118   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11119         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11120                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11121                         UNSPEC_TLSDTPRELLO))]
11122   "HAVE_AS_TLS"
11123   "addi %0,%1,%2@dtprel@l")
11124
11125 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11126   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11127         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11128                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11129                         UNSPEC_TLSGOTDTPREL))]
11130   "HAVE_AS_TLS"
11131   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
11132   "&& TARGET_CMODEL != CMODEL_SMALL"
11133   [(set (match_dup 3)
11134         (high:TLSmode
11135             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))
11136    (set (match_dup 0)
11137         (lo_sum:TLSmode (match_dup 3)
11138             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
11139   "
11140 {
11141   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11142 }"
11143   [(set (attr "length")
11144      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11145                    (const_int 8)
11146                    (const_int 4)))])
11147
11148 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
11149   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11150      (high:TLSmode
11151        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11152                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11153                        UNSPEC_TLSGOTDTPREL)))]
11154   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11155   "addis %0,%1,%2@got@dtprel@ha"
11156   [(set_attr "length" "4")])
11157
11158 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
11159   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11160      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11161          (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
11162                           (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11163                          UNSPEC_TLSGOTDTPREL)))]
11164   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11165   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
11166   [(set_attr "length" "4")])
11167
11168 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11169   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11170         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11171                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11172                         UNSPEC_TLSTPREL))]
11173   "HAVE_AS_TLS"
11174   "addi %0,%1,%2@tprel")
11175
11176 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11177   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11178         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11179                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11180                         UNSPEC_TLSTPRELHA))]
11181   "HAVE_AS_TLS"
11182   "addis %0,%1,%2@tprel@ha")
11183
11184 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11185   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11186         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11187                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11188                         UNSPEC_TLSTPRELLO))]
11189   "HAVE_AS_TLS"
11190   "addi %0,%1,%2@tprel@l")
11191
11192 ;; "b" output constraint here and on tls_tls input to support linker tls
11193 ;; optimization.  The linker may edit the instructions emitted by a
11194 ;; tls_got_tprel/tls_tls pair to addis,addi.
11195 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11196   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11197         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11198                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11199                         UNSPEC_TLSGOTTPREL))]
11200   "HAVE_AS_TLS"
11201   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
11202   "&& TARGET_CMODEL != CMODEL_SMALL"
11203   [(set (match_dup 3)
11204         (high:TLSmode
11205             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))
11206    (set (match_dup 0)
11207         (lo_sum:TLSmode (match_dup 3)
11208             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))]
11209   "
11210 {
11211   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11212 }"
11213   [(set (attr "length")
11214      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11215                    (const_int 8)
11216                    (const_int 4)))])
11217
11218 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
11219   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11220      (high:TLSmode
11221        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11222                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11223                        UNSPEC_TLSGOTTPREL)))]
11224   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11225   "addis %0,%1,%2@got@tprel@ha"
11226   [(set_attr "length" "4")])
11227
11228 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
11229   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11230      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11231          (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
11232                           (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11233                          UNSPEC_TLSGOTTPREL)))]
11234   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11235   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
11236   [(set_attr "length" "4")])
11237
11238 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11239   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11240         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11241                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11242                         UNSPEC_TLSTLS))]
11243   "TARGET_ELF && HAVE_AS_TLS"
11244   "add %0,%1,%2@tls")
11245
11246 (define_expand "tls_get_tpointer"
11247   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11248         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))]
11249   "TARGET_XCOFF && HAVE_AS_TLS"
11250   "
11251 {
11252   emit_insn (gen_tls_get_tpointer_internal ());
11253   emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
11254   DONE;
11255 }")
11256
11257 (define_insn "tls_get_tpointer_internal"
11258   [(set (reg:SI 3)
11259         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))
11260    (clobber (reg:SI LR_REGNO))]
11261   "TARGET_XCOFF && HAVE_AS_TLS"
11262   "bla __get_tpointer")
11263
11264 (define_expand "tls_get_addr<mode>"
11265   [(set (match_operand:P 0 "gpc_reg_operand" "")
11266         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "")
11267                    (match_operand:P 2 "gpc_reg_operand" "")] UNSPEC_TLSTLS))]
11268   "TARGET_XCOFF && HAVE_AS_TLS"
11269   "
11270 {
11271   emit_move_insn (gen_rtx_REG (Pmode, 3), operands[1]);
11272   emit_move_insn (gen_rtx_REG (Pmode, 4), operands[2]);
11273   emit_insn (gen_tls_get_addr_internal<mode> ());
11274   emit_move_insn (operands[0], gen_rtx_REG (Pmode, 3));
11275   DONE;
11276 }")
11277
11278 (define_insn "tls_get_addr_internal<mode>"
11279   [(set (reg:P 3)
11280         (unspec:P [(reg:P 3) (reg:P 4)] UNSPEC_TLSTLS))
11281    (clobber (reg:P 0))
11282    (clobber (reg:P 4))
11283    (clobber (reg:P 5))
11284    (clobber (reg:P 11))
11285    (clobber (reg:CC CR0_REGNO))
11286    (clobber (reg:P LR_REGNO))]
11287   "TARGET_XCOFF && HAVE_AS_TLS"
11288   "bla __tls_get_addr")
11289 \f
11290 ;; Next come insns related to the calling sequence.
11291 ;;
11292 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11293 ;; We move the back-chain and decrement the stack pointer.
11294
11295 (define_expand "allocate_stack"
11296   [(set (match_operand 0 "gpc_reg_operand" "")
11297         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11298    (set (reg 1)
11299         (minus (reg 1) (match_dup 1)))]
11300   ""
11301   "
11302 { rtx chain = gen_reg_rtx (Pmode);
11303   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11304   rtx neg_op0;
11305   rtx insn, par, set, mem;
11306
11307   emit_move_insn (chain, stack_bot);
11308
11309   /* Check stack bounds if necessary.  */
11310   if (crtl->limit_stack)
11311     {
11312       rtx available;
11313       available = expand_binop (Pmode, sub_optab,
11314                                 stack_pointer_rtx, stack_limit_rtx,
11315                                 NULL_RTX, 1, OPTAB_WIDEN);
11316       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11317     }
11318
11319   if (GET_CODE (operands[1]) != CONST_INT
11320       || INTVAL (operands[1]) < -32767
11321       || INTVAL (operands[1]) > 32768)
11322     {
11323       neg_op0 = gen_reg_rtx (Pmode);
11324       if (TARGET_32BIT)
11325         emit_insn (gen_negsi2 (neg_op0, operands[1]));
11326       else
11327         emit_insn (gen_negdi2 (neg_op0, operands[1]));
11328     }
11329   else
11330     neg_op0 = GEN_INT (- INTVAL (operands[1]));
11331
11332   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
11333                                        : gen_movdi_di_update_stack))
11334                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
11335                          chain));
11336   /* Since we didn't use gen_frame_mem to generate the MEM, grab
11337      it now and set the alias set/attributes. The above gen_*_update
11338      calls will generate a PARALLEL with the MEM set being the first
11339      operation. */
11340   par = PATTERN (insn);
11341   gcc_assert (GET_CODE (par) == PARALLEL);
11342   set = XVECEXP (par, 0, 0);
11343   gcc_assert (GET_CODE (set) == SET);
11344   mem = SET_DEST (set);
11345   gcc_assert (MEM_P (mem));
11346   MEM_NOTRAP_P (mem) = 1;
11347   set_mem_alias_set (mem, get_frame_alias_set ());
11348
11349   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
11350   DONE;
11351 }")
11352
11353 ;; These patterns say how to save and restore the stack pointer.  We need not
11354 ;; save the stack pointer at function level since we are careful to
11355 ;; preserve the backchain.  At block level, we have to restore the backchain
11356 ;; when we restore the stack pointer.
11357 ;;
11358 ;; For nonlocal gotos, we must save both the stack pointer and its
11359 ;; backchain and restore both.  Note that in the nonlocal case, the
11360 ;; save area is a memory location.
11361
11362 (define_expand "save_stack_function"
11363   [(match_operand 0 "any_operand" "")
11364    (match_operand 1 "any_operand" "")]
11365   ""
11366   "DONE;")
11367
11368 (define_expand "restore_stack_function"
11369   [(match_operand 0 "any_operand" "")
11370    (match_operand 1 "any_operand" "")]
11371   ""
11372   "DONE;")
11373
11374 ;; Adjust stack pointer (op0) to a new value (op1).
11375 ;; First copy old stack backchain to new location, and ensure that the
11376 ;; scheduler won't reorder the sp assignment before the backchain write.
11377 (define_expand "restore_stack_block"
11378   [(set (match_dup 2) (match_dup 3))
11379    (set (match_dup 4) (match_dup 2))
11380    (match_dup 5)
11381    (set (match_operand 0 "register_operand" "")
11382         (match_operand 1 "register_operand" ""))]
11383   ""
11384   "
11385 {
11386   rtvec p;
11387
11388   operands[1] = force_reg (Pmode, operands[1]);
11389   operands[2] = gen_reg_rtx (Pmode);
11390   operands[3] = gen_frame_mem (Pmode, operands[0]);
11391   operands[4] = gen_frame_mem (Pmode, operands[1]);
11392   p = rtvec_alloc (1);
11393   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
11394                                   gen_frame_mem (BLKmode, operands[0]),
11395                                   const0_rtx);
11396   operands[5] = gen_rtx_PARALLEL (VOIDmode, p);
11397 }")
11398
11399 (define_expand "save_stack_nonlocal"
11400   [(set (match_dup 3) (match_dup 4))
11401    (set (match_operand 0 "memory_operand" "") (match_dup 3))
11402    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
11403   ""
11404   "
11405 {
11406   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11407
11408   /* Copy the backchain to the first word, sp to the second.  */
11409   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
11410   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
11411   operands[3] = gen_reg_rtx (Pmode);
11412   operands[4] = gen_frame_mem (Pmode, operands[1]);
11413 }")
11414
11415 (define_expand "restore_stack_nonlocal"
11416   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
11417    (set (match_dup 3) (match_dup 4))
11418    (set (match_dup 5) (match_dup 2))
11419    (match_dup 6)
11420    (set (match_operand 0 "register_operand" "") (match_dup 3))]
11421   ""
11422   "
11423 {
11424   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11425   rtvec p;
11426
11427   /* Restore the backchain from the first word, sp from the second.  */
11428   operands[2] = gen_reg_rtx (Pmode);
11429   operands[3] = gen_reg_rtx (Pmode);
11430   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
11431   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
11432   operands[5] = gen_frame_mem (Pmode, operands[3]);
11433   p = rtvec_alloc (1);
11434   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
11435                                   gen_frame_mem (BLKmode, operands[0]),
11436                                   const0_rtx);
11437   operands[6] = gen_rtx_PARALLEL (VOIDmode, p);
11438 }")
11439 \f
11440 ;; TOC register handling.
11441
11442 ;; Code to initialize the TOC register...
11443
11444 (define_insn "load_toc_aix_si"
11445   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11446                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
11447               (use (reg:SI 2))])]
11448   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && TARGET_32BIT"
11449   "*
11450 {
11451   char buf[30];
11452   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11453   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11454   operands[2] = gen_rtx_REG (Pmode, 2);
11455   return \"lwz %0,%1(%2)\";
11456 }"
11457   [(set_attr "type" "load")
11458    (set_attr "update" "no")
11459    (set_attr "indexed" "no")])
11460
11461 (define_insn "load_toc_aix_di"
11462   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11463                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
11464               (use (reg:DI 2))])]
11465   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && TARGET_64BIT"
11466   "*
11467 {
11468   char buf[30];
11469 #ifdef TARGET_RELOCATABLE
11470   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
11471                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
11472 #else
11473   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11474 #endif
11475   if (TARGET_ELF)
11476     strcat (buf, \"@toc\");
11477   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11478   operands[2] = gen_rtx_REG (Pmode, 2);
11479   return \"ld %0,%1(%2)\";
11480 }"
11481   [(set_attr "type" "load")
11482    (set_attr "update" "no")
11483    (set_attr "indexed" "no")])
11484
11485 (define_insn "load_toc_v4_pic_si"
11486   [(set (reg:SI LR_REGNO)
11487         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
11488   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
11489   "bl _GLOBAL_OFFSET_TABLE_@local-4"
11490   [(set_attr "type" "branch")
11491    (set_attr "length" "4")])
11492
11493 (define_expand "load_toc_v4_PIC_1"
11494   [(parallel [(set (reg:SI LR_REGNO)
11495                    (match_operand:SI 0 "immediate_operand" "s"))
11496               (use (unspec [(match_dup 0)] UNSPEC_TOC))])]
11497   "TARGET_ELF && DEFAULT_ABI == ABI_V4
11498    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11499   "")
11500
11501 (define_insn "load_toc_v4_PIC_1_normal"
11502   [(set (reg:SI LR_REGNO)
11503         (match_operand:SI 0 "immediate_operand" "s"))
11504    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11505   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4
11506    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11507   "bcl 20,31,%0\\n%0:"
11508   [(set_attr "type" "branch")
11509    (set_attr "length" "4")])
11510
11511 (define_insn "load_toc_v4_PIC_1_476"
11512   [(set (reg:SI LR_REGNO)
11513         (match_operand:SI 0 "immediate_operand" "s"))
11514    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11515   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4
11516    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11517   "*
11518 {
11519   char name[32];
11520   static char templ[32];
11521
11522   get_ppc476_thunk_name (name);
11523   sprintf (templ, \"bl %s\\n%%0:\", name);
11524   return templ;
11525 }"
11526   [(set_attr "type" "branch")
11527    (set_attr "length" "4")])
11528
11529 (define_expand "load_toc_v4_PIC_1b"
11530   [(parallel [(set (reg:SI LR_REGNO)
11531                    (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11532                                (label_ref (match_operand 1 "" ""))]
11533                            UNSPEC_TOCPTR))
11534               (match_dup 1)])]
11535   "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11536   "")
11537
11538 (define_insn "load_toc_v4_PIC_1b_normal"
11539   [(set (reg:SI LR_REGNO)
11540         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11541                     (label_ref (match_operand 1 "" ""))]
11542                 UNSPEC_TOCPTR))
11543    (match_dup 1)]
11544   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11545   "bcl 20,31,$+8\;.long %0-$"
11546   [(set_attr "type" "branch")
11547    (set_attr "length" "8")])
11548
11549 (define_insn "load_toc_v4_PIC_1b_476"
11550   [(set (reg:SI LR_REGNO)
11551         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11552                     (label_ref (match_operand 1 "" ""))]
11553                 UNSPEC_TOCPTR))
11554    (match_dup 1)]
11555   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11556   "*
11557 {
11558   char name[32];
11559   static char templ[32];
11560
11561   get_ppc476_thunk_name (name);
11562   sprintf (templ, \"bl %s\\n\\tb $+8\\n\\t.long %%0-$\", name);
11563   return templ;
11564 }"
11565   [(set_attr "type" "branch")
11566    (set_attr "length" "16")])
11567
11568 (define_insn "load_toc_v4_PIC_2"
11569   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11570         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11571                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
11572                              (match_operand:SI 3 "immediate_operand" "s")))))]
11573   "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11574   "lwz %0,%2-%3(%1)"
11575   [(set_attr "type" "load")])
11576
11577 (define_insn "load_toc_v4_PIC_3b"
11578   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11579         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11580                  (high:SI
11581                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11582                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
11583   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
11584   "addis %0,%1,%2-%3@ha")
11585
11586 (define_insn "load_toc_v4_PIC_3c"
11587   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11588         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11589                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11590                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
11591   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
11592   "addi %0,%1,%2-%3@l")
11593
11594 ;; If the TOC is shared over a translation unit, as happens with all
11595 ;; the kinds of PIC that we support, we need to restore the TOC
11596 ;; pointer only when jumping over units of translation.
11597 ;; On Darwin, we need to reload the picbase.
11598
11599 (define_expand "builtin_setjmp_receiver"
11600   [(use (label_ref (match_operand 0 "" "")))]
11601   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11602    || (TARGET_TOC && TARGET_MINIMAL_TOC)
11603    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
11604   "
11605 {
11606 #if TARGET_MACHO
11607   if (DEFAULT_ABI == ABI_DARWIN)
11608     {
11609       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
11610       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
11611       rtx tmplabrtx;
11612       char tmplab[20];
11613
11614       crtl->uses_pic_offset_table = 1;
11615       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
11616                                   CODE_LABEL_NUMBER (operands[0]));
11617       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
11618
11619       emit_insn (gen_load_macho_picbase (tmplabrtx));
11620       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
11621       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
11622     }
11623   else
11624 #endif
11625     rs6000_emit_load_toc_table (FALSE);
11626   DONE;
11627 }")
11628
11629 ;; Largetoc support
11630 (define_insn "*largetoc_high"
11631   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11632         (high:DI
11633           (unspec [(match_operand:DI 1 "" "")
11634                    (match_operand:DI 2 "gpc_reg_operand" "b")]
11635                   UNSPEC_TOCREL)))]
11636    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11637    "addis %0,%2,%1@toc@ha")
11638
11639 (define_insn "*largetoc_high_aix<mode>"
11640   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11641         (high:P
11642           (unspec [(match_operand:P 1 "" "")
11643                    (match_operand:P 2 "gpc_reg_operand" "b")]
11644                   UNSPEC_TOCREL)))]
11645    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11646    "addis %0,%1@u(%2)")
11647
11648 (define_insn "*largetoc_high_plus"
11649   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11650         (high:DI
11651           (plus:DI
11652             (unspec [(match_operand:DI 1 "" "")
11653                      (match_operand:DI 2 "gpc_reg_operand" "b")]
11654                     UNSPEC_TOCREL)
11655             (match_operand:DI 3 "add_cint_operand" "n"))))]
11656    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11657    "addis %0,%2,%1+%3@toc@ha")
11658
11659 (define_insn "*largetoc_high_plus_aix<mode>"
11660   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11661         (high:P
11662           (plus:P
11663             (unspec [(match_operand:P 1 "" "")
11664                      (match_operand:P 2 "gpc_reg_operand" "b")]
11665                     UNSPEC_TOCREL)
11666             (match_operand:P 3 "add_cint_operand" "n"))))]
11667    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11668    "addis %0,%1+%3@u(%2)")
11669
11670 (define_insn "*largetoc_low"
11671   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11672         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,!*r")
11673                    (match_operand:DI 2 "" "")))]
11674    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11675    "@
11676     addi %0,%1,%2@l
11677     addic %0,%1,%2@l")
11678
11679 (define_insn "*largetoc_low_aix<mode>"
11680   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11681         (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
11682                    (match_operand:P 2 "" "")))]
11683    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11684    "la %0,%2@l(%1)")
11685
11686 (define_insn_and_split "*tocref<mode>"
11687   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11688         (match_operand:P 1 "small_toc_ref" "R"))]
11689    "TARGET_TOC"
11690    "la %0,%a1"
11691    "&& TARGET_CMODEL != CMODEL_SMALL && reload_completed"
11692   [(set (match_dup 0) (high:P (match_dup 1)))
11693    (set (match_dup 0) (lo_sum:P (match_dup 0) (match_dup 1)))])
11694
11695 ;; Elf specific ways of loading addresses for non-PIC code.
11696 ;; The output of this could be r0, but we make a very strong
11697 ;; preference for a base register because it will usually
11698 ;; be needed there.
11699 (define_insn "elf_high"
11700   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
11701         (high:SI (match_operand 1 "" "")))]
11702   "TARGET_ELF && ! TARGET_64BIT"
11703   "lis %0,%1@ha")
11704
11705 (define_insn "elf_low"
11706   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11707         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
11708                    (match_operand 2 "" "")))]
11709    "TARGET_ELF && ! TARGET_64BIT"
11710    "@
11711     la %0,%2@l(%1)
11712     addic %0,%1,%K2")
11713 \f
11714 ;; Call and call_value insns
11715 (define_expand "call"
11716   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11717                     (match_operand 1 "" ""))
11718               (use (match_operand 2 "" ""))
11719               (clobber (reg:SI LR_REGNO))])]
11720   ""
11721   "
11722 {
11723 #if TARGET_MACHO
11724   if (MACHOPIC_INDIRECT)
11725     operands[0] = machopic_indirect_call_target (operands[0]);
11726 #endif
11727
11728   gcc_assert (GET_CODE (operands[0]) == MEM);
11729   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11730
11731   operands[0] = XEXP (operands[0], 0);
11732
11733   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
11734     {
11735       rs6000_call_aix (NULL_RTX, operands[0], operands[1], operands[2]);
11736       DONE;
11737     }
11738
11739   if (GET_CODE (operands[0]) != SYMBOL_REF
11740       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
11741     {
11742       if (INTVAL (operands[2]) & CALL_LONG)
11743         operands[0] = rs6000_longcall_ref (operands[0]);
11744
11745       switch (DEFAULT_ABI)
11746         {
11747         case ABI_V4:
11748         case ABI_DARWIN:
11749           operands[0] = force_reg (Pmode, operands[0]);
11750           break;
11751
11752         default:
11753           gcc_unreachable ();
11754         }
11755     }
11756 }")
11757
11758 (define_expand "call_value"
11759   [(parallel [(set (match_operand 0 "" "")
11760                    (call (mem:SI (match_operand 1 "address_operand" ""))
11761                          (match_operand 2 "" "")))
11762               (use (match_operand 3 "" ""))
11763               (clobber (reg:SI LR_REGNO))])]
11764   ""
11765   "
11766 {
11767 #if TARGET_MACHO
11768   if (MACHOPIC_INDIRECT)
11769     operands[1] = machopic_indirect_call_target (operands[1]);
11770 #endif
11771
11772   gcc_assert (GET_CODE (operands[1]) == MEM);
11773   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11774
11775   operands[1] = XEXP (operands[1], 0);
11776
11777   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
11778     {
11779       rs6000_call_aix (operands[0], operands[1], operands[2], operands[3]);
11780       DONE;
11781     }
11782
11783   if (GET_CODE (operands[1]) != SYMBOL_REF
11784       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
11785     {
11786       if (INTVAL (operands[3]) & CALL_LONG)
11787         operands[1] = rs6000_longcall_ref (operands[1]);
11788
11789       switch (DEFAULT_ABI)
11790         {
11791         case ABI_V4:
11792         case ABI_DARWIN:
11793           operands[1] = force_reg (Pmode, operands[1]);
11794           break;
11795
11796         default:
11797           gcc_unreachable ();
11798         }
11799     }
11800 }")
11801
11802 ;; Call to function in current module.  No TOC pointer reload needed.
11803 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11804 ;; either the function was not prototyped, or it was prototyped as a
11805 ;; variable argument function.  It is > 0 if FP registers were passed
11806 ;; and < 0 if they were not.
11807
11808 (define_insn "*call_local32"
11809   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11810          (match_operand 1 "" "g,g"))
11811    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11812    (clobber (reg:SI LR_REGNO))]
11813   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11814   "*
11815 {
11816   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11817     output_asm_insn (\"crxor 6,6,6\", operands);
11818
11819   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11820     output_asm_insn (\"creqv 6,6,6\", operands);
11821
11822   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11823 }"
11824   [(set_attr "type" "branch")
11825    (set_attr "length" "4,8")])
11826
11827 (define_insn "*call_local64"
11828   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11829          (match_operand 1 "" "g,g"))
11830    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11831    (clobber (reg:SI LR_REGNO))]
11832   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11833   "*
11834 {
11835   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11836     output_asm_insn (\"crxor 6,6,6\", operands);
11837
11838   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11839     output_asm_insn (\"creqv 6,6,6\", operands);
11840
11841   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
11842 }"
11843   [(set_attr "type" "branch")
11844    (set_attr "length" "4,8")])
11845
11846 (define_insn "*call_value_local32"
11847   [(set (match_operand 0 "" "")
11848         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11849               (match_operand 2 "" "g,g")))
11850    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11851    (clobber (reg:SI LR_REGNO))]
11852   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11853   "*
11854 {
11855   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11856     output_asm_insn (\"crxor 6,6,6\", operands);
11857
11858   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11859     output_asm_insn (\"creqv 6,6,6\", operands);
11860
11861   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11862 }"
11863   [(set_attr "type" "branch")
11864    (set_attr "length" "4,8")])
11865
11866
11867 (define_insn "*call_value_local64"
11868   [(set (match_operand 0 "" "")
11869         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11870               (match_operand 2 "" "g,g")))
11871    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11872    (clobber (reg:SI LR_REGNO))]
11873   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11874   "*
11875 {
11876   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11877     output_asm_insn (\"crxor 6,6,6\", operands);
11878
11879   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11880     output_asm_insn (\"creqv 6,6,6\", operands);
11881
11882   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
11883 }"
11884   [(set_attr "type" "branch")
11885    (set_attr "length" "4,8")])
11886
11887
11888 ;; A function pointer under System V is just a normal pointer
11889 ;; operands[0] is the function pointer
11890 ;; operands[1] is the stack size to clean up
11891 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
11892 ;; which indicates how to set cr1
11893
11894 (define_insn "*call_indirect_nonlocal_sysv<mode>"
11895   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
11896          (match_operand 1 "" "g,g,g,g"))
11897    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
11898    (clobber (reg:SI LR_REGNO))]
11899   "DEFAULT_ABI == ABI_V4
11900    || DEFAULT_ABI == ABI_DARWIN"
11901 {
11902   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11903     output_asm_insn ("crxor 6,6,6", operands);
11904
11905   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11906     output_asm_insn ("creqv 6,6,6", operands);
11907
11908   return "b%T0l";
11909 }
11910   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
11911    (set_attr "length" "4,4,8,8")])
11912
11913 (define_insn_and_split "*call_nonlocal_sysv<mode>"
11914   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11915          (match_operand 1 "" "g,g"))
11916    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11917    (clobber (reg:SI LR_REGNO))]
11918   "(DEFAULT_ABI == ABI_DARWIN
11919    || (DEFAULT_ABI == ABI_V4
11920        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
11921 {
11922   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11923     output_asm_insn ("crxor 6,6,6", operands);
11924
11925   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11926     output_asm_insn ("creqv 6,6,6", operands);
11927
11928 #if TARGET_MACHO
11929   return output_call(insn, operands, 0, 2);
11930 #else
11931   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11932     {
11933       gcc_assert (!TARGET_SECURE_PLT);
11934       return "bl %z0@plt";
11935     }
11936   else
11937     return "bl %z0";
11938 #endif
11939 }
11940   "DEFAULT_ABI == ABI_V4
11941    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
11942    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11943   [(parallel [(call (mem:SI (match_dup 0))
11944                     (match_dup 1))
11945               (use (match_dup 2))
11946               (use (match_dup 3))
11947               (clobber (reg:SI LR_REGNO))])]
11948 {
11949   operands[3] = pic_offset_table_rtx;
11950 }
11951   [(set_attr "type" "branch,branch")
11952    (set_attr "length" "4,8")])
11953
11954 (define_insn "*call_nonlocal_sysv_secure<mode>"
11955   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11956          (match_operand 1 "" "g,g"))
11957    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11958    (use (match_operand:SI 3 "register_operand" "r,r"))
11959    (clobber (reg:SI LR_REGNO))]
11960   "(DEFAULT_ABI == ABI_V4
11961     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
11962     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
11963 {
11964   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11965     output_asm_insn ("crxor 6,6,6", operands);
11966
11967   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11968     output_asm_insn ("creqv 6,6,6", operands);
11969
11970   if (flag_pic == 2)
11971     /* The magic 32768 offset here and in the other sysv call insns
11972        corresponds to the offset of r30 in .got2, as given by LCTOC1.
11973        See sysv4.h:toc_section.  */
11974     return "bl %z0+32768@plt";
11975   else
11976     return "bl %z0@plt";
11977 }
11978   [(set_attr "type" "branch,branch")
11979    (set_attr "length" "4,8")])
11980
11981 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
11982   [(set (match_operand 0 "" "")
11983         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
11984               (match_operand 2 "" "g,g,g,g")))
11985    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
11986    (clobber (reg:SI LR_REGNO))]
11987   "DEFAULT_ABI == ABI_V4
11988    || DEFAULT_ABI == ABI_DARWIN"
11989 {
11990   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11991     output_asm_insn ("crxor 6,6,6", operands);
11992
11993   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11994     output_asm_insn ("creqv 6,6,6", operands);
11995
11996   return "b%T1l";
11997 }
11998   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
11999    (set_attr "length" "4,4,8,8")])
12000
12001 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12002   [(set (match_operand 0 "" "")
12003         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12004               (match_operand 2 "" "g,g")))
12005    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12006    (clobber (reg:SI LR_REGNO))]
12007   "(DEFAULT_ABI == ABI_DARWIN
12008    || (DEFAULT_ABI == ABI_V4
12009        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12010 {
12011   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12012     output_asm_insn ("crxor 6,6,6", operands);
12013
12014   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12015     output_asm_insn ("creqv 6,6,6", operands);
12016
12017 #if TARGET_MACHO
12018   return output_call(insn, operands, 1, 3);
12019 #else
12020   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12021     {
12022       gcc_assert (!TARGET_SECURE_PLT);
12023       return "bl %z1@plt";
12024     }
12025   else
12026     return "bl %z1";
12027 #endif
12028 }
12029   "DEFAULT_ABI == ABI_V4
12030    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12031    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12032   [(parallel [(set (match_dup 0)
12033                    (call (mem:SI (match_dup 1))
12034                          (match_dup 2)))
12035               (use (match_dup 3))
12036               (use (match_dup 4))
12037               (clobber (reg:SI LR_REGNO))])]
12038 {
12039   operands[4] = pic_offset_table_rtx;
12040 }
12041   [(set_attr "type" "branch,branch")
12042    (set_attr "length" "4,8")])
12043
12044 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12045   [(set (match_operand 0 "" "")
12046         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12047               (match_operand 2 "" "g,g")))
12048    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12049    (use (match_operand:SI 4 "register_operand" "r,r"))
12050    (clobber (reg:SI LR_REGNO))]
12051   "(DEFAULT_ABI == ABI_V4
12052     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12053     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12054 {
12055   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12056     output_asm_insn ("crxor 6,6,6", operands);
12057
12058   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12059     output_asm_insn ("creqv 6,6,6", operands);
12060
12061   if (flag_pic == 2)
12062     return "bl %z1+32768@plt";
12063   else
12064     return "bl %z1@plt";
12065 }
12066   [(set_attr "type" "branch,branch")
12067    (set_attr "length" "4,8")])
12068
12069
12070 ;; Call to AIX abi function in the same module.
12071
12072 (define_insn "*call_local_aix<mode>"
12073   [(call (mem:SI (match_operand:P 0 "current_file_function_operand" "s"))
12074          (match_operand 1 "" "g"))
12075    (clobber (reg:P LR_REGNO))]
12076   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12077   "bl %z0"
12078   [(set_attr "type" "branch")
12079    (set_attr "length" "4")])
12080
12081 (define_insn "*call_value_local_aix<mode>"
12082   [(set (match_operand 0 "" "")
12083         (call (mem:SI (match_operand:P 1 "current_file_function_operand" "s"))
12084               (match_operand 2 "" "g")))
12085    (clobber (reg:P LR_REGNO))]
12086   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12087   "bl %z1"
12088   [(set_attr "type" "branch")
12089    (set_attr "length" "4")])
12090
12091 ;; Call to AIX abi function which may be in another module.
12092 ;; Restore the TOC pointer (r2) after the call.
12093
12094 (define_insn "*call_nonlocal_aix<mode>"
12095   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s"))
12096          (match_operand 1 "" "g"))
12097    (clobber (reg:P LR_REGNO))]
12098   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12099   "bl %z0\;nop"
12100   [(set_attr "type" "branch")
12101    (set_attr "length" "8")])
12102
12103 (define_insn "*call_value_nonlocal_aix<mode>"
12104   [(set (match_operand 0 "" "")
12105         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s"))
12106               (match_operand 2 "" "g")))
12107    (clobber (reg:P LR_REGNO))]
12108   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12109   "bl %z1\;nop"
12110   [(set_attr "type" "branch")
12111    (set_attr "length" "8")])
12112
12113 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
12114 ;; Operand0 is the addresss of the function to call
12115 ;; Operand2 is the location in the function descriptor to load r2 from
12116 ;; Operand3 is the stack location to hold the current TOC pointer
12117
12118 (define_insn "*call_indirect_aix<mode>"
12119   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12120          (match_operand 1 "" "g,g"))
12121    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
12122    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12123    (clobber (reg:P LR_REGNO))]
12124   "DEFAULT_ABI == ABI_AIX"
12125   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
12126   [(set_attr "type" "jmpreg")
12127    (set_attr "length" "12")])
12128
12129 (define_insn "*call_value_indirect_aix<mode>"
12130   [(set (match_operand 0 "" "")
12131         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12132               (match_operand 2 "" "g,g")))
12133    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12134    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
12135    (clobber (reg:P LR_REGNO))]
12136   "DEFAULT_ABI == ABI_AIX"
12137   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12138   [(set_attr "type" "jmpreg")
12139    (set_attr "length" "12")])
12140
12141 ;; Call to indirect functions with the ELFv2 ABI.
12142 ;; Operand0 is the addresss of the function to call
12143 ;; Operand2 is the stack location to hold the current TOC pointer
12144
12145 (define_insn "*call_indirect_elfv2<mode>"
12146   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12147          (match_operand 1 "" "g,g"))
12148    (set (reg:P TOC_REGNUM) (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
12149    (clobber (reg:P LR_REGNO))]
12150   "DEFAULT_ABI == ABI_ELFv2"
12151   "b%T0l\;<ptrload> 2,%2"
12152   [(set_attr "type" "jmpreg")
12153    (set_attr "length" "8")])
12154
12155 (define_insn "*call_value_indirect_elfv2<mode>"
12156   [(set (match_operand 0 "" "")
12157         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12158               (match_operand 2 "" "g,g")))
12159    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12160    (clobber (reg:P LR_REGNO))]
12161   "DEFAULT_ABI == ABI_ELFv2"
12162   "b%T1l\;<ptrload> 2,%3"
12163   [(set_attr "type" "jmpreg")
12164    (set_attr "length" "8")])
12165
12166
12167 ;; Call subroutine returning any type.
12168 (define_expand "untyped_call"
12169   [(parallel [(call (match_operand 0 "" "")
12170                     (const_int 0))
12171               (match_operand 1 "" "")
12172               (match_operand 2 "" "")])]
12173   ""
12174   "
12175 {
12176   int i;
12177
12178   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12179
12180   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12181     {
12182       rtx set = XVECEXP (operands[2], 0, i);
12183       emit_move_insn (SET_DEST (set), SET_SRC (set));
12184     }
12185
12186   /* The optimizer does not know that the call sets the function value
12187      registers we stored in the result block.  We avoid problems by
12188      claiming that all hard registers are used and clobbered at this
12189      point.  */
12190   emit_insn (gen_blockage ());
12191
12192   DONE;
12193 }")
12194
12195 ;; sibling call patterns
12196 (define_expand "sibcall"
12197   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12198                     (match_operand 1 "" ""))
12199               (use (match_operand 2 "" ""))
12200               (use (reg:SI LR_REGNO))
12201               (simple_return)])]
12202   ""
12203   "
12204 {
12205 #if TARGET_MACHO
12206   if (MACHOPIC_INDIRECT)
12207     operands[0] = machopic_indirect_call_target (operands[0]);
12208 #endif
12209
12210   gcc_assert (GET_CODE (operands[0]) == MEM);
12211   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12212
12213   operands[0] = XEXP (operands[0], 0);
12214
12215   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12216     {
12217       rs6000_sibcall_aix (NULL_RTX, operands[0], operands[1], operands[2]);
12218       DONE;
12219     }
12220 }")
12221
12222 (define_expand "sibcall_value"
12223   [(parallel [(set (match_operand 0 "register_operand" "")
12224                 (call (mem:SI (match_operand 1 "address_operand" ""))
12225                       (match_operand 2 "" "")))
12226               (use (match_operand 3 "" ""))
12227               (use (reg:SI LR_REGNO))
12228               (simple_return)])]
12229   ""
12230   "
12231 {
12232 #if TARGET_MACHO
12233   if (MACHOPIC_INDIRECT)
12234     operands[1] = machopic_indirect_call_target (operands[1]);
12235 #endif
12236
12237   gcc_assert (GET_CODE (operands[1]) == MEM);
12238   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12239
12240   operands[1] = XEXP (operands[1], 0);
12241
12242   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12243     {
12244       rs6000_sibcall_aix (operands[0], operands[1], operands[2], operands[3]);
12245       DONE;
12246     }
12247 }")
12248
12249 ;; this and similar patterns must be marked as using LR, otherwise
12250 ;; dataflow will try to delete the store into it.  This is true
12251 ;; even when the actual reg to jump to is in CTR, when LR was
12252 ;; saved and restored around the PIC-setting BCL.
12253 (define_insn "*sibcall_local32"
12254   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12255          (match_operand 1 "" "g,g"))
12256    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12257    (use (reg:SI LR_REGNO))
12258    (simple_return)]
12259   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12260   "*
12261 {
12262   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12263     output_asm_insn (\"crxor 6,6,6\", operands);
12264
12265   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12266     output_asm_insn (\"creqv 6,6,6\", operands);
12267
12268   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12269 }"
12270   [(set_attr "type" "branch")
12271    (set_attr "length" "4,8")])
12272
12273 (define_insn "*sibcall_local64"
12274   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12275          (match_operand 1 "" "g,g"))
12276    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12277    (use (reg:SI LR_REGNO))
12278    (simple_return)]
12279   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12280   "*
12281 {
12282   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12283     output_asm_insn (\"crxor 6,6,6\", operands);
12284
12285   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12286     output_asm_insn (\"creqv 6,6,6\", operands);
12287
12288   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12289 }"
12290   [(set_attr "type" "branch")
12291    (set_attr "length" "4,8")])
12292
12293 (define_insn "*sibcall_value_local32"
12294   [(set (match_operand 0 "" "")
12295         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12296               (match_operand 2 "" "g,g")))
12297    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12298    (use (reg:SI LR_REGNO))
12299    (simple_return)]
12300   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12301   "*
12302 {
12303   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12304     output_asm_insn (\"crxor 6,6,6\", operands);
12305
12306   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12307     output_asm_insn (\"creqv 6,6,6\", operands);
12308
12309   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12310 }"
12311   [(set_attr "type" "branch")
12312    (set_attr "length" "4,8")])
12313
12314 (define_insn "*sibcall_value_local64"
12315   [(set (match_operand 0 "" "")
12316         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12317               (match_operand 2 "" "g,g")))
12318    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12319    (use (reg:SI LR_REGNO))
12320    (simple_return)]
12321   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12322   "*
12323 {
12324   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12325     output_asm_insn (\"crxor 6,6,6\", operands);
12326
12327   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12328     output_asm_insn (\"creqv 6,6,6\", operands);
12329
12330   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12331 }"
12332   [(set_attr "type" "branch")
12333    (set_attr "length" "4,8")])
12334
12335 (define_insn "*sibcall_nonlocal_sysv<mode>"
12336   [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c"))
12337          (match_operand 1 "" ""))
12338    (use (match_operand 2 "immediate_operand" "O,n,O,n"))
12339    (use (reg:SI LR_REGNO))
12340    (simple_return)]
12341   "(DEFAULT_ABI == ABI_DARWIN
12342     || DEFAULT_ABI == ABI_V4)
12343    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12344   "*
12345 {
12346   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12347     output_asm_insn (\"crxor 6,6,6\", operands);
12348
12349   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12350     output_asm_insn (\"creqv 6,6,6\", operands);
12351
12352   if (which_alternative >= 2)
12353     return \"b%T0\";
12354   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12355     {
12356       gcc_assert (!TARGET_SECURE_PLT);
12357       return \"b %z0@plt\";
12358     }
12359   else
12360     return \"b %z0\";
12361 }"
12362   [(set_attr "type" "branch")
12363    (set_attr "length" "4,8,4,8")])
12364
12365 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
12366   [(set (match_operand 0 "" "")
12367         (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c"))
12368               (match_operand 2 "" "")))
12369    (use (match_operand:SI 3 "immediate_operand" "O,n,O,n"))
12370    (use (reg:SI LR_REGNO))
12371    (simple_return)]
12372   "(DEFAULT_ABI == ABI_DARWIN
12373     || DEFAULT_ABI == ABI_V4)
12374    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12375   "*
12376 {
12377   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12378     output_asm_insn (\"crxor 6,6,6\", operands);
12379
12380   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12381     output_asm_insn (\"creqv 6,6,6\", operands);
12382
12383   if (which_alternative >= 2)
12384     return \"b%T1\";
12385   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12386     {
12387       gcc_assert (!TARGET_SECURE_PLT);
12388       return \"b %z1@plt\";
12389     }
12390   else
12391     return \"b %z1\";
12392 }"
12393   [(set_attr "type" "branch")
12394    (set_attr "length" "4,8,4,8")])
12395
12396 ;; AIX ABI sibling call patterns.
12397
12398 (define_insn "*sibcall_aix<mode>"
12399   [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
12400          (match_operand 1 "" "g,g"))
12401    (simple_return)]
12402   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12403   "@
12404    b %z0
12405    b%T0"
12406   [(set_attr "type" "branch")
12407    (set_attr "length" "4")])
12408
12409 (define_insn "*sibcall_value_aix<mode>"
12410   [(set (match_operand 0 "" "")
12411         (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
12412               (match_operand 2 "" "g,g")))
12413    (simple_return)]
12414   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12415   "@
12416    b %z1
12417    b%T1"
12418   [(set_attr "type" "branch")
12419    (set_attr "length" "4")])
12420
12421 (define_expand "sibcall_epilogue"
12422   [(use (const_int 0))]
12423   ""
12424 {
12425   if (!TARGET_SCHED_PROLOG)
12426     emit_insn (gen_blockage ());
12427   rs6000_emit_epilogue (TRUE);
12428   DONE;
12429 })
12430
12431 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12432 ;; all of memory.  This blocks insns from being moved across this point.
12433
12434 (define_insn "blockage"
12435   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
12436   ""
12437   "")
12438
12439 (define_expand "probe_stack"
12440   [(set (match_operand 0 "memory_operand" "=m")
12441         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
12442   ""
12443 {
12444   if (TARGET_64BIT)
12445     emit_insn (gen_probe_stack_di (operands[0]));
12446   else
12447     emit_insn (gen_probe_stack_si (operands[0]));
12448   DONE;
12449 })
12450
12451 (define_insn "probe_stack_<mode>"
12452   [(set (match_operand:P 0 "memory_operand" "=m")
12453         (unspec:P [(const_int 0)] UNSPEC_PROBE_STACK))]
12454   ""
12455 {
12456   operands[1] = gen_rtx_REG (Pmode, 0);
12457   return "st<wd>%U0%X0 %1,%0";
12458 }
12459   [(set_attr "type" "store")
12460    (set (attr "update")
12461         (if_then_else (match_operand 0 "update_address_mem")
12462                       (const_string "yes")
12463                       (const_string "no")))
12464    (set (attr "indexed")
12465         (if_then_else (match_operand 0 "indexed_address_mem")
12466                       (const_string "yes")
12467                       (const_string "no")))
12468    (set_attr "length" "4")])
12469
12470 (define_insn "probe_stack_range<P:mode>"
12471   [(set (match_operand:P 0 "register_operand" "=r")
12472         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
12473                             (match_operand:P 2 "register_operand" "r")]
12474                            UNSPECV_PROBE_STACK_RANGE))]
12475   ""
12476   "* return output_probe_stack_range (operands[0], operands[2]);"
12477   [(set_attr "type" "three")])
12478 \f
12479 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
12480 ;; signed & unsigned, and one type of branch.
12481 ;;
12482 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
12483 ;; insns, and branches.
12484
12485 (define_expand "cbranch<mode>4"
12486   [(use (match_operator 0 "rs6000_cbranch_operator"
12487          [(match_operand:GPR 1 "gpc_reg_operand" "")
12488           (match_operand:GPR 2 "reg_or_short_operand" "")]))
12489    (use (match_operand 3 ""))]
12490   ""
12491   "
12492 {
12493   /* Take care of the possibility that operands[2] might be negative but
12494      this might be a logical operation.  That insn doesn't exist.  */
12495   if (GET_CODE (operands[2]) == CONST_INT
12496       && INTVAL (operands[2]) < 0)
12497     {
12498       operands[2] = force_reg (<MODE>mode, operands[2]);
12499       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
12500                                     GET_MODE (operands[0]),
12501                                     operands[1], operands[2]);
12502    }
12503
12504   rs6000_emit_cbranch (<MODE>mode, operands);
12505   DONE;
12506 }")
12507
12508 (define_expand "cbranch<mode>4"
12509   [(use (match_operator 0 "rs6000_cbranch_operator"
12510          [(match_operand:FP 1 "gpc_reg_operand" "")
12511           (match_operand:FP 2 "gpc_reg_operand" "")]))
12512    (use (match_operand 3 ""))]
12513   ""
12514   "
12515 {
12516   rs6000_emit_cbranch (<MODE>mode, operands);
12517   DONE;
12518 }")
12519
12520 (define_expand "cstore<mode>4"
12521   [(use (match_operator 1 "rs6000_cbranch_operator"
12522          [(match_operand:GPR 2 "gpc_reg_operand" "")
12523           (match_operand:GPR 3 "reg_or_short_operand" "")]))
12524    (clobber (match_operand:SI 0 "register_operand"))]
12525   ""
12526   "
12527 {
12528   /* Take care of the possibility that operands[3] might be negative but
12529      this might be a logical operation.  That insn doesn't exist.  */
12530   if (GET_CODE (operands[3]) == CONST_INT
12531       && INTVAL (operands[3]) < 0)
12532     {
12533       operands[3] = force_reg (<MODE>mode, operands[3]);
12534       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
12535                                     GET_MODE (operands[1]),
12536                                     operands[2], operands[3]);
12537     }
12538
12539   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
12540      For SEQ, likewise, except that comparisons with zero should be done
12541      with an scc insns.  However, due to the order that combine see the
12542      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
12543      the cases we don't want to handle or are best handled by portable
12544      code.  */
12545   if (GET_CODE (operands[1]) == NE)
12546     FAIL;
12547   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
12548        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
12549       && operands[3] == const0_rtx)
12550     FAIL;
12551   rs6000_emit_sCOND (<MODE>mode, operands);
12552   DONE;
12553 }")
12554
12555 (define_expand "cstore<mode>4"
12556   [(use (match_operator 1 "rs6000_cbranch_operator"
12557          [(match_operand:FP 2 "gpc_reg_operand" "")
12558           (match_operand:FP 3 "gpc_reg_operand" "")]))
12559    (clobber (match_operand:SI 0 "register_operand"))]
12560   ""
12561   "
12562 {
12563   rs6000_emit_sCOND (<MODE>mode, operands);
12564   DONE;
12565 }")
12566
12567
12568 (define_expand "stack_protect_set"
12569   [(match_operand 0 "memory_operand" "")
12570    (match_operand 1 "memory_operand" "")]
12571   ""
12572 {
12573 #ifdef TARGET_THREAD_SSP_OFFSET
12574   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12575   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12576   operands[1] = gen_rtx_MEM (Pmode, addr);
12577 #endif
12578   if (TARGET_64BIT)
12579     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
12580   else
12581     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
12582   DONE;
12583 })
12584
12585 (define_insn "stack_protect_setsi"
12586   [(set (match_operand:SI 0 "memory_operand" "=m")
12587         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12588    (set (match_scratch:SI 2 "=&r") (const_int 0))]
12589   "TARGET_32BIT"
12590   "lwz%U1%X1 %2,%1\;stw%U0%X0 %2,%0\;li %2,0"
12591   [(set_attr "type" "three")
12592    (set_attr "length" "12")])
12593
12594 (define_insn "stack_protect_setdi"
12595   [(set (match_operand:DI 0 "memory_operand" "=Y")
12596         (unspec:DI [(match_operand:DI 1 "memory_operand" "Y")] UNSPEC_SP_SET))
12597    (set (match_scratch:DI 2 "=&r") (const_int 0))]
12598   "TARGET_64BIT"
12599   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;li %2,0"
12600   [(set_attr "type" "three")
12601    (set_attr "length" "12")])
12602
12603 (define_expand "stack_protect_test"
12604   [(match_operand 0 "memory_operand" "")
12605    (match_operand 1 "memory_operand" "")
12606    (match_operand 2 "" "")]
12607   ""
12608 {
12609   rtx test, op0, op1;
12610 #ifdef TARGET_THREAD_SSP_OFFSET
12611   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12612   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12613   operands[1] = gen_rtx_MEM (Pmode, addr);
12614 #endif
12615   op0 = operands[0];
12616   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
12617   test = gen_rtx_EQ (VOIDmode, op0, op1);
12618   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
12619   DONE;
12620 })
12621
12622 (define_insn "stack_protect_testsi"
12623   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12624         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
12625                       (match_operand:SI 2 "memory_operand" "m,m")]
12626                      UNSPEC_SP_TEST))
12627    (set (match_scratch:SI 4 "=r,r") (const_int 0))
12628    (clobber (match_scratch:SI 3 "=&r,&r"))]
12629   "TARGET_32BIT"
12630   "@
12631    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
12632    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;cmplw %0,%3,%4\;li %3,0\;li %4,0"
12633   [(set_attr "length" "16,20")])
12634
12635 (define_insn "stack_protect_testdi"
12636   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12637         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "Y,Y")
12638                       (match_operand:DI 2 "memory_operand" "Y,Y")]
12639                      UNSPEC_SP_TEST))
12640    (set (match_scratch:DI 4 "=r,r") (const_int 0))
12641    (clobber (match_scratch:DI 3 "=&r,&r"))]
12642   "TARGET_64BIT"
12643   "@
12644    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
12645    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;li %3,0\;li %4,0"
12646   [(set_attr "length" "16,20")])
12647
12648 \f
12649 ;; Here are the actual compare insns.
12650 (define_insn "*cmp<mode>_internal1"
12651   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
12652         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
12653                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
12654   ""
12655   "cmp<wd>%I2 %0,%1,%2"
12656   [(set_attr "type" "cmp")])
12657
12658 ;; If we are comparing a register for equality with a large constant,
12659 ;; we can do this with an XOR followed by a compare.  But this is profitable
12660 ;; only if the large constant is only used for the comparison (and in this
12661 ;; case we already have a register to reuse as scratch).
12662 ;;
12663 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
12664 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
12665
12666 (define_peephole2
12667   [(set (match_operand:SI 0 "register_operand")
12668         (match_operand:SI 1 "logical_const_operand" ""))
12669    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
12670                        [(match_dup 0)
12671                         (match_operand:SI 2 "logical_const_operand" "")]))
12672    (set (match_operand:CC 4 "cc_reg_operand" "")
12673         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
12674                     (match_dup 0)))
12675    (set (pc)
12676         (if_then_else (match_operator 6 "equality_operator"
12677                        [(match_dup 4) (const_int 0)])
12678                       (match_operand 7 "" "")
12679                       (match_operand 8 "" "")))]
12680   "peep2_reg_dead_p (3, operands[0])
12681    && peep2_reg_dead_p (4, operands[4])"
12682  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
12683   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
12684   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
12685  
12686 {
12687   /* Get the constant we are comparing against, and see what it looks like
12688      when sign-extended from 16 to 32 bits.  Then see what constant we could
12689      XOR with SEXTC to get the sign-extended value.  */
12690   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
12691                                               SImode,
12692                                               operands[1], operands[2]);
12693   HOST_WIDE_INT c = INTVAL (cnst);
12694   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
12695   HOST_WIDE_INT xorv = c ^ sextc;
12696
12697   operands[9] = GEN_INT (xorv);
12698   operands[10] = GEN_INT (sextc);
12699 })
12700
12701 (define_insn "*cmpsi_internal2"
12702   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12703         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12704                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
12705   ""
12706   "cmplw%I2 %0,%1,%b2"
12707   [(set_attr "type" "cmp")])
12708
12709 (define_insn "*cmpdi_internal2"
12710   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12711         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
12712                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
12713   ""
12714   "cmpld%I2 %0,%1,%b2"
12715   [(set_attr "type" "cmp")])
12716
12717 ;; The following two insns don't exist as single insns, but if we provide
12718 ;; them, we can swap an add and compare, which will enable us to overlap more
12719 ;; of the required delay between a compare and branch.  We generate code for
12720 ;; them by splitting.
12721
12722 (define_insn ""
12723   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
12724         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
12725                     (match_operand:SI 2 "short_cint_operand" "i")))
12726    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12727         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12728   ""
12729   "#"
12730   [(set_attr "length" "8")])
12731
12732 (define_insn ""
12733   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
12734         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
12735                        (match_operand:SI 2 "u_short_cint_operand" "i")))
12736    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
12737         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
12738   ""
12739   "#"
12740   [(set_attr "length" "8")])
12741
12742 (define_split
12743   [(set (match_operand:CC 3 "cc_reg_operand" "")
12744         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
12745                     (match_operand:SI 2 "short_cint_operand" "")))
12746    (set (match_operand:SI 0 "gpc_reg_operand" "")
12747         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12748   ""
12749   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
12750    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12751
12752 (define_split
12753   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
12754         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
12755                        (match_operand:SI 2 "u_short_cint_operand" "")))
12756    (set (match_operand:SI 0 "gpc_reg_operand" "")
12757         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
12758   ""
12759   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
12760    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
12761
12762 ;; Only need to compare second words if first words equal
12763 (define_insn "*cmptf_internal1"
12764   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12765         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12766                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
12767   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
12768    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12769   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
12770   [(set_attr "type" "fpcompare")
12771    (set_attr "length" "12")])
12772
12773 (define_insn_and_split "*cmptf_internal2"
12774   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12775         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
12776                       (match_operand:TF 2 "gpc_reg_operand" "d")))
12777     (clobber (match_scratch:DF 3 "=d"))
12778     (clobber (match_scratch:DF 4 "=d"))
12779     (clobber (match_scratch:DF 5 "=d"))
12780     (clobber (match_scratch:DF 6 "=d"))
12781     (clobber (match_scratch:DF 7 "=d"))
12782     (clobber (match_scratch:DF 8 "=d"))
12783     (clobber (match_scratch:DF 9 "=d"))
12784     (clobber (match_scratch:DF 10 "=d"))
12785     (clobber (match_scratch:GPR 11 "=b"))]
12786   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
12787    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
12788   "#"
12789   "&& reload_completed"
12790   [(set (match_dup 3) (match_dup 14))
12791    (set (match_dup 4) (match_dup 15))
12792    (set (match_dup 9) (abs:DF (match_dup 5)))
12793    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
12794    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
12795                            (label_ref (match_dup 12))
12796                            (pc)))
12797    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
12798    (set (pc) (label_ref (match_dup 13)))
12799    (match_dup 12)
12800    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
12801    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
12802    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
12803    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
12804    (match_dup 13)]
12805 {
12806   REAL_VALUE_TYPE rv;
12807   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
12808   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
12809
12810   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
12811   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
12812   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
12813   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
12814   operands[12] = gen_label_rtx ();
12815   operands[13] = gen_label_rtx ();
12816   real_inf (&rv);
12817   operands[14] = force_const_mem (DFmode,
12818                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
12819   operands[15] = force_const_mem (DFmode,
12820                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
12821                                                                 DFmode));
12822   if (TARGET_TOC)
12823     {
12824       rtx tocref;
12825       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
12826       operands[14] = gen_const_mem (DFmode, tocref);
12827       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
12828       operands[15] = gen_const_mem (DFmode, tocref);
12829       set_mem_alias_set (operands[14], get_TOC_alias_set ());
12830       set_mem_alias_set (operands[15], get_TOC_alias_set ());
12831     }
12832 })
12833 \f
12834 ;; Now we have the scc insns.  We can do some combinations because of the
12835 ;; way the machine works.
12836 ;;
12837 ;; Note that this is probably faster if we can put an insn between the
12838 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
12839 ;; cases the insns below which don't use an intermediate CR field will
12840 ;; be used instead.
12841 (define_insn ""
12842   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12843         (match_operator:SI 1 "scc_comparison_operator"
12844                            [(match_operand 2 "cc_reg_operand" "y")
12845                             (const_int 0)]))]
12846   ""
12847   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
12848   [(set (attr "type")
12849      (cond [(match_test "TARGET_MFCRF")
12850                 (const_string "mfcrf")
12851            ]
12852         (const_string "mfcr")))
12853    (set_attr "length" "8")])
12854
12855 ;; Same as above, but get the GT bit.
12856 (define_insn "move_from_CR_gt_bit"
12857   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12858         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
12859   "TARGET_HARD_FLOAT && !TARGET_FPRS"
12860   "mfcr %0\;rlwinm %0,%0,%D1,31,31"
12861   [(set_attr "type" "mfcr")
12862    (set_attr "length" "8")])
12863
12864 ;; Same as above, but get the OV/ORDERED bit.
12865 (define_insn "move_from_CR_ov_bit"
12866   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12867         (unspec:SI [(match_operand:CC 1 "cc_reg_operand" "y")]
12868                    UNSPEC_MV_CR_OV))]
12869   "TARGET_ISEL"
12870   "mfcr %0\;rlwinm %0,%0,%t1,1"
12871   [(set_attr "type" "mfcr")
12872    (set_attr "length" "8")])
12873
12874 (define_insn ""
12875   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12876         (match_operator:DI 1 "scc_comparison_operator"
12877                            [(match_operand 2 "cc_reg_operand" "y")
12878                             (const_int 0)]))]
12879   "TARGET_POWERPC64"
12880   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
12881   [(set (attr "type")
12882      (cond [(match_test "TARGET_MFCRF")
12883                 (const_string "mfcrf")
12884            ]
12885         (const_string "mfcr")))
12886    (set_attr "length" "8")])
12887
12888 (define_insn ""
12889   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12890         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12891                                        [(match_operand 2 "cc_reg_operand" "y,y")
12892                                         (const_int 0)])
12893                     (const_int 0)))
12894    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
12895         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12896   "TARGET_32BIT"
12897   "@
12898    mfcr %3%Q2\;rlwinm. %3,%3,%J1,1
12899    #"
12900   [(set_attr "type" "shift")
12901    (set_attr "dot" "yes")
12902    (set_attr "length" "8,16")])
12903
12904 (define_split
12905   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12906         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12907                                        [(match_operand 2 "cc_reg_operand" "")
12908                                         (const_int 0)])
12909                     (const_int 0)))
12910    (set (match_operand:SI 3 "gpc_reg_operand" "")
12911         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12912   "TARGET_32BIT && reload_completed"
12913   [(set (match_dup 3)
12914         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
12915    (set (match_dup 0)
12916         (compare:CC (match_dup 3)
12917                     (const_int 0)))]
12918   "")
12919
12920 (define_insn ""
12921   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12922         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12923                                       [(match_operand 2 "cc_reg_operand" "y")
12924                                        (const_int 0)])
12925                    (match_operand:SI 3 "const_int_operand" "n")))]
12926   ""
12927   "*
12928 {
12929   int is_bit = ccr_bit (operands[1], 1);
12930   int put_bit = 31 - (INTVAL (operands[3]) & 31);
12931   int count;
12932
12933   if (is_bit >= put_bit)
12934     count = is_bit - put_bit;
12935   else
12936     count = 32 - (put_bit - is_bit);
12937
12938   operands[4] = GEN_INT (count);
12939   operands[5] = GEN_INT (put_bit);
12940
12941   return \"mfcr %0%Q2\;rlwinm %0,%0,%4,%5,%5\";
12942 }"
12943   [(set (attr "type")
12944      (cond [(match_test "TARGET_MFCRF")
12945                 (const_string "mfcrf")
12946            ]
12947         (const_string "mfcr")))
12948    (set_attr "length" "8")])
12949
12950 (define_insn ""
12951   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12952         (compare:CC
12953          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12954                                        [(match_operand 2 "cc_reg_operand" "y,y")
12955                                         (const_int 0)])
12956                     (match_operand:SI 3 "const_int_operand" "n,n"))
12957          (const_int 0)))
12958    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
12959         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12960                    (match_dup 3)))]
12961   ""
12962   "*
12963 {
12964   int is_bit = ccr_bit (operands[1], 1);
12965   int put_bit = 31 - (INTVAL (operands[3]) & 31);
12966   int count;
12967
12968   /* Force split for non-cc0 compare.  */
12969   if (which_alternative == 1)
12970      return \"#\";
12971
12972   if (is_bit >= put_bit)
12973     count = is_bit - put_bit;
12974   else
12975     count = 32 - (put_bit - is_bit);
12976
12977   operands[5] = GEN_INT (count);
12978   operands[6] = GEN_INT (put_bit);
12979
12980   return \"mfcr %4%Q2\;rlwinm. %4,%4,%5,%6,%6\";
12981 }"
12982   [(set_attr "type" "shift")
12983    (set_attr "dot" "yes")
12984    (set_attr "length" "8,16")])
12985
12986 (define_split
12987   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
12988         (compare:CC
12989          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12990                                        [(match_operand 2 "cc_reg_operand" "")
12991                                         (const_int 0)])
12992                     (match_operand:SI 3 "const_int_operand" ""))
12993          (const_int 0)))
12994    (set (match_operand:SI 4 "gpc_reg_operand" "")
12995         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12996                    (match_dup 3)))]
12997   "reload_completed"
12998   [(set (match_dup 4)
12999         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13000                    (match_dup 3)))
13001    (set (match_dup 0)
13002         (compare:CC (match_dup 4)
13003                     (const_int 0)))]
13004   "")
13005
13006 ;; There is a 3 cycle delay between consecutive mfcr instructions
13007 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13008
13009 (define_peephole
13010   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13011         (match_operator:SI 1 "scc_comparison_operator"
13012                            [(match_operand 2 "cc_reg_operand" "y")
13013                             (const_int 0)]))
13014    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13015         (match_operator:SI 4 "scc_comparison_operator"
13016                            [(match_operand 5 "cc_reg_operand" "y")
13017                             (const_int 0)]))]
13018   "REGNO (operands[2]) != REGNO (operands[5])"
13019   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
13020   [(set_attr "type" "mfcr")
13021    (set_attr "length" "12")])
13022
13023 (define_peephole
13024   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13025         (match_operator:DI 1 "scc_comparison_operator"
13026                            [(match_operand 2 "cc_reg_operand" "y")
13027                             (const_int 0)]))
13028    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13029         (match_operator:DI 4 "scc_comparison_operator"
13030                            [(match_operand 5 "cc_reg_operand" "y")
13031                             (const_int 0)]))]
13032   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13033   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
13034   [(set_attr "type" "mfcr")
13035    (set_attr "length" "12")])
13036
13037 ;; There are some scc insns that can be done directly, without a compare.
13038 ;; These are faster because they don't involve the communications between
13039 ;; the FXU and branch units.   In fact, we will be replacing all of the
13040 ;; integer scc insns here or in the portable methods in emit_store_flag.
13041 ;;
13042 ;; Also support (neg (scc ..)) since that construct is used to replace
13043 ;; branches, (plus (scc ..) ..) since that construct is common and
13044 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13045 ;; cases where it is no more expensive than (neg (scc ..)).
13046
13047 ;; Have reload force a constant into a register for the simple insns that
13048 ;; otherwise won't accept constants.  We do this because it is faster than
13049 ;; the cmp/mfcr sequence we would otherwise generate.
13050
13051 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13052                               (DI "rKJI")])
13053
13054 (define_insn_and_split "*eq<mode>"
13055   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13056         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13057                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13058   ""
13059   "#"
13060   ""
13061   [(set (match_dup 0)
13062         (clz:GPR (match_dup 3)))
13063    (set (match_dup 0)
13064         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13065   {
13066     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13067       {
13068         /* Use output operand as intermediate.  */
13069         operands[3] = operands[0];
13070
13071         if (logical_operand (operands[2], <MODE>mode))
13072           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13073                                   gen_rtx_XOR (<MODE>mode,
13074                                                operands[1], operands[2])));
13075         else
13076           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13077                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13078                                                 negate_rtx (<MODE>mode,
13079                                                             operands[2]))));
13080       }
13081     else
13082       operands[3] = operands[1];
13083
13084     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13085   })
13086
13087 (define_insn_and_split "*eq<mode>_compare"
13088   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13089         (compare:CC
13090          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13091                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13092          (const_int 0)))
13093    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13094         (eq:P (match_dup 1) (match_dup 2)))]
13095   "optimize_size"
13096   "#"
13097   "optimize_size"
13098   [(set (match_dup 0)
13099         (clz:P (match_dup 4)))
13100    (parallel [(set (match_dup 3)
13101                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13102                                (const_int 0)))
13103               (set (match_dup 0)
13104                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13105   {
13106     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13107       {
13108         /* Use output operand as intermediate.  */
13109         operands[4] = operands[0];
13110
13111         if (logical_operand (operands[2], <MODE>mode))
13112           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13113                                   gen_rtx_XOR (<MODE>mode,
13114                                                operands[1], operands[2])));
13115         else
13116           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13117                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13118                                                 negate_rtx (<MODE>mode,
13119                                                             operands[2]))));
13120       }
13121     else
13122       operands[4] = operands[1];
13123
13124     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13125   })
13126
13127 ;; We have insns of the form shown by the first define_insn below.  If
13128 ;; there is something inside the comparison operation, we must split it.
13129 (define_split
13130   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13131         (plus:SI (match_operator 1 "comparison_operator"
13132                                  [(match_operand:SI 2 "" "")
13133                                   (match_operand:SI 3
13134                                                     "reg_or_cint_operand" "")])
13135                  (match_operand:SI 4 "gpc_reg_operand" "")))
13136    (clobber (match_operand:SI 5 "register_operand" ""))]
13137   "! gpc_reg_operand (operands[2], SImode)"
13138   [(set (match_dup 5) (match_dup 2))
13139    (set (match_dup 0) (plus:SI (match_op_dup 1 [(match_dup 5) (match_dup 3)])
13140                                (match_dup 4)))])
13141
13142 (define_insn "*plus_eqsi"
13143   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13144         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13145                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13146                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13147   "TARGET_32BIT"
13148   "@
13149    xor %0,%1,%2\;subfic %0,%0,0\;addze %0,%3
13150    subfic %0,%1,0\;addze %0,%3
13151    xori %0,%1,%b2\;subfic %0,%0,0\;addze %0,%3
13152    xoris %0,%1,%u2\;subfic %0,%0,0\;addze %0,%3
13153    subfic %0,%1,%2\;subfic %0,%0,0\;addze %0,%3"
13154   [(set_attr "type" "three,two,three,three,three")
13155    (set_attr "length" "12,8,12,12,12")])
13156
13157 (define_insn "*compare_plus_eqsi"
13158   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13159         (compare:CC
13160          (plus:SI
13161           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13162                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13163           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13164          (const_int 0)))
13165    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13166   "TARGET_32BIT && optimize_size"
13167   "@
13168    xor %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
13169    subfic %4,%1,0\;addze. %4,%3
13170    xori %4,%1,%b2\;subfic %4,%4,0\;addze. %4,%3
13171    xoris %4,%1,%u2\;subfic %4,%4,0\;addze. %4,%3
13172    subfic %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
13173    #
13174    #
13175    #
13176    #
13177    #"
13178   [(set_attr "type" "compare")
13179    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13180
13181 (define_split
13182   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13183         (compare:CC
13184          (plus:SI
13185           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13186                  (match_operand:SI 2 "scc_eq_operand" ""))
13187           (match_operand:SI 3 "gpc_reg_operand" ""))
13188          (const_int 0)))
13189    (clobber (match_scratch:SI 4 ""))]
13190   "TARGET_32BIT && optimize_size && reload_completed"
13191   [(set (match_dup 4)
13192         (plus:SI (eq:SI (match_dup 1)
13193                  (match_dup 2))
13194           (match_dup 3)))
13195    (set (match_dup 0)
13196         (compare:CC (match_dup 4)
13197                     (const_int 0)))]
13198   "")
13199
13200 (define_insn "*plus_eqsi_compare"
13201   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13202         (compare:CC
13203          (plus:SI
13204           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13205                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13206           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13207          (const_int 0)))
13208    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13209         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13210   "TARGET_32BIT && optimize_size"
13211   "@
13212    xor %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
13213    subfic %0,%1,0\;addze. %0,%3
13214    xori %0,%1,%b2\;subfic %0,%0,0\;addze. %0,%3
13215    xoris %0,%1,%u2\;subfic %0,%0,0\;addze. %0,%3
13216    subfic %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
13217    #
13218    #
13219    #
13220    #
13221    #"
13222   [(set_attr "type" "compare")
13223    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13224
13225 (define_split
13226   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13227         (compare:CC
13228          (plus:SI
13229           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13230                  (match_operand:SI 2 "scc_eq_operand" ""))
13231           (match_operand:SI 3 "gpc_reg_operand" ""))
13232          (const_int 0)))
13233    (set (match_operand:SI 0 "gpc_reg_operand" "")
13234         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13235   "TARGET_32BIT && optimize_size && reload_completed"
13236   [(set (match_dup 0)
13237         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13238    (set (match_dup 4)
13239         (compare:CC (match_dup 0)
13240                     (const_int 0)))]
13241   "")
13242
13243 (define_insn "*neg_eq0<mode>"
13244   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13245         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13246                      (const_int 0))))]
13247   ""
13248   "addic %0,%1,-1\;subfe %0,%0,%0"
13249   [(set_attr "type" "two")
13250    (set_attr "length" "8")])
13251
13252 (define_insn_and_split "*neg_eq<mode>"
13253   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13254         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
13255                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
13256   ""
13257   "#"
13258   ""
13259   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
13260   {
13261     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13262       {
13263         /* Use output operand as intermediate.  */
13264         operands[3] = operands[0];
13265
13266         if (logical_operand (operands[2], <MODE>mode))
13267           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13268                                   gen_rtx_XOR (<MODE>mode,
13269                                                operands[1], operands[2])));
13270         else
13271           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13272                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13273                                                 negate_rtx (<MODE>mode,
13274                                                             operands[2]))));
13275       }
13276     else
13277       operands[3] = operands[1];
13278   })
13279
13280 (define_insn "*ne0_<mode>"
13281   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13282         (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13283               (const_int 0)))
13284    (clobber (match_scratch:P 2 "=&r"))]
13285   "!(TARGET_32BIT && TARGET_ISEL)"
13286   "addic %2,%1,-1\;subfe %0,%2,%1"
13287   [(set_attr "type" "two")
13288    (set_attr "length" "8")])
13289
13290 (define_insn "*plus_ne0_<mode>"
13291   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13292         (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13293                       (const_int 0))
13294                 (match_operand:P 2 "gpc_reg_operand" "r")))
13295    (clobber (match_scratch:P 3 "=&r"))]
13296   ""
13297   "addic %3,%1,-1\;addze %0,%2"
13298   [(set_attr "type" "two")
13299    (set_attr "length" "8")])
13300
13301 (define_insn "*compare_plus_ne0_<mode>"
13302   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13303         (compare:CC (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13304                                   (const_int 0))
13305                             (match_operand:P 2 "gpc_reg_operand" "r,r"))
13306                     (const_int 0)))
13307    (clobber (match_scratch:P 3 "=&r,&r"))
13308    (clobber (match_scratch:P 4 "=X,&r"))]
13309   ""
13310   "@
13311    addic %3,%1,-1\;addze. %3,%2
13312    #"
13313   [(set_attr "type" "compare")
13314    (set_attr "length" "8,12")])
13315
13316 (define_split
13317   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13318         (compare:CC (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
13319                           (const_int 0))
13320                     (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
13321    (clobber (match_scratch:P 3 ""))
13322    (clobber (match_scratch:P 4 ""))]
13323   "reload_completed"
13324   [(parallel [(set (match_dup 3)
13325                    (plus:P (ne:P (match_dup 1)
13326                                  (const_int 0))
13327                            (match_dup 2)))
13328               (clobber (match_dup 4))])
13329    (set (match_dup 0)
13330         (compare:CC (match_dup 3)
13331                     (const_int 0)))]
13332   "")
13333
13334 ; For combine.
13335 (define_insn "*compare_plus_ne0_<mode>_1"
13336   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13337         (compare:CCEQ (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13338                             (const_int 0))
13339                       (neg:P (match_operand:P 2 "gpc_reg_operand" "r,r"))))
13340    (clobber (match_scratch:P 3 "=&r,&r"))
13341    (clobber (match_scratch:P 4 "=X,&r"))]
13342   ""
13343   "@
13344    addic %3,%1,-1\;addze. %3,%2
13345    #"
13346   [(set_attr "type" "compare")
13347    (set_attr "length" "8,12")])
13348
13349 (define_split
13350   [(set (match_operand:CCEQ 0 "cc_reg_not_micro_cr0_operand" "")
13351         (compare:CCEQ (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
13352                             (const_int 0))
13353                       (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
13354    (clobber (match_scratch:P 3 ""))
13355    (clobber (match_scratch:P 4 ""))]
13356   "reload_completed"
13357   [(parallel [(set (match_dup 3)
13358                    (plus:P (ne:P (match_dup 1)
13359                                  (const_int 0))
13360                            (match_dup 2)))
13361               (clobber (match_dup 4))])
13362    (set (match_dup 0)
13363         (compare:CC (match_dup 3)
13364                     (const_int 0)))]
13365   "")
13366
13367 (define_insn "*plus_ne0_<mode>_compare"
13368   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13369         (compare:CC
13370          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13371                        (const_int 0))
13372                  (match_operand:P 2 "gpc_reg_operand" "r,r"))
13373          (const_int 0)))
13374    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13375         (plus:P (ne:P (match_dup 1)
13376                       (const_int 0))
13377                 (match_dup 2)))
13378    (clobber (match_scratch:P 3 "=&r,&r"))]
13379   ""
13380   "@
13381    addic %3,%1,-1\;addze. %0,%2
13382    #"
13383   [(set_attr "type" "compare")
13384    (set_attr "length" "8,12")])
13385
13386 (define_split
13387   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
13388         (compare:CC
13389          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "")
13390                        (const_int 0))
13391                  (match_operand:P 2 "gpc_reg_operand" ""))
13392          (const_int 0)))
13393    (set (match_operand:P 0 "gpc_reg_operand" "")
13394         (plus:P (ne:P (match_dup 1)
13395                       (const_int 0))
13396                 (match_dup 2)))
13397    (clobber (match_scratch:P 3 ""))]
13398   "reload_completed"
13399   [(parallel [(set (match_dup 0)
13400                    (plus:P (ne:P (match_dup 1)
13401                                  (const_int 0))
13402                            (match_dup 2)))
13403               (clobber (match_dup 3))])
13404    (set (match_dup 4)
13405         (compare:CC (match_dup 0)
13406                     (const_int 0)))]
13407   "")
13408
13409 (define_insn "*leu<mode>"
13410   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13411         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13412                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13413   ""
13414   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
13415   [(set_attr "type" "three")
13416    (set_attr "length" "12")])
13417
13418 (define_insn "*leu<mode>_compare"
13419   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13420         (compare:CC
13421          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13422                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13423          (const_int 0)))
13424    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13425         (leu:P (match_dup 1) (match_dup 2)))]
13426   ""
13427   "@
13428    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
13429    #"
13430   [(set_attr "type" "compare")
13431    (set_attr "length" "12,16")])
13432
13433 (define_split
13434   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13435         (compare:CC
13436          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
13437                 (match_operand:P 2 "reg_or_short_operand" ""))
13438          (const_int 0)))
13439    (set (match_operand:P 0 "gpc_reg_operand" "")
13440         (leu:P (match_dup 1) (match_dup 2)))]
13441   "reload_completed"
13442   [(set (match_dup 0)
13443         (leu:P (match_dup 1) (match_dup 2)))
13444    (set (match_dup 3)
13445         (compare:CC (match_dup 0)
13446                     (const_int 0)))]
13447   "")
13448
13449 (define_insn "*plus_leu<mode>"
13450   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13451         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13452                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13453                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13454   ""
13455   "subf%I2c %0,%1,%2\;addze %0,%3"
13456   [(set_attr "type" "two")
13457    (set_attr "length" "8")])
13458
13459 (define_insn ""
13460   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13461         (compare:CC
13462          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13463                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13464                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13465          (const_int 0)))
13466    (clobber (match_scratch:SI 4 "=&r,&r"))]
13467   "TARGET_32BIT"
13468   "@
13469    subf%I2c %4,%1,%2\;addze. %4,%3
13470    #"
13471   [(set_attr "type" "compare")
13472    (set_attr "length" "8,12")])
13473
13474 (define_split
13475   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13476         (compare:CC
13477          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13478                           (match_operand:SI 2 "reg_or_short_operand" ""))
13479                   (match_operand:SI 3 "gpc_reg_operand" ""))
13480          (const_int 0)))
13481    (clobber (match_scratch:SI 4 ""))]
13482   "TARGET_32BIT && reload_completed"
13483   [(set (match_dup 4)
13484         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
13485                   (match_dup 3)))
13486    (set (match_dup 0)
13487         (compare:CC (match_dup 4)
13488                     (const_int 0)))]
13489   "")
13490
13491 (define_insn ""
13492   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13493         (compare:CC
13494          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13495                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13496                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13497          (const_int 0)))
13498    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13499         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13500   "TARGET_32BIT"
13501   "@
13502    subf%I2c %0,%1,%2\;addze. %0,%3
13503    #"
13504   [(set_attr "type" "compare")
13505    (set_attr "length" "8,12")])
13506
13507 (define_split
13508   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13509         (compare:CC
13510          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13511                           (match_operand:SI 2 "reg_or_short_operand" ""))
13512                   (match_operand:SI 3 "gpc_reg_operand" ""))
13513          (const_int 0)))
13514    (set (match_operand:SI 0 "gpc_reg_operand" "")
13515         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13516   "TARGET_32BIT && reload_completed"
13517   [(set (match_dup 0)
13518         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13519    (set (match_dup 4)
13520         (compare:CC (match_dup 0)
13521                     (const_int 0)))]
13522   "")
13523
13524 (define_insn "*neg_leu<mode>"
13525   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13526         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13527                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13528   ""
13529   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;nand %0,%0,%0"
13530    [(set_attr "type" "three")
13531     (set_attr "length" "12")])
13532
13533 (define_insn "*and_neg_leu<mode>"
13534   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13535         (and:P (neg:P
13536                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13537                         (match_operand:P 2 "reg_or_short_operand" "rI")))
13538                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13539   ""
13540   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc %0,%3,%0"
13541   [(set_attr "type" "three")
13542    (set_attr "length" "12")])
13543
13544 (define_insn ""
13545   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13546         (compare:CC
13547          (and:SI (neg:SI
13548                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13549                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13550                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13551          (const_int 0)))
13552    (clobber (match_scratch:SI 4 "=&r,&r"))]
13553   "TARGET_32BIT"
13554   "@
13555    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;andc. %4,%3,%4
13556    #"
13557   [(set_attr "type" "compare")
13558    (set_attr "length" "12,16")])
13559
13560 (define_split
13561   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13562         (compare:CC
13563          (and:SI (neg:SI
13564                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13565                           (match_operand:SI 2 "reg_or_short_operand" "")))
13566                  (match_operand:SI 3 "gpc_reg_operand" ""))
13567          (const_int 0)))
13568    (clobber (match_scratch:SI 4 ""))]
13569   "TARGET_32BIT && reload_completed"
13570   [(set (match_dup 4)
13571         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13572                 (match_dup 3)))
13573    (set (match_dup 0)
13574         (compare:CC (match_dup 4)
13575                     (const_int 0)))]
13576   "")
13577
13578 (define_insn ""
13579   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13580         (compare:CC
13581          (and:SI (neg:SI
13582                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13583                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13584                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13585          (const_int 0)))
13586    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13587         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13588   "TARGET_32BIT"
13589   "@
13590    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc. %0,%3,%0
13591    #"
13592   [(set_attr "type" "compare")
13593    (set_attr "length" "12,16")])
13594
13595 (define_split
13596   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13597         (compare:CC
13598          (and:SI (neg:SI
13599                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13600                           (match_operand:SI 2 "reg_or_short_operand" "")))
13601                  (match_operand:SI 3 "gpc_reg_operand" ""))
13602          (const_int 0)))
13603    (set (match_operand:SI 0 "gpc_reg_operand" "")
13604         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13605   "TARGET_32BIT && reload_completed"
13606   [(set (match_dup 0)
13607         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13608                 (match_dup 3)))
13609    (set (match_dup 4)
13610         (compare:CC (match_dup 0)
13611                     (const_int 0)))]
13612   "")
13613
13614 (define_insn_and_split "*ltu<mode>"
13615   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13616         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13617                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13618   ""
13619   "#"
13620   ""
13621   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13622    (set (match_dup 0) (neg:P (match_dup 0)))]
13623   "")
13624
13625 (define_insn_and_split "*ltu<mode>_compare"
13626   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13627         (compare:CC
13628          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13629                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13630          (const_int 0)))
13631    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13632         (ltu:P (match_dup 1) (match_dup 2)))]
13633   ""
13634   "#"
13635   ""
13636   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13637    (parallel [(set (match_dup 3)
13638                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13639               (set (match_dup 0) (neg:P (match_dup 0)))])]
13640   "")
13641
13642 (define_insn_and_split "*plus_ltu<mode>"
13643   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
13644         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13645                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13646                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
13647   ""
13648   "#"
13649   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13650   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13651    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13652   "")
13653
13654 (define_insn_and_split "*plus_ltu<mode>_compare"
13655   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13656         (compare:CC
13657          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13658                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13659                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13660          (const_int 0)))
13661    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13662         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13663   ""
13664   "#"
13665   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13666   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13667    (parallel [(set (match_dup 4)
13668                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13669                                (const_int 0)))
13670               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13671   "")
13672
13673 (define_insn "*neg_ltu<mode>"
13674   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13675         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13676                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
13677   ""
13678   "@
13679    subfc %0,%2,%1\;subfe %0,%0,%0
13680    addic %0,%1,%n2\;subfe %0,%0,%0"
13681   [(set_attr "type" "two")
13682    (set_attr "length" "8")])
13683
13684 (define_insn "*geu<mode>"
13685   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13686         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13687                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13688   ""
13689   "@
13690    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
13691    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
13692   [(set_attr "type" "three")
13693    (set_attr "length" "12")])
13694
13695 (define_insn "*geu<mode>_compare"
13696   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13697         (compare:CC
13698          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13699                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13700          (const_int 0)))
13701    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13702         (geu:P (match_dup 1) (match_dup 2)))]
13703   ""
13704   "@
13705    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
13706    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
13707    #
13708    #"
13709   [(set_attr "type" "compare")
13710    (set_attr "length" "12,12,16,16")])
13711
13712 (define_split
13713   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
13714         (compare:CC
13715          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
13716                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
13717          (const_int 0)))
13718    (set (match_operand:P 0 "gpc_reg_operand" "")
13719         (geu:P (match_dup 1) (match_dup 2)))]
13720   "reload_completed"
13721   [(set (match_dup 0)
13722         (geu:P (match_dup 1) (match_dup 2)))
13723    (set (match_dup 3)
13724         (compare:CC (match_dup 0)
13725                     (const_int 0)))]
13726   "")
13727
13728 (define_insn "*plus_geu<mode>"
13729   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13730         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13731                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13732                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13733   ""
13734   "@
13735    subfc %0,%2,%1\;addze %0,%3
13736    addic %0,%1,%n2\;addze %0,%3"
13737   [(set_attr "type" "two")
13738    (set_attr "length" "8")])
13739
13740 (define_insn ""
13741   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13742         (compare:CC
13743          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13744                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13745                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13746          (const_int 0)))
13747    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13748   "TARGET_32BIT"
13749   "@
13750    subfc %4,%2,%1\;addze. %4,%3
13751    addic %4,%1,%n2\;addze. %4,%3
13752    #
13753    #"
13754   [(set_attr "type" "compare")
13755    (set_attr "length" "8,8,12,12")])
13756
13757 (define_split
13758   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13759         (compare:CC
13760          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13761                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13762                   (match_operand:SI 3 "gpc_reg_operand" ""))
13763          (const_int 0)))
13764    (clobber (match_scratch:SI 4 ""))]
13765   "TARGET_32BIT && reload_completed"
13766   [(set (match_dup 4)
13767         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
13768                   (match_dup 3)))
13769    (set (match_dup 0)
13770         (compare:CC (match_dup 4)
13771                     (const_int 0)))]
13772   "")
13773
13774 (define_insn ""
13775   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13776         (compare:CC
13777          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13778                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13779                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13780          (const_int 0)))
13781    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13782         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13783   "TARGET_32BIT"
13784   "@
13785    subfc %0,%2,%1\;addze. %0,%3
13786    addic %0,%1,%n2\;addze. %0,%3
13787    #
13788    #"
13789   [(set_attr "type" "compare")
13790    (set_attr "length" "8,8,12,12")])
13791
13792 (define_split
13793   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13794         (compare:CC
13795          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13796                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13797                   (match_operand:SI 3 "gpc_reg_operand" ""))
13798          (const_int 0)))
13799    (set (match_operand:SI 0 "gpc_reg_operand" "")
13800         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13801   "TARGET_32BIT && reload_completed"
13802   [(set (match_dup 0)
13803         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13804    (set (match_dup 4)
13805         (compare:CC (match_dup 0)
13806                     (const_int 0)))]
13807   "")
13808
13809 (define_insn "*neg_geu<mode>"
13810   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13811         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13812                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
13813   ""
13814   "@
13815    subfc %0,%2,%1\;subfe %0,%0,%0\;nand %0,%0,%0
13816    subfic %0,%1,-1\;add%I2c %0,%0,%2\;subfe %0,%0,%0"
13817   [(set_attr "type" "three")
13818    (set_attr "length" "12")])
13819
13820 (define_insn "*and_neg_geu<mode>"
13821   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13822         (and:P (neg:P
13823                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13824                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
13825                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13826   ""
13827   "@
13828    subfc %0,%2,%1\;subfe %0,%0,%0\;andc %0,%3,%0
13829    addic %0,%1,%n2\;subfe %0,%0,%0\;andc %0,%3,%0"
13830   [(set_attr "type" "three")
13831    (set_attr "length" "12")])
13832
13833 (define_insn ""
13834   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13835         (compare:CC
13836          (and:SI (neg:SI
13837                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13838                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13839                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13840          (const_int 0)))
13841    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13842   "TARGET_32BIT"
13843   "@
13844    subfc %4,%2,%1\;subfe %4,%4,%4\;andc. %4,%3,%4
13845    addic %4,%1,%n2\;subfe %4,%4,%4\;andc. %4,%3,%4
13846    #
13847    #"
13848   [(set_attr "type" "compare")
13849    (set_attr "length" "12,12,16,16")])
13850
13851 (define_split
13852   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13853         (compare:CC
13854          (and:SI (neg:SI
13855                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13856                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13857                  (match_operand:SI 3 "gpc_reg_operand" ""))
13858          (const_int 0)))
13859    (clobber (match_scratch:SI 4 ""))]
13860   "TARGET_32BIT && reload_completed"
13861   [(set (match_dup 4)
13862         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
13863                 (match_dup 3)))
13864    (set (match_dup 0)
13865         (compare:CC (match_dup 4)
13866                     (const_int 0)))]
13867   "")
13868
13869 (define_insn ""
13870   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13871         (compare:CC
13872          (and:SI (neg:SI
13873                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13874                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13875                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13876          (const_int 0)))
13877    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13878         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13879   "TARGET_32BIT"
13880   "@
13881    subfc %0,%2,%1\;subfe %0,%0,%0\;andc. %0,%3,%0
13882    addic %0,%1,%n2\;subfe %0,%0,%0\;andc. %0,%3,%0
13883    #
13884    #"
13885   [(set_attr "type" "compare")
13886    (set_attr "length" "12,12,16,16")])
13887
13888 (define_split
13889   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13890         (compare:CC
13891          (and:SI (neg:SI
13892                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13893                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13894                  (match_operand:SI 3 "gpc_reg_operand" ""))
13895          (const_int 0)))
13896    (set (match_operand:SI 0 "gpc_reg_operand" "")
13897         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13898   "TARGET_32BIT && reload_completed"
13899   [(set (match_dup 0)
13900         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13901    (set (match_dup 4)
13902         (compare:CC (match_dup 0)
13903                     (const_int 0)))]
13904   "")
13905
13906 (define_insn "*plus_gt0<mode>"
13907   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13908         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
13909                       (const_int 0))
13910                  (match_operand:P 2 "gpc_reg_operand" "r")))]
13911   ""
13912   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13913   [(set_attr "type" "three")
13914    (set_attr "length" "12")])
13915
13916 (define_insn ""
13917   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13918         (compare:CC
13919          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13920                          (const_int 0))
13921                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13922          (const_int 0)))
13923    (clobber (match_scratch:SI 3 "=&r,&r"))]
13924   "TARGET_32BIT"
13925   "@
13926    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13927    #"
13928   [(set_attr "type" "compare")
13929    (set_attr "length" "12,16")])
13930
13931 (define_split
13932   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13933         (compare:CC
13934          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13935                          (const_int 0))
13936                   (match_operand:SI 2 "gpc_reg_operand" ""))
13937          (const_int 0)))
13938    (clobber (match_scratch:SI 3 ""))]
13939   "TARGET_32BIT && reload_completed"
13940   [(set (match_dup 3)
13941         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13942                   (match_dup 2)))
13943    (set (match_dup 0)
13944         (compare:CC (match_dup 3)
13945                     (const_int 0)))]
13946   "")
13947
13948 (define_insn ""
13949   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13950         (compare:CC
13951          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13952                          (const_int 0))
13953                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13954          (const_int 0)))
13955    (clobber (match_scratch:DI 3 "=&r,&r"))]
13956   "TARGET_64BIT"
13957   "@
13958    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13959    #"
13960   [(set_attr "type" "compare")
13961    (set_attr "length" "12,16")])
13962
13963 (define_split
13964   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13965         (compare:CC
13966          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13967                          (const_int 0))
13968                   (match_operand:DI 2 "gpc_reg_operand" ""))
13969          (const_int 0)))
13970    (clobber (match_scratch:DI 3 ""))]
13971   "TARGET_64BIT && reload_completed"
13972   [(set (match_dup 3)
13973         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13974                  (match_dup 2)))
13975    (set (match_dup 0)
13976         (compare:CC (match_dup 3)
13977                     (const_int 0)))]
13978   "")
13979
13980 (define_insn ""
13981   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13982         (compare:CC
13983          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13984                          (const_int 0))
13985                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13986          (const_int 0)))
13987    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13988         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13989   "TARGET_32BIT"
13990   "@
13991    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13992    #"
13993   [(set_attr "type" "compare")
13994    (set_attr "length" "12,16")])
13995
13996 (define_split
13997   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13998         (compare:CC
13999          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14000                          (const_int 0))
14001                   (match_operand:SI 2 "gpc_reg_operand" ""))
14002          (const_int 0)))
14003    (set (match_operand:SI 0 "gpc_reg_operand" "")
14004         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14005   "TARGET_32BIT && reload_completed"
14006   [(set (match_dup 0)
14007         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
14008    (set (match_dup 3)
14009         (compare:CC (match_dup 0)
14010                     (const_int 0)))]
14011   "")
14012
14013 (define_insn ""
14014   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14015         (compare:CC
14016          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14017                          (const_int 0))
14018                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14019          (const_int 0)))
14020    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
14021         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14022   "TARGET_64BIT"
14023   "@
14024    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14025    #"
14026   [(set_attr "type" "compare")
14027    (set_attr "length" "12,16")])
14028
14029 (define_split
14030   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14031         (compare:CC
14032          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14033                          (const_int 0))
14034                   (match_operand:DI 2 "gpc_reg_operand" ""))
14035          (const_int 0)))
14036    (set (match_operand:DI 0 "gpc_reg_operand" "")
14037         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14038   "TARGET_64BIT && reload_completed"
14039   [(set (match_dup 0)
14040         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
14041    (set (match_dup 3)
14042         (compare:CC (match_dup 0)
14043                     (const_int 0)))]
14044   "")
14045
14046 (define_insn_and_split "*gtu<mode>"
14047   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14048         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14049                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14050   ""
14051   "#"
14052   ""
14053   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14054    (set (match_dup 0) (neg:P (match_dup 0)))]
14055   "")
14056
14057 (define_insn_and_split "*gtu<mode>_compare"
14058   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14059         (compare:CC
14060          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14061                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14062          (const_int 0)))
14063    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14064         (gtu:P (match_dup 1) (match_dup 2)))]
14065   ""
14066   "#"
14067   ""
14068   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14069    (parallel [(set (match_dup 3)
14070                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14071               (set (match_dup 0) (neg:P (match_dup 0)))])]
14072   "")
14073
14074 (define_insn_and_split "*plus_gtu<mode>"
14075   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14076         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14077                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14078                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
14079   ""
14080   "#"
14081   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14082   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14083    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14084   "")
14085
14086 (define_insn_and_split "*plus_gtu<mode>_compare"
14087   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14088         (compare:CC
14089          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14090                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
14091                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14092          (const_int 0)))
14093    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14094         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14095   ""
14096   "#"
14097   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14098   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14099    (parallel [(set (match_dup 4)
14100                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14101                                (const_int 0)))
14102               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14103   "")
14104
14105 (define_insn "*neg_gtu<mode>"
14106   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14107         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14108                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14109   ""
14110   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
14111   [(set_attr "type" "two")
14112    (set_attr "length" "8")])
14113
14114 \f
14115 ;; Define both directions of branch and return.  If we need a reload
14116 ;; register, we'd rather use CR0 since it is much easier to copy a
14117 ;; register CC value to there.
14118
14119 (define_insn ""
14120   [(set (pc)
14121         (if_then_else (match_operator 1 "branch_comparison_operator"
14122                                       [(match_operand 2
14123                                                       "cc_reg_operand" "y")
14124                                        (const_int 0)])
14125                       (label_ref (match_operand 0 "" ""))
14126                       (pc)))]
14127   ""
14128   "*
14129 {
14130   return output_cbranch (operands[1], \"%l0\", 0, insn);
14131 }"
14132   [(set_attr "type" "branch")])
14133
14134 (define_insn ""
14135   [(set (pc)
14136         (if_then_else (match_operator 0 "branch_comparison_operator"
14137                                       [(match_operand 1
14138                                                       "cc_reg_operand" "y")
14139                                        (const_int 0)])
14140                       (any_return)
14141                       (pc)))]
14142   "<return_pred>"
14143   "*
14144 {
14145   return output_cbranch (operands[0], NULL, 0, insn);
14146 }"
14147   [(set_attr "type" "jmpreg")
14148    (set_attr "length" "4")])
14149
14150 (define_insn ""
14151   [(set (pc)
14152         (if_then_else (match_operator 1 "branch_comparison_operator"
14153                                       [(match_operand 2
14154                                                       "cc_reg_operand" "y")
14155                                        (const_int 0)])
14156                       (pc)
14157                       (label_ref (match_operand 0 "" ""))))]
14158   ""
14159   "*
14160 {
14161   return output_cbranch (operands[1], \"%l0\", 1, insn);
14162 }"
14163   [(set_attr "type" "branch")])
14164
14165 (define_insn ""
14166   [(set (pc)
14167         (if_then_else (match_operator 0 "branch_comparison_operator"
14168                                       [(match_operand 1
14169                                                       "cc_reg_operand" "y")
14170                                        (const_int 0)])
14171                       (pc)
14172                       (any_return)))]
14173   "<return_pred>"
14174   "*
14175 {
14176   return output_cbranch (operands[0], NULL, 1, insn);
14177 }"
14178   [(set_attr "type" "jmpreg")
14179    (set_attr "length" "4")])
14180
14181 ;; Logic on condition register values.
14182
14183 ; This pattern matches things like
14184 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
14185 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
14186 ;                                  (const_int 1)))
14187 ; which are generated by the branch logic.
14188 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
14189
14190 (define_insn "*cceq_ior_compare"
14191   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14192         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
14193                         [(match_operator:SI 2
14194                                       "branch_positive_comparison_operator"
14195                                       [(match_operand 3
14196                                                       "cc_reg_operand" "y,y")
14197                                        (const_int 0)])
14198                          (match_operator:SI 4
14199                                       "branch_positive_comparison_operator"
14200                                       [(match_operand 5
14201                                                       "cc_reg_operand" "0,y")
14202                                        (const_int 0)])])
14203                       (const_int 1)))]
14204   ""
14205   "cr%q1 %E0,%j2,%j4"
14206   [(set_attr "type" "cr_logical,delayed_cr")])
14207
14208 ; Why is the constant -1 here, but 1 in the previous pattern?
14209 ; Because ~1 has all but the low bit set.
14210 (define_insn ""
14211   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14212         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
14213                         [(not:SI (match_operator:SI 2
14214                                       "branch_positive_comparison_operator"
14215                                       [(match_operand 3
14216                                                       "cc_reg_operand" "y,y")
14217                                        (const_int 0)]))
14218                          (match_operator:SI 4
14219                                 "branch_positive_comparison_operator"
14220                                 [(match_operand 5
14221                                                 "cc_reg_operand" "0,y")
14222                                  (const_int 0)])])
14223                       (const_int -1)))]
14224   ""
14225   "cr%q1 %E0,%j2,%j4"
14226   [(set_attr "type" "cr_logical,delayed_cr")])
14227
14228 (define_insn "*cceq_rev_compare"
14229   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14230         (compare:CCEQ (match_operator:SI 1
14231                                       "branch_positive_comparison_operator"
14232                                       [(match_operand 2
14233                                                       "cc_reg_operand" "0,y")
14234                                        (const_int 0)])
14235                       (const_int 0)))]
14236   ""
14237   "crnot %E0,%j1"
14238   [(set_attr "type" "cr_logical,delayed_cr")])
14239
14240 ;; If we are comparing the result of two comparisons, this can be done
14241 ;; using creqv or crxor.
14242
14243 (define_insn_and_split ""
14244   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
14245         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
14246                               [(match_operand 2 "cc_reg_operand" "y")
14247                                (const_int 0)])
14248                       (match_operator 3 "branch_comparison_operator"
14249                               [(match_operand 4 "cc_reg_operand" "y")
14250                                (const_int 0)])))]
14251   ""
14252   "#"
14253   ""
14254   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
14255                                     (match_dup 5)))]
14256   "
14257 {
14258   int positive_1, positive_2;
14259
14260   positive_1 = branch_positive_comparison_operator (operands[1],
14261                                                     GET_MODE (operands[1]));
14262   positive_2 = branch_positive_comparison_operator (operands[3],
14263                                                     GET_MODE (operands[3]));
14264
14265   if (! positive_1)
14266     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
14267                                                             GET_CODE (operands[1])),
14268                                   SImode,
14269                                   operands[2], const0_rtx);
14270   else if (GET_MODE (operands[1]) != SImode)
14271     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
14272                                   operands[2], const0_rtx);
14273
14274   if (! positive_2)
14275     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
14276                                                             GET_CODE (operands[3])),
14277                                   SImode,
14278                                   operands[4], const0_rtx);
14279   else if (GET_MODE (operands[3]) != SImode)
14280     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
14281                                   operands[4], const0_rtx);
14282
14283   if (positive_1 == positive_2)
14284     {
14285       operands[1] = gen_rtx_NOT (SImode, operands[1]);
14286       operands[5] = constm1_rtx;
14287     }
14288   else
14289     {
14290       operands[5] = const1_rtx;
14291     }
14292 }")
14293
14294 ;; Unconditional branch and return.
14295
14296 (define_insn "jump"
14297   [(set (pc)
14298         (label_ref (match_operand 0 "" "")))]
14299   ""
14300   "b %l0"
14301   [(set_attr "type" "branch")])
14302
14303 (define_insn "<return_str>return"
14304   [(any_return)]
14305   "<return_pred>"
14306   "blr"
14307   [(set_attr "type" "jmpreg")])
14308
14309 (define_expand "indirect_jump"
14310   [(set (pc) (match_operand 0 "register_operand" ""))])
14311
14312 (define_insn "*indirect_jump<mode>"
14313   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
14314   ""
14315   "@
14316    bctr
14317    blr"
14318   [(set_attr "type" "jmpreg")])
14319
14320 ;; Table jump for switch statements:
14321 (define_expand "tablejump"
14322   [(use (match_operand 0 "" ""))
14323    (use (label_ref (match_operand 1 "" "")))]
14324   ""
14325   "
14326 {
14327   if (TARGET_32BIT)
14328     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
14329   else
14330     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
14331   DONE;
14332 }")
14333
14334 (define_expand "tablejumpsi"
14335   [(set (match_dup 3)
14336         (plus:SI (match_operand:SI 0 "" "")
14337                  (match_dup 2)))
14338    (parallel [(set (pc) (match_dup 3))
14339               (use (label_ref (match_operand 1 "" "")))])]
14340   "TARGET_32BIT"
14341   "
14342 { operands[0] = force_reg (SImode, operands[0]);
14343   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
14344   operands[3] = gen_reg_rtx (SImode);
14345 }")
14346
14347 (define_expand "tablejumpdi"
14348   [(set (match_dup 4)
14349         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
14350    (set (match_dup 3)
14351         (plus:DI (match_dup 4)
14352                  (match_dup 2)))
14353    (parallel [(set (pc) (match_dup 3))
14354               (use (label_ref (match_operand 1 "" "")))])]
14355   "TARGET_64BIT"
14356   "
14357 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
14358   operands[3] = gen_reg_rtx (DImode);
14359   operands[4] = gen_reg_rtx (DImode);
14360 }")
14361
14362 (define_insn "*tablejump<mode>_internal1"
14363   [(set (pc)
14364         (match_operand:P 0 "register_operand" "c,*l"))
14365    (use (label_ref (match_operand 1 "" "")))]
14366   ""
14367   "@
14368    bctr
14369    blr"
14370   [(set_attr "type" "jmpreg")])
14371
14372 (define_insn "nop"
14373   [(const_int 0)]
14374   ""
14375   "nop")
14376
14377 (define_insn "group_ending_nop"
14378   [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
14379   ""
14380   "*
14381 {
14382   if (rs6000_cpu_attr == CPU_POWER6)
14383     return \"ori 1,1,0\";
14384   return \"ori 2,2,0\";
14385 }")
14386 \f
14387 ;; Define the subtract-one-and-jump insns, starting with the template
14388 ;; so loop.c knows what to generate.
14389
14390 (define_expand "doloop_end"
14391   [(use (match_operand 0 "" ""))        ; loop pseudo
14392    (use (match_operand 1 "" ""))]       ; label
14393   ""
14394   "
14395 {
14396   if (TARGET_64BIT)
14397     {
14398       if (GET_MODE (operands[0]) != DImode)
14399         FAIL;
14400       emit_jump_insn (gen_ctrdi (operands[0], operands[1]));
14401     }
14402   else
14403     {
14404       if (GET_MODE (operands[0]) != SImode)
14405         FAIL;
14406       emit_jump_insn (gen_ctrsi (operands[0], operands[1]));
14407     }
14408   DONE;
14409 }")
14410
14411 (define_expand "ctr<mode>"
14412   [(parallel [(set (pc)
14413                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
14414                                      (const_int 1))
14415                                  (label_ref (match_operand 1 "" ""))
14416                                  (pc)))
14417               (set (match_dup 0)
14418                    (plus:P (match_dup 0)
14419                             (const_int -1)))
14420               (clobber (match_scratch:CC 2 ""))
14421               (clobber (match_scratch:P 3 ""))])]
14422   ""
14423   "")
14424
14425 ;; We need to be able to do this for any operand, including MEM, or we
14426 ;; will cause reload to blow up since we don't allow output reloads on
14427 ;; JUMP_INSNs.
14428 ;; For the length attribute to be calculated correctly, the
14429 ;; label MUST be operand 0.
14430
14431 (define_insn "*ctr<mode>_internal1"
14432   [(set (pc)
14433         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14434                           (const_int 1))
14435                       (label_ref (match_operand 0 "" ""))
14436                       (pc)))
14437    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14438         (plus:P (match_dup 1)
14439                  (const_int -1)))
14440    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14441    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14442   ""
14443   "*
14444 {
14445   if (which_alternative != 0)
14446     return \"#\";
14447   else if (get_attr_length (insn) == 4)
14448     return \"bdnz %l0\";
14449   else
14450     return \"bdz $+8\;b %l0\";
14451 }"
14452   [(set_attr "type" "branch")
14453    (set_attr "length" "*,12,16,16")])
14454
14455 (define_insn "*ctr<mode>_internal2"
14456   [(set (pc)
14457         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14458                           (const_int 1))
14459                       (pc)
14460                       (label_ref (match_operand 0 "" ""))))
14461    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14462         (plus:P (match_dup 1)
14463                  (const_int -1)))
14464    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14465    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14466   ""
14467   "*
14468 {
14469   if (which_alternative != 0)
14470     return \"#\";
14471   else if (get_attr_length (insn) == 4)
14472     return \"bdz %l0\";
14473   else
14474     return \"bdnz $+8\;b %l0\";
14475 }"
14476   [(set_attr "type" "branch")
14477    (set_attr "length" "*,12,16,16")])
14478
14479 ;; Similar but use EQ
14480
14481 (define_insn "*ctr<mode>_internal5"
14482   [(set (pc)
14483         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14484                           (const_int 1))
14485                       (label_ref (match_operand 0 "" ""))
14486                       (pc)))
14487    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14488         (plus:P (match_dup 1)
14489                  (const_int -1)))
14490    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14491    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14492   ""
14493   "*
14494 {
14495   if (which_alternative != 0)
14496     return \"#\";
14497   else if (get_attr_length (insn) == 4)
14498     return \"bdz %l0\";
14499   else
14500     return \"bdnz $+8\;b %l0\";
14501 }"
14502   [(set_attr "type" "branch")
14503    (set_attr "length" "*,12,16,16")])
14504
14505 (define_insn "*ctr<mode>_internal6"
14506   [(set (pc)
14507         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14508                           (const_int 1))
14509                       (pc)
14510                       (label_ref (match_operand 0 "" ""))))
14511    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14512         (plus:P (match_dup 1)
14513                  (const_int -1)))
14514    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14515    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14516   ""
14517   "*
14518 {
14519   if (which_alternative != 0)
14520     return \"#\";
14521   else if (get_attr_length (insn) == 4)
14522     return \"bdnz %l0\";
14523   else
14524     return \"bdz $+8\;b %l0\";
14525 }"
14526   [(set_attr "type" "branch")
14527    (set_attr "length" "*,12,16,16")])
14528
14529 ;; Now the splitters if we could not allocate the CTR register
14530
14531 (define_split
14532   [(set (pc)
14533         (if_then_else (match_operator 2 "comparison_operator"
14534                                       [(match_operand:P 1 "gpc_reg_operand" "")
14535                                        (const_int 1)])
14536                       (match_operand 5 "" "")
14537                       (match_operand 6 "" "")))
14538    (set (match_operand:P 0 "gpc_reg_operand" "")
14539         (plus:P (match_dup 1) (const_int -1)))
14540    (clobber (match_scratch:CC 3 ""))
14541    (clobber (match_scratch:P 4 ""))]
14542   "reload_completed"
14543   [(parallel [(set (match_dup 3)
14544                    (compare:CC (plus:P (match_dup 1)
14545                                         (const_int -1))
14546                                (const_int 0)))
14547               (set (match_dup 0)
14548                    (plus:P (match_dup 1)
14549                             (const_int -1)))])
14550    (set (pc) (if_then_else (match_dup 7)
14551                            (match_dup 5)
14552                            (match_dup 6)))]
14553   "
14554 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14555                                 operands[3], const0_rtx); }")
14556
14557 (define_split
14558   [(set (pc)
14559         (if_then_else (match_operator 2 "comparison_operator"
14560                                       [(match_operand:P 1 "gpc_reg_operand" "")
14561                                        (const_int 1)])
14562                       (match_operand 5 "" "")
14563                       (match_operand 6 "" "")))
14564    (set (match_operand:P 0 "nonimmediate_operand" "")
14565         (plus:P (match_dup 1) (const_int -1)))
14566    (clobber (match_scratch:CC 3 ""))
14567    (clobber (match_scratch:P 4 ""))]
14568   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
14569   [(parallel [(set (match_dup 3)
14570                    (compare:CC (plus:P (match_dup 1)
14571                                         (const_int -1))
14572                                (const_int 0)))
14573               (set (match_dup 4)
14574                    (plus:P (match_dup 1)
14575                             (const_int -1)))])
14576    (set (match_dup 0)
14577         (match_dup 4))
14578    (set (pc) (if_then_else (match_dup 7)
14579                            (match_dup 5)
14580                            (match_dup 6)))]
14581   "
14582 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14583                                 operands[3], const0_rtx); }")
14584 \f
14585 (define_insn "trap"
14586   [(trap_if (const_int 1) (const_int 0))]
14587   ""
14588   "trap"
14589   [(set_attr "type" "trap")])
14590
14591 (define_expand "ctrap<mode>4"
14592   [(trap_if (match_operator 0 "ordered_comparison_operator"
14593                             [(match_operand:GPR 1 "register_operand")
14594                              (match_operand:GPR 2 "reg_or_short_operand")])
14595             (match_operand 3 "zero_constant" ""))]
14596   ""
14597   "")
14598
14599 (define_insn ""
14600   [(trap_if (match_operator 0 "ordered_comparison_operator"
14601                             [(match_operand:GPR 1 "register_operand" "r")
14602                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
14603             (const_int 0))]
14604   ""
14605   "t<wd>%V0%I2 %1,%2"
14606   [(set_attr "type" "trap")])
14607 \f
14608 ;; Insns related to generating the function prologue and epilogue.
14609
14610 (define_expand "prologue"
14611   [(use (const_int 0))]
14612   ""
14613 {
14614   rs6000_emit_prologue ();
14615   if (!TARGET_SCHED_PROLOG)
14616     emit_insn (gen_blockage ());
14617   DONE;
14618 })
14619
14620 (define_insn "*movesi_from_cr_one"
14621   [(match_parallel 0 "mfcr_operation"
14622                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14623                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14624                                      (match_operand 3 "immediate_operand" "n")]
14625                           UNSPEC_MOVESI_FROM_CR))])]
14626   "TARGET_MFCRF"
14627   "*
14628 {
14629   int mask = 0;
14630   int i;
14631   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14632   {
14633     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14634     operands[4] = GEN_INT (mask);
14635     output_asm_insn (\"mfcr %1,%4\", operands);
14636   }
14637   return \"\";
14638 }"
14639   [(set_attr "type" "mfcrf")])
14640
14641 (define_insn "movesi_from_cr"
14642   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14643         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
14644                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
14645                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
14646                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
14647                    UNSPEC_MOVESI_FROM_CR))]
14648   ""
14649   "mfcr %0"
14650   [(set_attr "type" "mfcr")])
14651
14652 (define_insn "*crsave"
14653   [(match_parallel 0 "crsave_operation"
14654                    [(set (match_operand:SI 1 "memory_operand" "=m")
14655                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14656   ""
14657   "stw %2,%1"
14658   [(set_attr "type" "store")])
14659
14660 (define_insn "*stmw"
14661   [(match_parallel 0 "stmw_operation"
14662                    [(set (match_operand:SI 1 "memory_operand" "=m")
14663                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14664   "TARGET_MULTIPLE"
14665   "stmw %2,%1"
14666   [(set_attr "type" "store")
14667    (set_attr "update" "yes")
14668    (set_attr "indexed" "yes")])
14669
14670 ; The following comment applies to:
14671 ;     save_gpregs_*
14672 ;     save_fpregs_*
14673 ;     restore_gpregs*
14674 ;     return_and_restore_gpregs*
14675 ;     return_and_restore_fpregs*
14676 ;     return_and_restore_fpregs_aix*
14677 ;
14678 ; The out-of-line save / restore functions expects one input argument.
14679 ; Since those are not standard call_insn's, we must avoid using
14680 ; MATCH_OPERAND for that argument. That way the register rename
14681 ; optimization will not try to rename this register.
14682 ; Each pattern is repeated for each possible register number used in 
14683 ; various ABIs (r11, r1, and for some functions r12)
14684
14685 (define_insn "*save_gpregs_<mode>_r11"
14686   [(match_parallel 0 "any_parallel_operand"
14687                    [(clobber (reg:P 65))
14688                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14689                     (use (reg:P 11))
14690                     (set (match_operand:P 2 "memory_operand" "=m")
14691                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
14692   ""
14693   "bl %1"
14694   [(set_attr "type" "branch")
14695    (set_attr "length" "4")])
14696
14697 (define_insn "*save_gpregs_<mode>_r12"
14698   [(match_parallel 0 "any_parallel_operand"
14699                    [(clobber (reg:P 65))
14700                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14701                     (use (reg:P 12))
14702                     (set (match_operand:P 2 "memory_operand" "=m")
14703                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
14704   ""
14705   "bl %1"
14706   [(set_attr "type" "branch")
14707    (set_attr "length" "4")])
14708
14709 (define_insn "*save_gpregs_<mode>_r1"
14710   [(match_parallel 0 "any_parallel_operand"
14711                    [(clobber (reg:P 65))
14712                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14713                     (use (reg:P 1))
14714                     (set (match_operand:P 2 "memory_operand" "=m")
14715                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
14716   ""
14717   "bl %1"
14718   [(set_attr "type" "branch")
14719    (set_attr "length" "4")])
14720
14721 (define_insn "*save_fpregs_<mode>_r11"
14722   [(match_parallel 0 "any_parallel_operand"
14723                    [(clobber (reg:P 65))
14724                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14725                     (use (reg:P 11))
14726                     (set (match_operand:DF 2 "memory_operand" "=m")
14727                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14728   ""
14729   "bl %1"
14730   [(set_attr "type" "branch")
14731    (set_attr "length" "4")])
14732
14733 (define_insn "*save_fpregs_<mode>_r12"
14734   [(match_parallel 0 "any_parallel_operand"
14735                    [(clobber (reg:P 65))
14736                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14737                     (use (reg:P 12))
14738                     (set (match_operand:DF 2 "memory_operand" "=m")
14739                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14740   ""
14741   "bl %1"
14742   [(set_attr "type" "branch")
14743    (set_attr "length" "4")])
14744
14745 (define_insn "*save_fpregs_<mode>_r1"
14746   [(match_parallel 0 "any_parallel_operand"
14747                    [(clobber (reg:P 65))
14748                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
14749                     (use (reg:P 1))
14750                     (set (match_operand:DF 2 "memory_operand" "=m")
14751                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14752   ""
14753   "bl %1"
14754   [(set_attr "type" "branch")
14755    (set_attr "length" "4")])
14756
14757 ; This is to explain that changes to the stack pointer should
14758 ; not be moved over loads from or stores to stack memory.
14759 (define_insn "stack_tie"
14760   [(match_parallel 0 "tie_operand"
14761                    [(set (mem:BLK (reg 1)) (const_int 0))])]
14762   ""
14763   ""
14764   [(set_attr "length" "0")])
14765
14766 (define_expand "epilogue"
14767   [(use (const_int 0))]
14768   ""
14769 {
14770   if (!TARGET_SCHED_PROLOG)
14771     emit_insn (gen_blockage ());
14772   rs6000_emit_epilogue (FALSE);
14773   DONE;
14774 })
14775
14776 ; On some processors, doing the mtcrf one CC register at a time is
14777 ; faster (like on the 604e).  On others, doing them all at once is
14778 ; faster; for instance, on the 601 and 750.
14779
14780 (define_expand "movsi_to_cr_one"
14781   [(set (match_operand:CC 0 "cc_reg_operand" "")
14782         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
14783                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14784   ""
14785   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14786
14787 (define_insn "*movsi_to_cr"
14788   [(match_parallel 0 "mtcrf_operation"
14789                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14790                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14791                                      (match_operand 3 "immediate_operand" "n")]
14792                                     UNSPEC_MOVESI_TO_CR))])]
14793  ""
14794  "*
14795 {
14796   int mask = 0;
14797   int i;
14798   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14799     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14800   operands[4] = GEN_INT (mask);
14801   return \"mtcrf %4,%2\";
14802 }"
14803   [(set_attr "type" "mtcr")])
14804
14805 (define_insn "*mtcrfsi"
14806   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14807         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14808                     (match_operand 2 "immediate_operand" "n")]
14809                    UNSPEC_MOVESI_TO_CR))]
14810   "GET_CODE (operands[0]) == REG
14811    && CR_REGNO_P (REGNO (operands[0]))
14812    && GET_CODE (operands[2]) == CONST_INT
14813    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14814   "mtcrf %R0,%1"
14815   [(set_attr "type" "mtcr")])
14816
14817 ; The load-multiple instructions have similar properties.
14818 ; Note that "load_multiple" is a name known to the machine-independent
14819 ; code that actually corresponds to the PowerPC load-string.
14820
14821 (define_insn "*lmw"
14822   [(match_parallel 0 "lmw_operation"
14823                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14824                          (match_operand:SI 2 "memory_operand" "m"))])]
14825   "TARGET_MULTIPLE"
14826   "lmw %1,%2"
14827   [(set_attr "type" "load")
14828    (set_attr "update" "yes")
14829    (set_attr "indexed" "yes")
14830    (set_attr "cell_micro" "always")])
14831
14832 (define_insn "*return_internal_<mode>"
14833   [(simple_return)
14834    (use (match_operand:P 0 "register_operand" "lc"))]
14835   ""
14836   "b%T0"
14837   [(set_attr "type" "jmpreg")])
14838
14839 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14840 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14841
14842 ; The following comment applies to:
14843 ;     save_gpregs_*
14844 ;     save_fpregs_*
14845 ;     restore_gpregs*
14846 ;     return_and_restore_gpregs*
14847 ;     return_and_restore_fpregs*
14848 ;     return_and_restore_fpregs_aix*
14849 ;
14850 ; The out-of-line save / restore functions expects one input argument.
14851 ; Since those are not standard call_insn's, we must avoid using
14852 ; MATCH_OPERAND for that argument. That way the register rename
14853 ; optimization will not try to rename this register.
14854 ; Each pattern is repeated for each possible register number used in 
14855 ; various ABIs (r11, r1, and for some functions r12)
14856
14857 (define_insn "*restore_gpregs_<mode>_r11"
14858  [(match_parallel 0 "any_parallel_operand"
14859                   [(clobber (match_operand:P 1 "register_operand" "=l"))
14860                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14861                    (use (reg:P 11))
14862                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14863                         (match_operand:P 4 "memory_operand" "m"))])]
14864  ""
14865  "bl %2"
14866  [(set_attr "type" "branch")
14867   (set_attr "length" "4")])
14868
14869 (define_insn "*restore_gpregs_<mode>_r12"
14870  [(match_parallel 0 "any_parallel_operand"
14871                   [(clobber (match_operand:P 1 "register_operand" "=l"))
14872                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14873                    (use (reg:P 12))
14874                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14875                         (match_operand:P 4 "memory_operand" "m"))])]
14876  ""
14877  "bl %2"
14878  [(set_attr "type" "branch")
14879   (set_attr "length" "4")])
14880
14881 (define_insn "*restore_gpregs_<mode>_r1"
14882  [(match_parallel 0 "any_parallel_operand"
14883                   [(clobber (match_operand:P 1 "register_operand" "=l"))
14884                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14885                    (use (reg:P 1))
14886                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14887                         (match_operand:P 4 "memory_operand" "m"))])]
14888  ""
14889  "bl %2"
14890  [(set_attr "type" "branch")
14891   (set_attr "length" "4")])
14892
14893 (define_insn "*return_and_restore_gpregs_<mode>_r11"
14894  [(match_parallel 0 "any_parallel_operand"
14895                   [(return)
14896                    (clobber (match_operand:P 1 "register_operand" "=l"))
14897                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14898                    (use (reg:P 11))
14899                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14900                         (match_operand:P 4 "memory_operand" "m"))])]
14901  ""
14902  "b %2"
14903  [(set_attr "type" "branch")
14904   (set_attr "length" "4")])
14905
14906 (define_insn "*return_and_restore_gpregs_<mode>_r12"
14907  [(match_parallel 0 "any_parallel_operand"
14908                   [(return)
14909                    (clobber (match_operand:P 1 "register_operand" "=l"))
14910                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14911                    (use (reg:P 12))
14912                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14913                         (match_operand:P 4 "memory_operand" "m"))])]
14914  ""
14915  "b %2"
14916  [(set_attr "type" "branch")
14917   (set_attr "length" "4")])
14918
14919 (define_insn "*return_and_restore_gpregs_<mode>_r1"
14920  [(match_parallel 0 "any_parallel_operand"
14921                   [(return)
14922                    (clobber (match_operand:P 1 "register_operand" "=l"))
14923                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14924                    (use (reg:P 1))
14925                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
14926                         (match_operand:P 4 "memory_operand" "m"))])]
14927  ""
14928  "b %2"
14929  [(set_attr "type" "branch")
14930   (set_attr "length" "4")])
14931
14932 (define_insn "*return_and_restore_fpregs_<mode>_r11"
14933  [(match_parallel 0 "any_parallel_operand"
14934                   [(return)
14935                    (clobber (match_operand:P 1 "register_operand" "=l"))
14936                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14937                    (use (reg:P 11))
14938                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
14939                         (match_operand:DF 4 "memory_operand" "m"))])]
14940  ""
14941  "b %2"
14942  [(set_attr "type" "branch")
14943   (set_attr "length" "4")])
14944
14945 (define_insn "*return_and_restore_fpregs_<mode>_r12"
14946  [(match_parallel 0 "any_parallel_operand"
14947                   [(return)
14948                    (clobber (match_operand:P 1 "register_operand" "=l"))
14949                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14950                    (use (reg:P 12))
14951                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
14952                         (match_operand:DF 4 "memory_operand" "m"))])]
14953  ""
14954  "b %2"
14955  [(set_attr "type" "branch")
14956   (set_attr "length" "4")])
14957
14958 (define_insn "*return_and_restore_fpregs_<mode>_r1"
14959  [(match_parallel 0 "any_parallel_operand"
14960                   [(return)
14961                    (clobber (match_operand:P 1 "register_operand" "=l"))
14962                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14963                    (use (reg:P 1))
14964                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
14965                         (match_operand:DF 4 "memory_operand" "m"))])]
14966  ""
14967  "b %2"
14968  [(set_attr "type" "branch")
14969   (set_attr "length" "4")])
14970
14971 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
14972  [(match_parallel 0 "any_parallel_operand"
14973                   [(return)
14974                    (use (match_operand:P 1 "register_operand" "l"))
14975                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14976                    (use (reg:P 11))
14977                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
14978                         (match_operand:DF 4 "memory_operand" "m"))])]
14979  ""
14980  "b %2"
14981  [(set_attr "type" "branch")
14982   (set_attr "length" "4")])
14983
14984 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
14985  [(match_parallel 0 "any_parallel_operand"
14986                   [(return)
14987                    (use (match_operand:P 1 "register_operand" "l"))
14988                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
14989                    (use (reg:P 1))
14990                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
14991                         (match_operand:DF 4 "memory_operand" "m"))])]
14992  ""
14993  "b %2"
14994  [(set_attr "type" "branch")
14995   (set_attr "length" "4")])
14996
14997 ; This is used in compiling the unwind routines.
14998 (define_expand "eh_return"
14999   [(use (match_operand 0 "general_operand" ""))]
15000   ""
15001   "
15002 {
15003   if (TARGET_32BIT)
15004     emit_insn (gen_eh_set_lr_si (operands[0]));
15005   else
15006     emit_insn (gen_eh_set_lr_di (operands[0]));
15007   DONE;
15008 }")
15009
15010 ; We can't expand this before we know where the link register is stored.
15011 (define_insn "eh_set_lr_<mode>"
15012   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
15013                     UNSPECV_EH_RR)
15014    (clobber (match_scratch:P 1 "=&b"))]
15015   ""
15016   "#")
15017
15018 (define_split
15019   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
15020    (clobber (match_scratch 1 ""))]
15021   "reload_completed"
15022   [(const_int 0)]
15023   "
15024 {
15025   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
15026   DONE;
15027 }")
15028
15029 (define_insn "prefetch"
15030   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
15031              (match_operand:SI 1 "const_int_operand" "n")
15032              (match_operand:SI 2 "const_int_operand" "n"))]
15033   ""
15034   "*
15035 {
15036   if (GET_CODE (operands[0]) == REG)
15037     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
15038   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
15039 }"
15040   [(set_attr "type" "load")])
15041 \f
15042 (define_insn "bpermd_<mode>"
15043   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15044         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
15045                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
15046   "TARGET_POPCNTD"
15047   "bpermd %0,%1,%2"
15048   [(set_attr "type" "popcnt")])
15049
15050 \f
15051 ;; Builtin fma support.  Handle 
15052 ;; Note that the conditions for expansion are in the FMA_F iterator.
15053
15054 (define_expand "fma<mode>4"
15055   [(set (match_operand:FMA_F 0 "register_operand" "")
15056         (fma:FMA_F
15057           (match_operand:FMA_F 1 "register_operand" "")
15058           (match_operand:FMA_F 2 "register_operand" "")
15059           (match_operand:FMA_F 3 "register_operand" "")))]
15060   ""
15061   "")
15062
15063 (define_insn "*fma<mode>4_fpr"
15064   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15065         (fma:SFDF
15066           (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>,<Fv>")
15067           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15068           (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>")))]
15069   "TARGET_<MODE>_FPR"
15070   "@
15071    fmadd<Ftrad> %0,%1,%2,%3
15072    xsmadda<Fvsx> %x0,%x1,%x2
15073    xsmaddm<Fvsx> %x0,%x1,%x3"
15074   [(set_attr "type" "fp")
15075    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15076
15077 ; Altivec only has fma and nfms.
15078 (define_expand "fms<mode>4"
15079   [(set (match_operand:FMA_F 0 "register_operand" "")
15080         (fma:FMA_F
15081           (match_operand:FMA_F 1 "register_operand" "")
15082           (match_operand:FMA_F 2 "register_operand" "")
15083           (neg:FMA_F (match_operand:FMA_F 3 "register_operand" ""))))]
15084   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15085   "")
15086
15087 (define_insn "*fms<mode>4_fpr"
15088   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15089         (fma:SFDF
15090          (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15091          (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15092          (neg:SFDF (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>"))))]
15093   "TARGET_<MODE>_FPR"
15094   "@
15095    fmsub<Ftrad> %0,%1,%2,%3
15096    xsmsuba<Fvsx> %x0,%x1,%x2
15097    xsmsubm<Fvsx> %x0,%x1,%x3"
15098   [(set_attr "type" "fp")
15099    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15100
15101 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
15102 (define_expand "fnma<mode>4"
15103   [(set (match_operand:FMA_F 0 "register_operand" "")
15104         (neg:FMA_F
15105           (fma:FMA_F
15106             (match_operand:FMA_F 1 "register_operand" "")
15107             (match_operand:FMA_F 2 "register_operand" "")
15108             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
15109   "!HONOR_SIGNED_ZEROS (<MODE>mode)"
15110   "")
15111
15112 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
15113 (define_expand "fnms<mode>4"
15114   [(set (match_operand:FMA_F 0 "register_operand" "")
15115         (neg:FMA_F
15116           (fma:FMA_F
15117             (match_operand:FMA_F 1 "register_operand" "")
15118             (match_operand:FMA_F 2 "register_operand" "")
15119             (match_operand:FMA_F 3 "register_operand" ""))))]
15120   "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15121   "")
15122
15123 ; Not an official optab name, but used from builtins.
15124 (define_expand "nfma<mode>4"
15125   [(set (match_operand:FMA_F 0 "register_operand" "")
15126         (neg:FMA_F
15127           (fma:FMA_F
15128             (match_operand:FMA_F 1 "register_operand" "")
15129             (match_operand:FMA_F 2 "register_operand" "")
15130             (match_operand:FMA_F 3 "register_operand" ""))))]
15131   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15132   "")
15133
15134 (define_insn "*nfma<mode>4_fpr"
15135   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15136         (neg:SFDF
15137          (fma:SFDF
15138           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15139           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15140           (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>"))))]
15141   "TARGET_<MODE>_FPR"
15142   "@
15143    fnmadd<Ftrad> %0,%1,%2,%3
15144    xsnmadda<Fvsx> %x0,%x1,%x2
15145    xsnmaddm<Fvsx> %x0,%x1,%x3"
15146   [(set_attr "type" "fp")
15147    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15148
15149 ; Not an official optab name, but used from builtins.
15150 (define_expand "nfms<mode>4"
15151   [(set (match_operand:FMA_F 0 "register_operand" "")
15152         (neg:FMA_F
15153           (fma:FMA_F
15154             (match_operand:FMA_F 1 "register_operand" "")
15155             (match_operand:FMA_F 2 "register_operand" "")
15156             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
15157   ""
15158   "")
15159
15160 (define_insn "*nfmssf4_fpr"
15161   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15162         (neg:SFDF
15163          (fma:SFDF
15164           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15165           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15166           (neg:SFDF
15167            (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>")))))]
15168   "TARGET_<MODE>_FPR"
15169   "@
15170    fnmsub<Ftrad> %0,%1,%2,%3
15171    xsnmsuba<Fvsx> %x0,%x1,%x2
15172    xsnmsubm<Fvsx> %x0,%x1,%x3"
15173   [(set_attr "type" "fp")
15174    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15175
15176 \f
15177 (define_expand "rs6000_get_timebase"
15178   [(use (match_operand:DI 0 "gpc_reg_operand" ""))]
15179   ""
15180 {
15181   if (TARGET_POWERPC64)
15182     emit_insn (gen_rs6000_mftb_di (operands[0]));
15183   else
15184     emit_insn (gen_rs6000_get_timebase_ppc32 (operands[0]));
15185   DONE;
15186 })
15187
15188 (define_insn "rs6000_get_timebase_ppc32"
15189   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
15190         (unspec_volatile:DI [(const_int 0)] UNSPECV_MFTB))
15191    (clobber (match_scratch:SI 1 "=r"))
15192    (clobber (match_scratch:CC 2 "=y"))]
15193   "!TARGET_POWERPC64"
15194 {
15195   if (WORDS_BIG_ENDIAN)
15196     if (TARGET_MFCRF)
15197       {
15198         return "mfspr %0,269\;"
15199                "mfspr %L0,268\;"
15200                "mfspr %1,269\;"
15201                "cmpw %2,%0,%1\;"
15202                "bne- %2,$-16";
15203       }
15204     else
15205       {
15206         return "mftbu %0\;"
15207                "mftb %L0\;"
15208                "mftbu %1\;"
15209                "cmpw %2,%0,%1\;"
15210                "bne- %2,$-16";
15211       }
15212   else
15213     if (TARGET_MFCRF)
15214       {
15215         return "mfspr %L0,269\;"
15216                "mfspr %0,268\;"
15217                "mfspr %1,269\;"
15218                "cmpw %2,%L0,%1\;"
15219                "bne- %2,$-16";
15220       }
15221     else
15222       {
15223         return "mftbu %L0\;"
15224                "mftb %0\;"
15225                "mftbu %1\;"
15226                "cmpw %2,%L0,%1\;"
15227                "bne- %2,$-16";
15228       }
15229 }
15230   [(set_attr "length" "20")])
15231
15232 (define_insn "rs6000_mftb_<mode>"
15233   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15234         (unspec_volatile:P [(const_int 0)] UNSPECV_MFTB))]
15235   ""
15236 {
15237   if (TARGET_MFCRF)
15238     return "mfspr %0,268";
15239   else
15240     return "mftb %0";
15241 })
15242
15243 \f
15244 (define_insn "rs6000_mffs"
15245   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
15246         (unspec_volatile:DF [(const_int 0)] UNSPECV_MFFS))]
15247   "TARGET_HARD_FLOAT && TARGET_FPRS"
15248   "mffs %0")
15249
15250 (define_insn "rs6000_mtfsf"
15251   [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "i")
15252                      (match_operand:DF 1 "gpc_reg_operand" "d")]
15253                     UNSPECV_MTFSF)]
15254   "TARGET_HARD_FLOAT && TARGET_FPRS"
15255   "mtfsf %0,%1")
15256
15257 \f
15258 ;; Power8 fusion support for fusing an addis instruction with a D-form load of
15259 ;; a GPR.  The addis instruction must be adjacent to the load, and use the same
15260 ;; register that is being loaded.  The fused ops must be physically adjacent.
15261
15262 ;; We use define_peephole for the actual addis/load, and the register used to
15263 ;; hold the addis value must be the same as the register being loaded.  We use
15264 ;; define_peephole2 to change the register used for addis to be the register
15265 ;; being loaded, since we can look at whether it is dead after the load insn.
15266
15267 (define_peephole
15268   [(set (match_operand:P 0 "base_reg_operand" "")
15269         (match_operand:P 1 "fusion_gpr_addis" ""))
15270    (set (match_operand:INT1 2 "base_reg_operand" "")
15271         (match_operand:INT1 3 "fusion_gpr_mem_load" ""))]
15272   "TARGET_P8_FUSION && fusion_gpr_load_p (operands, false)"
15273 {
15274   return emit_fusion_gpr_load (operands);
15275 }
15276   [(set_attr "type" "load")
15277    (set_attr "length" "8")])
15278
15279 (define_peephole2
15280   [(set (match_operand:P 0 "base_reg_operand" "")
15281         (match_operand:P 1 "fusion_gpr_addis" ""))
15282    (set (match_operand:INT1 2 "base_reg_operand" "")
15283         (match_operand:INT1 3 "fusion_gpr_mem_load" ""))]
15284   "TARGET_P8_FUSION
15285    && (REGNO (operands[0]) != REGNO (operands[2])
15286        || GET_CODE (operands[3]) == SIGN_EXTEND)
15287    && fusion_gpr_load_p (operands, true)"
15288   [(const_int 0)]
15289 {
15290   expand_fusion_gpr_load (operands);
15291   DONE;
15292 })
15293
15294 \f
15295 ;; Miscellaneous ISA 2.06 (power7) instructions
15296 (define_insn "addg6s"
15297   [(set (match_operand:SI 0 "register_operand" "=r")
15298         (unspec:SI [(match_operand:SI 1 "register_operand" "r")
15299                     (match_operand:SI 2 "register_operand" "r")]
15300                    UNSPEC_ADDG6S))]
15301   "TARGET_POPCNTD"
15302   "addg6s %0,%1,%2"
15303   [(set_attr "type" "integer")
15304    (set_attr "length" "4")])
15305
15306 (define_insn "cdtbcd"
15307   [(set (match_operand:SI 0 "register_operand" "=r")
15308         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
15309                    UNSPEC_CDTBCD))]
15310   "TARGET_POPCNTD"
15311   "cdtbcd %0,%1"
15312   [(set_attr "type" "integer")
15313    (set_attr "length" "4")])
15314
15315 (define_insn "cbcdtd"
15316   [(set (match_operand:SI 0 "register_operand" "=r")
15317         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
15318                    UNSPEC_CBCDTD))]
15319   "TARGET_POPCNTD"
15320   "cbcdtd %0,%1"
15321   [(set_attr "type" "integer")
15322    (set_attr "length" "4")])
15323
15324 (define_int_iterator UNSPEC_DIV_EXTEND [UNSPEC_DIVE
15325                                         UNSPEC_DIVEO
15326                                         UNSPEC_DIVEU
15327                                         UNSPEC_DIVEUO])
15328
15329 (define_int_attr div_extend [(UNSPEC_DIVE       "e")
15330                              (UNSPEC_DIVEO      "eo")
15331                              (UNSPEC_DIVEU      "eu")
15332                              (UNSPEC_DIVEUO     "euo")])
15333
15334 (define_insn "div<div_extend>_<mode>"
15335   [(set (match_operand:GPR 0 "register_operand" "=r")
15336         (unspec:GPR [(match_operand:GPR 1 "register_operand" "r")
15337                      (match_operand:GPR 2 "register_operand" "r")]
15338                     UNSPEC_DIV_EXTEND))]
15339   "TARGET_POPCNTD"
15340   "div<wd><div_extend> %0,%1,%2"
15341   [(set_attr "type" "div")
15342    (set_attr "size" "<bits>")])
15343
15344 \f
15345 ;; Pack/unpack 128-bit floating point types that take 2 scalar registers
15346
15347 ; Type of the 64-bit part when packing/unpacking 128-bit floating point types
15348 (define_mode_attr FP128_64 [(TF "DF") (TD "DI")])
15349
15350 (define_expand "unpack<mode>"
15351   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "")
15352         (unspec:<FP128_64>
15353          [(match_operand:FMOVE128 1 "register_operand" "")
15354           (match_operand:QI 2 "const_0_to_1_operand" "")]
15355          UNSPEC_UNPACK_128BIT))]
15356   ""
15357   "")
15358
15359 (define_insn_and_split "unpack<mode>_dm"
15360   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "=d,m,d,r,m")
15361         (unspec:<FP128_64>
15362          [(match_operand:FMOVE128 1 "register_operand" "d,d,r,d,r")
15363           (match_operand:QI 2 "const_0_to_1_operand" "i,i,i,i,i")]
15364          UNSPEC_UNPACK_128BIT))]
15365   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
15366   "#"
15367   "&& reload_completed"
15368   [(set (match_dup 0) (match_dup 3))]
15369 {
15370   unsigned fp_regno = REGNO (operands[1]) + UINTVAL (operands[2]);
15371
15372   if (REG_P (operands[0]) && REGNO (operands[0]) == fp_regno)
15373     {
15374       emit_note (NOTE_INSN_DELETED);
15375       DONE;
15376     }
15377
15378   operands[3] = gen_rtx_REG (<FP128_64>mode, fp_regno);
15379 }
15380   [(set_attr "type" "fp,fpstore,mffgpr,mftgpr,store")
15381    (set_attr "length" "4")])
15382
15383 (define_insn_and_split "unpack<mode>_nodm"
15384   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "=d,m")
15385         (unspec:<FP128_64>
15386          [(match_operand:FMOVE128 1 "register_operand" "d,d")
15387           (match_operand:QI 2 "const_0_to_1_operand" "i,i")]
15388          UNSPEC_UNPACK_128BIT))]
15389   "!TARGET_POWERPC64 || !TARGET_DIRECT_MOVE"
15390   "#"
15391   "&& reload_completed"
15392   [(set (match_dup 0) (match_dup 3))]
15393 {
15394   unsigned fp_regno = REGNO (operands[1]) + UINTVAL (operands[2]);
15395
15396   if (REG_P (operands[0]) && REGNO (operands[0]) == fp_regno)
15397     {
15398       emit_note (NOTE_INSN_DELETED);
15399       DONE;
15400     }
15401
15402   operands[3] = gen_rtx_REG (<FP128_64>mode, fp_regno);
15403 }
15404   [(set_attr "type" "fp,fpstore")
15405    (set_attr "length" "4")])
15406
15407 (define_insn_and_split "pack<mode>"
15408   [(set (match_operand:FMOVE128 0 "register_operand" "=d,&d")
15409         (unspec:FMOVE128
15410          [(match_operand:<FP128_64> 1 "register_operand" "0,d")
15411           (match_operand:<FP128_64> 2 "register_operand" "d,d")]
15412          UNSPEC_PACK_128BIT))]
15413   ""
15414   "@
15415    fmr %L0,%2
15416    #"
15417   "&& reload_completed && REGNO (operands[0]) != REGNO (operands[1])"
15418   [(set (match_dup 3) (match_dup 1))
15419    (set (match_dup 4) (match_dup 2))]
15420 {
15421   unsigned dest_hi = REGNO (operands[0]);
15422   unsigned dest_lo = dest_hi + 1;
15423
15424   gcc_assert (!IN_RANGE (REGNO (operands[1]), dest_hi, dest_lo));
15425   gcc_assert (!IN_RANGE (REGNO (operands[2]), dest_hi, dest_lo));
15426
15427   operands[3] = gen_rtx_REG (<FP128_64>mode, dest_hi);
15428   operands[4] = gen_rtx_REG (<FP128_64>mode, dest_lo);
15429 }
15430   [(set_attr "type" "fp,fp")
15431    (set_attr "length" "4,8")])
15432
15433 (define_insn "unpackv1ti"
15434   [(set (match_operand:DI 0 "register_operand" "=d,d")
15435         (unspec:DI [(match_operand:V1TI 1 "register_operand" "0,wa")
15436                     (match_operand:QI 2 "const_0_to_1_operand" "O,i")]
15437          UNSPEC_UNPACK_128BIT))]
15438   "TARGET_VSX"
15439 {
15440   if (REGNO (operands[0]) == REGNO (operands[1]) && INTVAL (operands[2]) == 0)
15441     return ASM_COMMENT_START " xxpermdi to same register";
15442
15443   operands[3] = GEN_INT (INTVAL (operands[2]) == 0 ? 0 : 3);
15444   return "xxpermdi %x0,%x1,%x1,%3";
15445 }
15446   [(set_attr "type" "vecperm")
15447    (set_attr "length" "4")])
15448
15449 (define_insn "packv1ti"
15450   [(set (match_operand:V1TI 0 "register_operand" "=wa")
15451         (unspec:V1TI
15452          [(match_operand:DI 1 "register_operand" "d")
15453           (match_operand:DI 2 "register_operand" "d")]
15454          UNSPEC_PACK_128BIT))]
15455   "TARGET_VSX"
15456   "xxpermdi %x0,%x1,%x2,0"
15457   [(set_attr "type" "vecperm")
15458    (set_attr "length" "4")])
15459
15460 \f
15461
15462 (include "sync.md")
15463 (include "vector.md")
15464 (include "vsx.md")
15465 (include "altivec.md")
15466 (include "spe.md")
15467 (include "dfp.md")
15468 (include "paired.md")
15469 (include "crypto.md")
15470 (include "htm.md")